[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-prote
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-protected variables |
Date: |
Thu, 13 Oct 2016 16:45:00 -0400 (EDT) |
> Is tsan happy with the way seqlocks are written right now?
I honestly don't know. But if there are tsan bugs there's
not much we can do. The alternative below has overhead on
ARM and PPC and does not quite fit in atomic.h.
In any case, a bigger issue is that this patch breaks on
32-bit because it does 64-bit atomic_read. We might have
to fall back to volatile when not running on tsan.
Paolo
> Dmitry Vyukov wrote:
> > 1. Tsan is bad at handling stand-alone memory barriers.
> > And here is a way to express seqlock that is both correct, is
> > understood by tsan and is no overhead on x86:
> >
> > // writer
> > atomic_store(&seq, seq+1, memory_order_relaxed);
> > atomic_store(&data[0], ..., memory_order_release);
> > ...
> > atomic_store(&data[N], ..., memory_order_release);
> > atomic_store(&seq, seq+1, memory_order_release);
> >
> > // reader
> > atomic_load(&seq, memory_order_acquire);
> > d0 = atomic_load(&data[0], memory_order_acquire);
> > ...
> > dN = atomic_load(&data[N], memory_order_acquire);
> > atomic_load(&seq, memory_order_relaxed);
>
> Source: https://groups.google.com/forum/#!topic/thread-sanitizer/B4i9EMQ4BQE
>
> Thanks,
>
> Emilio
>
- [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements, Paolo Bonzini, 2016/10/10
- [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-protected variables, Paolo Bonzini, 2016/10/10
- [Qemu-devel] [PATCH 3/5] qemu-thread: use acquire/release to clarify semantics of QemuEvent, Paolo Bonzini, 2016/10/10
- [Qemu-devel] [PATCH 1/5] atomic: introduce smp_mb_acquire and smp_mb_release, Paolo Bonzini, 2016/10/10
- [Qemu-devel] [PATCH 4/5] rcu: simplify memory barriers, Paolo Bonzini, 2016/10/10
- [Qemu-devel] [PATCH 5/5] atomic: base mb_read/mb_set on load-acquire and store-release, Paolo Bonzini, 2016/10/10