All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Emilio G. Cota" <cota@braap.org>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, alex.bennee@linaro.org
Subject: Re: [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-protected variables
Date: Thu, 13 Oct 2016 15:20:15 -0400	[thread overview]
Message-ID: <20161013192015.GA22617@flamenco> (raw)
In-Reply-To: <1476107947-31430-3-git-send-email-pbonzini@redhat.com>

On Mon, Oct 10, 2016 at 15:59:04 +0200, Paolo Bonzini wrote:
> There is a data race if the variable is written concurrently to the
> read.  In C11 this has undefined behavior.  Use atomic_read.  The
> write side does not need atomic_set, because it is protected by a
> mutex.

Is tsan happy with the way seqlocks are written right now?

According to this message I just found by Dmitry Vyukov, tsan
shouldn't be. Note however that the message is from April'15,
so it might be outdated:

Dmitry Vyukov wrote:
> 1. Tsan is bad at handling stand-alone memory barriers. 
<snip>
> 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

  parent reply	other threads:[~2016-10-13 19:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10 13:59 [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 1/5] atomic: introduce smp_mb_acquire and smp_mb_release Paolo Bonzini
2016-10-10 15:29   ` Eric Blake
2016-10-10 16:38     ` Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 2/5] cpus: use atomic_read to read seqlock-protected variables Paolo Bonzini
2016-10-12  8:44   ` Alex Bennée
2016-10-13 19:20   ` Emilio G. Cota [this message]
2016-10-13 20:45     ` Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 3/5] qemu-thread: use acquire/release to clarify semantics of QemuEvent Paolo Bonzini
2016-10-12  9:21   ` Alex Bennée
2016-10-12  9:31     ` Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 4/5] rcu: simplify memory barriers Paolo Bonzini
2016-10-10 13:59 ` [Qemu-devel] [PATCH 5/5] atomic: base mb_read/mb_set on load-acquire and store-release Paolo Bonzini
2016-10-12  9:28   ` Alex Bennée
2016-10-12  9:30     ` Paolo Bonzini
2016-10-20 18:36   ` Pranith Kumar
2016-10-10 16:53 ` [Qemu-devel] [PATCH 0/5] More thread sanitizer fixes and atomic.h improvements no-reply
2016-10-11 19:21 ` no-reply
2016-10-12 11:32 ` Alex Bennée
2016-10-12 11:34   ` Paolo Bonzini
2016-10-12 22:45 ` Emilio G. Cota
2016-10-13  7:39   ` Paolo Bonzini
2016-10-13 19:29     ` Emilio G. Cota
2016-10-14  9:55       ` Paolo Bonzini
2016-10-21 17:38 ` Alex Bennée
2016-10-22  9:10   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161013192015.GA22617@flamenco \
    --to=cota@braap.org \
    --cc=alex.bennee@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.