From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Akira Yokosawa <akiyks@gmail.com>
Cc: Imre Palik <imrep.amz@gmail.com>, perfbook@vger.kernel.org
Subject: Re: [PATCH] CodeSamples/count: Use READ_ONCE/WRITE_ONCE in count_nonatomic.c
Date: Wed, 12 Sep 2018 06:18:56 -0700 [thread overview]
Message-ID: <20180912131856.GH4225@linux.vnet.ibm.com> (raw)
In-Reply-To: <59ab187c-a663-1e84-9241-919f358ba663@gmail.com>
On Wed, Sep 12, 2018 at 07:53:24PM +0900, Akira Yokosawa wrote:
> >From 13fa1b9b162483df5d88b7aefe408a4e17e83338 Mon Sep 17 00:00:00 2001
> From: Akira Yokosawa <akiyks@gmail.com>
> Date: Wed, 12 Sep 2018 19:27:41 +0900
> Subject: [PATCH] CodeSamples/count: Use READ_ONCE/WRITE_ONCE in count_nonatomic.c
>
> Without them, inlined accesses can be optimized away by "-O3".
That code was written in a far more innocent time when compilers were
far less aggressive, wasn't it?
Great catch, both on the data and on the code, thank you! Applied and
pushed.
Thanx, Paul
> Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
> ---
> CodeSamples/count/count_nonatomic.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/CodeSamples/count/count_nonatomic.c b/CodeSamples/count/count_nonatomic.c
> index 90979c5..50df475 100644
> --- a/CodeSamples/count/count_nonatomic.c
> +++ b/CodeSamples/count/count_nonatomic.c
> @@ -25,12 +25,12 @@ unsigned long counter = 0;
>
> __inline__ void inc_count(void)
> {
> - counter++;
> + WRITE_ONCE(counter, READ_ONCE(counter) + 1);
> }
>
> __inline__ unsigned long read_count(void)
> {
> - return counter;
> + return READ_ONCE(counter);
> }
>
> __inline__ void count_init(void)
> --
> 2.7.4
>
>
prev parent reply other threads:[~2018-09-12 18:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-02 8:54 Question on updated Figure 5.1 "Atomic Increment Scalability on Kaby Lake" Akira Yokosawa
[not found] ` <CAFMy-Rk76bc+oOXq7ijGT4wzYkFbs1F7bkLWQ-VwE_O2Q-Z2VQ@mail.gmail.com>
2018-09-12 10:51 ` Akira Yokosawa
2018-09-12 10:53 ` [PATCH] CodeSamples/count: Use READ_ONCE/WRITE_ONCE in count_nonatomic.c Akira Yokosawa
2018-09-12 13:18 ` 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=20180912131856.GH4225@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=akiyks@gmail.com \
--cc=imrep.amz@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.