mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 05:02:12 +00:00
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>
This commit is contained in:
parent
b941699760
commit
a15fd609ad
@ -53,23 +53,24 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
|
||||
* "Define 'is'", Bill Clinton
|
||||
* "Define 'if'", Steven Rostedt
|
||||
*/
|
||||
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
|
||||
#define __trace_if(cond) \
|
||||
if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
|
||||
({ \
|
||||
int ______r; \
|
||||
static struct ftrace_branch_data \
|
||||
__aligned(4) \
|
||||
__section("_ftrace_branch") \
|
||||
______f = { \
|
||||
.func = __func__, \
|
||||
.file = __FILE__, \
|
||||
.line = __LINE__, \
|
||||
}; \
|
||||
______r = !!(cond); \
|
||||
______f.miss_hit[______r]++; \
|
||||
______r; \
|
||||
}))
|
||||
#define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
|
||||
|
||||
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
|
||||
|
||||
#define __trace_if_value(cond) ({ \
|
||||
static struct ftrace_branch_data \
|
||||
__aligned(4) \
|
||||
__section("_ftrace_branch") \
|
||||
__if_trace = { \
|
||||
.func = __func__, \
|
||||
.file = __FILE__, \
|
||||
.line = __LINE__, \
|
||||
}; \
|
||||
(cond) ? \
|
||||
(__if_trace.miss_hit[1]++,1) : \
|
||||
(__if_trace.miss_hit[0]++,0); \
|
||||
})
|
||||
|
||||
#endif /* CONFIG_PROFILE_ALL_BRANCHES */
|
||||
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user