summaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
authorMarkus Metzger <markut.t.metzger@intel.com>2008-12-11 13:53:26 +0100
committerIngo Molnar <mingo@elte.hu>2008-12-12 08:08:14 +0100
commita93751cab71d63126687551823ed3e70cd85854a (patch)
tree665e9bf274c457edd672ad44320fad962e6c16f5 /kernel/trace
parentc2724775ce57c98b8af9694857b941dc61056516 (diff)
downloadop-kernel-dev-a93751cab71d63126687551823ed3e70cd85854a.zip
op-kernel-dev-a93751cab71d63126687551823ed3e70cd85854a.tar.gz
x86, bts, ftrace: adapt the hw-branch-tracer to the ds.c interface
Impact: restructure code, cleanup Remove BTS bits from the hw-branch-tracer (renamed from bts-tracer) and use the ds interface. Signed-off-by: Markus Metzger <markut.t.metzger@intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/Kconfig4
-rw-r--r--kernel/trace/Makefile2
-rw-r--r--kernel/trace/trace.c2
-rw-r--r--kernel/trace/trace.h14
-rw-r--r--kernel/trace/trace_hw_branches.c (renamed from kernel/trace/trace_bts.c)163
5 files changed, 56 insertions, 129 deletions
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index bde6f03..d8bae6f 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -251,9 +251,9 @@ config STACK_TRACER
Say N if unsure.
-config BTS_TRACER
+config HW_BRANCH_TRACER
depends on HAVE_HW_BRANCH_TRACER
- bool "Trace branches"
+ bool "Trace hw branches"
select TRACING
help
This tracer records all branches on the system in a circular
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index 62dc561..349d5a9 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -31,7 +31,7 @@ obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
obj-$(CONFIG_BOOT_TRACER) += trace_boot.o
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o
obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o
-obj-$(CONFIG_BTS_TRACER) += trace_bts.o
+obj-$(CONFIG_HW_BRANCH_TRACER) += trace_hw_branches.o
obj-$(CONFIG_POWER_TRACER) += trace_power.o
libftrace-y := ftrace.o
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8ebe007..639344a 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2425,7 +2425,7 @@ __tracing_open(struct inode *inode, struct file *file, int *ret)
/* Notify the tracer early; before we stop tracing. */
if (iter->trace && iter->trace->open)
- iter->trace->open(iter);
+ iter->trace->open(iter);
/* Annotate start of buffers if we had overruns */
if (ring_buffer_overruns(iter->tr->buffer))
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 5ac6970..f07c246 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -28,7 +28,7 @@ enum trace_type {
TRACE_GRAPH_RET,
TRACE_GRAPH_ENT,
TRACE_USER_STACK,
- TRACE_BTS,
+ TRACE_HW_BRANCHES,
TRACE_POWER,
__TRACE_LAST_TYPE
@@ -159,10 +159,10 @@ struct trace_branch {
char correct;
};
-struct bts_entry {
+struct hw_branch_entry {
struct trace_entry ent;
- unsigned long from;
- unsigned long to;
+ u64 from;
+ u64 to;
};
struct trace_power {
@@ -278,7 +278,7 @@ extern void __ftrace_bad_type(void);
TRACE_GRAPH_ENT); \
IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
TRACE_GRAPH_RET); \
- IF_ASSIGN(var, ent, struct bts_entry, TRACE_BTS);\
+ IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
__ftrace_bad_type(); \
} while (0)
@@ -414,9 +414,7 @@ void trace_function(struct trace_array *tr,
void trace_graph_return(struct ftrace_graph_ret *trace);
int trace_graph_entry(struct ftrace_graph_ent *trace);
-void trace_bts(struct trace_array *tr,
- unsigned long from,
- unsigned long to);
+void trace_hw_branch(struct trace_array *tr, u64 from, u64 to);
void tracing_start_cmdline_record(void);
void tracing_stop_cmdline_record(void);
diff --git a/kernel/trace/trace_bts.c b/kernel/trace/trace_hw_branches.c
index 23b76e4..ee29e01 100644
--- a/kernel/trace/trace_bts.c
+++ b/kernel/trace/trace_hw_branches.c
@@ -1,5 +1,5 @@
/*
- * BTS tracer
+ * h/w branch tracer for x86 based on bts
*
* Copyright (C) 2008 Markus Metzger <markus.t.metzger@gmail.com>
*
@@ -25,68 +25,6 @@ static DEFINE_PER_CPU(unsigned char[SIZEOF_BTS], buffer);
#define this_buffer per_cpu(buffer, smp_processor_id())
-/*
- * Information to interpret a BTS record.
- * This will go into an in-kernel BTS interface.
- */
-static unsigned char sizeof_field;
-static unsigned long debugctl_mask;
-
-#define sizeof_bts (3 * sizeof_field)
-
-static void bts_trace_cpuinit(struct cpuinfo_x86 *c)
-{
- switch (c->x86) {
- case 0x6:
- switch (c->x86_model) {
- case 0x0 ... 0xC:
- break;
- case 0xD:
- case 0xE: /* Pentium M */
- sizeof_field = sizeof(long);
- debugctl_mask = (1<<6)|(1<<7);
- break;
- default:
- sizeof_field = 8;
- debugctl_mask = (1<<6)|(1<<7);
- break;
- }
- break;
- case 0xF:
- switch (c->x86_model) {
- case 0x0:
- case 0x1:
- case 0x2: /* Netburst */
- sizeof_field = sizeof(long);
- debugctl_mask = (1<<2)|(1<<3);
- break;
- default:
- /* sorry, don't know about them */
- break;
- }
- break;
- default:
- /* sorry, don't know about them */
- break;
- }
-}
-
-static inline void bts_enable(void)
-{
- unsigned long debugctl;
-
- rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
- wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl | debugctl_mask);
-}
-
-static inline void bts_disable(void)
-{
- unsigned long debugctl;
-
- rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
- wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl & ~debugctl_mask);
-}
-
static void bts_trace_reset(struct trace_array *tr)
{
int cpu;
@@ -99,15 +37,17 @@ static void bts_trace_reset(struct trace_array *tr)
static void bts_trace_start_cpu(void *arg)
{
+ if (this_tracer)
+ ds_release_bts(this_tracer);
+
this_tracer =
ds_request_bts(/* task = */ NULL, this_buffer, SIZEOF_BTS,
- /* ovfl = */ NULL, /* th = */ (size_t)-1);
+ /* ovfl = */ NULL, /* th = */ (size_t)-1,
+ BTS_KERNEL);
if (IS_ERR(this_tracer)) {
this_tracer = NULL;
return;
}
-
- bts_enable();
}
static void bts_trace_start(struct trace_array *tr)
@@ -123,8 +63,6 @@ static void bts_trace_start(struct trace_array *tr)
static void bts_trace_stop_cpu(void *arg)
{
if (this_tracer) {
- bts_disable();
-
ds_release_bts(this_tracer);
this_tracer = NULL;
}
@@ -140,7 +78,6 @@ static void bts_trace_stop(struct trace_array *tr)
static int bts_trace_init(struct trace_array *tr)
{
- bts_trace_cpuinit(&boot_cpu_data);
bts_trace_reset(tr);
bts_trace_start(tr);
@@ -149,47 +86,37 @@ static int bts_trace_init(struct trace_array *tr)
static void bts_trace_print_header(struct seq_file *m)
{
-#ifdef __i386__
- seq_puts(m, "# CPU# FROM TO FUNCTION\n");
- seq_puts(m, "# | | | |\n");
-#else
seq_puts(m,
"# CPU# FROM TO FUNCTION\n");
seq_puts(m,
"# | | | |\n");
-#endif
}
static enum print_line_t bts_trace_print_line(struct trace_iterator *iter)
{
struct trace_entry *entry = iter->ent;
struct trace_seq *seq = &iter->seq;
- struct bts_entry *it;
+ struct hw_branch_entry *it;
trace_assign_type(it, entry);
- if (entry->type == TRACE_BTS) {
- int ret;
-#ifdef CONFIG_KALLSYMS
- char function[KSYM_SYMBOL_LEN];
- sprint_symbol(function, it->from);
-#else
- char *function = "<unknown>";
-#endif
-
- ret = trace_seq_printf(seq, "%4d 0x%lx -> 0x%lx [%s]\n",
- entry->cpu, it->from, it->to, function);
- if (!ret)
- return TRACE_TYPE_PARTIAL_LINE;;
- return TRACE_TYPE_HANDLED;
+ if (entry->type == TRACE_HW_BRANCHES) {
+ if (trace_seq_printf(seq, "%4d ", entry->cpu) &&
+ trace_seq_printf(seq, "0x%016llx -> 0x%016llx ",
+ it->from, it->to) &&
+ (!it->from ||
+ seq_print_ip_sym(seq, it->from, /* sym_flags = */ 0)) &&
+ trace_seq_printf(seq, "\n"))
+ return TRACE_TYPE_HANDLED;
+ return TRACE_TYPE_PARTIAL_LINE;;
}
return TRACE_TYPE_UNHANDLED;
}
-void trace_bts(struct trace_array *tr, unsigned long from, unsigned long to)
+void trace_hw_branch(struct trace_array *tr, u64 from, u64 to)
{
struct ring_buffer_event *event;
- struct bts_entry *entry;
+ struct hw_branch_entry *entry;
unsigned long irq;
event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry), &irq);
@@ -197,56 +124,58 @@ void trace_bts(struct trace_array *tr, unsigned long from, unsigned long to)
return;
entry = ring_buffer_event_data(event);
tracing_generic_entry_update(&entry->ent, 0, from);
- entry->ent.type = TRACE_BTS;
+ entry->ent.type = TRACE_HW_BRANCHES;
entry->ent.cpu = smp_processor_id();
entry->from = from;
entry->to = to;
ring_buffer_unlock_commit(tr->buffer, event, irq);
}
-static void trace_bts_at(struct trace_array *tr, size_t index)
+static void trace_bts_at(struct trace_array *tr,
+ const struct bts_trace *trace, void *at)
{
- const void *raw = NULL;
- unsigned long from, to;
- int err;
+ struct bts_struct bts;
+ int err = 0;
- err = ds_access_bts(this_tracer, index, &raw);
- if (err < 0)
+ WARN_ON_ONCE(!trace->read);
+ if (!trace->read)
return;
- from = *(const unsigned long *)raw;
- to = *(const unsigned long *)((const char *)raw + sizeof_field);
+ err = trace->read(this_tracer, at, &bts);
+ if (err < 0)
+ return;
- trace_bts(tr, from, to);
+ switch (bts.qualifier) {
+ case BTS_BRANCH:
+ trace_hw_branch(tr, bts.variant.lbr.from, bts.variant.lbr.to);
+ break;
+ }
}
static void trace_bts_cpu(void *arg)
{
struct trace_array *tr = (struct trace_array *) arg;
- size_t index = 0, end = 0, i;
- int err;
+ const struct bts_trace *trace;
+ unsigned char *at;
if (!this_tracer)
return;
- bts_disable();
-
- err = ds_get_bts_index(this_tracer, &index);
- if (err < 0)
- goto out;
-
- err = ds_get_bts_end(this_tracer, &end);
- if (err < 0)
+ ds_suspend_bts(this_tracer);
+ trace = ds_read_bts(this_tracer);
+ if (!trace)
goto out;
- for (i = index; i < end; i++)
- trace_bts_at(tr, i);
+ for (at = trace->ds.top; (void *)at < trace->ds.end;
+ at += trace->ds.size)
+ trace_bts_at(tr, trace, at);
- for (i = 0; i < index; i++)
- trace_bts_at(tr, i);
+ for (at = trace->ds.begin; (void *)at < trace->ds.top;
+ at += trace->ds.size)
+ trace_bts_at(tr, trace, at);
out:
- bts_enable();
+ ds_resume_bts(this_tracer);
}
static void trace_bts_prepare(struct trace_iterator *iter)
@@ -259,7 +188,7 @@ static void trace_bts_prepare(struct trace_iterator *iter)
struct tracer bts_tracer __read_mostly =
{
- .name = "bts",
+ .name = "hw-branch-tracer",
.init = bts_trace_init,
.reset = bts_trace_stop,
.print_header = bts_trace_print_header,
OpenPOWER on IntegriCloud