atomicity of unlocked reads

Alan Cox alc at cs.rice.edu
Wed Sep 17 11:22:42 PDT 2003


On Wed, Sep 17, 2003 at 10:50:58AM -0700, Frank Mayhar wrote:
> John Baldwin wrote:
> > I think you can assume that the read will be atomic.  I don't think FreeBSD
> > would work very well on a machine where aligned pointer reads/writes weren't
> > atomic.
> 
> I dunno, I tend to think that making such assumptions may well come back to
> bite me in the ass when I least expect it.  In such situation, I invariably
> use some kind of "atomic_xxx_load/store" primitive that does the job safely
> and in a machine-dependent way while hiding the details from the MI code.
> 

Indeed.  Atomicity of the read is not the only issue.  Unless I
misunderstood, Bruce is proposing to perform an unsynchronized read of
a location that is updated by a different processor.  This
unsynchronized read is to obtain a pointer.  In weaker memory
consistency models (than that of the x86), there is no guarantee that
the data that the pointer refers to will be consistent.  In other
words, updates to the data that the pointer refers to may not have
completed, even though the update to the memory location containing
the pointer has completed.

This is what an "acquire load" is for.  Roughly speaking, it should
guarantee that any updates prior to a corresponding "release store"
(by a different processor) will be seen.

If we don't use "acquire loads" and "release stores" under such
circumstances, the poor guy who ports FreeBSD to a processor that, for
example, reorders loads, will be an unhappy camper.

Alan


More information about the freebsd-smp mailing list