Discussions of the Parallel Programming book
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Akira Yokosawa <akiyks@gmail.com>
Cc: perfbook@vger.kernel.org
Subject: Re: [RFC PATCH 4/4] CodeSamples/defer: Add compiler barriers in gettimestampmp.c
Date: Mon, 29 May 2017 17:12:48 -0700	[thread overview]
Message-ID: <20170530001247.GS3956@linux.vnet.ibm.com> (raw)
In-Reply-To: <7422a673-c911-4916-b626-348f693f1180@gmail.com>

On Tue, May 30, 2017 at 07:18:51AM +0900, Akira Yokosawa wrote:
> >From fd5fb9afb6b99b15370a9823b42fa2a92342b92a Mon Sep 17 00:00:00 2001
> From: Akira Yokosawa <akiyks@gmail.com>
> Date: Sun, 28 May 2017 15:42:45 +0900
> Subject: [RFC PATCH 4/4] CodeSamples/defer: Add compiler barriers in gettimestampmp.c
> 
> They ensure curtimestamp is read and written once in every
> iteration.
> 
> Signed-off-by: Akira Yokosawa <akiyks@gmail.com>

I was actually more or less OK with this one, but it does not apply
cleanly without 3/4.

Nevertheless, given that it needs change anyway, would it be better to
replace the ++ with a WRITE_ONCE and capture the value in the "while"
expression?

							Thanx, Paul

> ---
>  CodeSamples/defer/gettimestampmp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/CodeSamples/defer/gettimestampmp.c b/CodeSamples/defer/gettimestampmp.c
> index e794e82..7012caa 100644
> --- a/CodeSamples/defer/gettimestampmp.c
> +++ b/CodeSamples/defer/gettimestampmp.c
> @@ -32,7 +32,7 @@ void *collect_timestamps(void *mask_in)
>  	intptr_t mask = (intptr_t)mask_in;
> 
>  	while (curtimestamp < MAX_TIMESTAMPS) {
> -		while ((curtimestamp & CURTIMESTAMP_MASK) != mask)
> +		while ((READ_ONCE(curtimestamp) & CURTIMESTAMP_MASK) != mask)
>  			continue;
>  		if (curtimestamp >= MAX_TIMESTAMPS)
>  			break;
> @@ -40,6 +40,7 @@ void *collect_timestamps(void *mask_in)
>  		/* Don't need memory barrier -- no other shared vars!!! */
> 
>  		ts[curtimestamp++] = get_timestamp();
> +		barrier();
>  	}
>  	smp_mb();
>  	return (NULL);
> -- 
> 2.7.4
> 
> 


  reply	other threads:[~2017-05-30  0:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-29 22:13 [RFC PATCH 0/4] CodeSamples: Cleanups and fixes Akira Yokosawa
2017-05-29 22:14 ` [RFC PATCH 1/4] CodeSamples: Add rule to generate Makefile.arch and api.h Akira Yokosawa
2017-05-29 22:16 ` [RFC PATCH 2/4] CodeSamples: Remove generated files from repository Akira Yokosawa
2017-05-29 22:17 ` [RFC PATCH 3/4] CodeSamples: Use 'intptr_t' to be compatible with 'void *' Akira Yokosawa
2017-05-30  0:10   ` Paul E. McKenney
2017-05-29 22:18 ` [RFC PATCH 4/4] CodeSamples/defer: Add compiler barriers in gettimestampmp.c Akira Yokosawa
2017-05-30  0:12   ` Paul E. McKenney [this message]
2017-05-30  0:02 ` [RFC PATCH 0/4] CodeSamples: Cleanups and fixes Paul E. McKenney
2017-05-30  1:44   ` Akira Yokosawa
2017-05-30 12:05 ` [RFC PATCH v2 0/2] " Akira Yokosawa
2017-05-30 12:06   ` [RFC PATCH v2 1/2] CodeSamples: Use 'intptr_t' to be compatible with 'void *' Akira Yokosawa
2017-05-30 12:07   ` [RFC PATCH v2 2/2] CodeSamples/defer: Add compiler barriers in gettimestampmp.c Akira Yokosawa
2017-05-31 18:46   ` [RFC PATCH v2 0/2] CodeSamples: Cleanups and fixes Paul E. McKenney
2017-05-31 21:19     ` Akira Yokosawa
2017-06-01  0:05       ` Paul E. McKenney
2017-06-01  1:45     ` Junchang Wang
2017-06-01  4:19       ` Paul E. McKenney
2017-06-01  4:34         ` Junchang Wang

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=20170530001247.GS3956@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akiyks@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