jump label: Introduce static_branch() interface
[deliverable/linux.git] / include / linux / jump_label.h
CommitLineData
bf5438fc
JB
1#ifndef _LINUX_JUMP_LABEL_H
2#define _LINUX_JUMP_LABEL_H
3
d430d3d7
JB
4#include <linux/types.h>
5#include <linux/compiler.h>
6
45f81b1c 7#if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
d430d3d7
JB
8
9struct jump_label_key {
10 atomic_t enabled;
11 struct jump_entry *entries;
12#ifdef CONFIG_MODULES
13 struct jump_label_mod *next;
14#endif
15};
16
bf5438fc
JB
17# include <asm/jump_label.h>
18# define HAVE_JUMP_LABEL
19#endif
20
21enum jump_label_type {
d430d3d7 22 JUMP_LABEL_DISABLE = 0,
bf5438fc 23 JUMP_LABEL_ENABLE,
bf5438fc
JB
24};
25
26struct module;
27
28#ifdef HAVE_JUMP_LABEL
29
d430d3d7
JB
30#ifdef CONFIG_MODULES
31#define JUMP_LABEL_INIT {{ 0 }, NULL, NULL}
32#else
33#define JUMP_LABEL_INIT {{ 0 }, NULL}
34#endif
35
36static __always_inline bool static_branch(struct jump_label_key *key)
37{
38 return arch_static_branch(key);
39}
40
bf5438fc
JB
41extern struct jump_entry __start___jump_table[];
42extern struct jump_entry __stop___jump_table[];
43
91bad2f8
JB
44extern void jump_label_lock(void);
45extern void jump_label_unlock(void);
bf5438fc
JB
46extern void arch_jump_label_transform(struct jump_entry *entry,
47 enum jump_label_type type);
4c3ef6d7 48extern void arch_jump_label_text_poke_early(jump_label_t addr);
4c3ef6d7 49extern int jump_label_text_reserved(void *start, void *end);
d430d3d7
JB
50extern void jump_label_inc(struct jump_label_key *key);
51extern void jump_label_dec(struct jump_label_key *key);
52extern bool jump_label_enabled(struct jump_label_key *key);
53extern void jump_label_apply_nops(struct module *mod);
bf5438fc 54
d430d3d7 55#else
bf5438fc 56
d430d3d7 57#include <asm/atomic.h>
bf5438fc 58
d430d3d7 59#define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
bf5438fc 60
d430d3d7
JB
61struct jump_label_key {
62 atomic_t enabled;
63};
bf5438fc 64
d430d3d7
JB
65static __always_inline bool static_branch(struct jump_label_key *key)
66{
67 if (unlikely(atomic_read(&key->enabled)))
68 return true;
69 return false;
70}
bf5438fc 71
d430d3d7
JB
72static inline void jump_label_inc(struct jump_label_key *key)
73{
74 atomic_inc(&key->enabled);
75}
bf5438fc 76
d430d3d7 77static inline void jump_label_dec(struct jump_label_key *key)
bf5438fc 78{
d430d3d7 79 atomic_dec(&key->enabled);
bf5438fc
JB
80}
81
4c3ef6d7
JB
82static inline int jump_label_text_reserved(void *start, void *end)
83{
84 return 0;
85}
86
91bad2f8
JB
87static inline void jump_label_lock(void) {}
88static inline void jump_label_unlock(void) {}
89
d430d3d7
JB
90static inline bool jump_label_enabled(struct jump_label_key *key)
91{
92 return !!atomic_read(&key->enabled);
93}
bf5438fc 94
d430d3d7
JB
95static inline int jump_label_apply_nops(struct module *mod)
96{
97 return 0;
98}
99
100#endif
ebf31f50 101
bf5438fc 102#endif
This page took 0.09209 seconds and 5 git commands to generate.