Linux Trace Kernel
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: Puranjay Mohan <puranjay12@gmail.com>
Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
	Joel Fernandes <joelagnelf@nvidia.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Boqun Feng <boqun@kernel.org>,
	Uladzislau Rezki <urezki@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Zqiang <qiang.zhang@linux.dev>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Breno Leitao <leitao@debian.org>
Subject: Re: [PATCH v1 10/11] rcu: Advance callbacks for expedited GP completion in rcu_core()
Date: Mon, 17 Aug 2026 16:12:18 +0200	[thread overview]
Message-ID: <aoMWwva-MkA-OHkp@localhost.localdomain> (raw)
In-Reply-To: <CANk7y0g24_wj+PUKSRdkrCqY2P1tQ=5JxbWYZbWsbTLhR0M9Lw@mail.gmail.com>

Hi Puranjay,

Le Fri, Jul 24, 2026 at 03:54:20PM +0100, Puranjay Mohan a écrit :
> Hi Frederic.
> 
> I took your approach and created this commit with minor changes to your diff:
> 
> A few points I'd like a second opinion on. I kept the unordered
> poll_state_synchronize_rcu_full_unordered() for the advance check (the
> old rcu_core() block used the ordered variant): this looks safe
> because rcu_segcblist_advance() re-checks each segment with the
> ordered poll_state_synchronize_rcu_full() before moving callbacks to
> RCU_DONE_TAIL, so the check here is only a gate and the barriers still
> apply where callbacks are actually advanced, please confirm that
> reasoning.

I confirm!

> need_note_gp_changes() runs the callback-list poll on the
> lockless preamble for both callers, including offloaded rdps where
> __note_gp_changes() won't advance anything; I left it ungated since it
> only leads to a trylock, but it could take a
> !rcu_rdp_is_offloaded(rdp) guard.

May make sense to spare the trylock if it's offloaded &&
rdp->gpnum == rnp->gpnum && likely(!rdp->gpwrap).

> I also dropped the
> rcu_segcblist_is_enabled() guard the rcu_core() block had, relying on
> __note_gp_changes() already operating on the cblist unconditionally
> for non-offloaded rdps.

Ok, some more below:

