The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sched/core: initialize resched_latency in sched_tick()
@ 2026-03-17 19:58 Joseph Salisbury
  2026-03-17 21:09 ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph Salisbury @ 2026-03-17 19:58 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel

sched_tick() only assigns resched_latency when the LATENCY_WARN feature is
enabled, but tests the variable later in a separate feature check.

That leaves the code dependent on both checks observing identical state.
Initializing resched_latency to zero makes the later test safe even if the
feature state changes between the two checks.

This does not change behavior when LATENCY_WARN is enabled. It only avoids
using an uninitialized local value.

Fixes: c006fac556e4 ("sched: Warn on long periods of pending need_resched")
Cc: stable@vger.kernel.org
Assisted-by: Codex:GPT-5
Signed-off-by: Joseph Salisbury <joseph.salisbury@oracle.com>
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 08a06162dd9a..15916186e4ff 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5548,7 +5548,7 @@ void sched_tick(void)
 	struct task_struct *donor;
 	struct rq_flags rf;
 	unsigned long hw_pressure;
-	u64 resched_latency;
+	u64 resched_latency = 0;
 
 	if (housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE))
 		arch_scale_freq_tick();
-- 
2.47.3

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

* Re: [PATCH] sched/core: initialize resched_latency in sched_tick()
  2026-03-17 19:58 [PATCH] sched/core: initialize resched_latency in sched_tick() Joseph Salisbury
@ 2026-03-17 21:09 ` Steven Rostedt
  2026-03-18  6:30   ` Shrikanth Hegde
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2026-03-17 21:09 UTC (permalink / raw)
  To: Joseph Salisbury
  Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Ben Segall, Mel Gorman, Valentin Schneider,
	linux-kernel

On Tue, 17 Mar 2026 15:58:07 -0400
Joseph Salisbury <joseph.salisbury@oracle.com> wrote:

> sched_tick() only assigns resched_latency when the LATENCY_WARN feature is
> enabled, but tests the variable later in a separate feature check.
> 
> That leaves the code dependent on both checks observing identical state.
> Initializing resched_latency to zero makes the later test safe even if the
> feature state changes between the two checks.
> 
> This does not change behavior when LATENCY_WARN is enabled. It only avoids
> using an uninitialized local value.
> 
> Fixes: c006fac556e4 ("sched: Warn on long periods of pending need_resched")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:GPT-5
> Signed-off-by: Joseph Salisbury <joseph.salisbury@oracle.com>
> ---
>  kernel/sched/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 08a06162dd9a..15916186e4ff 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -5548,7 +5548,7 @@ void sched_tick(void)
>  	struct task_struct *donor;
>  	struct rq_flags rf;
>  	unsigned long hw_pressure;
> -	u64 resched_latency;
> +	u64 resched_latency = 0;
>  
>  	if (housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE))
>  		arch_scale_freq_tick();

The code has:

	if (sched_feat(LATENCY_WARN))
		resched_latency = cpu_resched_latency(rq);
	calc_global_load_tick(rq);
	sched_core_tick(rq);
	scx_tick(rq);

	rq_unlock(rq, &rf);

	if (sched_feat(LATENCY_WARN) && resched_latency)
		resched_latency_warn(cpu, resched_latency);


I guess if LATENCY_WARN gets enabled between the first check and the
second, then the resched_latency could be uninitialized.

Heck, probably could even get rid of the second sched_feat(LATENCY_WARN),
and make it simply:

	if (resched_latency)

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve

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

* Re: [PATCH] sched/core: initialize resched_latency in sched_tick()
  2026-03-17 21:09 ` Steven Rostedt
@ 2026-03-18  6:30   ` Shrikanth Hegde
  2026-03-18 14:48     ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Shrikanth Hegde @ 2026-03-18  6:30 UTC (permalink / raw)
  To: Steven Rostedt, Peter Zijlstra, Joseph Salisbury, Ingo Molnar
  Cc: Juri Lelli, Vincent Guittot, Dietmar Eggemann, Ben Segall,
	Mel Gorman, Valentin Schneider, linux-kernel

