x86, ftrace, hw-branch-tracer: dump on oops
Subsystems (4)
PATCH 3/5 x86, ftrace, hw-branch-tracer: dump on oops
Dump the branch trace on an oops (based on ftrace_dump_on_oops).
---
arch/x86/kernel/dumpstack.c +6 -0
@@ -14,6 +14,7 @@#include <linux/bug.h> #include <linux/nmi.h> #include <linux/sysfs.h> +#include <linux/ftrace.h> #include <asm/stacktrace.h>
@@ -195,6 +196,11 @@int cpu;unsigned long flags; +/* notify the hw-branch tracer so it may disable tracing and +add the last trace to the trace buffer - +the earlier this happens, the more useful the trace. */ +trace_hw_branch_oops (); +oops_enter ();/* racy, but better than risking deadlock. */
kernel/trace/trace.h +0 -1
@@ -415,7 +415,6 @@void trace_graph_return (struct ftrace_graph_ret *trace);int trace_graph_entry (struct ftrace_graph_ent *trace); -void trace_hw_branch (struct trace_array *tr,u64 from,u64 to);void tracing_start_cmdline_record (void );void tracing_stop_cmdline_record (void );
kernel/trace/trace_hw_branches.c +24 -7
@@ -39,6 +39,7 @@#define this_buffer per_cpu(buffer, smp_processor_id())static int __read_mostly trace_hw_branches_enabled; +static struct trace_array *hw_branch_trace__read_mostly ;/*
@@ -127,6 +128,8 @@static int bts_trace_init (struct trace_array *tr) { + hw_branch_trace = tr; +register_hotcpu_notifier (&bts_hotcpu_notifier);tracing_reset_online_cpus (tr);bts_trace_start (tr);
@@ -138,6 +141,8 @@ {bts_trace_stop (tr);unregister_hotcpu_notifier (&bts_hotcpu_notifier); + + hw_branch_trace =NULL ; }static void bts_trace_print_header (struct seq_file *m)
@@ -166,8 +171,9 @@return TRACE_TYPE_UNHANDLED ; } -void trace_hw_branch (struct trace_array *tr,u64 from,u64 to) +void trace_hw_branch (u64 from,u64 to) { +struct trace_array *tr = hw_branch_trace;struct ring_buffer_event *event;struct hw_branch_entry *entry;unsigned long irq1, irq2;
@@ -200,8 +206,7 @@local_irq_restore (irq1); } -static void trace_bts_at (struct trace_array *tr, -const struct bts_trace *trace,void *at) +static void trace_bts_at (const struct bts_trace *trace,void *at) {struct bts_struct bts;int err =0 ;
@@ -216,7 +221,7 @@switch (bts.qualifier) {case BTS_BRANCH : -trace_hw_branch (tr, bts.variant.lbr.from, bts.variant.lbr.to); +trace_hw_branch (bts.variant.lbr.from, bts.variant.lbr.to);break ; } }
@@ -232,12 +237,15 @@const struct bts_trace *trace;unsigned char *at; -if (!this_tracer) +if (unlikely (!tr))return ;if (unlikely (atomic_read (&tr->data[raw_smp_processor_id ()]->disabled)))return ; +if (unlikely (!this_tracer)) +return ; +ds_suspend_bts (this_tracer); trace =ds_read_bts (this_tracer);if (!trace)
@@ -245,11 +253,11 @@for (at = trace->ds.top; (void *)at < trace->ds.end; at += trace->ds.size) -trace_bts_at (tr, trace, at); +trace_bts_at (trace, at);for (at = trace->ds.begin; (void *)at < trace->ds.top; at += trace->ds.size) -trace_bts_at (tr, trace, at); +trace_bts_at (trace, at); out:ds_resume_bts (this_tracer);
@@ -264,6 +272,15 @@mutex_unlock (&bts_tracer_mutex); } +void trace_hw_branch_oops (void ) +{ +mutex_lock (&bts_tracer_mutex); + +trace_bts_cpu (hw_branch_trace); + +mutex_unlock (&bts_tracer_mutex); +} +struct tracer bts_tracer__read_mostly = { .name ="hw-branch-tracer" ,
include/linux/ftrace.h +13 -0
@@ -492,4 +492,17 @@#endif /* CONFIG_TRACING */ + +#ifdef CONFIG_HW_BRANCH_TRACER + +void trace_hw_branch (u64 from,u64 to); +void trace_hw_branch_oops (void ); + +#else /* CONFIG_HW_BRANCH_TRACER */ + +static inline void trace_hw_branch (u64 from,u64 to) {} +static inline void trace_hw_branch_oops (void ) {} + +#endif /* CONFIG_HW_BRANCH_TRACER */ +#endif /* _LINUX_FTRACE_H */
---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
BTW, you have two 1/5 patches but no 2/5 patch.
Quoted 1 line · Markus Metzger
Dump the branch trace on an oops (based on
ftrace_dump_on_oops).
Does the ftrace_dump_on_oops not work? We may want to change ftrace_dump to see if a tracer has been registered, and use its format for output.
Quoted 62 lines
Signed-off-by Markus Metzger <[email protected]>---
Index:
ftrace/arch/x86/kernel/dumpstack.c
===================================================================arch/x86/kernel/dumpstack.c +6
-0@@ -14,6 +14,7 @@#include <linux/bug.h> #include <linux/nmi.h> #include <linux/sysfs.h> +#include <linux/ftrace.h> #include <asm/stacktrace.h> @@ -195,6 +196,11 @@int cpu;unsigned long flags; +/* notify the hw-branch tracer so it may disable tracing and +add the last trace to the trace buffer - +the earlier this happens, the more useful the trace. */ +trace_hw_branch_oops (); +oops_enter ();/* racy, but better than risking deadlock. */ Index:
ftrace/kernel/trace/trace.h
===================================================================kernel/trace/trace.h +0
-1@@ -415,7 +415,6 @@void trace_graph_return (struct ftrace_graph_ret *trace);int trace_graph_entry (struct ftrace_graph_ent *trace); -void trace_hw_branch (struct trace_array *tr,u64 from,u64 to);void tracing_start_cmdline_record (void );void tracing_stop_cmdline_record (void );Index:
ftrace/kernel/trace/trace_hw_branches.c
===================================================================kernel/trace/trace_hw_branches.c +3
-0@@ -39,6 +39,7 @@#define this_buffer per_cpu(buffer, smp_processor_id())static int __read_mostly trace_hw_branches_enabled; +static struct trace_array *hw_branch_trace__read_mostly ;/* @@ -127,6 +128,8 @@static int bts_trace_init (struct trace_array *tr) { + hw_branch_trace = tr; +register_hotcpu_notifier (&bts_hotcpu_notifier);tracing_reset_online_cpus (tr);bts_trace_start (tr);
kernel/trace/trace_hw_branches.c line 145
Quoted 5 lines
kernel/trace/trace_hw_branches.c +2
-0@@ -138,6 +141,8 @@ {bts_trace_stop (tr);unregister_hotcpu_notifier (&bts_hotcpu_notifier); + + hw_branch_trace =NULL ;
unless you test hw_branch_trace for content, I usually never NULL the local tracer variable. This prevents races. The worst that can happen without nulling it, is that your tracer will write into another tracer's buffer. No real harm done. But if you have it as null and a race happens, you can crash the kernel.
-- Steve
Quoted 117 lines
kernel/trace/trace_hw_branches.c +19
-7}static void bts_trace_print_header (struct seq_file *m)@@ -166,8 +171,9 @@return TRACE_TYPE_UNHANDLED ; } -void trace_hw_branch (struct trace_array *tr,u64 from,u64 to) +void trace_hw_branch (u64 from,u64 to) { +struct trace_array *tr = hw_branch_trace;struct ring_buffer_event *event;struct hw_branch_entry *entry;unsigned long irq1, irq2;@@ -200,8 +206,7 @@local_irq_restore (irq1); } -static void trace_bts_at (struct trace_array *tr, -const struct bts_trace *trace,void *at) +static void trace_bts_at (const struct bts_trace *trace,void *at) {struct bts_struct bts;int err =0 ;@@ -216,7 +221,7 @@switch (bts.qualifier) {case BTS_BRANCH : -trace_hw_branch (tr, bts.variant.lbr.from, bts.variant.lbr.to); +trace_hw_branch (bts.variant.lbr.from, bts.variant.lbr.to);break ; } }@@ -232,12 +237,15 @@const struct bts_trace *trace;unsigned char *at; -if (!this_tracer) +if (unlikely (!tr))return ;if (unlikely (atomic_read (&tr->data[raw_smp_processor_id ()]->disabled)))return ; +if (unlikely (!this_tracer)) +return ; +ds_suspend_bts (this_tracer); trace =ds_read_bts (this_tracer);if (!trace)@@ -245,11 +253,11 @@for (at = trace->ds.top; (void *)at < trace->ds.end; at += trace->ds.size) -trace_bts_at (tr, trace, at); +trace_bts_at (trace, at);for (at = trace->ds.begin; (void *)at < trace->ds.top; at += trace->ds.size) -trace_bts_at (tr, trace, at); +trace_bts_at (trace, at); out:ds_resume_bts (this_tracer);@@ -264,6 +272,15 @@mutex_unlock (&bts_tracer_mutex); } +void trace_hw_branch_oops (void ) +{ +mutex_lock (&bts_tracer_mutex); + +trace_bts_cpu (hw_branch_trace); + +mutex_unlock (&bts_tracer_mutex); +} +struct tracer bts_tracer__read_mostly = { .name ="hw-branch-tracer" ,Index:
ftrace/include/linux/ftrace.h
===================================================================include/linux/ftrace.h +13
-1@@ -492,4 +492,17 @@#endif /* CONFIG_TRACING */ + +#ifdef CONFIG_HW_BRANCH_TRACER + +void trace_hw_branch (u64 from,u64 to); +void trace_hw_branch_oops (void ); + +#else /* CONFIG_HW_BRANCH_TRACER */ + +static inline void trace_hw_branch (u64 from,u64 to) {} +static inline void trace_hw_branch_oops (void ) {} + +#endif /* CONFIG_HW_BRANCH_TRACER */ +#endif /* _LINUX_FTRACE_H */ ---------------------------------------------------------------------Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Quoted 8 lines
-----Original Message-----
From: Steven Rostedt [mailto:[email protected]]
Sent: Friday, January 16, 2009 3:55 PM
To: Metzger, Markus T
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [patch 3/5] x86, ftrace, hw-branch-tracer: dump on oops
Quoted 8 lines
BTW, you have two 1/5 patches but no 2/5 patch.
Quoted 1 line · Markus Metzger
Dump the branch trace on an oops (based on
ftrace_dump_on_oops).Does the
ftrace_dump_on_oopsnot work? We may want to changeftrace_dumpto see if a tracer has been registered, and use its format for output.
It does work and I am using it.
It only works one time, though. Ftrace kills itself before dumping its buffer.
The trace is collected in a separate buffer. trace_hw_branch_oops() reads that buffer and adds the trace to the ftrace buffer, so ftrace can then dump it.
Quoted 10 lines
kernel/trace/trace_hw_branches.c line 145
Quoted 4 lines
bts_trace_stop(tr); unregister_hotcpu_notifier(&bts_hotcpu_notifier);kernel/trace/trace_hw_branches.c +2
-0+ + hw_branch_trace =NULL ;unless you test
hw_branch_tracefor content, I usually never NULL the local tracer variable. This prevents races. The worst that can happen without nulling it, is that your tracer will write into another tracer's buffer. No real harm done. But if you have it as null and a race happens, you can crash the kernel.
Sounds reasonable. I'll change it.
regards,
markus.
---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.