From: "Paul E. McKenney" <paulmck@kernel.org>
To: Neeraj Upadhyay <neeraju@codeaurora.org>
Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com,
akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org,
rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com,
fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org,
kent.overstreet@gmail.com
Subject: Re: [PATCH v2 tip/core/rcu 4/6] srcu: Provide polling interfaces for Tiny SRCU grace periods
Date: Tue, 24 Nov 2020 11:30:43 -0800 [thread overview]
Message-ID: <20201124193043.GK1437@paulmck-ThinkPad-P72> (raw)
In-Reply-To: <9ebe7c82-6fc2-a759-dde8-eec90b483735@codeaurora.org>
On Tue, Nov 24, 2020 at 10:44:24AM +0530, Neeraj Upadhyay wrote:
>
>
> On 11/24/2020 2:42 AM, Paul E. McKenney wrote:
> > On Mon, Nov 23, 2020 at 10:13:13AM +0530, Neeraj Upadhyay wrote:
> > >
> > >
> > > On 11/21/2020 6:29 AM, paulmck@kernel.org wrote:
> > > > From: "Paul E. McKenney" <paulmck@kernel.org>
> > > >
> > > > There is a need for a polling interface for SRCU grace
> > > > periods, so this commit supplies get_state_synchronize_srcu(),
> > > > start_poll_synchronize_srcu(), and poll_state_synchronize_srcu() for this
> > > > purpose. The first can be used if future grace periods are inevitable
> > > > (perhaps due to a later call_srcu() invocation), the second if future
> > > > grace periods might not otherwise happen, and the third to check if a
> > > > grace period has elapsed since the corresponding call to either of the
> > > > first two.
> > > >
> > > > As with get_state_synchronize_rcu() and cond_synchronize_rcu(),
> > > > the return value from either get_state_synchronize_srcu() or
> > > > start_poll_synchronize_srcu() must be passed in to a later call to
> > > > poll_state_synchronize_srcu().
> > > >
> > > > Link: https://lore.kernel.org/rcu/20201112201547.GF3365678@moria.home.lan/
> > > > Reported-by: Kent Overstreet <kent.overstreet@gmail.com>
> > > > [ paulmck: Add EXPORT_SYMBOL_GPL() per kernel test robot feedback. ]
> > > > [ paulmck: Apply feedback from Neeraj Upadhyay. ]
> > > > Link: https://lore.kernel.org/lkml/20201117004017.GA7444@paulmck-ThinkPad-P72/
> > > > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > > > ---
> > > > include/linux/rcupdate.h | 2 ++
> > > > include/linux/srcu.h | 3 +++
> > > > include/linux/srcutiny.h | 1 +
> > > > kernel/rcu/srcutiny.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++--
> > > > 4 files changed, 56 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> > > > index de08264..e09c0d8 100644
> > > > --- a/include/linux/rcupdate.h
> > > > +++ b/include/linux/rcupdate.h
> > > > @@ -33,6 +33,8 @@
> > > > #define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b))
> > > > #define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
> > > > #define ulong2long(a) (*(long *)(&(a)))
> > > > +#define USHORT_CMP_GE(a, b) (USHRT_MAX / 2 >= (unsigned short)((a) - (b)))
> > > > +#define USHORT_CMP_LT(a, b) (USHRT_MAX / 2 < (unsigned short)((a) - (b)))
> > > > /* Exported common interfaces */
> > > > void call_rcu(struct rcu_head *head, rcu_callback_t func);
> > > > diff --git a/include/linux/srcu.h b/include/linux/srcu.h
> > > > index e432cc9..a0895bb 100644
> > > > --- a/include/linux/srcu.h
> > > > +++ b/include/linux/srcu.h
> > > > @@ -60,6 +60,9 @@ void cleanup_srcu_struct(struct srcu_struct *ssp);
> > > > int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp);
> > > > void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp);
> > > > void synchronize_srcu(struct srcu_struct *ssp);
> > > > +unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp);
> > > > +unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp);
> > > > +bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie);
> > > > #ifdef CONFIG_DEBUG_LOCK_ALLOC
> > > > diff --git a/include/linux/srcutiny.h b/include/linux/srcutiny.h
> > > > index d9edb67..c7f0c1f 100644
> > > > --- a/include/linux/srcutiny.h
> > > > +++ b/include/linux/srcutiny.h
> > > > @@ -16,6 +16,7 @@
> > > > struct srcu_struct {
> > > > short srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */
> > > > unsigned short srcu_idx; /* Current reader array element in bit 0x2. */
> > > > + unsigned short srcu_idx_max; /* Furthest future srcu_idx request. */
> > > > u8 srcu_gp_running; /* GP workqueue running? */
> > > > u8 srcu_gp_waiting; /* GP waiting for readers? */
> > > > struct swait_queue_head srcu_wq;
> > > > diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
> > > > index 3bac1db..b073175 100644
> > > > --- a/kernel/rcu/srcutiny.c
> > > > +++ b/kernel/rcu/srcutiny.c
> > > > @@ -34,6 +34,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp)
> > > > ssp->srcu_gp_running = false;
> > > > ssp->srcu_gp_waiting = false;
> > > > ssp->srcu_idx = 0;
> > > > + ssp->srcu_idx_max = 0;
> > > > INIT_WORK(&ssp->srcu_work, srcu_drive_gp);
> > > > INIT_LIST_HEAD(&ssp->srcu_work.entry);
> > > > return 0;
> > >
> > > Minor: cleanup_srcu_struct() can probably have 2 new sanity checks?
> > >
> > > WARN_ON(ssp->srcu_idx != ssp->srcu_idx_max);
> > > WARN_ON(ssp->srcu_idx & 1);
> >
> > Good point, added and under test.
> >
> > > Thanks
> > > Neeraj
> > >
> > > > @@ -114,7 +115,7 @@ void srcu_drive_gp(struct work_struct *wp)
> > > > struct srcu_struct *ssp;
> > > > ssp = container_of(wp, struct srcu_struct, srcu_work);
> > > > - if (ssp->srcu_gp_running || !READ_ONCE(ssp->srcu_cb_head))
> > > > + if (ssp->srcu_gp_running || USHORT_CMP_GE(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
> > > > return; /* Already running or nothing to do. */
> > > > /* Remove recently arrived callbacks and wait for readers. */
> > > > @@ -147,13 +148,18 @@ void srcu_drive_gp(struct work_struct *wp)
> > > > * straighten that out.
> > > > */
> > > > WRITE_ONCE(ssp->srcu_gp_running, false);
> > > > - if (READ_ONCE(ssp->srcu_cb_head))
> > > > + if (USHORT_CMP_GE(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
> > > > schedule_work(&ssp->srcu_work);
> > > > }
> > > > EXPORT_SYMBOL_GPL(srcu_drive_gp);
> > > > static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
> > > > {
> > > > + unsigned short cookie;
> > > > +
> > > > + cookie = get_state_synchronize_srcu(ssp);
> > > > + if (USHORT_CMP_LT(READ_ONCE(ssp->srcu_idx_max), cookie))
> > > > + WRITE_ONCE(ssp->srcu_idx_max, cookie);
> > >
> > > Minor: Maybe we can return in the else part of USHORT_CMP_LT check, to avoid
> > > scheduling work?
> >
> > How about like this?
>
> Looks good!
Are you willing to give an ack or reviewed-by for either patch?
Thanx, Paul
> Thanks
> Neeraj
>
> >
> > static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
> > {
> > unsigned short cookie;
> >
> > cookie = get_state_synchronize_srcu(ssp);
> > if (USHORT_CMP_GE(READ_ONCE(ssp->srcu_idx_max), cookie))
> > return;
> > WRITE_ONCE(ssp->srcu_idx_max, cookie);
> > if (!READ_ONCE(ssp->srcu_gp_running)) {
> > if (likely(srcu_init_done))
> > schedule_work(&ssp->srcu_work);
> > else if (list_empty(&ssp->srcu_work.entry))
> > list_add(&ssp->srcu_work.entry, &srcu_boot_list);
> > }
> > }
> >
> > Testing this next. ;-)
> >
> > Thanx, Paul
> >
> > > Thanks
> > > Neeraj
> > >
> > > > if (!READ_ONCE(ssp->srcu_gp_running)) {
> > > > if (likely(srcu_init_done))
> > > > schedule_work(&ssp->srcu_work);
> > > > @@ -196,6 +202,48 @@ void synchronize_srcu(struct srcu_struct *ssp)
> > > > }
> > > > EXPORT_SYMBOL_GPL(synchronize_srcu);
> > > > +/*
> > > > + * get_state_synchronize_srcu - Provide an end-of-grace-period cookie
> > > > + */
> > > > +unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp)
> > > > +{
> > > > + unsigned long ret;
> > > > +
> > > > + barrier();
> > > > + ret = (READ_ONCE(ssp->srcu_idx) + 3) & ~0x1;
> > > > + barrier();
> > > > + return ret & USHRT_MAX;
> > > > +}
> > > > +EXPORT_SYMBOL_GPL(get_state_synchronize_srcu);
> > > > +
> > > > +/*
> > > > + * start_poll_synchronize_srcu - Provide cookie and start grace period
> > > > + *
> > > > + * The difference between this and get_state_synchronize_srcu() is that
> > > > + * this function ensures that the poll_state_synchronize_srcu() will
> > > > + * eventually return the value true.
> > > > + */
> > > > +unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp)
> > > > +{
> > > > + unsigned long ret = get_state_synchronize_srcu(ssp);
> > > > +
> > > > + srcu_gp_start_if_needed(ssp);
> > > > + return ret;
> > > > +}
> > > > +EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);
> > > > +
> > > > +/*
> > > > + * poll_state_synchronize_srcu - Has cookie's grace period ended?
> > > > + */
> > > > +bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie)
> > > > +{
> > > > + bool ret = USHORT_CMP_GE(READ_ONCE(ssp->srcu_idx), cookie);
> > > > +
> > > > + barrier();
> > > > + return ret;
> > > > +}
> > > > +EXPORT_SYMBOL_GPL(poll_state_synchronize_srcu);
> > > > +
> > > > /* Lockdep diagnostics. */
> > > > void __init rcu_scheduler_starting(void)
> > > > {
> > > >
> > >
> > > --
> > > QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of
> > > the Code Aurora Forum, hosted by The Linux Foundation
>
> --
> QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of
> the Code Aurora Forum, hosted by The Linux Foundation
next prev parent reply other threads:[~2020-11-24 19:31 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <@@@>
2017-06-06 17:07 ` [PATCH v2 tip/core/rcu 1/2] srcu: Allow use of Tiny/Tree SRCU from both process and interrupt context Paul E. McKenney
2017-06-06 17:07 ` [PATCH v2 tip/core/rcu 2/2] srcu: Allow use of Classic " Paul E. McKenney
2020-02-14 23:38 ` [PATCH tip/core/rcu 1/9] doc: Add some more RCU list patterns in the kernel paulmck
2020-02-14 23:38 ` [PATCH tip/core/rcu 2/9] doc/RCU/Design: Remove remaining HTML tags in ReST files paulmck
2020-02-14 23:38 ` [PATCH tip/core/rcu 3/9] doc/RCU/listRCU: Fix typos in a example code snippets paulmck
2020-02-14 23:38 ` [PATCH tip/core/rcu 4/9] doc/RCU/listRCU: Update example function name paulmck
2020-02-14 23:38 ` [PATCH tip/core/rcu 5/9] doc/RCU/rcu: Use ':ref:' for links to other docs paulmck
2020-02-14 23:39 ` [PATCH tip/core/rcu 6/9] doc/RCU/rcu: Use absolute paths for non-rst files paulmck
2020-02-14 23:39 ` [PATCH tip/core/rcu 7/9] doc/RCU/rcu: Use https instead of http if possible paulmck
2020-02-14 23:39 ` [PATCH tip/core/rcu 8/9] doc: Add rcutorture scripting to torture.txt paulmck
2020-02-14 23:39 ` [PATCH tip/core/rcu 9/9] Documentation/memory-barriers: Fix typos paulmck
2020-11-21 0:59 ` [PATCH v2 tip/core/rcu 1/6] srcu: Make Tiny SRCU use multi-bit grace-period counter paulmck
2020-11-23 4:31 ` Neeraj Upadhyay
2020-11-23 19:55 ` Paul E. McKenney
2020-11-24 5:18 ` Neeraj Upadhyay
2020-11-25 4:33 ` Neeraj Upadhyay
2020-11-28 2:16 ` Paul E. McKenney
2020-11-28 4:12 ` Neeraj Upadhyay
2020-11-21 0:59 ` [PATCH v2 tip/core/rcu 2/6] srcu: Provide internal interface to start a Tiny SRCU grace period paulmck
2020-11-21 0:59 ` [PATCH v2 tip/core/rcu 3/6] srcu: Provide internal interface to start a Tree " paulmck
2020-11-21 0:59 ` [PATCH v2 tip/core/rcu 4/6] srcu: Provide polling interfaces for Tiny SRCU grace periods paulmck
2020-11-22 14:30 ` Neeraj Upadhyay
2020-11-22 17:57 ` Paul E. McKenney
2020-11-23 4:43 ` Neeraj Upadhyay
2020-11-23 21:12 ` Paul E. McKenney
2020-11-24 5:14 ` Neeraj Upadhyay
2020-11-24 19:30 ` Paul E. McKenney [this message]
2020-11-25 4:39 ` Neeraj Upadhyay
2020-11-21 0:59 ` [PATCH v2 tip/core/rcu 5/6] srcu: Provide polling interfaces for Tree " paulmck
2020-11-27 4:52 ` Neeraj Upadhyay
2020-11-21 0:59 ` [PATCH v2 tip/core/rcu 6/6] srcu: Document " paulmck
2020-11-27 8:27 ` Neeraj Upadhyay
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=20201124193043.GK1437@paulmck-ThinkPad-P72 \
--to=paulmck@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=kent.overstreet@gmail.com \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=neeraju@codeaurora.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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 NNTP newsgroup(s).