Commit 45b797492a0758e64dff74e9db70e1f65e0603a5
Committed by
Ingo Molnar
1 parent
42f565e116
Exists in
master
and in
7 other branches
trace: consolidate unlikely and likely profiler
Impact: clean up to make one profiler of like and unlikely tracer The likely and unlikely profiler prints out the file and line numbers of the annotated branches that it is profiling. It shows the number of times it was correct or incorrect in its guess. Having two different files or sections for that matter to tell us if it was a likely or unlikely is pretty pointless. We really only care if it was correct or not. Signed-off-by: Steven Rostedt <srostedt@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Showing 4 changed files with 22 additions and 53 deletions Side-by-side Diff
include/asm-generic/vmlinux.lds.h
... | ... | @@ -46,12 +46,9 @@ |
46 | 46 | #endif |
47 | 47 | |
48 | 48 | #ifdef CONFIG_TRACE_BRANCH_PROFILING |
49 | -#define LIKELY_PROFILE() VMLINUX_SYMBOL(__start_likely_profile) = .; \ | |
50 | - *(_ftrace_likely) \ | |
51 | - VMLINUX_SYMBOL(__stop_likely_profile) = .; \ | |
52 | - VMLINUX_SYMBOL(__start_unlikely_profile) = .; \ | |
53 | - *(_ftrace_unlikely) \ | |
54 | - VMLINUX_SYMBOL(__stop_unlikely_profile) = .; | |
49 | +#define LIKELY_PROFILE() VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \ | |
50 | + *(_ftrace_annotated_branch) \ | |
51 | + VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .; | |
55 | 52 | #else |
56 | 53 | #define LIKELY_PROFILE() |
57 | 54 | #endif |
include/linux/compiler.h
... | ... | @@ -77,34 +77,20 @@ |
77 | 77 | #define likely_notrace(x) __builtin_expect(!!(x), 1) |
78 | 78 | #define unlikely_notrace(x) __builtin_expect(!!(x), 0) |
79 | 79 | |
80 | -#define likely_check(x) ({ \ | |
80 | +#define __branch_check__(x, expect) ({ \ | |
81 | 81 | int ______r; \ |
82 | 82 | static struct ftrace_branch_data \ |
83 | 83 | __attribute__((__aligned__(4))) \ |
84 | - __attribute__((section("_ftrace_likely"))) \ | |
84 | + __attribute__((section("_ftrace_annotated_branch"))) \ | |
85 | 85 | ______f = { \ |
86 | 86 | .func = __func__, \ |
87 | 87 | .file = __FILE__, \ |
88 | 88 | .line = __LINE__, \ |
89 | 89 | }; \ |
90 | 90 | ______r = likely_notrace(x); \ |
91 | - ftrace_likely_update(&______f, ______r, 1); \ | |
91 | + ftrace_likely_update(&______f, ______r, expect); \ | |
92 | 92 | ______r; \ |
93 | 93 | }) |
94 | -#define unlikely_check(x) ({ \ | |
95 | - int ______r; \ | |
96 | - static struct ftrace_branch_data \ | |
97 | - __attribute__((__aligned__(4))) \ | |
98 | - __attribute__((section("_ftrace_unlikely"))) \ | |
99 | - ______f = { \ | |
100 | - .func = __func__, \ | |
101 | - .file = __FILE__, \ | |
102 | - .line = __LINE__, \ | |
103 | - }; \ | |
104 | - ______r = unlikely_notrace(x); \ | |
105 | - ftrace_likely_update(&______f, ______r, 0); \ | |
106 | - ______r; \ | |
107 | - }) | |
108 | 94 | |
109 | 95 | /* |
110 | 96 | * Using __builtin_constant_p(x) to ignore cases where the return |
111 | 97 | |
... | ... | @@ -112,10 +98,10 @@ |
112 | 98 | * written by Daniel Walker. |
113 | 99 | */ |
114 | 100 | # ifndef likely |
115 | -# define likely(x) (__builtin_constant_p(x) ? !!(x) : likely_check(x)) | |
101 | +# define likely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 1)) | |
116 | 102 | # endif |
117 | 103 | # ifndef unlikely |
118 | -# define unlikely(x) (__builtin_constant_p(x) ? !!(x) : unlikely_check(x)) | |
104 | +# define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0)) | |
119 | 105 | # endif |
120 | 106 | #else |
121 | 107 | # define likely(x) __builtin_expect(!!(x), 1) |
kernel/trace/Kconfig
... | ... | @@ -166,8 +166,7 @@ |
166 | 166 | This tracer profiles all the the likely and unlikely macros |
167 | 167 | in the kernel. It will display the results in: |
168 | 168 | |
169 | - /debugfs/tracing/profile_likely | |
170 | - /debugfs/tracing/profile_unlikely | |
169 | + /debugfs/tracing/profile_annotated_branch | |
171 | 170 | |
172 | 171 | Note: this will add a significant overhead, only turn this |
173 | 172 | on if you need to profile the system's use of these macros. |
kernel/trace/trace_branch.c
... | ... | @@ -261,7 +261,7 @@ |
261 | 261 | .show = t_show, |
262 | 262 | }; |
263 | 263 | |
264 | -static int tracing_likely_open(struct inode *inode, struct file *file) | |
264 | +static int tracing_branch_open(struct inode *inode, struct file *file) | |
265 | 265 | { |
266 | 266 | int ret; |
267 | 267 | |
268 | 268 | |
269 | 269 | |
270 | 270 | |
... | ... | @@ -274,27 +274,20 @@ |
274 | 274 | return ret; |
275 | 275 | } |
276 | 276 | |
277 | -static struct file_operations tracing_likely_fops = { | |
278 | - .open = tracing_likely_open, | |
277 | +static const struct file_operations tracing_branch_fops = { | |
278 | + .open = tracing_branch_open, | |
279 | 279 | .read = seq_read, |
280 | 280 | .llseek = seq_lseek, |
281 | 281 | }; |
282 | 282 | |
283 | -extern unsigned long __start_likely_profile[]; | |
284 | -extern unsigned long __stop_likely_profile[]; | |
285 | -extern unsigned long __start_unlikely_profile[]; | |
286 | -extern unsigned long __stop_unlikely_profile[]; | |
283 | +extern unsigned long __start_annotated_branch_profile[]; | |
284 | +extern unsigned long __stop_annotated_branch_profile[]; | |
287 | 285 | |
288 | -static struct ftrace_pointer ftrace_likely_pos = { | |
289 | - .start = __start_likely_profile, | |
290 | - .stop = __stop_likely_profile, | |
286 | +static const struct ftrace_pointer ftrace_annotated_branch_pos = { | |
287 | + .start = __start_annotated_branch_profile, | |
288 | + .stop = __stop_annotated_branch_profile, | |
291 | 289 | }; |
292 | 290 | |
293 | -static struct ftrace_pointer ftrace_unlikely_pos = { | |
294 | - .start = __start_unlikely_profile, | |
295 | - .stop = __stop_unlikely_profile, | |
296 | -}; | |
297 | - | |
298 | 291 | static __init int ftrace_branch_init(void) |
299 | 292 | { |
300 | 293 | struct dentry *d_tracer; |
301 | 294 | |
... | ... | @@ -302,18 +295,12 @@ |
302 | 295 | |
303 | 296 | d_tracer = tracing_init_dentry(); |
304 | 297 | |
305 | - entry = debugfs_create_file("profile_likely", 0444, d_tracer, | |
306 | - &ftrace_likely_pos, | |
307 | - &tracing_likely_fops); | |
298 | + entry = debugfs_create_file("profile_annotated_branch", 0444, d_tracer, | |
299 | + &ftrace_annotated_branch_pos, | |
300 | + &tracing_branch_fops); | |
308 | 301 | if (!entry) |
309 | - pr_warning("Could not create debugfs 'profile_likely' entry\n"); | |
310 | - | |
311 | - entry = debugfs_create_file("profile_unlikely", 0444, d_tracer, | |
312 | - &ftrace_unlikely_pos, | |
313 | - &tracing_likely_fops); | |
314 | - if (!entry) | |
315 | - pr_warning("Could not create debugfs" | |
316 | - " 'profile_unlikely' entry\n"); | |
302 | + pr_warning("Could not create debugfs " | |
303 | + "'profile_annotatet_branch' entry\n"); | |
317 | 304 | |
318 | 305 | return 0; |
319 | 306 | } |