public inbox for rcu@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rcu: Align stall warning 'idle=' output with documentation
@ 2026-01-04  8:10 Donglin Peng
  2026-01-04 19:45 ` Joel Fernandes
  0 siblings, 1 reply; 5+ messages in thread
From: Donglin Peng @ 2026-01-04  8:10 UTC (permalink / raw)
  To: paulmck
  Cc: frederic, neeraj.upadhyay, joelagnelf, qiang.zhang, rostedt, rcu,
	linux-kernel, Donglin Peng

From: Donglin Peng <pengdonglin@xiaomi.com>

The RCU stall warning message includes an "idle=" field to indicate
the dyntick-idle state of a CPU. According to Documentation/RCU/stallwarn.rst,
the hexadecimal number before the first '/' represents the low-order 16
bits of the dynticks counter. An even value denotes that the CPU is in
dyntick-idle mode, while an odd value indicates otherwise.

This was accurate until commit 171476775d32 ("context_tracking: Convert state to atomic_t"),
which merged the context tracking state and the dynticks counter into a
single atomic value. Consequently, the value printed in the stall warning
no longer directly corresponds to the documented dynticks counter bits.

To restore consistency between the code's output and the documentation,
right-shift the merged atomic state value to extract and display the
correct low-order bits of the dynticks counter.

Fixes: 171476775d32 ("context_tracking: Convert state to atomic_t")
Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com>
---
 kernel/rcu/tree_stall.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
index b67532cb8770..d25cc826d77a 100644
--- a/kernel/rcu/tree_stall.h
+++ b/kernel/rcu/tree_stall.h
@@ -555,7 +555,7 @@ static void print_cpu_stall_info(int cpu)
 			rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
 				"!."[!delta],
 	       ticks_value, ticks_title,
-	       ct_rcu_watching_cpu(cpu) & 0xffff,
+	       (ct_rcu_watching_cpu(cpu) >> ilog2(CT_RCU_WATCHING)) & 0xffff,
 	       ct_nesting_cpu(cpu), ct_nmi_nesting_cpu(cpu),
 	       rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
 	       data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,
-- 
2.34.1


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

* Re: [PATCH] rcu: Align stall warning 'idle=' output with documentation
  2026-01-04  8:10 [PATCH] rcu: Align stall warning 'idle=' output with documentation Donglin Peng
@ 2026-01-04 19:45 ` Joel Fernandes
  2026-01-05  0:26   ` Zqiang
  0 siblings, 1 reply; 5+ messages in thread
From: Joel Fernandes @ 2026-01-04 19:45 UTC (permalink / raw)
  To: Donglin Peng
  Cc: paulmck, frederic, neeraj.upadhyay, qiang.zhang, rostedt, rcu,
	linux-kernel, Donglin Peng

On Sun, Jan 04, 2026 at 04:10:27PM +0800, Donglin Peng wrote:
> From: Donglin Peng <pengdonglin@xiaomi.com>
> 
> The RCU stall warning message includes an "idle=" field to indicate
> the dyntick-idle state of a CPU. According to Documentation/RCU/stallwarn.rst,
> the hexadecimal number before the first '/' represents the low-order 16
> bits of the dynticks counter. An even value denotes that the CPU is in
> dyntick-idle mode, while an odd value indicates otherwise.
> 
> This was accurate until commit 171476775d32 ("context_tracking: Convert state to atomic_t"),
> which merged the context tracking state and the dynticks counter into a
> single atomic value. Consequently, the value printed in the stall warning
> no longer directly corresponds to the documented dynticks counter bits.
> 
> To restore consistency between the code's output and the documentation,
> right-shift the merged atomic state value to extract and display the
> correct low-order bits of the dynticks counter.
> 
> Fixes: 171476775d32 ("context_tracking: Convert state to atomic_t")
> Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com>

Looks good to me! Also nice use of ilog2() which resolves to a single shift
right instruction per my testing (shift right of 2).

Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>

thanks,

 - Joel


> ---
>  kernel/rcu/tree_stall.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
> index b67532cb8770..d25cc826d77a 100644
> --- a/kernel/rcu/tree_stall.h
> +++ b/kernel/rcu/tree_stall.h
> @@ -555,7 +555,7 @@ static void print_cpu_stall_info(int cpu)
>  			rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
>  				"!."[!delta],
>  	       ticks_value, ticks_title,
> -	       ct_rcu_watching_cpu(cpu) & 0xffff,
> +	       (ct_rcu_watching_cpu(cpu) >> ilog2(CT_RCU_WATCHING)) & 0xffff,
>  	       ct_nesting_cpu(cpu), ct_nmi_nesting_cpu(cpu),
>  	       rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
>  	       data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,
> -- 
> 2.34.1
> 

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

* Re: [PATCH] rcu: Align stall warning 'idle=' output with documentation
  2026-01-04 19:45 ` Joel Fernandes
