[PATCH] amd64/pcpu.h: Use Clang builtins for clarity when referencing thread's pcpu
Meyer, Conrad
conrad.meyer at isilon.com
Tue Mar 18 19:38:16 UTC 2014
From: John Baldwin [jhb at freebsd.org]
Sent: Tuesday, March 18, 2014 11:52 AM
To: freebsd-hackers at freebsd.org
Cc: Meyer, Conrad; Bryan Drewery
Subject: Re: [PATCH] amd64/pcpu.h: Use Clang builtins for clarity when referencing thread's pcpu
> > - How atomic does PCPU_INC() need to be? It looks like it updates cpu-local
> > counters; as long as it's a single asm instruction, should it be fine
> > w.r.t. interrupts? The existing implementation does NOT use the 'lock; ' prefix.
>
> I think a single instruction is fine.
Unfortunately, I'm seeing crashes under stress in internal testing that I can't attribute to anything else. I'm not sure why Clang would generate more than one instruction for any of this, but I haven't probed too deeply.
> > diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h
> > index fe898e9..68892fc 100644
> > --- a/sys/amd64/include/pcpu.h
> > +++ b/sys/amd64/include/pcpu.h
> > +#define curthread __extension__ ({ \
> > + *((volatile __pcpu_type(pc_curthread) __GS_RELATIVE *) \
> > + __pcpu_offset(pc_curthread)); \
> > +})
>
> Would be nice to not lose the __pure2 attribute for curthread (you
> might need it to still be an inline function to keep that)
Yeah, I think you would need it to be a function for that. As is I don't think Clang has any reason to optimize away redundant loads from a volatile pointer.
Thanks,
Conrad
More information about the freebsd-hackers
mailing list