aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/compiler.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-03-20 13:26:17 -0400
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2019-05-09 15:25:13 -0400
commita15fd609ad53a631a927c6680e8fb606f42a712b (patch)
treef885028fcbbbc46022e69053638c88d984ef9df5 /include/linux/compiler.h
parentb9416997603ef7e17d4de10b6408f19da2feb72c (diff)
tracing: Simplify "if" macro code
Peter Zijlstra noticed that with CONFIG_PROFILE_ALL_BRANCHES, the "if" macro converts the conditional to an array index. This can cause GCC to create horrible code. When there are nested ifs, the generated code uses register values to encode branching decisions. Josh Poimboeuf found that replacing the define "if" macro from using the condition as an array index and incrementing the branch statics with an if statement itself, reduced the asm complexity and shrinks the generated code quite a bit. But this can be simplified even further by replacing the internal if statement with a ternary operator. Link: https://lkml.kernel.org/r/20190307174802.46fmpysxyo35hh43@treble Link: http://lkml.kernel.org/r/CAHk-=wiALN3jRuzARpwThN62iKd476Xj-uom+YnLZ4=eqcz7xQ@mail.gmail.com Reported-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reported-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Diffstat (limited to 'include/linux/compiler.h')
-rw-r--r--include/linux/compiler.h35
1 files changed, 18 insertions, 17 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 445348facea9..8aaf7cd026b0 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -53,23 +53,24 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
53 * "Define 'is'", Bill Clinton 53 * "Define 'is'", Bill Clinton
54 * "Define 'if'", Steven Rostedt 54 * "Define 'if'", Steven Rostedt
55 */ 55 */
56#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) ) 56#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
57#define __trace_if(cond) \ 57
58 if (__builtin_constant_p(!!(cond)) ? !!(cond) : \ 58#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
59 ({ \ 59
60 int ______r; \ 60#define __trace_if_value(cond) ({ \
61 static struct ftrace_branch_data \ 61 static struct ftrace_branch_data \
62 __aligned(4) \ 62 __aligned(4) \
63 __section("_ftrace_branch") \ 63 __section("_ftrace_branch") \
64 ______f = { \ 64 __if_trace = { \
65 .func = __func__, \ 65 .func = __func__, \
66 .file = __FILE__, \ 66 .file = __FILE__, \
67 .line = __LINE__, \ 67 .line = __LINE__, \
68 }; \ 68 }; \
69 ______r = !!(cond); \ 69 (cond) ? \
70 ______f.miss_hit[______r]++; \ 70 (__if_trace.miss_hit[1]++,1) : \
71 ______r; \ 71 (__if_trace.miss_hit[0]++,0); \
72 })) 72})
73
73#endif /* CONFIG_PROFILE_ALL_BRANCHES */ 74#endif /* CONFIG_PROFILE_ALL_BRANCHES */
74 75
75#else 76#else