[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
- [Qemu-devel] [PATCH v2 0/9] A couple of fixes for ThreadSanitizer, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 2/9] tcg/optimize: move default return out of if statement, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 1/9] ui/vnc-enc-tight: remove switch and have single return, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 4/9] seqlock: use atomic writes for the sequence, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 6/9] cpu: atomically modify cpu->exit_request, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 3/9] new: blacklist.tsan, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 8/9] qga/command: use QEMU atomic primitives, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 5/9] qom/object: update class cache atomically, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 9/9] .travis.yml: add gcc sanitizer build, Alex Bennée, 2016/09/22
- [Qemu-devel] [PATCH v2 7/9] util/qht: atomically set b->hashes, Alex Bennée, 2016/09/22