>>> On 12.06.17 at 12:24, <julien.gr...@arm.com> wrote:
> I am trying to understand why we decided to implement the helpers 
> read_atomic, write_atomic, add_sized in assembly rather than directly in C.
> 
> AFAICT implementation in C similar to Linux helpers WRITE_ONCE/READ_ONCE 
> would work here. Did I miss anything?

For one at least our current ACCESS_ONCE() doesn't allow non-
scalar types to be read/written, whereas {read,write}_atomic()
solely look at sizeof(). Plus ACCESS_ONCE() doesn't enforce a
single instruction to be used in the resulting assembly - while the
compiler may not fold multiple accesses, it still may break them
up if it wishes to (but of course it usually won't it the whole thing
can be expressed with a single instruction).

For add_sized() it's even worse: The macro enforces (on x86) an
operation on a memory operand (i.e. again a single instruction).
"ACCESS_ONCE(x) += n", otoh, may (and iirc normally will) be
translated to a memory of x, addition of the read value with n,
and a memory write.

> Note that the naming is also confusing as it is easily to mix with the 
> atomic_read, atomic_write helpers.

Well, yes, unfortunately.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

Reply via email to