Remove deprecated static key API in scheduler code
cover Remove deprecated static key API in scheduler code
From: Hongyan Xia <[email protected]>
While working on something static-key-related I noticed we still have a few sites calling the deprecated static key APIs. The old API with name static_key_true and static_key_false are also super confusing. Move all of them to the new API.
The first two are straightforward. The 3rd one is tricky and needs more review. After this series, all deprecated APIs are gone except two lines of code in SCHED_FEAT.
No functional change intended for the entire series.
Hongyan Xia (3):
sched/fair: Move __cfs_bandwidth_used to new static key API
sched: Convert paravirt_steal to new static key APIs sched/feat: Use the new static key API for sched_feat
arch/arm64/kernel/paravirt.c | 4 ++-- arch/loongarch/kernel/paravirt.c | 4 ++-- arch/powerpc/platforms/pseries/setup.c | 4 ++-- arch/riscv/kernel/paravirt.c | 4 ++-- arch/x86/kernel/cpu/vmware.c | 4 ++-- arch/x86/kernel/kvm.c | 4 ++-- drivers/xen/time.c | 4 ++-- include/linux/sched/cputime.h | 6 +++--- kernel/sched/core.c | 4 ++-- kernel/sched/cputime.c | 4 ++-- kernel/sched/debug.c | 10 +++++----- kernel/sched/fair.c | 8 ++++---- kernel/sched/sched.h | 19 ++++++++++++++----- 13 files changed, 44 insertions(+), 35 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/3 sched/fair: Move __cfs_bandwidth_used to new static key API
From: Hongyan Xia <[email protected]>
Using struct static_key directly is deprecated. Fix.
No functional change.
--- kernel/sched/fair.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/sched/fair.c +4 -4
@@ -6442,21 +6442,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 )
Signature · 1 line
2.47.3
Re: [PATCH 1/3] sched/fair: Move __cfs_bandwidth_used to new static key API
Quoted 7 lines · Hongyan Xia
From: Hongyan Xia <[email protected]>
Using struct
static_keydirectly is deprecated. Fix.No functional change.
Signed-off-by Hongyan Xia <[email protected]>
Quoted 34 lines
--- kernel/sched/fair.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)kernel/sched/fair.c +4
-4@@ -6442,21 +6442,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 )
PATCH 2/3 sched: Convert paravirt_steal to new static key APIs
In reply to Hongyan XiaFrom: Hongyan Xia <[email protected]>
paravirt_steal_rq_enabled and paravirt_steal_enabled use raw static_key APIs which are now deprecated. Use the new API instead.
No functional change.
--- arch/arm64/kernel/paravirt.c | 4 ++-- arch/loongarch/kernel/paravirt.c | 4 ++-- arch/powerpc/platforms/pseries/setup.c | 4 ++-- arch/riscv/kernel/paravirt.c | 4 ++-- arch/x86/kernel/cpu/vmware.c | 4 ++-- arch/x86/kernel/kvm.c | 4 ++-- drivers/xen/time.c | 4 ++-- include/linux/sched/cputime.h | 6 +++--- kernel/sched/core.c | 4 ++-- kernel/sched/cputime.c | 4 ++-- 10 files changed, 21 insertions(+), 21 deletions(-)
arch/arm64/kernel/paravirt.c +2 -2
@@ -157,9 +157,9 @@ int __init pv_time_init(void)static_call_update (pv_steal_clock, para_steal_clock); -static_key_slow_inc (¶virt_steal_enabled); +static_branch_inc (¶virt_steal_enabled);if (steal_acc) -static_key_slow_inc (¶virt_steal_rq_enabled); +static_branch_inc (¶virt_steal_rq_enabled);pr_info ("using stolen time PV\n" );
arch/loongarch/kernel/paravirt.c +2 -2
@@ -308,10 +308,10 @@ int __init pv_time_init(void)static_call_update (pv_steal_clock, paravt_steal_clock); -static_key_slow_inc (¶virt_steal_enabled); +static_branch_inc (¶virt_steal_enabled);#ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING if (steal_acc) -static_key_slow_inc (¶virt_steal_rq_enabled); +static_branch_inc (¶virt_steal_rq_enabled);#endif if (static_key_enabled (&virt_preempt_key))
arch/powerpc/platforms/pseries/setup.c +2 -2
@@ -852,9 +852,9 @@ static void __init pSeries_setup_arch(void)static_branch_enable (&shared_processor);pv_spinlocks_init ();#ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING -static_key_slow_inc (¶virt_steal_enabled); +static_branch_inc (¶virt_steal_enabled);if (steal_acc) -static_key_slow_inc (¶virt_steal_rq_enabled); +static_branch_inc (¶virt_steal_rq_enabled);#endif }
arch/riscv/kernel/paravirt.c +2 -2
@@ -116,9 +116,9 @@ int __init pv_time_init(void)static_call_update (pv_steal_clock, pv_time_steal_clock); -static_key_slow_inc (¶virt_steal_enabled); +static_branch_inc (¶virt_steal_enabled);if (steal_acc) -static_key_slow_inc (¶virt_steal_rq_enabled); +static_branch_inc (¶virt_steal_rq_enabled);pr_info ("Computing paravirt steal-time\n" );
arch/x86/kernel/cpu/vmware.c +2 -2
@@ -328,9 +328,9 @@ static int vmware_cpu_down_prepare(unsigned int cpu)static __init int activate_jump_labels (void ) {if (has_steal_clock) { -static_key_slow_inc (¶virt_steal_enabled); +static_branch_inc (¶virt_steal_enabled);if (steal_acc) -static_key_slow_inc (¶virt_steal_rq_enabled); +static_branch_inc (¶virt_steal_rq_enabled); }return 0 ;
arch/x86/kernel/kvm.c +2 -2
@@ -1052,9 +1052,9 @@ const __initconst struct hypervisor_x86 x86_hyper_kvm = {static __init int activate_jump_labels (void ) {if (has_steal_clock) { -static_key_slow_inc (¶virt_steal_enabled); +static_branch_inc (¶virt_steal_enabled);if (steal_acc) -static_key_slow_inc (¶virt_steal_rq_enabled); +static_branch_inc (¶virt_steal_rq_enabled); }return 0 ;
drivers/xen/time.c +2 -2
@@ -169,7 +169,7 @@ void __init xen_time_setup_guest(void)static_call_update (pv_steal_clock, xen_steal_clock); -static_key_slow_inc (¶virt_steal_enabled); +static_branch_inc (¶virt_steal_enabled);if (xen_runstate_remote) -static_key_slow_inc (¶virt_steal_rq_enabled); +static_branch_inc (¶virt_steal_rq_enabled); }
include/linux/sched/cputime.h +3 -3
@@ -182,9 +182,9 @@ extern unsigned long long task_sched_runtime(struct task_struct *task);#ifdef CONFIG_PARAVIRT -struct static_key ; -extern struct static_key paravirt_steal_enabled; -extern struct static_key paravirt_steal_rq_enabled; +#include <linux/jump_label.h> +DECLARE_STATIC_KEY_FALSE (paravirt_steal_enabled); +DECLARE_STATIC_KEY_FALSE (paravirt_steal_rq_enabled);#ifdef CONFIG_HAVE_PV_STEAL_CLOCK_GEN u64 dummy_steal_clock (int cpu);
kernel/sched/core.c +2 -2
@@ -795,7 +795,7 @@ struct rq *_task_rq_lock(struct task_struct *p, struct rq_flags *rf)/* Use CONFIG_PARAVIRT as this will avoid more #ifdef in arch code. */ #ifdef CONFIG_PARAVIRT -struct static_key paravirt_steal_rq_enabled; +DEFINE_STATIC_KEY_FALSE (paravirt_steal_rq_enabled);#endif static void update_rq_clock_task (struct rq *rq,s64 delta)
@@ -834,7 +834,7 @@ static void update_rq_clock_task(struct rq *rq, s64 delta) }#endif #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING -if (static_key_false ((¶virt_steal_rq_enabled))) { +if (static_branch_unlikely (¶virt_steal_rq_enabled)) {u64 prev_steal; steal = prev_steal =paravirt_steal_clock (cpu_of (rq));
kernel/sched/cputime.c +2 -2
@@ -255,7 +255,7 @@ void __account_forceidle_time(struct task_struct *p, u64 delta)* occasion account more time than the calling functions think elapsed. */ #ifdef CONFIG_PARAVIRT -struct static_key paravirt_steal_enabled; +DEFINE_STATIC_KEY_FALSE (paravirt_steal_enabled);#ifdef CONFIG_HAVE_PV_STEAL_CLOCK_GEN static u64 native_steal_clock (int cpu)
@@ -270,7 +270,7 @@ DEFINE_STATIC_CALL(pv_steal_clock, native_steal_clock); static __always_inline u64 steal_account_process_time(u64 maxtime) {#ifdef CONFIG_PARAVIRT -if (static_key_false (¶virt_steal_enabled)) { +if (static_branch_unlikely (¶virt_steal_enabled)) {u64 steal; steal =paravirt_steal_clock (smp_processor_id ());
Signature · 1 line
2.47.3
Re: [PATCH 2/3] sched: Convert paravirt_steal to new static key APIs
Quoted 8 lines · Hongyan Xia
From: Hongyan Xia <[email protected]>
paravirt_steal_rq_enabledandparavirt_steal_enableduse rawstatic_keyAPIs which are now deprecated. Use the new API instead.No functional change.
Signed-off-by Hongyan Xia <[email protected]>
Juergen
PATCH 3/3 sched/feat: Use the new static key API for sched_feat
In reply to Hongyan XiaFrom: Hongyan Xia <[email protected]>
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.
--- kernel/sched/debug.c | 10 +++++----- kernel/sched/sched.h | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-)
kernel/sched/debug.c +5 -5
@@ -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) { };
kernel/sched/sched.h +14 -5
@@ -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: */
Signature · 1 line
2.47.3
This patch was applied to riscv/linux.git (fixes) by Peter Zijlstra <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Peter Zijlstra <[email protected]>:
Quoted 8 lines · On Mon, 20 Jul 2026 09:38:02 +0000 you wrote:
From: Hongyan Xia <[email protected]>
While working on something static-key-related I noticed we still have a few sites calling the deprecated static key APIs. The old API with name
static_key_trueandstatic_key_falseare also super confusing. Move all of them to the new API.[...]
Here is the summary with links:
- [2/3] sched: Convert paravirt_steal to new static key APIs
https://git.kernel.org/riscv/c/a5576ebce920
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html