Skip to content

Commit ac8c3b0

Browse files
committed
ftrace: Do not disable interrupts in profiler
The function profiler disables interrupts before processing. This was there since the profiler was introduced back in 2009 when there were recursion issues to deal with. The function tracer is much more robust today and has its own internal recursion protection. There's no reason to disable interrupts in the function profiler. Instead, just disable preemption and use the guard() infrastructure while at it. Before this change: ~# echo 1 > /sys/kernel/tracing/function_profile_enabled ~# perf stat -r 10 ./hackbench 10 Time: 3.099 Time: 2.556 Time: 2.500 Time: 2.705 Time: 2.985 Time: 2.959 Time: 2.859 Time: 2.621 Time: 2.742 Time: 2.631 Performance counter stats for '/work/c/hackbench 10' (10 runs): 23,156.77 msec task-clock # 6.951 CPUs utilized ( +- 2.36% ) 18,306 context-switches # 790.525 /sec ( +- 5.95% ) 495 cpu-migrations # 21.376 /sec ( +- 8.61% ) 11,522 page-faults # 497.565 /sec ( +- 1.80% ) 47,967,124,606 cycles # 2.071 GHz ( +- 0.41% ) 80,009,078,371 instructions # 1.67 insn per cycle ( +- 0.34% ) 16,389,249,798 branches # 707.752 M/sec ( +- 0.36% ) 139,943,109 branch-misses # 0.85% of all branches ( +- 0.61% ) 3.332 +- 0.101 seconds time elapsed ( +- 3.04% ) After this change: ~# echo 1 > /sys/kernel/tracing/function_profile_enabled ~# perf stat -r 10 ./hackbench 10 Time: 1.869 Time: 1.428 Time: 1.575 Time: 1.569 Time: 1.685 Time: 1.511 Time: 1.611 Time: 1.672 Time: 1.724 Time: 1.715 Performance counter stats for '/work/c/hackbench 10' (10 runs): 13,578.21 msec task-clock # 6.931 CPUs utilized ( +- 2.23% ) 12,736 context-switches # 937.973 /sec ( +- 3.86% ) 341 cpu-migrations # 25.114 /sec ( +- 5.27% ) 11,378 page-faults # 837.960 /sec ( +- 1.74% ) 27,638,039,036 cycles # 2.035 GHz ( +- 0.27% ) 45,107,762,498 instructions # 1.63 insn per cycle ( +- 0.23% ) 8,623,868,018 branches # 635.125 M/sec ( +- 0.27% ) 125,738,443 branch-misses # 1.46% of all branches ( +- 0.32% ) 1.9590 +- 0.0484 seconds time elapsed ( +- 2.47% ) Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 7d137e6 commit ac8c3b0

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

kernel/trace/ftrace.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -789,27 +789,24 @@ function_profile_call(unsigned long ip, unsigned long parent_ip,
789789
{
790790
struct ftrace_profile_stat *stat;
791791
struct ftrace_profile *rec;
792-
unsigned long flags;
793792

794793
if (!ftrace_profile_enabled)
795794
return;
796795

797-
local_irq_save(flags);
796+
guard(preempt_notrace)();
798797

799798
stat = this_cpu_ptr(&ftrace_profile_stats);
800799
if (!stat->hash || !ftrace_profile_enabled)
801-
goto out;
800+
return;
802801

803802
rec = ftrace_find_profiled_func(stat, ip);
804803
if (!rec) {
805804
rec = ftrace_profile_alloc(stat, ip);
806805
if (!rec)
807-
goto out;
806+
return;
808807
}
809808

810809
rec->counter++;
811-
out:
812-
local_irq_restore(flags);
813810
}
814811

815812
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
@@ -856,19 +853,19 @@ static void profile_graph_return(struct ftrace_graph_ret *trace,
856853
unsigned long long calltime;
857854
unsigned long long rettime = trace_clock_local();
858855
struct ftrace_profile *rec;
859-
unsigned long flags;
860856
int size;
861857

862-
local_irq_save(flags);
858+
guard(preempt_notrace)();
859+
863860
stat = this_cpu_ptr(&ftrace_profile_stats);
864861
if (!stat->hash || !ftrace_profile_enabled)
865-
goto out;
862+
return;
866863

867864
profile_data = fgraph_retrieve_data(gops->idx, &size);
868865

869866
/* If the calltime was zero'd ignore it */
870867
if (!profile_data || !profile_data->calltime)
871-
goto out;
868+
return;
872869

873870
calltime = rettime - profile_data->calltime;
874871

@@ -896,9 +893,6 @@ static void profile_graph_return(struct ftrace_graph_ret *trace,
896893
rec->time += calltime;
897894
rec->time_squared += calltime * calltime;
898895
}
899-
900-
out:
901-
local_irq_restore(flags);
902896
}
903897

904898
static struct fgraph_ops fprofiler_ops = {

0 commit comments

Comments
 (0)