From: "Paul E. McKenney" <paulmck@kernel.org>
To: Alan Huang <mmpgouride@gmail.com>
Cc: perfbook@vger.kernel.org
Subject: Re: [PATCH] CodeSample/count: Update the places where READ_ONCE is used
Date: Fri, 2 Jun 2023 13:45:09 -0700 [thread overview]
Message-ID: <90b826cb-8ad5-4c5b-b0f8-47e7e5006042@paulmck-laptop> (raw)
In-Reply-To: <20230530145127.18738-1-mmpgouride@gmail.com>
On Tue, May 30, 2023 at 02:51:27PM +0000, Alan Huang wrote:
> There is no concurrent updates to 'total' by other threads, plain access
> is enough. But there might be threads updating 'counter', READ_ONCE is
> required.
>
> Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Queued and pushed, thank you!
Thanx, Paul
> ---
> CodeSamples/count/count_end_rcu.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/CodeSamples/count/count_end_rcu.c b/CodeSamples/count/count_end_rcu.c
> index 8fc70611..71bd5269 100644
> --- a/CodeSamples/count/count_end_rcu.c
> +++ b/CodeSamples/count/count_end_rcu.c
> @@ -48,10 +48,10 @@ unsigned long read_count(void) //\lnlbl{read:b}
>
> rcu_read_lock(); //\lnlbl{read:rrl}
> cap = rcu_dereference(countarrayp); //\lnlbl{read:deref}
> - sum = READ_ONCE(cap->total); //\lnlbl{read:init}
> + sum = cap->total; //\lnlbl{read:init}
> for_each_thread(t) { //\lnlbl{read:add:b}
> ctrp = READ_ONCE(cap->counterp[t]);
> - if (ctrp != NULL) sum += *ctrp; //\lnlbl{read:add:e}
> + if (ctrp != NULL) sum += READ_ONCE(*ctrp); //\lnlbl{read:add:e}
> }
> rcu_read_unlock(); //\lnlbl{read:rru}
> return sum; //\lnlbl{read:ret}
> --
> 2.34.1
>
prev parent reply other threads:[~2023-06-02 20:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 14:51 [PATCH] CodeSample/count: Update the places where READ_ONCE is used Alan Huang
2023-06-02 20:45 ` Paul E. McKenney [this message]
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=90b826cb-8ad5-4c5b-b0f8-47e7e5006042@paulmck-laptop \
--to=paulmck@kernel.org \
--cc=mmpgouride@gmail.com \
--cc=perfbook@vger.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).