All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ralf Baechle <ralf@linux-mips.org>
To: David Daney <ddaney@avtrex.com>
Cc: Richard Sandiford <rsandifo@nildram.co.uk>,
	GCC Mailing List <gcc@gcc.gnu.org>,
	linux-mips@linux-mips.org
Subject: Re: MIPS atomic memory operations (A.K.A PR 33479).
Date: Wed, 19 Sep 2007 17:58:09 +0100	[thread overview]
Message-ID: <20070919165809.GA14767@linux-mips.org> (raw)
In-Reply-To: <46F06980.4080500@avtrex.com>

On Tue, Sep 18, 2007 at 05:12:48PM -0700, David Daney wrote:

> There seems to be a small problem with the MIPS atomic memory operations 
> patch I recently committed 
> (http://gcc.gnu.org/ml/gcc-patches/2007-08/msg01290.html), in that on a 
> dual CPU machine it does not quite work.
> 
> You can look at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33479#c3 for 
> more information.
> 
> Here is the code in question (from mips.h):
> 
> #define MIPS_COMPARE_AND_SWAP(SUFFIX, OP)	\
>   "%(%<%[sync\n"				\
>   "1:\tll" SUFFIX "\t%0,%1\n"			\
>   "\tbne\t%0,%2,2f\n"				\
>   "\t" OP "\t%@,%3\n"				\
>   "\tsc" SUFFIX "\t%@,%1\n"			\
>   "\tbeq\t%@,%.,1b\n"				\

Please make this loop closure branch a branch-likely.  This is necessary
as a errata workaround for some processors.

(I know silicon people hate me for keeping branch likely instruction alive
this way but it's my job to make sure Linux and software are working without
unpleasant surprises.)

>   "\tnop\n"					\
>   "2:%]%>%)"
> 
> 
> 
> I guess my basic question is:  Should MIPS_COMPARE_AND_SWAP have a 
> 'sync' after the 'sc'?  I would have thought that 'sc' made the write 
> visible to all CPUs, but on the SB1 it appears not to be the case.

The MIPS architecture specification specifies no memory model, so for
portable code you need to make a worst case assumption which is weak
ordering.

Only on R4000 and R4400 SC and SCD did imply a SYNC operation.

> If we do need to add another 'sync' should it go in the delay slot of 
> the branch?  I would say yes because we would expect the branch to 
> rarely taken.

Not when using a branch likely.

Btw, I recently wrote an article about memory consistency which is at
http://www.linux-mips.org/wiki/Memory_consistency.  It gives a bit of
an overview of things in general and on MIPS specifically.  I request
people with detailed knowledge of MIPS cores not specifically covered
in that article to contribute.

  Ralf

  parent reply	other threads:[~2007-09-19 16:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-19  0:12 MIPS atomic memory operations (A.K.A PR 33479) David Daney
2007-09-19  2:32 ` Daniel Jacobowitz
2007-09-19  8:45 ` Thiemo Seufer
2007-09-19 16:58 ` Ralf Baechle [this message]
2007-09-19 17:07   ` Maciej W. Rozycki
2007-09-19 17:26     ` David Daney
2007-09-19 17:46       ` Maciej W. Rozycki
2007-09-19 17:49         ` David Daney
2007-09-19 18:12           ` Thiemo Seufer
2007-09-19 18:28             ` Ralf Baechle
2007-09-19 17:47       ` David Daney
2007-09-19 18:08         ` Maciej W. Rozycki

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=20070919165809.GA14767@linux-mips.org \
    --to=ralf@linux-mips.org \
    --cc=ddaney@avtrex.com \
    --cc=gcc@gcc.gnu.org \
    --cc=linux-mips@linux-mips.org \
    --cc=rsandifo@nildram.co.uk \
    /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.