[parisc-linux] Re: [parisc-linux-cvs] linux grundler

John David Anglin dave@hiauly1.hia.nrc.ca
Sat, 8 Feb 2003 21:18:44 -0500 (EST)


> 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++;

Nothing.  The reset needs to be a volatile asm.  This will stop GCC from
doing the above.  On PA 2.0, the processor can do similar reordering.  So,
the reset needs to be an ordered store.  Well, I think the scheduling
model tends to try to do things as early as possible, consistent with
not over feeding the pipeline.  However, I wouldn't rely on this to
get the instrunction order that you want.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)