> 
> -- >8 --
> 
> From c38c5f599d699e2c40d3459fdf3ef383a99c0097 Mon Sep 17 00:00:00 2001
> From: Puranjay Mohan <puranjay@kernel.org>
> Date: Fri, 24 Jul 2026 07:26:25 -0700
> Subject: [PATCH] rcu: Advance callbacks for expedited GP completion in
>  note_gp_changes()
> 
> When rcu_pending() triggers rcu_core(), the callback advancement path
> through note_gp_changes() -> __note_gp_changes() bails out when
> rdp->gp_seq == rnp->gp_seq (no normal GP change). Since expedited GPs do
> not update rnp->gp_seq, rcu_advance_cbs() is never reached from there and
> callbacks satisfied by an expedited GP would otherwise remain stuck in
> RCU_WAIT_TAIL until the next normal GP.
> 
> This is currently handled by a dedicated advancement block in rcu_core()
> that polls the callback list and advances under a trylock. But callback
> advancement no longer depends on the leaf-node grace-period delta; it is
> driven by the grace-period state stored in the callback list, which
> tracks both normal and expedited GPs. __note_gp_changes() is the natural
> home for it, and hosting it there lets every note_gp_changes() caller
> benefit from expedited completions rather than just rcu_core().
> 
> Move the advancement into __note_gp_changes(): trigger rcu_advance_cbs()
> whenever rcu_segcblist_nextgp() confirmed with
> poll_state_synchronize_rcu_full_unordered() reports a completed grace
> period, and add need_note_gp_changes() so the lockless preamble takes the
> lock for an expedited-only completion instead of short-circuiting on
> rdp->gp_seq == rnp->gp_seq. Remove the now-redundant rcu_core() block.
> 
> The quiescent-state bookkeeping stays keyed to an actual rnp->gp_seq
> change, so an expedited completion never clears a still-pending
> core_needs_qs and stalls the normal grace period.
> 
> Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
> ---
>  kernel/rcu/tree.c | 56 ++++++++++++++++++++++++-----------------------
>  kernel/rcu/tree.h |  1 +
>  2 files changed, 30 insertions(+), 27 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index 21b6ce1dffb63..0e700d0ecf27e 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -1270,27 +1270,33 @@ static bool __note_gp_changes(struct rcu_node
> *rnp, struct rcu_data *rdp)
>  {
>         bool ret = false;
>         bool need_qs;
> +       struct rcu_gp_seq gp_state;
>         const bool offloaded = rcu_rdp_is_offloaded(rdp);
> +       bool completed = rcu_seq_completed_gp(rdp->gp_seq, rnp->gp_seq) ||
> +                        unlikely(rdp->gpwrap);
> 
>         raw_lockdep_assert_held_rcu_node(rnp);
> 
> -       if (rdp->gp_seq == rnp->gp_seq)
> -               return false; /* Nothing to do. */
> -
>         /* Handle the ends of any preceding grace periods first. */
> -       if (rcu_seq_completed_gp(rdp->gp_seq, rnp->gp_seq) ||
> -           unlikely(rdp->gpwrap)) {
> +       if (completed ||
> +           (rcu_segcblist_nextgp(&rdp->cblist, &gp_state) &&
> +            poll_state_synchronize_rcu_full_unordered(&gp_state))) {
>                 if (!offloaded)
>                         ret = rcu_advance_cbs(rnp, rdp); /* Advance CBs. */
> -               rdp->core_needs_qs = false;
> -               trace_rcu_grace_period(rcu_state.name, rdp->gp_seq,
> TPS("cpuend"));
> -       } else {
> +               if (completed) {
> +                       rdp->core_needs_qs = false;
> +                       trace_rcu_grace_period(rcu_state.name,
> rdp->gp_seq, TPS("cpuend"));
> +               }
> +       } else if (rdp->gp_seq != rnp->gp_seq) {
>                 if (!offloaded)
>                         ret = rcu_accelerate_cbs(rnp, rdp); /* Recent CBs. */
>                 if (rdp->core_needs_qs)
>                         rdp->core_needs_qs = !!(rnp->qsmask & rdp->grpmask);
>         }
> 
> +       if (rdp->gp_seq == rnp->gp_seq)
> +               return ret; /* Nothing else to do. */

We still need to process the below block if rdp->gpwrap, because rnp->gp_seq
might have wrapped and equal again rdp->gp_seq.

> +
>         /* Now handle the beginnings of any new-to-this-CPU grace periods. */
>         if (rcu_seq_new_gp(rdp->gp_seq, rnp->gp_seq) ||
>             unlikely(rdp->gpwrap)) {

Thanks.

-- 
Frederic Weisbecker
SUSE Labs

  reply	other threads:[~2026-08-17 14:12 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24 13:23 [PATCH v1 00/11] RCU: Enable callbacks to benefit from expedited grace periods Puranjay Mohan
2026-06-24 13:23 ` [PATCH v1 01/11] rcu: Rename struct rcu_gp_oldstate to rcu_gp_seq Puranjay Mohan
2026-07-09 11:47   ` Frederic Weisbecker
2026-06-24 13:23 ` [PATCH v1 02/11] rcu/segcblist: Add SRCU and Tasks RCU wrapper functions Puranjay Mohan
2026-07-09 11:51   ` Frederic Weisbecker
2026-06-24 13:23 ` [PATCH v1 03/11] rcu/segcblist: Factor out rcu_segcblist_advance_compact() helper Puranjay Mohan
2026-07-09 13:21   ` Frederic Weisbecker
2026-06-24 13:23 ` [PATCH v1 04/11] rcu/segcblist: Track segment grace periods with struct rcu_gp_seq Puranjay Mohan
2026-07-09 13:33   ` Frederic Weisbecker
2026-06-24 13:23 ` [PATCH v1 05/11] rcu: Add RCU_GET_STATE_NOT_TRACKED for subsystems without expedited GPs Puranjay Mohan
2026-07-09 13:48   ` Frederic Weisbecker
2026-06-24 13:23 ` [PATCH v1 06/11] rcu: Enable RCU callbacks to benefit from expedited grace periods Puranjay Mohan
2026-07-09 13:58   ` Frederic Weisbecker
2026-07-09 15:36     ` Puranjay Mohan
2026-07-10 13:58   ` Frederic Weisbecker
2026-07-14 18:48     ` Paul E. McKenney
2026-07-20 14:22       ` Frederic Weisbecker
2026-07-20 16:55         ` Paul E. McKenney
2026-07-21 12:06           ` Frederic Weisbecker
2026-07-24 18:31   ` [PATCH v2 6/11] " Puranjay Mohan
2026-07-25  0:23     ` Paul E. McKenney
2026-07-25 12:04       ` Puranjay Mohan
2026-07-25 18:58         ` Paul E. McKenney
2026-06-24 13:23 ` [PATCH v1 07/11] rcu: Update comments for gp_seq and expedited GP tracking Puranjay Mohan
2026-07-20 14:56   ` Frederic Weisbecker
2026-06-24 13:23 ` [PATCH v1 08/11] rcu: Wake NOCB rcuog kthreads on expedited grace period completion Puranjay Mohan
2026-07-20 15:56   ` Frederic Weisbecker
2026-06-24 13:23 ` [PATCH v1 09/11] rcu: Detect expedited grace period completion in rcu_pending() Puranjay Mohan
2026-07-21 12:45   ` Frederic Weisbecker
2026-07-21 14:32     ` Paul E. McKenney
2026-06-24 13:23 ` [PATCH v1 10/11] rcu: Advance callbacks for expedited GP completion in rcu_core() Puranjay Mohan
2026-07-21 14:35   ` Frederic Weisbecker
2026-07-21 15:06     ` Puranjay Mohan
2026-07-22 21:50       ` Frederic Weisbecker
2026-07-24 14:54         ` Puranjay Mohan
2026-08-17 14:12           ` Frederic Weisbecker [this message]
2026-06-24 13:23 ` [PATCH v1 11/11] rcuscale: Add concurrent expedited GP threads for callback scaling tests Puranjay Mohan
2026-07-20 18:02 ` [PATCH v1 00/11] RCU: Enable callbacks to benefit from expedited grace periods Paul E. McKenney
2026-07-24  0:31 ` Paul E. McKenney
2026-07-24 12:44   ` Frederic Weisbecker
2026-07-24 12:52     ` Puranjay Mohan
2026-07-24 13:47       ` Puranjay Mohan
2026-07-24 14:06         ` Paul E. McKenney
2026-07-24 17:41           ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aoMWwva-MkA-OHkp@localhost.localdomain \
    --to=frederic@kernel.org \
    --cc=boqun@kernel.org \
    --cc=dave@stgolabs.net \
    --cc=jiangshanlai@gmail.com \
    --cc=joelagnelf@nvidia.com \
    --cc=josh@joshtriplett.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=puranjay12@gmail.com \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=urezki@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox