Skip to content

Commit 36a367b

Browse files
committed
ftrace: Show timings of how long nop patching took
Since the beginning of ftrace, the code that did the patching had its timings saved on how long it took to complete. But this information was never exposed. It was used for debugging and exposing it was always something that was on the TODO list. Now it's time to expose it. There's even a file that is where it should go! Also include how long patching modules took as a separate value. # cat /sys/kernel/tracing/dyn_ftrace_total_info 57680 pages:231 groups: 9 ftrace boot update time = 14024666 (ns) ftrace module total update time = 126070 (ns) Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 8b0cb3a commit 36a367b

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

kernel/trace/ftrace.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,7 +3686,8 @@ static int ftrace_hash_move_and_update_subops(struct ftrace_ops *subops,
36863686
}
36873687

36883688

3689-
static u64 ftrace_update_time;
3689+
u64 ftrace_update_time;
3690+
u64 ftrace_total_mod_time;
36903691
unsigned long ftrace_update_tot_cnt;
36913692
unsigned long ftrace_number_of_pages;
36923693
unsigned long ftrace_number_of_groups;
@@ -3706,7 +3707,7 @@ static int ftrace_update_code(struct module *mod, struct ftrace_page *new_pgs)
37063707
bool init_nop = ftrace_need_init_nop();
37073708
struct ftrace_page *pg;
37083709
struct dyn_ftrace *p;
3709-
u64 start, stop;
3710+
u64 start, stop, update_time;
37103711
unsigned long update_cnt = 0;
37113712
unsigned long rec_flags = 0;
37123713
int i;
@@ -3750,7 +3751,11 @@ static int ftrace_update_code(struct module *mod, struct ftrace_page *new_pgs)
37503751
}
37513752

37523753
stop = ftrace_now(raw_smp_processor_id());
3753-
ftrace_update_time = stop - start;
3754+
update_time = stop - start;
3755+
if (mod)
3756+
ftrace_total_mod_time += update_time;
3757+
else
3758+
ftrace_update_time = update_time;
37543759
ftrace_update_tot_cnt += update_cnt;
37553760

37563761
return 0;

kernel/trace/trace.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8548,15 +8548,22 @@ tracing_read_dyn_info(struct file *filp, char __user *ubuf,
85488548
char *buf;
85498549
int r;
85508550

8551-
/* 256 should be plenty to hold the amount needed */
8552-
buf = kmalloc(256, GFP_KERNEL);
8551+
/* 512 should be plenty to hold the amount needed */
8552+
#define DYN_INFO_BUF_SIZE 512
8553+
8554+
buf = kmalloc(DYN_INFO_BUF_SIZE, GFP_KERNEL);
85538555
if (!buf)
85548556
return -ENOMEM;
85558557

8556-
r = scnprintf(buf, 256, "%ld pages:%ld groups: %ld\n",
8558+
r = scnprintf(buf, DYN_INFO_BUF_SIZE,
8559+
"%ld pages:%ld groups: %ld\n"
8560+
"ftrace boot update time = %llu (ns)\n"
8561+
"ftrace module total update time = %llu (ns)\n",
85578562
ftrace_update_tot_cnt,
85588563
ftrace_number_of_pages,
8559-
ftrace_number_of_groups);
8564+
ftrace_number_of_groups,
8565+
ftrace_update_time,
8566+
ftrace_total_mod_time);
85608567

85618568
ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
85628569
kfree(buf);

kernel/trace/trace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
775775
extern unsigned long ftrace_update_tot_cnt;
776776
extern unsigned long ftrace_number_of_pages;
777777
extern unsigned long ftrace_number_of_groups;
778+
extern u64 ftrace_update_time;
779+
extern u64 ftrace_total_mod_time;
778780
void ftrace_init_trace_array(struct trace_array *tr);
779781
#else
780782
static inline void ftrace_init_trace_array(struct trace_array *tr) { }

0 commit comments

Comments
 (0)