[PATCH 3/3] sched/feat: Use the new static key API for sched_feat

From: Hongyan Xia

Date: Mon Jul 20 2026 - 05:51:36 EST


From: Hongyan Xia <hongyan.xia@xxxxxxxxxxxxx>

Both raw static keys and static_key_true/false() have been deprecated.
Migrate to new API.

It's a bit tricky to convert the sched_feat array to the new API because
the new one has two different types for true and false keys. Use a union
to wrap it. Still, I haven't found a good way to deal with the
sched_feat_enable/disable() sites in debug.c, so sadly they remain on
the old API.

No functional change.

Signed-off-by: Hongyan Xia <hongyan.xia@xxxxxxxxxxxxx>
---
kernel/sched/debug.c | 10 +++++-----
kernel/sched/sched.h | 19 ++++++++++++++-----
2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 40584b27ea0c..e3258faa80d5 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -73,13 +73,13 @@ static int sched_feat_show(struct seq_file *m, void *v)

#ifdef CONFIG_JUMP_LABEL

-#define jump_label_key__true STATIC_KEY_INIT_TRUE
-#define jump_label_key__false STATIC_KEY_INIT_FALSE
+#define jump_label_key__true { .key_true = STATIC_KEY_TRUE_INIT }
+#define jump_label_key__false { .key_false = STATIC_KEY_FALSE_INIT }

#define SCHED_FEAT(name, enabled) \
jump_label_key__##enabled ,

-struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
+union sched_feat_key sched_feat_keys[__SCHED_FEAT_NR] = {
#include "features.h"
};

@@ -87,12 +87,12 @@ struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {

static void sched_feat_disable(int i)
{
- static_key_disable_cpuslocked(&sched_feat_keys[i]);
+ static_key_disable_cpuslocked((struct static_key *)&sched_feat_keys[i]);
}

static void sched_feat_enable(int i)
{
- static_key_enable_cpuslocked(&sched_feat_keys[i]);
+ static_key_enable_cpuslocked((struct static_key *)&sched_feat_keys[i]);
}
#else /* !CONFIG_JUMP_LABEL: */
static void sched_feat_disable(int i) { };
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index b494e24efebb..abcf7d00bc5f 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2409,16 +2409,25 @@ extern __read_mostly unsigned int sysctl_sched_features;

#ifdef CONFIG_JUMP_LABEL

-#define SCHED_FEAT(name, enabled) \
-static __always_inline bool static_branch_##name(struct static_key *key) \
-{ \
- return static_key_##enabled(key); \
+union sched_feat_key {
+ struct static_key_true key_true;
+ struct static_key_false key_false;
+};
+
+#define sched_feat_branch_true(key) static_branch_likely(&(key)->key_true)
+#define sched_feat_branch_false(key) static_branch_unlikely(&(key)->key_false)
+
+#define SCHED_FEAT(name, enabled) \
+static __always_inline bool \
+static_branch_##name(union sched_feat_key *key) \
+{ \
+ return sched_feat_branch_##enabled(key); \
}

#include "features.h"
#undef SCHED_FEAT

-extern struct static_key sched_feat_keys[__SCHED_FEAT_NR];
+extern union sched_feat_key sched_feat_keys[__SCHED_FEAT_NR];
#define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]))

#else /* !CONFIG_JUMP_LABEL: */
--
2.47.3