@ 2026-01-05  0:26   ` Zqiang
  2026-01-05  0:34     ` Joel Fernandes
  0 siblings, 1 reply; 5+ messages in thread
From: Zqiang @ 2026-01-05  0:26 UTC (permalink / raw)
  To: Joel Fernandes, Donglin Peng
  Cc: paulmck, frederic, neeraj.upadhyay, rostedt, rcu, linux-kernel,
	Donglin Peng

> 
> On Sun, Jan 04, 2026 at 04:10:27PM +0800, Donglin Peng wrote:
> 
> > 
> > From: Donglin Peng <pengdonglin@xiaomi.com>
> >  
> >  The RCU stall warning message includes an "idle=" field to indicate
> >  the dyntick-idle state of a CPU. According to Documentation/RCU/stallwarn.rst,
> >  the hexadecimal number before the first '/' represents the low-order 16
> >  bits of the dynticks counter. An even value denotes that the CPU is in
> >  dyntick-idle mode, while an odd value indicates otherwise.
> >  
> >  This was accurate until commit 171476775d32 ("context_tracking: Convert state to atomic_t"),
> >  which merged the context tracking state and the dynticks counter into a
> >  single atomic value. Consequently, the value printed in the stall warning
> >  no longer directly corresponds to the documented dynticks counter bits.
> >  
> >  To restore consistency between the code's output and the documentation,
> >  right-shift the merged atomic state value to extract and display the
> >  correct low-order bits of the dynticks counter.
> >  
> >  Fixes: 171476775d32 ("context_tracking: Convert state to atomic_t")
> >  Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com>
> > 
> Looks good to me! Also nice use of ilog2() which resolves to a single shift
> right instruction per my testing (shift right of 2).
> 
> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
> 
> thanks,
> 
>  - Joel
> 
> > 
> > ---
> >  kernel/rcu/tree_stall.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >  
> >  diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
> >  index b67532cb8770..d25cc826d77a 100644
> >  --- a/kernel/rcu/tree_stall.h
> >  +++ b/kernel/rcu/tree_stall.h
> >  @@ -555,7 +555,7 @@ static void print_cpu_stall_info(int cpu)
> >  rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
> >  "!."[!delta],
> >  ticks_value, ticks_title,
> >  - ct_rcu_watching_cpu(cpu) & 0xffff,
> >  + (ct_rcu_watching_cpu(cpu) >> ilog2(CT_RCU_WATCHING)) & 0xffff,



