Re: [ANNOUNCE] mdb: Merkey's Linux Kernel Debugger 2.6.27-rc4released

From: Peter Zijlstra
Date: Thu Aug 21 2008 - 10:51:43 EST


On Thu, 2008-08-21 at 07:30 -0700, Paul E. McKenney wrote:
> On Thu, Aug 21, 2008 at 04:09:59PM +0200, Peter Zijlstra wrote:
> > On Thu, 2008-08-21 at 23:37 +1000, Nick Piggin wrote:
> > > On Thursday 21 August 2008 22:26, jmerkey@xxxxxxxxxxxxxxxxxxxxx wrote:
> > >
> > > > I used the smp_wmb() functions. I noted a couple of things. a) some of
> > > > these macros just emit __asm__ __volatile__ into the code so why not just
> > > > say "volatile" to begin with
> > >
> > > It is not the same as volatile type. What it does is tell the compiler
> > > to clobber all registers or temporaries. This something pretty well
> > > defined and hard to get wrong compared to volatile type.
> >
> > Right, asm volatile () means that the asm may not be discarted. Very
> > different from the volatile type qualifier.
> >
> > > > b) smp_wmb() in some cases worked and in
> > > > other cases jut optimized away the global reference.
> > >
> > > Linux barriers aren't going to force a load to be emitted, if it can be
> > > optimized away. If it optimized away a store, then I'd like to see a
> > > test case.
> >
> > Not sure - I think all barrier clobber the full register and memory set.
> > So if you access a variable after a barrier it will have to issue a
> > load.
>
> Here is one example (which might or might not be what Nick had in mind):
>
> extern int v;
>
> void foo(void)
> {
> do_something_with(v);
> barrier();
> do_something_else_with(v - v);
> }
>
> The second set of loads from v can be optimized away unless v is
> declared volatile. In contrast:
>
> void bar(void)
> {
> do_something_with(v);
> barrier();
> do_something_else_with(v);
> }
>
> Here the compiler must refetch v after the barrier.

Ah, right. But in that case:

v-v := tmp1 = v; tmp2 = v; sub tmp1,tmp2;

Which you can of course write out more explicitly in C as well and
insert a barrier between the two reads of v, giving the same effect as
volatile.

Still, point taken.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/