|
|
Subscribe / Log in / New account

Jump label reworked

By Jonathan Corbet
March 30, 2011
The jump label mechanism was last seen here in October, 2010. In short, jump label allows the optimization of "highly unlikely" code branches to the point that their normal overhead is close to zero. This speedup is done with runtime code patching; that is also the cost: enabling or disabling the unlikely case is an expensive operation. Thus, jump label is best used for code which is almost never enabled; tracepoints and dynamic debugging statements are obvious cases.

There were a number of complaints about the initial jump label implementation, including the fact that it was somewhat awkward to use. In response, a reworked version has been posted which changes the interface considerably. One starts by declaring a "jump key":

    #include <linux/jump_label.h>

    struct jump_label_key my_key;

Enabling and disabling the key is a simple matter of calling:

    jump_label_inc(struct jump_label_key *key);
    jump_label_dec(struct jump_label_key *key);

And using the key to control the execution of rarely-needed code becomes:

    if (static_branch(&my_key)) {
	/* Unlikely stuff happens here */
    }

In the absence of full jump label support, a jump key is represented by an atomic_t value. jump_label_inc() becomes atomic_inc(), jump_label_dec() becomes atomic_dec(), and static_branch() is implemented with atomic_read(). If jump label is configured into the kernel, enabling and disabling a jump key become heavier operations, while static_branch() becomes nearly free. For the intended use cases for jump labels, that is a worthwhile tradeoff.

As of this writing, these changes have not been merged for 2.6.39. There is always a possibility that they could be pulled in before -rc2, but chances are that, at this point, the new jump label will have to jump into 2.6.40.

Index entries for this article
KernelJump label


to post comments

Jump label reworked

Posted Mar 31, 2011 0:46 UTC (Thu) by nevets (subscriber, #11875) [Link]

The jump label work is in the queue for .40 so do not expect to see this change in any of the .39-rc releases. After several rounds of review, we finally got something everyone was in agreement with, but this happened just before the merge window opened. As we have not had time to get the changes into linux-next (due to the constant churn of updating due to minor change suggestions by reviewers), that we decided to hold off a full release cycle.

Jump label reworked

Posted Mar 31, 2011 13:25 UTC (Thu) by jwessel (guest, #63702) [Link]

This is great news that this has a possibility of being merged.

At the point in time this is merged it opens the door for fixing a long standing problem with the kernel debugger which you can only change today at kernel compilation time. The problem is that of keeping the debugger out of any kind of hot or default path while not in use.

The prime example on x86 is in the trap code. To avoid the possibility of recursive faults in any notification code, all traps need to pass through the kernel debug core first. Today you turn on CONFIG_KGDB_LOW_LEVEL_TRAP or you could choose to "use the debugger _very_ carefully". The jump label interface would allow us to easily turn this behavior on and off based on if an end user turn on the kernel debugger at runtime.

If you take this a step further it might also be plausible to solve the age old problem of who gets called first when killing a system, kexec or the debugger because you cannot use a notifier in the hard fail path for reliability issues. Today you change the oops handler, or unconfigure kexec if you want the debugger (kgdb or kdb) to get called first.

Question: where is cyg_profile ?

Posted Mar 1, 2012 10:14 UTC (Thu) by razb (guest, #43424) [Link]

Does anyone knows how is the tracer implemented ? I saw the kernel compiles with -pg , but i cannot see the regular __cyg_profile enter and exit routines.

How do the callbacks are implemented ?


Copyright © 2011, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds