qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 4/9] seqlock: use atomic writes for the seque


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH v2 4/9] seqlock: use atomic writes for the sequence
Date: Thu, 22 Sep 2016 18:14:40 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0


On 22/09/2016 17:38, Richard Henderson wrote:
>> diff --git a/include/qemu/seqlock.h b/include/qemu/seqlock.h
>> index 2e2be4c..8dee11d 100644
>> --- a/include/qemu/seqlock.h
>> +++ b/include/qemu/seqlock.h
>> @@ -31,7 +31,7 @@ static inline void seqlock_init(QemuSeqLock *sl)
>>  /* Lock out other writers and update the count.  */
>>  static inline void seqlock_write_begin(QemuSeqLock *sl)
>>  {
>> -    ++sl->sequence;
>> +    atomic_set(&sl->sequence, sl->sequence + 1);
> 
> The read side isn't using a atomic_read right here.

There cannot be concurrent writes, so this is okay (and actually helps
catching seqlock write-side critical sections not protected by a mutex
or something else).

The rule is that there is a race if two accesses, one of them a write
_and_ one of them not atomic, are concurrent.

So reads not concurrent with any writes are fine (e.g. if all writes are
under a mutex, reads under the mutex are fine too).

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]