By Jonathan Corbet
February 29, 2012
The facility formerly known as
jump labels
is designed to minimize the cost of rarely-used features in the kernel.
The classic example is tracepoints, which are turned off almost all of the
time. Ideally, the overhead of a disabled tracepoint would be zero, or
something very close to it. Jump labels (now "static keys") use runtime
code modification to patch unused features out of the code path entirely
until somebody turns them on.
With Ingo Molnar's encouragement, Jason Baron recently posted a patch set changing the jump label mechanism
to look like this:
if (very_unlikely(&jump_label_key)) {
/* Rarely-used code appears here */
}
A number of reviewers complained, saying that very_unlikely()
looks like just a stronger form of the unlikely() macro, which
works in a different way. Ingo responded
that the resemblance was not coincidental and made sense, but he made few
converts. After arguing the point for a while, Ingo gave in to the inevitable and stopped pushing
for the very_unlikely() name.
Instead, we have yet another format for jump labels, as described in this document. A jump label
static key is defined with one of:
struct static_key key = STATIC_KEY_INIT_FALSE;
struct static_key key = STATIC_KEY_INIT_TRUE;
The initial value should match the normal operational setting - the one
that should be fast. Testing of static keys is done with:
if (static_key_false(&key)) {
/* Unlikely code here */
}
Note that static_key_false() can only be used with a key
initialized with STATIC_KEY_INIT_FALSE; for default-true keys,
static_key_true() must be used instead. To make a key true, pass
it to static_key_slow_inc(); removing a reference to a key (and
possibly making it false) is done with static_key_slow_dec().
This version of the change was rather less controversial and, presumably,
will find its way in through the 3.4 merge window. After that, one
assumes, this mechanism will not be reworked again for at least a
development cycle or two.
(
Log in to post comments)