public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Jason Baron <jbaron@redhat.com>
Cc: peterz@infradead.org, hpa@zytor.com, rostedt@goodmis.org,
	mingo@elte.hu, tglx@linutronix.de, andi@firstfloor.org,
	roland@redhat.com, rth@redhat.com,
	masami.hiramatsu.pt@hitachi.com, fweisbec@gmail.com,
	avi@redhat.com, davem@davemloft.net, sam@ravnborg.org,
	ddaney@caviumnetworks.com, michael@ellerman.id.au,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH/RFC 0/2] jump label: simplify API
Date: Thu, 16 Dec 2010 14:22:41 -0500	[thread overview]
Message-ID: <20101216192241.GA8239@Krystal> (raw)
In-Reply-To: <cover.1292522251.git.jbaron@redhat.com>

* Jason Baron (jbaron@redhat.com) wrote:
> Hi,
> 
> The first patch uses the storage space of the jump label key address
> as a pointer into the update table. In this way, we can find all
> the addresses that need to be updated without hashing.
> 
> The second patch introduces:
> 
> static __always_inline bool unlikely_switch(struct jump_label_key *key);
> 
> instead of the old JUMP_LABEL(key, label) macro.
> 
> In this way, jump labels become really easy to use:
> 
> Define:
> 
> 	struct jump_label_key jump_key;
> 
> Can be used as:
> 
> 	if (unlikely_switch(&jump_key))
> 		do unlikely code

Ah, yes, that's an improvement!

I'm just wondering about the terminology here. Isn't that more a
"branch" than a "switch" ?

I'm concerned about the fact that if we ever want to use the asm goto
ability to jump to multiple targets (which is closer to a statically
computed switch than a branch), we might want to reserve "switch" name
for that rather than the branch.

I wonder if the "if (unlikely_switch(&jump_key))" you propose above is
the right thing to do. Why does the unlikely_ have to be included in the
name ? Maybe there is a good reason for it, but it would be nice to have
it spelled out. We might consider:

if (unlikely(static_branch(&jump_key)))
  ...

instead.

For the switch statement, from the top of my head the idea would be to
get something close to the following:

static __always_inline
int static_switch_{3,4,5,6...}(struct jump_label_key *key);

e.g.:

static __always_inline
int static_switch_3(struct jump_label_key *key)
{
	asm goto("1:"
		JUMP_LABEL_INITIAL_NOP
		".pushsection __switch_table_3,  \"a\" \n\t"
		_ASM_PTR "%c0, 1b, %l[l_1], %l[l_2] \n\t"
		".popsection \n\t"
		: :  "i" (key) : : l_1, l_2 );
	return 0;
l_1:
	return 1;
l_2:
	return 2;
}

switch(static_switch_3(&switch_key)) {
	case 0: .....
		break;
	case 1: .....
		break;
	case 2: .....
		break;
}

(I have not tried to give that to gcc 4.5.x to see how the resulting
assembly looks like. It would be interesting to see if it handles this
case well)

Thoughts ?

Thanks,

Mathieu

> 
> enable/disale via:
> 
> 	jump_label_enable(&jump_key);
> 	jump_label_disable(&jump_key);
> 
> that's it!
> 
> Thanks to H. Peter Anvin for suggesting the simpler 'unlikely_switch()'
> function.
> 
> thanks,
> 
> -Jason
> 
> 
> Jason Baron (2):
>   jump label: make enable/disable o(1)
>   jump label: introduce unlikely_switch()
> 
>  arch/x86/include/asm/jump_label.h |   22 +++--
>  arch/x86/kernel/jump_label.c      |    2 +-
>  include/linux/dynamic_debug.h     |   24 ++----
>  include/linux/jump_label.h        |   72 ++++++++++-------
>  include/linux/jump_label_ref.h    |   41 ++++++----
>  include/linux/perf_event.h        |   25 +++---
>  include/linux/tracepoint.h        |    8 +-
>  kernel/jump_label.c               |  159 ++++++++++++++++++++++++++++++-------
>  kernel/perf_event.c               |    4 +-
>  kernel/tracepoint.c               |   22 ++---
>  10 files changed, 243 insertions(+), 136 deletions(-)
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

  parent reply	other threads:[~2010-12-16 20:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-16 18:25 [PATCH/RFC 0/2] jump label: simplify API Jason Baron
2010-12-16 18:25 ` [PATCH/RFC 1/2] jump label: make enable/disable o(1) Jason Baron
2010-12-16 19:10   ` Peter Zijlstra
2010-12-16 19:23     ` Jason Baron
2010-12-16 19:33       ` Peter Zijlstra
2010-12-16 19:36         ` Jason Baron
2010-12-16 19:41           ` Peter Zijlstra
2010-12-16 19:48             ` Jason Baron
2010-12-16 20:09               ` Steven Rostedt
2010-12-16 20:36               ` Mathieu Desnoyers
2010-12-16 20:43                 ` Peter Zijlstra
2010-12-16 20:50                   ` Mathieu Desnoyers
2010-12-16 20:56                     ` Peter Zijlstra
2010-12-17 20:07                       ` Jason Baron
2010-12-17 20:51                         ` David Daney
2010-12-17 21:12                           ` Steven Rostedt
2010-12-17 21:32                             ` Jason Baron
2010-12-16 20:45               ` Mathieu Desnoyers
2010-12-16 18:25 ` [PATCH/RFC 2/2] jump label: introduce unlikely_switch() Jason Baron
2010-12-16 19:22 ` Mathieu Desnoyers [this message]
2010-12-16 20:18   ` [PATCH/RFC 0/2] jump label: simplify API Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101216192241.GA8239@Krystal \
    --to=mathieu.desnoyers@polymtl.ca \
    --cc=andi@firstfloor.org \
    --cc=avi@redhat.com \
    --cc=davem@davemloft.net \
    --cc=ddaney@caviumnetworks.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jbaron@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=michael@ellerman.id.au \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=roland@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=rth@redhat.com \
    --cc=sam@ravnborg.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox