[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [DOC v1] Xen transport for 9pfs



On 02/12/16 00:29, Stefano Stabellini wrote:
> On Wed, 30 Nov 2016, David Vrabel wrote:
>> On 29/11/16 23:34, Stefano Stabellini wrote:
>>> The producer (the backend for **in**, the frontend for **out**) writes to 
>>> the
>>> array in the following way:
>>>
>> - read memory barrier
>>> - read *cons*, *prod* from shared memory
>>> - write to array at position *prod* up to *cons*, wrapping around the 
>>> circular
>>>   buffer when necessary
>> - write memory barrier
>>> - increase *prod*
>>> - notify the other end via evtchn
>>>
>>> The consumer (the backend for **out**, the frontend for **in**) reads from 
>>> the
>>> array in the following way:
>> - read memory barrier
>>> - read *prod*, *cons* from shared memory
>>> - read from array at position *cons* up to *prod*, wrapping around the 
>>> circular
>>>   buffer when necessary
>>> - memory barrier
>>> - increase *cons*
>>> - notify the other end via evtchn
>> Your barriers are wrong (see corrections above).
> Thanks for the review. Sorry for not specifying the type of memory
> barriers. I agree with some of your suggestions, but I don't understand
> why you moved the read memory barrier before reading prod and cons.
>
> Shouldn't it be for a producer:
>   - read *cons*, *prod* from shared memory
>   - read memory barrier
>   - write to array at position *prod* up to *cons*, wrapping around the 
> circular
>     buffer when necessary
>   - write memory barrier
>   - increase *prod*
>   - notify the other end via evtchn
>  
> and for a consumer:
>   - read *prod*, *cons* from shared memory
>   - read memory barrier
>   - read from array at position *cons* up to *prod*, wrapping around the 
> circular
>     buffer when necessary
>   - general memory barrier
>   - increase *cons*
>   - notify the other end via evtchn
>
> If this is wrong, could you please explain why?

It is wrong.  A read barrier is used to separate two reads which must
happen in a certain order.  A write barrier separates two writes.  A
full memory barrier is required to separate a read from a write.

e.g.

foo = a;
smp_rmb();
bar = b;

and

a = foo';
smp_wmb();
b = bar';

Read and write barriers must come in matched pairs excluding the same
fields.  If your pattern looks different to that, then you are using
them wrong.

If instead, you need to exclude reads from writes, then you must use
something looking like:

foo = a;
smp_mb();
b = bar;

on both sides.

~Andrew

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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.