public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Zqiang" <qiang.zhang@linux.dev>
To: "Paul E. McKenney" <paulmck@kernel.org>, rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
	rostedt@goodmis.org, "Paul E. McKenney" <paulmck@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	bpf@vger.kernel.org
Subject: Re: [PATCH 23/34] srcu: Create an srcu_expedite_current() function
Date: Wed, 24 Sep 2025 00:10:22 +0000	[thread overview]
Message-ID: <91810f6e76fb2e97b0519c9442f1877e1de223fa@linux.dev> (raw)
In-Reply-To: <20250923142036.112290-23-paulmck@kernel.org>

> 
> This commit creates an srcu_expedite_current() function that expedites
> the current (and possibly the next) SRCU grace period for the specified
> srcu_struct structure. This functionality will be inherited by RCU
> Tasks Trace courtesy of its mapping to SRCU fast.
> 
> If the current SRCU grace period is already waiting, that wait will
> complete before the expediting takes effect. If there is no SRCU grace
> period in flight, this function might well create one.
> 
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Cc: Andrii Nakryiko <andrii@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: <bpf@vger.kernel.org>
> ---
>  include/linux/srcutiny.h | 1 +
>  include/linux/srcutree.h | 8 ++++++
>  kernel/rcu/srcutree.c | 58 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 67 insertions(+)
> 
> diff --git a/include/linux/srcutiny.h b/include/linux/srcutiny.h
> index 00e5f05288d5e7..941e8210479607 100644
> --- a/include/linux/srcutiny.h
> +++ b/include/linux/srcutiny.h
> @@ -104,6 +104,7 @@ static inline void srcu_barrier(struct srcu_struct *ssp)
>  synchronize_srcu(ssp);
>  }
>  
> +static inline void srcu_expedite_current(struct srcu_struct *ssp) { }
>  #define srcu_check_read_flavor(ssp, read_flavor) do { } while (0)
>  #define srcu_check_read_flavor_force(ssp, read_flavor) do { } while (0)
>  
> diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
> index 1adc58d2ab6425..4a5d1c0e7db361 100644
> --- a/include/linux/srcutree.h
> +++ b/include/linux/srcutree.h
> @@ -42,6 +42,8 @@ struct srcu_data {
>  struct timer_list delay_work; /* Delay for CB invoking */
>  struct work_struct work; /* Context for CB invoking. */
>  struct rcu_head srcu_barrier_head; /* For srcu_barrier() use. */
> + struct rcu_head srcu_ec_head; /* For srcu_expedite_current() use. */
> + int srcu_ec_state; /* State for srcu_expedite_current(). */
>  struct srcu_node *mynode; /* Leaf srcu_node. */
>  unsigned long grpmask; /* Mask for leaf srcu_node */
>  /* ->srcu_data_have_cbs[]. */
> @@ -135,6 +137,11 @@ struct srcu_struct {
>  #define SRCU_STATE_SCAN1 1
>  #define SRCU_STATE_SCAN2 2
>  
> +/* Values for srcu_expedite_current() state (->srcu_ec_state). */
> +#define SRCU_EC_IDLE 0
> +#define SRCU_EC_PENDING 1
> +#define SRCU_EC_REPOST 2
> +
>  /*
>  * Values for initializing gp sequence fields. Higher values allow wrap arounds to
>  * occur earlier.
> @@ -220,6 +227,7 @@ struct srcu_struct {
>  int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp);
>  void synchronize_srcu_expedited(struct srcu_struct *ssp);
>  void srcu_barrier(struct srcu_struct *ssp);
> +void srcu_expedite_current(struct srcu_struct *ssp);
>  void srcu_torture_stats_print(struct srcu_struct *ssp, char *tt, char *tf);
>  
>  // Converts a per-CPU pointer to an ->srcu_ctrs[] array element to that
> diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> index 1ff94b76d91f15..f2f11492e6936e 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> @@ -1688,6 +1688,64 @@ void srcu_barrier(struct srcu_struct *ssp)
>  }
>  EXPORT_SYMBOL_GPL(srcu_barrier);
>  
> +/* Callback for srcu_expedite_current() usage. */
> +static void srcu_expedite_current_cb(struct rcu_head *rhp)
> +{
> + unsigned long flags;
> + bool needcb = false;
> + struct srcu_data *sdp = container_of(rhp, struct srcu_data, srcu_ec_head);
> +
> + spin_lock_irqsave_sdp_contention(sdp, &flags);
> + if (sdp->srcu_ec_state == SRCU_EC_IDLE) {
> + WARN_ON_ONCE(1);
> + } else if (sdp->srcu_ec_state == SRCU_EC_PENDING) {
> + sdp->srcu_ec_state = SRCU_EC_IDLE;
> + } else {
> + WARN_ON_ONCE(sdp->srcu_ec_state != SRCU_EC_REPOST);
> + sdp->srcu_ec_state = SRCU_EC_PENDING;
> + needcb = true;
> + }
> + spin_unlock_irqrestore_rcu_node(sdp, flags);
> + // If needed, requeue ourselves as an expedited SRCU callback.
> + if (needcb)
> + __call_srcu(sdp->ssp, &sdp->srcu_ec_head, srcu_expedite_current_cb, false);
> +}
> +
> +/**
> + * srcu_expedite_current - Expedite the current SRCU grace period
> + * @ssp: srcu_struct to expedite.
> + *
> + * Cause the current SRCU grace period to become expedited. The grace
> + * period following the current one might also be expedited. If there is
> + * no current grace period, one might be created. If the current grace
> + * period is currently sleeping, that sleep will complete before expediting
> + * will take effect.
> + */
> +void srcu_expedite_current(struct srcu_struct *ssp)
> +{
> + unsigned long flags;
> + bool needcb = false;
> + struct srcu_data *sdp;
> +
> + preempt_disable();
> + sdp = this_cpu_ptr(ssp->sda);
> + spin_lock_irqsave_sdp_contention(sdp, &flags);

For PREEMPT_RT kernels, a locking warnings may occur here.


> + if (sdp->srcu_ec_state == SRCU_EC_IDLE) {
> + sdp->srcu_ec_state = SRCU_EC_PENDING;
> + needcb = true;
> + } else if (sdp->srcu_ec_state == SRCU_EC_PENDING) {
> + sdp->srcu_ec_state = SRCU_EC_REPOST;
> + } else {
> + WARN_ON_ONCE(sdp->srcu_ec_state != SRCU_EC_REPOST);
> + }
> + spin_unlock_irqrestore_rcu_node(sdp, flags);
> + // If needed, queue an expedited SRCU callback.
> + if (needcb)
> + __call_srcu(ssp, &sdp->srcu_ec_head, srcu_expedite_current_cb, false);

The locking warnings may also occur in the __call_srcu().

Thanks
Zqiang

> + preempt_enable();
> +}
> +EXPORT_SYMBOL_GPL(srcu_expedite_current);
> +
>  /**
>  * srcu_batches_completed - return batches completed.
>  * @ssp: srcu_struct on which to report batch completion.
> -- 
> 2.40.1
>

  reply	other threads:[~2025-09-24  0:10 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23 14:20 [PATCH 0/34] Implement RCU Tasks Trace in terms of SRCU-fast and optimize Paul E. McKenney
2025-09-23 14:20 ` [PATCH 01/34] rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast Paul E. McKenney
2025-09-25 18:39   ` Andrii Nakryiko
2025-09-25 18:58     ` Paul E. McKenney
2025-09-23 14:20 ` [PATCH 02/34] rcu: Remove unused ->trc_ipi_to_cpu and ->trc_blkd_cpu from task_struct Paul E. McKenney
2025-09-23 14:20 ` [PATCH 03/34] rcu: Remove ->trc_blkd_node " Paul E. McKenney
2025-09-23 14:20 ` [PATCH 04/34] rcu: Remove ->trc_holdout_list " Paul E. McKenney
2025-09-23 14:20 ` [PATCH 05/34] rcu: Remove rcu_tasks_trace_qs() and the functions that it calls Paul E. McKenney
2025-09-23 14:20 ` [PATCH 06/34] context_tracking: Remove rcu_task_trace_heavyweight_{enter,exit}() Paul E. McKenney
2025-09-23 14:20 ` [PATCH 07/34] rcu: Remove ->trc_reader_special from task_struct Paul E. McKenney
2025-09-23 14:20 ` [PATCH 08/34] rcu: Remove now-empty RCU Tasks Trace functions and calls to them Paul E. McKenney
2025-09-23 14:20 ` [PATCH 09/34] rcu: Remove unused rcu_tasks_trace_lazy_ms and trc_stall_chk_rdr struct Paul E. McKenney
2025-09-23 14:20 ` [PATCH 10/34] rcu: Remove now-empty show_rcu_tasks_trace_gp_kthread() function Paul E. McKenney
2025-09-23 14:20 ` [PATCH 11/34] rcu: Remove now-empty rcu_tasks_trace_get_gp_data() function Paul E. McKenney
2025-09-23 14:20 ` [PATCH 12/34] rcu: Remove now-empty rcu_tasks_trace_torture_stats_print() function Paul E. McKenney
2025-09-23 14:20 ` [PATCH 13/34] rcu: Remove now-empty get_rcu_tasks_trace_gp_kthread() function Paul E. McKenney
2025-09-23 14:20 ` [PATCH 14/34] rcu: Move rcu_tasks_trace_srcu_struct out of #ifdef CONFIG_TASKS_RCU_GENERIC Paul E. McKenney
2025-09-23 14:20 ` [PATCH 15/34] rcu: Add noinstr-fast rcu_read_{,un}lock_tasks_trace() APIs Paul E. McKenney
2025-09-23 17:32   ` Peter Zijlstra
2025-09-24  8:44     ` Paul E. McKenney
2025-09-24  9:08       ` Peter Zijlstra
2025-09-23 14:20 ` [PATCH 16/34] rcu: Remove now-unused rcu_task_ipi_delay and TASKS_TRACE_RCU_READ_MB Paul E. McKenney
2025-09-23 14:20 ` [PATCH 17/34] srcu: Create a DEFINE_SRCU_FAST() Paul E. McKenney
2025-09-23 14:20 ` [PATCH 18/34] rcu: Use smp_mb() only when necessary in RCU Tasks Trace readers Paul E. McKenney
2025-09-23 14:20 ` [PATCH 19/34] rcu: Update Requirements.rst for RCU Tasks Trace Paul E. McKenney
2025-09-25 18:40   ` Andrii Nakryiko
2025-09-25 18:53     ` Paul E. McKenney
2025-09-23 14:20 ` [PATCH 20/34] checkpatch: Deprecate rcu_read_{,un}lock_trace() Paul E. McKenney
2025-09-23 15:47   ` Joe Perches
2025-09-23 17:01     ` Paul E. McKenney
2025-09-23 14:20 ` [PATCH 21/34] rcu: Mark diagnostic functions as notrace Paul E. McKenney
2025-09-23 14:20 ` [PATCH 22/34] tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast Paul E. McKenney
2025-09-23 14:20 ` [PATCH 23/34] srcu: Create an srcu_expedite_current() function Paul E. McKenney
2025-09-24  0:10   ` Zqiang [this message]
2025-09-24  8:56     ` Paul E. McKenney
2025-09-23 14:20 ` [PATCH 24/34] rcutorture: Test srcu_expedite_current() Paul E. McKenney
2025-09-23 14:20 ` [PATCH 25/34] srcu: Create an rcu_tasks_trace_expedite_current() function Paul E. McKenney
2025-09-23 14:20 ` [PATCH 26/34] rcutorture: Test rcu_tasks_trace_expedite_current() Paul E. McKenney
2025-09-23 14:20 ` [PATCH 27/34] srcu: Make DEFINE_SRCU_FAST() available to modules Paul E. McKenney
2025-09-23 14:20 ` [PATCH 28/34] srcu: Make SRCU-fast available to heap srcu_struct structures Paul E. McKenney
2025-09-23 14:20 ` [PATCH 29/34] srcu: Make grace-period determination use ssp->srcu_reader_flavor Paul E. McKenney
2025-09-23 14:20 ` [PATCH 30/34] rcutorture: Exercise DEFINE_STATIC_SRCU_FAST() and init_srcu_struct_fast() Paul E. McKenney
2025-09-23 14:20 ` [PATCH 31/34] refscale: " Paul E. McKenney
2025-09-23 14:20 ` [PATCH 32/34] srcu: Require special srcu_struct define/init for SRCU-fast readers Paul E. McKenney
2025-09-23 14:20 ` [PATCH 33/34] srcu: Make SRCU-fast readers enforce use of SRCU-fast definition/init Paul E. McKenney
2025-09-23 14:20 ` [PATCH 34/34] doc: Update for SRCU-fast definitions and initialization Paul E. McKenney
2025-09-24  7:49 ` [PATCH 0/34] Implement RCU Tasks Trace in terms of SRCU-fast and optimize Alexei Starovoitov
2025-09-24  8:20   ` 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=91810f6e76fb2e97b0519c9442f1877e1de223fa@linux.dev \
    --to=qiang.zhang@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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