[PATCH v2] sched: Convert last bits of deprecated static key usage

From: Hongyan Xia

Date: Thu Sep 03 2026 - 09:06:15 EST


From: Hongyan Xia <hongyan.xia@xxxxxxxxxxxxx>

Raw static keys have no type information and do not prevent mis-matches
(like static_key_false() on a default TRUE key). The helper names
static_key_{true/false}() are also confusing, hence the deprecation.

We have already converted other sites in previous patches. Convert the
last sites of deprecated static key APIs. After this fix, scheduler code
has zero deprecated static key APIs now.

sk_dynamic_* uses static_key_{enable/disable}(), which aren't really
deprecated, but take the opportunity to move to the new static_branch_*
APIs to be consistent.

No functional change.

Signed-off-by: Hongyan Xia <hongyan.xia@xxxxxxxxxxxxx>
---
Changed in v2:
- Explain why old ones are deprecated.
- Rebase and fix a big conflict in core.c.

kernel/sched/core.c | 8 ++++----
kernel/sched/fair.c | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5a61650f12b7..792931f5ef13 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7881,8 +7881,8 @@ int sched_dynamic_mode(const char *str)
return -EINVAL;
}

-# define preempt_dynamic_key_enable(f) static_key_enable(&sk_dynamic_##f.key)
-# define preempt_dynamic_key_disable(f) static_key_disable(&sk_dynamic_##f.key)
+# define preempt_dynamic_branch_enable(f) static_branch_enable(&sk_dynamic_##f)
+# define preempt_dynamic_branch_disable(f) static_branch_disable(&sk_dynamic_##f)

static DEFINE_MUTEX(sched_dynamic_mutex);

@@ -7890,13 +7890,13 @@ static void __sched_dynamic_update(int mode)
{
switch (mode) {
case preempt_dynamic_full:
- preempt_dynamic_key_disable(preempt_lazy);
+ preempt_dynamic_branch_disable(preempt_lazy);
if (mode != preempt_dynamic_mode)
pr_info("Dynamic Preempt: full\n");
break;

case preempt_dynamic_lazy:
- preempt_dynamic_key_enable(preempt_lazy);
+ preempt_dynamic_branch_enable(preempt_lazy);
if (mode != preempt_dynamic_mode)
pr_info("Dynamic Preempt: lazy\n");
break;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index b8bd308c2d5b..d8abc940ab0f 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6575,21 +6575,21 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)
#ifdef CONFIG_CFS_BANDWIDTH

#ifdef CONFIG_JUMP_LABEL
-static struct static_key __cfs_bandwidth_used;
+static DEFINE_STATIC_KEY_FALSE(__cfs_bandwidth_used);

static inline bool cfs_bandwidth_used(void)
{
- return static_key_false(&__cfs_bandwidth_used);
+ return static_branch_unlikely(&__cfs_bandwidth_used);
}

void cfs_bandwidth_usage_inc(void)
{
- static_key_slow_inc_cpuslocked(&__cfs_bandwidth_used);
+ static_branch_inc_cpuslocked(&__cfs_bandwidth_used);
}

void cfs_bandwidth_usage_dec(void)
{
- static_key_slow_dec_cpuslocked(&__cfs_bandwidth_used);
+ static_branch_dec_cpuslocked(&__cfs_bandwidth_used);
}
#else /* !CONFIG_JUMP_LABEL: */
static bool cfs_bandwidth_used(void)
--
2.47.3