Subject: Re: how to avoid re-ordering?
To: Luke Mewburn <lukem@wasabisystems.com>
From: Gregory McGarry <g.mcgarry@ieee.org>
List: tech-kern
Date: 12/17/2001 15:48:19
Luke Mewburn wrote:
> > > > > I noticed that spl*/splx are inlined and re-orderd
> > > > > with "-O3 -march=pentium", and it produce bad codes as a result.
> > > > > I actually experienced panics due to this.
> > > >
> > > > I'll commit attached patch some days later if no objection.
> > > > thanks.
> > >
> > > Should't we just declare "cpl" as __volatile?
> >
> > cpl is already volatile, isn't it?
> > am I missing something important?
>
> (Note: I am not a gcc guru.)
>
> What if ncpl or ocpl (local variables to the appropriate functions)
> are marked volatile as well, because as far as I can tell, it's the
> reordering of access to those variables which is what's causing the
> problem, not the access to the volatile cpl.
It seems that __asm statements are atomic and gcc won't reschedule
around them. This seems to work:
static __inline int
splraise(ncpl)
int ncpl;
{
int ocpl;
__asm __volatile(" \
movl %1, %%edx; \
movl %%edx, %0; \
orl %2,%%edx; \
movl %%edx, %1" : "=&r" (ocpl), "=m" (cpl) \
: "r" (ncpl) : "%edx" );
return (ocpl);
}
static __inline void
spllower(ncpl)
int ncpl;
{
__asm __volatile("movl %1, %0" : "=m" (cpl) : "r" (ncpl));
}
-- Gregory McGarry <g.mcgarry@ieee.org>