Re: [PATCH 2/2] jump label: introduce static_branch()

From: Jason Baron
Date: Wed Jan 05 2011 - 16:17:42 EST


On Wed, Jan 05, 2011 at 09:32:11AM -0800, David Daney wrote:
> On 01/05/2011 07:43 AM, Jason Baron wrote:
>> Introduce:
>>
>> static __always_inline bool static_branch(struct jump_label_key *key)
>>
>> to replace the old JUMP_LABEL(key, label) macro.
>>
>> The new static_branch(), simplifies the usage of jump labels. Since,
>> static_branch() returns a boolean, it can be used as part of an if()
>> construct. It also, allows us to drop the 'label' argument from the
>> prototype. Its probably best understood with an example, here is the part
>> of the patch that converts the tracepoints to use unlikely_switch():
>>
>> --- a/include/linux/tracepoint.h
>> +++ b/include/linux/tracepoint.h
>> @@ -146,9 +146,7 @@ static inline void tracepoint_update_probe_range(struct tracepoint *begin,
>> extern struct tracepoint __tracepoint_##name; \
>> static inline void trace_##name(proto) \
>> { \
>> - JUMP_LABEL(&__tracepoint_##name.key, do_trace); \
>> - return; \
>> -do_trace: \
>> + if (static_branch(&__tracepoint_##name.key)) \
>> __DO_TRACE(&__tracepoint_##name, \
>> TP_PROTO(data_proto), \
>> TP_ARGS(data_args)); \
>>
>>
>> I analyzed the code produced by static_branch(), and it seems to be
>> at least as good as the code generated by the JUMP_LABEL(). As a reminder,
>> we get a single nop in the fastpath for -02. But will often times get
>> a 'double jmp' in the -Os case. That is, 'jmp 0', followed by a jmp around
>> the disabled code. We believe that future gcc tweaks to allow block
>> re-ordering in the -Os, will solve the -Os case in the future.
>>
>> I also saw a 1-2% tbench throughput improvement when compiling with
>> jump labels.
>>
>> This patch also addresses a build issue that Tetsuo Handa reported where
>> gcc v3.3 currently chokes on compiling 'dynamic debug':
>>
>> include/net/inet_connection_sock.h: In function `inet_csk_reset_xmit_timer':
>> include/net/inet_connection_sock.h:236: error: duplicate label declaration `do_printk'
>> include/net/inet_connection_sock.h:219: error: this is a previous declaration
>> include/net/inet_connection_sock.h:236: error: duplicate label declaration `out'
>> include/net/inet_connection_sock.h:219: error: this is a previous declaration
>> include/net/inet_connection_sock.h:236: error: duplicate label `do_printk'
>> include/net/inet_connection_sock.h:236: error: duplicate label `out'
>>
>>
>> Thanks to H. Peter Anvin for suggesting this improved syntax.
>>
>> Suggested-by: H. Peter Anvin<hpa@xxxxxxxxxxxxxxx>
>> Signed-off-by: Jason Baron<jbaron@xxxxxxxxxx>
>> Tested-by: Tetsuo Handa<penguin-kernel@xxxxxxxxxxxxxxxxxxx>
>> ---
>> arch/sparc/include/asm/jump_label.h | 25 ++++++++++++++-----------
>> arch/x86/include/asm/jump_label.h | 22 +++++++++++++---------
>> arch/x86/kernel/jump_label.c | 2 +-
>> include/linux/dynamic_debug.h | 18 ++++--------------
>> include/linux/jump_label.h | 26 +++++++++++---------------
>> include/linux/jump_label_ref.h | 18 +++++++++++-------
>> include/linux/perf_event.h | 26 +++++++++++++-------------
>> include/linux/tracepoint.h | 4 +---
>> kernel/jump_label.c | 2 +-
>> 9 files changed, 69 insertions(+), 74 deletions(-)
>>
> [...]
>
> This patch will conflict with the MIPS jump label support that Ralf has
> queued up for 2.6.38.
>
> David Daney

indeed. If you look at the x86 or sparc bits the fixup should be quite
small. The bulk of the changes are in the common code.

thanks,

-Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/