tracing: Last minute updates for 4.6
Subsystems (5)
Steven Rostedt
maintainercover tracing: Last minute updates for 4.6
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: 741f3a69f101250dc6b171b88e14ea51b099b1a9
Chunyu Hu (1):
tracing: Fix return while holding a lock in register_tracer()
Dmitry Safonov (1):
tracing: Remove redundant reset per-CPU buff in irqsoff tracer
Geliang Tang (1):
ftrace: Use kasprintf() in ftrace_profile_tracefs()
Jiri Olsa (2):
ftrace: Make ftrace_hash_rec_enable return update bool
ftrace: Update dynamic ftrace calls only if necessary
Li Bin (1):
x86: ftrace: Fix the misleading comment for arch/x86/kernel/ftrace.c
Steven Rostedt (Red Hat) (2):
tracing: Have preempt(irqs)off trace preempt disabled functions
tracing: Fix crash from reading trace_pipe with sendfile
----
arch/x86/kernel/ftrace.c | 2 +- kernel/trace/ftrace.c | 41 +++++++++++++++++++++++------------------ kernel/trace/trace.c | 11 ++++++++--- kernel/trace/trace_irqsoff.c | 9 ++++++--- 4 files changed, 38 insertions(+), 25 deletions(-)
Steven Rostedt
maintainerPATCH 1/8 ftrace: Make ftrace_hash_rec_enable return update bool
From: Jiri Olsa <[email protected]>
Change __ftrace_hash_rec_update to return true in case we need to update dynamic ftrace call records. It return false in case no update is needed.
--- kernel/trace/ftrace.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
kernel/trace/ftrace.c +17 -10
@@ -1610,7 +1610,7 @@ static bool test_rec_ops_needs_regs(struct dyn_ftrace *rec)return keep_regs; } -static void __ftrace_hash_rec_update (struct ftrace_ops *ops, +static bool __ftrace_hash_rec_update (struct ftrace_ops *ops,int filter_hash,bool inc) {
@@ -1618,12 +1618,13 @@ static void __ftrace_hash_rec_update(struct ftrace_ops *ops,struct ftrace_hash *other_hash;struct ftrace_page *pg;struct dyn_ftrace *rec; +bool update = false;int count =0 ;int all =0 ;/* Only update if the ops has been registered */ if (!(ops->flags &FTRACE_OPS_FL_ENABLED )) -return ; +return false;/* * In the filter_hash case:
@@ -1650,7 +1651,7 @@ static void __ftrace_hash_rec_update(struct ftrace_ops *ops,* then there's nothing to do. */ if (ftrace_hash_empty (hash)) -return ; +return false; }do_for_each_ftrace_rec (pg, rec) {
@@ -1694,7 +1695,7 @@ static void __ftrace_hash_rec_update(struct ftrace_ops *ops,if (inc) { rec->flags++;if (FTRACE_WARN_ON (ftrace_rec_count (rec) ==FTRACE_REF_MAX )) -return ; +return false;/* * If there's only a single callback registered to a
@@ -1720,7 +1721,7 @@ static void __ftrace_hash_rec_update(struct ftrace_ops *ops, rec->flags |=FTRACE_FL_REGS ; }else {if (FTRACE_WARN_ON (ftrace_rec_count (rec) ==0 )) -return ; +return false; rec->flags--;/*
@@ -1753,22 +1754,28 @@ static void __ftrace_hash_rec_update(struct ftrace_ops *ops,*/ } count++; + +/* Must match FTRACE_UPDATE_CALLS in ftrace_modify_all_code() */ + update |=ftrace_test_record (rec,1 ) !=FTRACE_UPDATE_IGNORE ; +/* Shortcut, if we handled all records, we are done. */ if (!all && count == hash->count) -return ; +return update; }while_for_each_ftrace_rec (); + +return update; } -static void ftrace_hash_rec_disable (struct ftrace_ops *ops, +static bool ftrace_hash_rec_disable (struct ftrace_ops *ops,int filter_hash) { -__ftrace_hash_rec_update (ops, filter_hash,0 ); +return __ftrace_hash_rec_update (ops, filter_hash,0 ); } -static void ftrace_hash_rec_enable (struct ftrace_ops *ops, +static bool ftrace_hash_rec_enable (struct ftrace_ops *ops,int filter_hash) { -__ftrace_hash_rec_update (ops, filter_hash,1 ); +return __ftrace_hash_rec_update (ops, filter_hash,1 ); } static void ftrace_hash_rec_update_modify(struct ftrace_ops *ops,
Signature · 1 line
2.7.0
Steven Rostedt
maintainerPATCH 2/8 ftrace: Update dynamic ftrace calls only if necessary
In reply to Steven RostedtFrom: Jiri Olsa <[email protected]>
Currently dynamic ftrace calls are updated any time the ftrace_ops is un/registered. If we do this update only when it's needed, we save lot of time for perf system wide ftrace function sampling/counting.
The reason is that for system wide sampling/counting, perf creates event for each cpu in the system.
Each event then registers separate copy of ftrace_ops, which ends up in FTRACE_UPDATE_CALLS updates. On servers with many cpus that means serious stall (240 cpus server):
Counting:
# time ./perf stat -e ftrace:function -a sleep 1
Performance counter stats for 'system wide':
370,663 ftrace:function
1.401427505 seconds time elapsedreal 3m51.743s user 0m0.023s sys 3m48.569s
Sampling:
# time ./perf record -e ftrace:function -a sleep 1 [ perf record: Woken up 0 times to write data ] Warning: Processed 141200 events and lost 5 chunks!
[ perf record: Captured and wrote 10.703 MB perf.data (135950 samples) ]
real 2m31.429s user 0m0.213s sys 2m29.494s
There's no reason to do the FTRACE_UPDATE_CALLS update for each event in perf case, because all the ftrace_ops always share the same filter, so the updated calls are always the same.
It's required that only first ftrace_ops registration does the FTRACE_UPDATE_CALLS update (also sometimes the second if the first one used the trampoline), but the rest can be only cheaply linked into the ftrace_ops list.
Counting:
# time ./perf stat -e ftrace:function -a sleep 1
Performance counter stats for 'system wide':
398,571 ftrace:function
1.377503733 seconds time elapsedreal 0m2.787s user 0m0.005s sys 0m1.883s
Sampling:
# time ./perf record -e ftrace:function -a sleep 1 [ perf record: Woken up 0 times to write data ] Warning: Processed 261730 events and lost 9 chunks!
[ perf record: Captured and wrote 19.907 MB perf.data (256293 samples) ]
real 1m31.948s user 0m0.309s sys 1m32.051s
--- kernel/trace/ftrace.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/trace/ftrace.c +5 -5
@@ -2651,7 +2651,6 @@ static int ftrace_startup(struct ftrace_ops *ops, int command)return ret; ftrace_start_up++; - command |=FTRACE_UPDATE_CALLS ;/* * Note that ftrace probes uses this to start up
@@ -2672,7 +2671,8 @@ static int ftrace_startup(struct ftrace_ops *ops, int command)return ret; } -ftrace_hash_rec_enable (ops,1 ); +if (ftrace_hash_rec_enable (ops,1 )) + command |=FTRACE_UPDATE_CALLS ;ftrace_startup_enable (command);
@@ -2702,11 +2702,11 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command)/* Disabling ipmodify never fails */ ftrace_hash_ipmodify_disable (ops); -ftrace_hash_rec_disable (ops,1 ); - ops->flags &= ~FTRACE_OPS_FL_ENABLED ; +if (ftrace_hash_rec_disable (ops,1 )) + command |=FTRACE_UPDATE_CALLS ; - command |=FTRACE_UPDATE_CALLS ; + ops->flags &= ~FTRACE_OPS_FL_ENABLED ;if (saved_ftrace_func != ftrace_trace_function) { saved_ftrace_func = ftrace_trace_function;
Signature · 1 line
2.7.0
Steven Rostedt
maintainerPATCH 3/8 ftrace: Use kasprintf() in ftrace_profile_tracefs()
In reply to Steven RostedtFrom: Geliang Tang <[email protected]>
Use kasprintf() instead of kmalloc() and snprintf().
--- kernel/trace/ftrace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/ftrace.c +1 -3
@@ -1030,8 +1030,7 @@ static __init void ftrace_profile_tracefs(struct dentry *d_tracer)for_each_possible_cpu (cpu) { stat = &per_cpu (ftrace_profile_stats, cpu); -/* allocate enough for function name + cpu number */ - name =kmalloc (32 ,GFP_KERNEL ); + name =kasprintf (GFP_KERNEL ,"function%d" , cpu);if (!name) {/* * The files created are permanent, if something happens
@@ -1043,7 +1042,6 @@ static __init void ftrace_profile_tracefs(struct dentry *d_tracer)return ; } stat->stat = function_stats; -snprintf (name,32 ,"function%d" , cpu); stat->stat.name = name; ret =register_stat_tracer (&stat->stat);if (ret) {
Signature · 1 line
2.7.0
Steven Rostedt
maintainerPATCH 4/8 tracing: Fix return while holding a lock in register_tracer()
In reply to Steven RostedtFrom: Chunyu Hu <[email protected]>
commit d39cdd2036a6 ("tracing: Make tracer_flags use the right set_flag callback") introduces a potential mutex deadlock issue, as it forgets to free the mutex when allocaing the tracer_flags gets fail.
The issue was found by Dan Carpenter through Smatch static code check tool.
--- kernel/trace/trace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/trace/trace.c +4 -2
@@ -1256,8 +1256,10 @@ int __init register_tracer(struct tracer *type)if (!type->flags) {/*allocate a dummy tracer_flags*/ type->flags =kmalloc (sizeof (*type->flags),GFP_KERNEL ); -if (!type->flags) -return -ENOMEM ; +if (!type->flags) { + ret = -ENOMEM ; + goto out; + } type->flags->val =0 ; type->flags->opts = dummy_tracer_opt; }else
Signature · 1 line
2.7.0
Steven Rostedt
maintainerPATCH 5/8 tracing: Have preempt(irqs)off trace preempt disabled functions
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
Joel Fernandes reported that the function tracing of preempt disabled sections was not being reported when running either the preemptirqsoff or preemptoff tracers. This was due to the fact that the function tracer callback for those tracers checked if irqs were disabled before tracing. But this fails when we want to trace preempt off locations as well.
Joel explained that he wanted to see funcitons where interrupts are enabled but preemption was disabled. The expected output he wanted:
<...>-2265 1d.h1 3419us : preempt_count_sub <-irq_exit <...>-2265 1d..1 3419us : __do_softirq <-irq_exit <...>-2265 1d..1 3419us : msecs_to_jiffies <-__do_softirq <...>-2265 1d..1 3420us : irqtime_account_irq <-__do_softirq <...>-2265 1d..1 3420us : __local_bh_disable_ip <-__do_softirq <...>-2265 1..s1 3421us : run_timer_softirq <-__do_softirq <...>-2265 1..s1 3421us : hrtimer_run_pending <-run_timer_softirq <...>-2265 1..s1 3421us : _raw_spin_lock_irq <-run_timer_softirq <...>-2265 1d.s1 3422us : preempt_count_add <-_raw_spin_lock_irq <...>-2265 1d.s2 3422us : _raw_spin_unlock_irq <-run_timer_softirq <...>-2265 1..s2 3422us : preempt_count_sub <-_raw_spin_unlock_irq <...>-2265 1..s1 3423us : rcu_bh_qs <-__do_softirq <...>-2265 1d.s1 3423us : irqtime_account_irq <-__do_softirq <...>-2265 1d.s1 3423us : __local_bh_enable <-__do_softirq
There's a comment saying that the irq disabled check is because there's a possible race that tracing_cpu may be set when the function is executed. But I don't remember that race. For now, I added a check for preemption being enabled too to not record the function, as there would be no race if that was the case. I need to re-investigate this, as I'm now thinking that the tracing_cpu will always be correct. But no harm in keeping the check for now, except for the slight performance hit.
--- kernel/trace/trace_irqsoff.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/trace/trace_irqsoff.c +6 -2
@@ -109,8 +109,12 @@ static int func_prolog_dec(struct trace_array *tr,return 0 ;local_save_flags (*flags); -/* slight chance to get a false positive on tracing_cpu */ -if (!irqs_disabled_flags (*flags)) +/* +* Slight chance to get a false positive on tracing_cpu, +* although I'm starting to think there isn't a chance. +* Leave this for now just to be paranoid. +*/ +if (!irqs_disabled_flags (*flags) && !preempt_count ())return 0 ; *data =per_cpu_ptr (tr->trace_buffer.data, cpu);
Signature · 1 line
2.7.0
Steven Rostedt
maintainerPATCH 6/8 tracing: Fix crash from reading trace_pipe with sendfile
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
If tracing contains data and the trace_pipe file is read with sendfile(), then it can trigger a NULL pointer dereference and various BUG_ON within the VM code.
There's a patch to fix this in the splice_to_pipe() code, but it's also a good idea to not let that happen from trace_pipe either.
--- kernel/trace/trace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/trace/trace.c +4 -1
@@ -4954,7 +4954,10 @@ static ssize_t tracing_splice_read_pipe(struct file *filp, spd.nr_pages = i; - ret =splice_to_pipe (pipe, &spd); +if (i) + ret =splice_to_pipe (pipe, &spd); +else + ret =0 ; out:splice_shrink_spd (&spd);return ret;
Signature · 1 line
2.7.0
Steven Rostedt
maintainerPATCH 7/8 x86: ftrace: Fix the misleading comment for arch/x86/kernel/ftrace.c
In reply to Steven RostedtFrom: Li Bin <[email protected]>
Fix the misleading comment for arch/x86/kernel/ftrace.c that it had used nop instead of jmp.
--- arch/x86/kernel/ftrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/ftrace.c +1 -1
@@ -1,5 +1,5 @@/* -* Code for replacing ftrace calls with jumps. +* Dynamic function tracing support. * * Copyright (C) 2007-2008 Steven Rostedt <[email protected]> *
Signature · 1 line
2.7.0
Steven Rostedt
maintainerPATCH 8/8 tracing: Remove redundant reset per-CPU buff in irqsoff tracer
In reply to Steven RostedtFrom: Dmitry Safonov <[email protected]>
There is no reason to do it twice: from commit b6f11df26fdc28
("trace: Call tracing_reset_online_cpus before tracer->init()") resetting of per-CPU buffers done before tracer->init() call.
tracer->init() calls {irqs,preempt,preemptirqs}off_tracer_init() and it calls __irqsoff_tracer_init(), which resets per-CPU ringbuffer second time.
It's slowpath, but anyway.
--- kernel/trace/trace_irqsoff.c | 1 - 1 file changed, 1 deletion(-)
kernel/trace/trace_irqsoff.c +0 -1
@@ -626,7 +626,6 @@ static int __irqsoff_tracer_init(struct trace_array *tr) irqsoff_trace = tr;/* make sure that the tracer is visible */ smp_wmb (); -tracing_reset_online_cpus (&tr->trace_buffer);ftrace_init_array_ops (tr, irqsoff_tracer_call);
Signature · 1 line
2.7.0