Re: [PATCH 02/25] tracing: Improve "if" macro code generation

From: Steven Rostedt
Date: Mon Mar 18 2019 - 13:41:56 EST


On Mon, 18 Mar 2019 16:38:42 +0100
Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:

> 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.
>
> Make it easier for GCC to optimize by keeping the conditional as a
> conditional rather than converting it to an integer. This shrinks the
> generated code quite a bit, and also makes the code sane enough for
> objtool to understand.
>
> Cc: rostedt@xxxxxxxxxxx
> Cc: valentin.schneider@xxxxxxx
> Cc: luto@xxxxxxxxxxxxxx
> Cc: brgerst@xxxxxxxxx
> Cc: catalin.marinas@xxxxxxx
> Cc: mingo@xxxxxxxxxx
> Cc: dvlasenk@xxxxxxxxxx
> Cc: will.deacon@xxxxxxx
> Cc: julien.thierry@xxxxxxx
> Cc: torvalds@xxxxxxxxxxxxxxxxxxxx
> Cc: dvyukov@xxxxxxxxxx
> Cc: bp@xxxxxxxxx
> Cc: tglx@xxxxxxxxxxxxx
> Cc: james.morse@xxxxxxx
> Cc: luto@xxxxxxxxxx
> Cc: hpa@xxxxxxxxx
> Reported-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>

Acked-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>

-- Steve

> Link: https://lkml.kernel.org/r/20190307174802.46fmpysxyo35hh43@treble
> ---
> include/linux/compiler.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -67,7 +67,7 @@ void ftrace_likely_update(struct ftrace_
> .line = __LINE__, \
> }; \
> ______r = !!(cond); \
> - ______f.miss_hit[______r]++; \
> + ______r ? ______f.miss_hit[1]++ : ______f.miss_hit[0]++;\
> ______r; \
> }))
> #endif /* CONFIG_PROFILE_ALL_BRANCHES */
>