Linux RCU subsystem development
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Pingfan Liu <kernelfans@gmail.com>
Cc: rcu@vger.kernel.org, Lai Jiangshan <jiangshanlai@gmail.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	"Zhang, Qiang1" <qiang1.zhang@intel.com>
Subject: Re: [PATCH] srcu: switch work func to allow concurrent gp
Date: Wed, 30 Nov 2022 08:53:43 -0800	[thread overview]
Message-ID: <Y4eKl2fCNDX2ka1g@boqun-archlinux> (raw)
In-Reply-To: <20221130083902.31577-1-kernelfans@gmail.com>

On Wed, Nov 30, 2022 at 04:39:02PM +0800, Pingfan Liu wrote:
> ssp->srcu_cb_mutex is introduced to allow the other srcu state machine
> to advance as soon as possible. But according to the implement of
> workqueue, the same work_struct is serialized and can not run
> concurrently in fact.
> 
> Quoting from Documentation/core-api/workqueue.rst
> "
> Non-reentrance Conditions
> =========================
> 
> Workqueue guarantees that a work item cannot be re-entrant if the following
> conditions hold after a work item gets queued:
> 
>         1. The work function hasn't been changed.
>         2. No one queues the work item to another workqueue.
>         3. The work item hasn't been reinitiated.
> "
> 
> To allow the concurrence to some extent, it can be achieved by changing
> the work function to break the conditions. As a result, when
> srcu_gp_end() releases srcu_gp_mutex, a new state machine can begin.
> 
> Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
> Cc: Lai Jiangshan <jiangshanlai@gmail.com>
> Cc: "Paul E. McKenney" <paulmck@kernel.org>
> Cc: Frederic Weisbecker <frederic@kernel.org>
> Cc: Josh Triplett <josh@joshtriplett.org>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Cc: "Zhang, Qiang1" <qiang1.zhang@intel.com>
> To: rcu@vger.kernel.org
> ---
>  kernel/rcu/srcutree.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> index 1c304fec89c0..56dd9bb2c8b8 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> @@ -75,6 +75,7 @@ static bool __read_mostly srcu_init_done;
>  static void srcu_invoke_callbacks(struct work_struct *work);
>  static void srcu_reschedule(struct srcu_struct *ssp, unsigned long delay);
>  static void process_srcu(struct work_struct *work);
> +static void process_srcu_wrap(struct work_struct *work);
>  static void srcu_delay_timer(struct timer_list *t);
>  
>  /* Wrappers for lock acquisition and release, see raw_spin_lock_rcu_node(). */
> @@ -763,6 +764,11 @@ static void srcu_gp_end(struct srcu_struct *ssp)
>  		cbdelay = 0;
>  
>  	WRITE_ONCE(ssp->srcu_last_gp_end, ktime_get_mono_fast_ns());
> +	/* Change work func so work can be concurrent */
> +	if (ssp->work.work.func == process_srcu_wrap)
> +		ssp->work.work.func = process_srcu;
> +	else
> +		ssp->work.work.func = process_srcu_wrap;

This looks really hacky ;-) It would be good that workqueue has an API
to allow "resetting" a work.

Do you have any number of the potential performance improvement?

Regards,
Boqun

>  	rcu_seq_end(&ssp->srcu_gp_seq);
>  	gpseq = rcu_seq_current(&ssp->srcu_gp_seq);
>  	if (ULONG_CMP_LT(ssp->srcu_gp_seq_needed_exp, gpseq))
> @@ -1637,6 +1643,19 @@ static void process_srcu(struct work_struct *work)
>  	srcu_reschedule(ssp, curdelay);
>  }
>  
> +/*
> + * The ssp->work is expected to be concurrent to some extent, but the current
> + * workqueue does not support the concurrence on the same work. (Refer to the
> + * section "Non-reentrance Conditions" in the file workqueue.rst)
> + * Resolving it by changing the work func.
> + *
> + * Prevent compilering from optimizing out it.
> + */
> +static __used void process_srcu_wrap(struct work_struct *work)
> +{
> +	process_srcu(work);
> +}
> +
>  void srcutorture_get_gp_data(enum rcutorture_type test_type,
>  			     struct srcu_struct *ssp, int *flags,
>  			     unsigned long *gp_seq)
> -- 
> 2.31.1
> 

  reply	other threads:[~2022-11-30 16:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30  8:39 [PATCH] srcu: switch work func to allow concurrent gp Pingfan Liu
2022-11-30 16:53 ` Boqun Feng [this message]
2022-11-30 17:39   ` Joel Fernandes
2022-12-01 13:54     ` Pingfan Liu
2022-12-01 13:53   ` Pingfan Liu
2022-12-13 13:00     ` Pingfan Liu
2022-12-13 19:51       ` Boqun Feng
2022-12-14 12:34         ` Pingfan Liu

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=Y4eKl2fCNDX2ka1g@boqun-archlinux \
    --to=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=kernelfans@gmail.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=qiang1.zhang@intel.com \
    --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