Skip to content

Commit ef0da55

Browse files
ctmarinaswildea01
authored andcommitted
jump_labels: Allow array initialisers
The static key API is currently designed around single variable definitions. There are cases where an array of static keys is desirable, so extend the API to allow this rather than using the internal static key implementation directly. Cc: Jason Baron <[email protected]> Cc: Jonathan Corbet <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Suggested-by: Dave P Martin <[email protected]> Signed-off-by: Catalin Marinas <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent dae8c23 commit ef0da55

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Documentation/static-keys.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The updated API replacements are:
1515

1616
DEFINE_STATIC_KEY_TRUE(key);
1717
DEFINE_STATIC_KEY_FALSE(key);
18+
DEFINE_STATIC_KEY_ARRAY_TRUE(keys, count);
19+
DEFINE_STATIC_KEY_ARRAY_FALSE(keys, count);
1820
static_branch_likely()
1921
static_branch_unlikely()
2022

@@ -140,6 +142,13 @@ static_branch_inc(), will change the branch back to true. Likewise, if the
140142
key is initialized false, a 'static_branch_inc()', will change the branch to
141143
true. And then a 'static_branch_dec()', will again make the branch false.
142144

145+
Where an array of keys is required, it can be defined as:
146+
147+
DEFINE_STATIC_KEY_ARRAY_TRUE(keys, count);
148+
149+
or:
150+
151+
DEFINE_STATIC_KEY_ARRAY_FALSE(keys, count);
143152

144153
4) Architecture level code patching interface, 'jump labels'
145154

include/linux/jump_label.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*
2222
* DEFINE_STATIC_KEY_TRUE(key);
2323
* DEFINE_STATIC_KEY_FALSE(key);
24+
* DEFINE_STATIC_KEY_ARRAY_TRUE(keys, count);
25+
* DEFINE_STATIC_KEY_ARRAY_FALSE(keys, count);
2426
* static_branch_likely()
2527
* static_branch_unlikely()
2628
*
@@ -270,6 +272,16 @@ struct static_key_false {
270272
#define DEFINE_STATIC_KEY_FALSE(name) \
271273
struct static_key_false name = STATIC_KEY_FALSE_INIT
272274

275+
#define DEFINE_STATIC_KEY_ARRAY_TRUE(name, count) \
276+
struct static_key_true name[count] = { \
277+
[0 ... (count) - 1] = STATIC_KEY_TRUE_INIT, \
278+
}
279+
280+
#define DEFINE_STATIC_KEY_ARRAY_FALSE(name, count) \
281+
struct static_key_false name[count] = { \
282+
[0 ... (count) - 1] = STATIC_KEY_FALSE_INIT, \
283+
}
284+
273285
extern bool ____wrong_branch_error(void);
274286

275287
#define static_key_enabled(x) \

0 commit comments

Comments
 (0)