static keys: Introduce 'struct static_key',static_key_true()/false() and static_key_slow_[inc|dec]()

From: Ingo Molnar
Date: Fri Feb 24 2012 - 02:53:08 EST



* Ingo Molnar <mingo@xxxxxxx> wrote:

> * Ingo Molnar <mingo@xxxxxxx> 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.

So, below is the second version of my 'struct static_key' patch,
with the confusing very_likely()/very_unlikely() method renamed
to static_key_true()/static_key_false().

Thanks,

Ingo

-------------------->