Re: [PATCH] jump label: introduce static_branch() interface

From: Peter Zijlstra
Date: Wed Feb 23 2011 - 05:08:43 EST


On Tue, 2011-02-22 at 17:28 -0500, Jason Baron wrote:
>
> Define:
>
> struct jump_label_key jump_key;
>
> Can be used as:
>
> if (static_branch(&jump_key))
> do unlikely code
>
> enable/disale via:
>
> jump_label_enable(&jump_key);
> jump_label_disable(&jump_key);
>
> that's it!

I think you'll find jump_label_{inc,dec}() works better ;-)

Also the below cleans up a comment, flips a conditional so that we dno't
evaluate kernel_text_address() for entries we already know are dead and
uses notifier_from_errno() so as not to confuse the notifier code.

---
Index: linux-2.6/kernel/jump_label.c
===================================================================
--- linux-2.6.orig/kernel/jump_label.c
+++ linux-2.6/kernel/jump_label.c
@@ -108,10 +108,12 @@ static void __jump_label_update(struct j
struct jump_entry *entry, int enable)
{
for (; entry->key == (jump_label_t)(unsigned long)key; entry++) {
- /* entry->code set to 0 invalidates module init text sections
- * kernel_text_address() verifies we are not in core kernel init
- * code */
- if (kernel_text_address(entry->code) && entry->code)
+ /*
+ * entry->code set to 0 invalidates module init text sections
+ * kernel_text_address() verifies we are not in core kernel
+ * init code, see jump_label_invalidate_module_init().
+ */
+ if (entry->code && kernel_text_address(entry->code))
arch_jump_label_transform(entry, enable);
}
}
@@ -315,7 +317,8 @@ jump_label_module_notify(struct notifier
jump_label_unlock();
break;
}
- return ret;
+
+ return notifier_from_errno(ret);
}

struct notifier_block jump_label_module_nb = {

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