RCU Archive mirror
 help / color / mirror / Atom feed
From: Lai Jiangshan <jiangshanlai@gmail.com>
To: Joel Fernandes <joel@joelfernandes.org>
Cc: linux-kernel@vger.kernel.org, rcu@vger.kernel.org,
	x86@kernel.org,  Lai Jiangshan <jiangshan.ljs@antgroup.com>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	 Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	 Neeraj Upadhyay <quic_neeraju@quicinc.com>,
	Josh Triplett <josh@joshtriplett.org>,
	 Boqun Feng <boqun.feng@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Zqiang <qiang.zhang1211@gmail.com>
Subject: Re: [PATCH V2 09/11] rcu: Implement PCPU_RCU_PREEMPT_COUNT framework
Date: Wed, 24 Apr 2024 11:02:51 +0800	[thread overview]
Message-ID: <CAJhGHyCKE4+g9X=OMXTZ=V=4W+of4D3ZvuywniJOdLYp3pe0cA@mail.gmail.com> (raw)
In-Reply-To: <CAEXW_YSz8xD4WXO0dOyKC6X7BZeqMD2TOCm0=43=owLjJj=PVA@mail.gmail.com>

On Wed, Apr 24, 2024 at 2:19 AM Joel Fernandes <joel@joelfernandes.org> wrote:
>
> On Sun, Apr 7, 2024 at 5:04 AM Lai Jiangshan <jiangshanlai@gmail.com> wrote:
> >
> > From: Lai Jiangshan <jiangshan.ljs@antgroup.com>
> >
> > When the arch code provides HAVE_PCPU_RCU_PREEMPT_COUNT and the
> > corresponding functions, rcu core uses the functions to implement
> > rcu_preempt_depth(), special bits, switching and so on.
> >
> > Cc: "Paul E. McKenney" <paulmck@kernel.org>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Frederic Weisbecker <frederic@kernel.org>
> > Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
> > ---
> >  include/linux/rcupdate.h | 33 +++++++++++++++++++++++++++++++++
> >  kernel/rcu/Kconfig       |  8 ++++++++
> >  kernel/rcu/rcu.h         |  4 ++++
> >  kernel/rcu/tree_plugin.h |  8 ++++++++
> >  4 files changed, 53 insertions(+)
> >
> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> > index 328667ae8086..e3e5ce44c7dc 100644
> > --- a/include/linux/rcupdate.h
> > +++ b/include/linux/rcupdate.h
> > @@ -70,6 +70,8 @@ static inline bool same_state_synchronize_rcu(unsigned long oldstate1, unsigned
> >
> >  void rcu_read_unlock_special(void);
> >
> > +#ifndef CONFIG_PCPU_RCU_PREEMPT_COUNT
> > +
> >  void __rcu_read_lock(void);
> >  void __rcu_read_unlock(void);
> >
> > @@ -81,6 +83,37 @@ void __rcu_read_unlock(void);
> >   */
> >  #define rcu_preempt_depth() READ_ONCE(current->rcu_read_lock_nesting)
> >  #define rcu_preempt_depth_set(val) WRITE_ONCE(current->rcu_read_lock_nesting, (val))
> > +#define pcpu_rcu_preempt_special_set() do { } while (0)
> > +#define pcpu_rcu_preempt_special_clear() do { } while (0)
> > +
> > +#else /* #ifndef CONFIG_PCPU_RCU_PREEMPT_COUNT */
> > +
> > +#include <asm/rcu_preempt.h>
> > +
> > +static __always_inline void __rcu_read_lock(void)
> > +{
> > +       pcpu_rcu_preempt_count_add(1);
> > +       barrier();
> > +}
> > +
> > +static __always_inline void __rcu_read_unlock(void)
> > +{
> > +       barrier();
> > +       if (unlikely(pcpu_rcu_preempt_count_dec_and_test()))
> > +               pcpu_rcu_read_unlock_special();
> > +}
>
> Previous code had comments about the barrier(); , can you add back
> those comments?
>
> Also there was a compiler barrier in the body of the if() as well?
>

The two "if"s in the referenced __rcu_read_unlock() are condensed into
a single "if" ("if (unlikely(pcpu_rcu_preempt_count_dec_and_test()))"),
so there is no extra barrier() needed in the body of the "if" which
is analogue to the body of the second "if" of the referenced
__rcu_read_unlock().

The special bit and the rcu_depth_count are condensed, so the code
mostly follows the way how preempt_enable() works.

Thanks
Lai

> For reference:
>
> void __rcu_read_unlock(void)
> {
>         struct task_struct *t = current;
>
>         barrier();  // critical section before exit code.
>         if (rcu_preempt_read_exit() == 0) {
>                 barrier();  // critical-section exit before .s check.
>                 if (unlikely(READ_ONCE(t->rcu_read_unlock_special.s)))
>                         rcu_read_unlock_special(t);
>         }

  reply	other threads:[~2024-04-24  3:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-07  9:05 [PATCH V2 00/11] rcu/x86: Use per-cpu rcu preempt count Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 01/11] lib: Use rcu_preempt_depth() to replace current->rcu_read_lock_nesting Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 02/11] rcu: Move rcu_preempt_depth_set() to rcupdate.h Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 03/11] rcu: Reorder tree_exp.h after tree_plugin.h Lai Jiangshan
2024-04-23 17:58   ` Joel Fernandes
2024-04-24  2:47     ` Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 04/11] rcu: Add macros set_rcu_preempt_special() and clear_rcu_preempt_special() Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 05/11] rcu: Make rcu_read_unlock_special() global Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 06/11] rcu: Rename marco __LINUX_RCU_H to __KERNEL_RCU_H Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 07/11] sched/core: Add rcu_preempt_switch() Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 08/11] x86/entry: Merge thunk_64.S and thunk_32.S into thunk.S Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 09/11] rcu: Implement PCPU_RCU_PREEMPT_COUNT framework Lai Jiangshan
2024-04-23 18:19   ` Joel Fernandes
2024-04-24  3:02     ` Lai Jiangshan [this message]
2024-04-07  9:05 ` [PATCH V2 10/11] x86/rcu: Add rcu_preempt_count Lai Jiangshan
2024-04-23 18:09   ` Joel Fernandes
2024-04-24  2:53     ` Lai Jiangshan
2024-04-07  9:05 ` [PATCH V2 11/11] x86/rcu: Add THUNK rcu_read_unlock_special_thunk Lai Jiangshan
2024-04-23 17:26   ` Joel Fernandes
2024-04-24  2:43     ` Lai Jiangshan
2024-05-20 20:03 ` [PATCH V2 00/11] rcu/x86: Use per-cpu rcu preempt count 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='CAJhGHyCKE4+g9X=OMXTZ=V=4W+of4D3ZvuywniJOdLYp3pe0cA@mail.gmail.com' \
    --to=jiangshanlai@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=frederic@kernel.org \
    --cc=jiangshan.ljs@antgroup.com \
    --cc=joel@joelfernandes.org \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qiang.zhang1211@gmail.com \
    --cc=quic_neeraju@quicinc.com \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=x86@kernel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).