atomicity of unlocked reads

Terry Lambert tlambert2 at mindspring.com
Thu Sep 18 01:24:00 PDT 2003


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.
> 
> Just call me paranoid.

It would definitely bite you on an MP PPC machine, which can do
the operations non-atomically, branch-predictively, and doesn't
support a "lock" prefix to its instructions.  One of the side
effects of doing a lock is that you will get an idync and dsync
that flush the data and instruction caches, and ensure cache line
coherency between processors.

It would probably bite you on a SPARC as well, unless you explicitly
flushed your register windows before and after the operation (and
even then, you would likely need additional voodoo for anything over
4 CPUs, the way they do things).

-- Terry


More information about the freebsd-smp mailing list