Discussions of the Parallel Programming book
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.ibm.com>
To: Junchang Wang <junchangwang@gmail.com>
Cc: akiyks@gmail.com, perfbook@vger.kernel.org
Subject: Re: [PATCH] atomic_cmpxchg: Handle spurious failure of __atomic_compare_exchange_n in Power8 and ARMv8
Date: Fri, 26 Oct 2018 13:58:15 -0700	[thread overview]
Message-ID: <20181026205815.GY4170@linux.ibm.com> (raw)
In-Reply-To: <1540569805-7066-1-git-send-email-junchangwang@gmail.com>

On Sat, Oct 27, 2018 at 12:03:25AM +0800, Junchang Wang wrote:
> If the 4th parameter (field *weak*) of __atomic_compare_exchange_n is set, it
> may refuse to perform the CAS operation and return a failure, even if the value
> of field *old* is equal to the content of the specified memory location. This
> happens in architectures where LL/SC is used to emulate CAS primitive (e.g., PPC
> and ARM).
> 
> This patch returns the *old* value if __atomic_compare_exchange_n has been
> successfully performed; otherwise, *old*+1 is returned, which forces the caller
> to retry the CAS loop.
> 
> Signed-off-by: Junchang Wang <junchangwang@gmail.com>
> Signed-off-by: kira Yokosawa <akiyks@gmail.com>

Very good, queued and pushed with adjustments to the commit log above,
thank you!!!

Please let me know if further adjustments are required.

							Thanx, Paul

> ---
>  CodeSamples/api-pthreads/api-gcc.h | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/CodeSamples/api-pthreads/api-gcc.h b/CodeSamples/api-pthreads/api-gcc.h
> index 1dd26ca..3afe340 100644
> --- a/CodeSamples/api-pthreads/api-gcc.h
> +++ b/CodeSamples/api-pthreads/api-gcc.h
> @@ -168,9 +168,8 @@ struct __xchg_dummy {
>  ({ \
>  	typeof(*ptr) _____actual = (o); \
>  	\
> -	(void)__atomic_compare_exchange_n(ptr, (void *)&_____actual, (n), 1, \
> -					  __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \
> -	_____actual; \
> +	__atomic_compare_exchange_n(ptr, (void *)&_____actual, (n), 1, \
> +			__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? (o) : (o)+1; \
>  })
>  
>  static __inline__ int atomic_cmpxchg(atomic_t *v, int old, int new)
> -- 
> 2.7.4
> 


      reply	other threads:[~2018-10-27  5:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-26 16:03 [PATCH] atomic_cmpxchg: Handle spurious failure of __atomic_compare_exchange_n in Power8 and ARMv8 Junchang Wang
2018-10-26 20:58 ` 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=20181026205815.GY4170@linux.ibm.com \
    --to=paulmck@linux.ibm.com \
    --cc=akiyks@gmail.com \
    --cc=junchangwang@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