Hi.

> 
> The code has:
> 
> 	if (sched_feat(LATENCY_WARN))
> 		resched_latency = cpu_resched_latency(rq);
> 	calc_global_load_tick(rq);
> 	sched_core_tick(rq);
> 	scx_tick(rq);
> 
> 	rq_unlock(rq, &rf);
> 
> 	if (sched_feat(LATENCY_WARN) && resched_latency)
> 		resched_latency_warn(cpu, resched_latency);
> 
> 
> I guess if LATENCY_WARN gets enabled between the first check and the
> second, then the resched_latency could be uninitialized.
> 
> Heck, probably could even get rid of the second sched_feat(LATENCY_WARN),
> and make it simply:
> 
> 	if (resched_latency)
> 
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> 
> -- Steve

Whats the relevance of resched_latency warnings in the age of preempt
kernels being the default for majority of the archs.

In case of full/lazy preemption, at the end of sched_tick itself we would call
schedule if need_resched is set provided it was preemptible.

It kind of makes sense for non preemptive kernels. But we have preemptoff and
preemptirqoff tracers which one could use. (although may need a kernel build)

What bugs is it catching these days?

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

* Re: [PATCH] sched/core: initialize resched_latency in sched_tick()
  2026-03-18  6:30   ` Shrikanth Hegde
@ 2026-03-18 14:48     ` Steven Rostedt
  2026-03-18 14:53       ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2026-03-18 14:48 UTC (permalink / raw)
  To: Shrikanth Hegde
  Cc: Peter Zijlstra, Joseph Salisbury, Ingo Molnar, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel

On Wed, 18 Mar 2026 12:00:58 +0530
Shrikanth Hegde <sshegde@linux.ibm.com> wrote:

> Whats the relevance of resched_latency warnings in the age of preempt
> kernels being the default for majority of the archs.
> 
> In case of full/lazy preemption, at the end of sched_tick itself we would call
> schedule if need_resched is set provided it was preemptible.
> 
> It kind of makes sense for non preemptive kernels. But we have preemptoff and
> preemptirqoff tracers which one could use. (although may need a kernel build)
> 
> What bugs is it catching these days?

Good point. I've never used it. I guess the question is, does anyone?

-- Steve

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

* Re: [PATCH] sched/core: initialize resched_latency in sched_tick()
  2026-03-18 14:48     ` Steven Rostedt
@ 2026-03-18 14:53       ` Peter Zijlstra
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2026-03-18 14:53 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Shrikanth Hegde, Joseph Salisbury, Ingo Molnar, Juri Lelli,
	Vincent Guittot, Dietmar Eggemann, Ben Segall, Mel Gorman,
	Valentin Schneider, linux-kernel

On Wed, Mar 18, 2026 at 10:48:26AM -0400, Steven Rostedt wrote:
> On Wed, 18 Mar 2026 12:00:58 +0530
> Shrikanth Hegde <sshegde@linux.ibm.com> wrote:
> 
> > Whats the relevance of resched_latency warnings in the age of preempt
> > kernels being the default for majority of the archs.
> > 
> > In case of full/lazy preemption, at the end of sched_tick itself we would call
> > schedule if need_resched is set provided it was preemptible.
> > 
> > It kind of makes sense for non preemptive kernels. But we have preemptoff and
> > preemptirqoff tracers which one could use. (although may need a kernel build)
> > 
> > What bugs is it catching these days?
> 
> Good point. I've never used it. I guess the question is, does anyone?

Google added that, Ben are you guys still needing that?

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

end of thread, other threads:[~2026-03-18 15:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 19:58 [PATCH] sched/core: initialize resched_latency in sched_tick() Joseph Salisbury
2026-03-17 21:09 ` Steven Rostedt
2026-03-18  6:30   ` Shrikanth Hegde
2026-03-18 14:48     ` Steven Rostedt
2026-03-18 14:53       ` Peter Zijlstra

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