lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20120224153537.GB2395@redhat.com>
Date:	Fri, 24 Feb 2012 10:35:37 -0500
From:	Jason Baron <jbaron@...hat.com>
To:	Ingo Molnar <mingo@...e.hu>
Cc:	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Paul Mackerras <paulus@...ba.org>,
	"H. Peter Anvin" <hpa@...or.com>,
	Steven Rostedt <rostedt@...dmis.org>, a.p.zijlstra@...llo.nl,
	davem@...emloft.net, ddaney.cavm@...il.com,
	akpm@...ux-foundation.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 00/10] jump label: introduce very_[un]likely + cleanups +
 docs

On Fri, Feb 24, 2012 at 10:08:11AM +0100, Ingo Molnar wrote:
> * Jason Baron <jbaron@...hat.com> wrote:
> 
> > On Thu, Feb 23, 2012 at 06:18:42PM -0500, Mathieu Desnoyers wrote:
> > > * Ingo Molnar (mingo@...e.hu) wrote:
> > > > 
> > > > * Ingo Molnar <mingo@...e.hu> wrote:
> > > > 
> > > > > So, a modified scheme would be:
> > > > > 
> > > > >         #include <linux/static_key.h>
> > > > > 
> > > > >         struct static_key key = STATIC_KEY_INIT_TRUE;
> > > > > 
> > > > >         if (static_key_false(&key))
> > > > >                 do unlikely code
> > > > >         else
> > > > >                 do likely code
> > > > > 
> > > > > Or:
> > > > > 
> > > > >         if (static_key_true(&key))
> > > > >                 do likely code
> > > > >         else
> > > > >                 do unlikely code
> > > > > 
> > > > > The static key is modified via:
> > > > > 
> > > > >         static_key_slow_inc(&key);
> > > > >         ...
> > > > >         static_key_slow_dec(&key);
> > > > > 
> > > > > Is that API fine? I'll rework the series to such an effect if 
> > > > > everyone agrees.
> > > > 
> > > > I.e. something like the patch below on top of 
> > > > tip:perf/jump-labels.
> > > > 
> > > > Untested - will test it and will refactor the series if 
> > > > everyone's happy.
> > > 
> > > Hi Ingo,
> > > 
> > > Reading your documentation updates makes me realise that adding the
> > > "inline" keyword in there would make the whole thing even clearer:
> > > 
> > > struct static_key key = STATIC_KEY_INLINE_TRUE_INIT;
> > > struct static_key key = STATIC_KEY_INLINE_FALSE_INIT;
> > > 
> > > static_key_inline_true() / static_key_inline_false()
> > > 
> > > to show that the "true/false" in there does not mean that the key will
> > > always be true or false (the key value can indeed by changed by calling
> > > static_key_slow_inc/dec), but that the inlined path is either the true
> > > of false branch.
> > > 
> > 
> > Also, as part of the API, there is a test to check the branch 
> > direction - which was 'jump_label_true(key)', but is now also 
> > 'static_key_true(key)', [...]
> 
> Yeah, there is such an overlap - I've renamed it to 
> static_key_enabled(), which makes sense anyway as the original 
> was jump_label_enabled()..
> 
> Btw., shouldnt it be an inline function? Currently it's:
> 

Yes. I've had thought that too. In fact, it is already 'static inline' for the
!JUMP_LABEL case. So we can probably just remove the function from the
.c and move the 'static inline' such that its defined for all cases.

> bool static_key_enabled(struct static_key *key)
> {
>         return (atomic_read(&key->enabled) > 0);
> }
> 
> which is the perfect candidate for inlining. The difference to 
> static_key_true() is the lack of the jump label patching and the 
> lack of an unlikely() hint.
> 
> > [...] so we are going to have to change either the branch site 
> > or the test for true/false name. The above 
> > 'static_key_inline_true/false' solves that.
> 
> It's generally good practice to make the mostly commonly used 
> method names the simplest/shortest names - i.e. I don't think we 
> should make it longer via adding an _inline to every use.
> 
> In that sense static_key_true() has pretty optimal length - we'd 
> like these tests to also be visually unintrusive.
> 
> So in the latest patch (still under testing, will push it out 
> soon) we have:
> 
> 	static_key_true()
> 	static_key_false()
> 	static_key_enabled()
> 

Ok. Looks good. 

Acked-by: Jason Baron <jbaron@...hat.com>

Thanks,

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