mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] sched: Convert last bits of deprecated static key usage
@ 2026-09-03 11:57 Hongyan Xia
  2026-10-06 10:50 ` Valentin Schneider
  0 siblings, 1 reply; 4+ messages in thread
From: Hongyan Xia @ 2026-09-03 11:57 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak
  Cc: Jiazi Li, linux-kernel

From: Hongyan Xia <hongyan.xia@transsion.com>

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@transsion.com>
---
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched: Convert last bits of deprecated static key usage
  2026-09-03 11:57 [PATCH v2] sched: Convert last bits of deprecated static key usage Hongyan Xia
@ 2026-10-06 10:50 ` Valentin Schneider
  2026-10-06 11:01   ` Valentin Schneider
  2026-10-08  1:53   ` Hongyan Xia
  0 siblings, 2 replies; 4+ messages in thread
From: Valentin Schneider @ 2026-10-06 10:50 UTC (permalink / raw)
  To: Hongyan Xia, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, K Prateek Nayak
  Cc: Jiazi Li, linux-kernel

On 03/09/26 11:57, Hongyan Xia wrote:
> From: Hongyan Xia <hongyan.xia@transsion.com>
>
> 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@transsion.com>

Some comprehension/changelog explanation nit below, otherwise:

Reviewed-by: Valentin Schneider <vschneid@redhat.com>

> @@ -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);
>  }

Usual likely/unlikely/true/false static key confusion for me here;

The previous definition was pretty much
 = STATIC_KEY_INIT_FALSE
due to static storage initialization.

And then for the static_key_*() naming, false == unlikely.

Because it's all #define magic I assume the compilation delta will be zero,
but I can't be bothered given I'm on a laptop running power saver mode.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched: Convert last bits of deprecated static key usage
  2026-10-06 10:50 ` Valentin Schneider
@ 2026-10-06 11:01   ` Valentin Schneider
  2026-10-08  1:53   ` Hongyan Xia
  1 sibling, 0 replies; 4+ messages in thread
From: Valentin Schneider @ 2026-10-06 11:01 UTC (permalink / raw)
  To: Hongyan Xia, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, K Prateek Nayak
  Cc: Jiazi Li, linux-kernel

On 06/10/26 12:50, Valentin Schneider wrote:
> On 03/09/26 11:57, Hongyan Xia wrote:
>> From: Hongyan Xia <hongyan.xia@transsion.com>
>>
>> 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@transsion.com>
>
> Some comprehension/changelog explanation nit below, otherwise:
>
> Reviewed-by: Valentin Schneider <vschneid@redhat.com>
>

A quick search tells me there's still some static_key() usage spread
through the kernel, that really should be fixed in a single series powered
by coccinelle or somesuch.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched: Convert last bits of deprecated static key usage
  2026-10-06 10:50 ` Valentin Schneider
  2026-10-06 11:01   ` Valentin Schneider
@ 2026-10-08  1:53   ` Hongyan Xia
  1 sibling, 0 replies; 4+ messages in thread
From: Hongyan Xia @ 2026-10-08  1:53 UTC (permalink / raw)
  To: Valentin Schneider, Ingo Molnar, Peter Zijlstra, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, K Prateek Nayak
  Cc: Jiazi Li, linux-kernel

On 10/6/2026 6:50 PM, Valentin Schneider wrote:
> On 03/09/26 11:57, Hongyan Xia wrote:
>> From: Hongyan Xia <hongyan.xia@transsion.com>
>>
>> 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@transsion.com>
> 
> Some comprehension/changelog explanation nit below, otherwise:
> 
> Reviewed-by: Valentin Schneider <vschneid@redhat.com>
> 
>> @@ -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);
>>   }
> 
> Usual likely/unlikely/true/false static key confusion for me here;
> 
> The previous definition was pretty much
>   = STATIC_KEY_INIT_FALSE
> due to static storage initialization.
> 
> And then for the static_key_*() naming, false == unlikely.
> 
> Because it's all #define magic I assume the compilation delta will be zero,
> but I can't be bothered given I'm on a laptop running power saver mode.

This is exactly what I checked before sending this patch. The good news 
is that at least on my machine, the delta in the machine code is zero 
under aarch64 and x86.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-08  1:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-03 11:57 [PATCH v2] sched: Convert last bits of deprecated static key usage Hongyan Xia
2026-10-06 10:50 ` Valentin Schneider
2026-10-06 11:01   ` Valentin Schneider
2026-10-08  1:53   ` Hongyan Xia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®