All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@steeleye.com>
To: Matthew Wilcox <willy@debian.org>
Cc: Randolph Chung <tausq@debian.org>,
	John David Anglin <dave@hiauly1.hia.nrc.ca>,
	grundler@dsl2.external.hp.com,
	parisc-linux@lists.parisc-linux.org
Subject: Re: [parisc-linux] Re: [parisc-linux-cvs] linux grundler
Date: 09 Feb 2003 08:55:33 -0600	[thread overview]
Message-ID: <1044802535.1741.30.camel@mulgrave> (raw)
In-Reply-To: <20030209020325.D27544@parcelfarce.linux.theplanet.co.uk>

On Sat, 2003-02-08 at 20:03, Matthew Wilcox wrote:
> I think it's even worse than that.  What stops gcc reordering:
> 
> typedef struct {
>         spinlock_t lock;
>         volatile int counter;
> } rwlock_t;
> 
> static  __inline__ void _raw_read_lock(rwlock_t *rw)
> {
>         while (__ldcw (&(x)->lock) == 0) \
>                 while (((x)->lock) == 0) ; } while (0)
>         rw->counter++;
>         do { (x)->lock = 1; } while(0)
> }
> 
> to:
> 
>         while (__ldcw (&(x)->lock) == 0) \
>                 while (((x)->lock) == 0) ; } while (0)
>         do { (x)->lock = 1; } while(0)
>         rw->counter++;

Compilers themselves have fairly strong reordering rules.  For instance,
do { } while() blocks cannot be reordered like your example (that's why
the kernel uses do { } while(0); as a compiler reordering barrier.

You can if you prefer use the barrier() macro, which prevents the
compiler from reordering statements around it.

Of course, the processor can still reorder what the compiler doesn't as
part of its speculation and optimisation (that's what mb(), rmb() and
wmb() are all about).

James

  parent reply	other threads:[~2003-02-09 14:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20030208222242.AA3554829@dsl2.external.hp.com>
     [not found] ` <20030208222746.GB19683@dsl2.external.hp.com>
2003-02-08 23:23   ` [parisc-linux] Re: [parisc-linux-cvs] linux grundler Matthew Wilcox
2003-02-09  0:35     ` John David Anglin
2003-02-09  0:49       ` Randolph Chung
2003-02-09  0:56         ` Randolph Chung
2003-02-09  2:03           ` Matthew Wilcox
2003-02-09  2:18             ` John David Anglin
2003-02-09 14:55             ` James Bottomley [this message]
2003-02-09  2:11           ` John David Anglin
2003-02-09  3:27       ` Grant Grundler
2003-02-09  4:06         ` John David Anglin
2003-02-09  3:10     ` Grant Grundler
2003-02-09 12:29       ` Matthew Wilcox
2003-02-09 14:35         ` Matthew Wilcox
2003-02-09 19:14         ` Grant Grundler
2003-02-09 21:24           ` Aaron St. Pierre
2003-02-10 16:47             ` Grant Grundler
2003-02-09 23:56           ` Randolph Chung
2003-02-09  8:11     ` Grant Grundler
2003-02-09 12:21       ` Matthew Wilcox
2003-07-09 10:35 Joel Soete
     [not found] <20030708022259.B62B849404E@palinux.hppa>
2003-07-08 15:06 ` Carlos O'Donell
  -- strict thread matches above, loose matches on Subject: below --
2003-02-10  8:38 John Marvin
2003-02-09  8:55 [parisc-linux] " John Marvin
2003-02-09  7:40 John Marvin
2003-02-09  8:26 ` [parisc-linux] " Grant Grundler
     [not found] <20020804011707.2B9164860@dsl2.external.hp.com>
2002-08-04  2:03 ` Grant Grundler

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=1044802535.1741.30.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=dave@hiauly1.hia.nrc.ca \
    --cc=grundler@dsl2.external.hp.com \
    --cc=parisc-linux@lists.parisc-linux.org \
    --cc=tausq@debian.org \
    --cc=willy@debian.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.