May be also use CT_RCU_WATCHING_START to
replace ilog2(CT_RCU_WATCHING) operations? (I didn't actually test it)

Thanks
Zqiang


> >  ct_nesting_cpu(cpu), ct_nmi_nesting_cpu(cpu),
> >  rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
> >  data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,
> >  -- 
> >  2.34.1
> >
>

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

* Re: [PATCH] rcu: Align stall warning 'idle=' output with documentation
  2026-01-05  0:26   ` Zqiang
@ 2026-01-05  0:34     ` Joel Fernandes
  2026-01-05  1:31       ` Donglin Peng
  0 siblings, 1 reply; 5+ messages in thread
From: Joel Fernandes @ 2026-01-05  0:34 UTC (permalink / raw)
  To: Zqiang
  Cc: Joel Fernandes, Donglin Peng, paulmck, frederic, neeraj.upadhyay,
	rostedt, rcu, linux-kernel, Donglin Peng

On Sun, Jan 4, 2026 at 7:32 PM Zqiang <qiang.zhang@linux.dev> wrote:
>
> >
> > On Sun, Jan 04, 2026 at 04:10:27PM +0800, Donglin Peng wrote:
> >
> > >
> > > From: Donglin Peng <pengdonglin@xiaomi.com>
> > >
> > >  The RCU stall warning message includes an "idle=" field to indicate
> > >  the dyntick-idle state of a CPU. According to Documentation/RCU/stallwarn.rst,
> > >  the hexadecimal number before the first '/' represents the low-order 16
> > >  bits of the dynticks counter. An even value denotes that the CPU is in
> > >  dyntick-idle mode, while an odd value indicates otherwise.
[...]
> > >  kernel/rcu/tree_stall.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > >  diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
> > >  index b67532cb8770..d25cc826d77a 100644
> > >  --- a/kernel/rcu/tree_stall.h
> > >  +++ b/kernel/rcu/tree_stall.h
> > >  @@ -555,7 +555,7 @@ static void print_cpu_stall_info(int cpu)
> > >  rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
> > >  "!."[!delta],
> > >  ticks_value, ticks_title,
> > >  - ct_rcu_watching_cpu(cpu) & 0xffff,
> > >  + (ct_rcu_watching_cpu(cpu) >> ilog2(CT_RCU_WATCHING)) & 0xffff,
>
>
>
> May be also use CT_RCU_WATCHING_START to
> replace ilog2(CT_RCU_WATCHING) operations? (I didn't actually test it)

It should compile down to the same thing, but either is fine with me.

thanks,

 - Joel

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

* Re: [PATCH] rcu: Align stall warning 'idle=' output with documentation
  2026-01-05  0:34     ` Joel Fernandes
@ 2026-01-05  1:31       ` Donglin Peng
  0 siblings, 0 replies; 5+ messages in thread
From: Donglin Peng @ 2026-01-05  1:31 UTC (permalink / raw)
  To: Joel Fernandes
  Cc: Zqiang, Joel Fernandes, paulmck, frederic, neeraj.upadhyay,
	rostedt, rcu, linux-kernel, Donglin Peng

On Mon, Jan 5, 2026 at 8:34 AM Joel Fernandes <joel@joelfernandes.org> wrote:
>
> On Sun, Jan 4, 2026 at 7:32 PM Zqiang <qiang.zhang@linux.dev> wrote:
> >
> > >
> > > On Sun, Jan 04, 2026 at 04:10:27PM +0800, Donglin Peng wrote:
> > >
> > > >
> > > > From: Donglin Peng <pengdonglin@xiaomi.com>
> > > >
> > > >  The RCU stall warning message includes an "idle=" field to indicate
> > > >  the dyntick-idle state of a CPU. According to Documentation/RCU/stallwarn.rst,
> > > >  the hexadecimal number before the first '/' represents the low-order 16
> > > >  bits of the dynticks counter. An even value denotes that the CPU is in
> > > >  dyntick-idle mode, while an odd value indicates otherwise.
> [...]
> > > >  kernel/rcu/tree_stall.h | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > >  diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
> > > >  index b67532cb8770..d25cc826d77a 100644
> > > >  --- a/kernel/rcu/tree_stall.h
> > > >  +++ b/kernel/rcu/tree_stall.h
> > > >  @@ -555,7 +555,7 @@ static void print_cpu_stall_info(int cpu)
> > > >  rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
> > > >  "!."[!delta],
> > > >  ticks_value, ticks_title,
> > > >  - ct_rcu_watching_cpu(cpu) & 0xffff,
> > > >  + (ct_rcu_watching_cpu(cpu) >> ilog2(CT_RCU_WATCHING)) & 0xffff,
> >
> >
> >
> > May be also use CT_RCU_WATCHING_START to
> > replace ilog2(CT_RCU_WATCHING) operations? (I didn't actually test it)

Thank you for the suggestion. I agree that using the CT_RCU_WATCHING_START
macro is cleaner. I will fix it in the next version.

I noted that the CT_RCU_WATCHING_START macro was introduced in
kernel version 6.19-rc1 by commit d1e6d2773898 ("rcu: Add a
small-width RCU watching counter debug option").
Therefore, if this patch needs to be backported to older kernel versions
that lack this macro, using ilog2(CT_RCU_WATCHING) would be the
simpler, more compatible approach.

>
> It should compile down to the same thing, but either is fine with me.
>
> thanks,
>
>  - Joel

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

end of thread, other threads:[~2026-01-05  1:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-04  8:10 [PATCH] rcu: Align stall warning 'idle=' output with documentation Donglin Peng
2026-01-04 19:45 ` Joel Fernandes
2026-01-05  0:26   ` Zqiang
2026-01-05  0:34     ` Joel Fernandes
2026-01-05  1:31       ` Donglin Peng

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