From: Neeraj Upadhyay <neeraju@codeaurora.org>
To: paulmck@kernel.org, rcu@vger.kernel.org
Cc: 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 5/6] srcu: Provide polling interfaces for Tree SRCU grace periods
Date: Fri, 27 Nov 2020 10:22:59 +0530 [thread overview]
Message-ID: <05712100-9f65-d81c-1eb0-671bc54f3baa@codeaurora.org> (raw)
In-Reply-To: <20201121005919.17152-5-paulmck@kernel.org>
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>
> ---
For version in -rcu dev
Reviewed-by: Neeraj Upadhyay <neeraju@codeaurora.org>
Thanks
Neeraj
> kernel/rcu/srcutiny.c | 2 +-
> kernel/rcu/srcutree.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 64 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c
> index b073175..c8f4202 100644
> --- a/kernel/rcu/srcutiny.c
> +++ b/kernel/rcu/srcutiny.c
> @@ -148,7 +148,7 @@ void srcu_drive_gp(struct work_struct *wp)
> * straighten that out.
> */
> WRITE_ONCE(ssp->srcu_gp_running, false);
> - if (USHORT_CMP_GE(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
> + if (USHORT_CMP_LT(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
> schedule_work(&ssp->srcu_work);
> }
> EXPORT_SYMBOL_GPL(srcu_drive_gp);
> diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> index d930ece..945c047 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> @@ -810,7 +810,8 @@ static void srcu_leak_callback(struct rcu_head *rhp)
> /*
> * Start an SRCU grace period, and also queue the callback if non-NULL.
> */
> -static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head *rhp, bool do_norm)
> +static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,
> + struct rcu_head *rhp, bool do_norm)
> {
> unsigned long flags;
> int idx;
> @@ -819,10 +820,12 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head *rh
> unsigned long s;
> struct srcu_data *sdp;
>
> + check_init_srcu_struct(ssp);
> idx = srcu_read_lock(ssp);
> sdp = raw_cpu_ptr(ssp->sda);
> spin_lock_irqsave_rcu_node(sdp, flags);
> - rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp);
> + if (rhp)
> + rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp);
> rcu_segcblist_advance(&sdp->srcu_cblist,
> rcu_seq_current(&ssp->srcu_gp_seq));
> s = rcu_seq_snap(&ssp->srcu_gp_seq);
> @@ -841,6 +844,7 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head *rh
> else if (needexp)
> srcu_funnel_exp_start(ssp, sdp->mynode, s);
> srcu_read_unlock(ssp, idx);
> + return s;
> }
>
> /*
> @@ -874,7 +878,6 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head *rh
> static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
> rcu_callback_t func, bool do_norm)
> {
> - check_init_srcu_struct(ssp);
> if (debug_rcu_head_queue(rhp)) {
> /* Probable double call_srcu(), so leak the callback. */
> WRITE_ONCE(rhp->func, srcu_leak_callback);
> @@ -882,7 +885,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
> return;
> }
> rhp->func = func;
> - srcu_gp_start_if_needed(ssp, rhp, do_norm);
> + (void)srcu_gp_start_if_needed(ssp, rhp, do_norm);
> }
>
> /**
> @@ -1011,6 +1014,62 @@ void synchronize_srcu(struct srcu_struct *ssp)
> }
> EXPORT_SYMBOL_GPL(synchronize_srcu);
>
> +/**
> + * get_state_synchronize_srcu - Provide an end-of-grace-period cookie
> + * @ssp: srcu_struct to provide cookie for.
> + *
> + * This function returns a cookie that can be passed to
> + * poll_state_synchronize_srcu(), which will return true if a full grace
> + * period has elapsed in the meantime. It is the caller's responsibility
> + * to make sure that grace period happens, for example, by invoking
> + * call_srcu() after return from get_state_synchronize_srcu().
> + */
> +unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp)
> +{
> + // Any prior manipulation of SRCU-protected data must happen
> + // before the load from ->srcu_gp_seq.
> + smp_mb();
> + return rcu_seq_snap(&ssp->srcu_gp_seq);
> +}
> +EXPORT_SYMBOL_GPL(get_state_synchronize_srcu);
> +
> +/**
> + * start_poll_synchronize_srcu - Provide cookie and start grace period
> + * @ssp: srcu_struct to provide cookie for.
> + *
> + * This function returns a cookie that can be passed to
> + * poll_state_synchronize_srcu(), which will return true if a full grace
> + * period has elapsed in the meantime. Unlike get_state_synchronize_srcu(),
> + * this function also ensures that any needed SRCU grace period will be
> + * started. This convenience does come at a cost in terms of CPU overhead.
> + */
> +unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp)
> +{
> + return srcu_gp_start_if_needed(ssp, NULL, true);
> +}
> +EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);
> +
> +/**
> + * poll_state_synchronize_srcu - Has cookie's grace period ended?
> + * @ssp: srcu_struct to provide cookie for.
> + * @cookie: Return value from get_state_synchronize_srcu() or start_poll_synchronize_srcu().
> + *
> + * This function takes the cookie that was returned from either
> + * get_state_synchronize_srcu() or start_poll_synchronize_srcu(), and
> + * returns @true if an SRCU grace period elapsed since the time that the
> + * cookie was created.
> + */
> +bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie)
> +{
> + if (!rcu_seq_done(&ssp->srcu_gp_seq, cookie))
> + return false;
> + // Ensure that the end of the SRCU grace period happens before
> + // any subsequent code that the caller might execute.
> + smp_mb(); // ^^^
> + return true;
> +}
> +EXPORT_SYMBOL_GPL(poll_state_synchronize_srcu);
> +
> /*
> * Callback function for srcu_barrier() use.
> */
>
--
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-27 4:53 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
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 [this message]
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=05712100-9f65-d81c-1eb0-671bc54f3baa@codeaurora.org \
--to=neeraju@codeaurora.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=oleg@redhat.com \
--cc=paulmck@kernel.org \
--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