Received: from eggs.gnu.org ([2001:4830:134:3::10]:46451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byfbU-0003xh-28 for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:47:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byfbR-0006Hc-0t for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:47:52 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33108) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1byfbQ-0006H7-R5 for qemu-devel@nongnu.org; Mon, 24 Oct 2016 09:47:48 -0400 Received: by mail-wm0-x241.google.com with SMTP id d128so9934781wmf.0 for ; Mon, 24 Oct 2016 06:47:48 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-246-178.clienti.tiscali.it. [78.12.246.178]) by smtp.gmail.com with ESMTPSA id us3sm19434867wjb.32.2016.10.24.06.47.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Oct 2016 06:47:46 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 24 Oct 2016 15:46:53 +0200 Message-Id: <1477316855-42218-9-git-send-email-pbonzini@redhat.com> In-Reply-To: <1477316855-42218-1-git-send-email-pbonzini@redhat.com> References: <1477316855-42218-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 08/50] rcu: simplify memory barriers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Thanks to the acquire semantics of qemu_event_reset and qemu_event_wait, some memory barriers can be removed. Signed-off-by: Paolo Bonzini --- util/rcu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/util/rcu.c b/util/rcu.c index bceb3e4..9adc5e4 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -82,14 +82,16 @@ static void wait_for_readers(void) /* Instead of using atomic_mb_set for index->waiting, and * atomic_mb_read for index->ctr, memory barriers are placed * manually since writes to different threads are independent. - * atomic_mb_set has a smp_wmb before... + * qemu_event_reset has acquire semantics, so no memory barrier + * is needed here. */ - smp_wmb(); QLIST_FOREACH(index, ®istry, node) { atomic_set(&index->waiting, true); } - /* ... and a smp_mb after. */ + /* Here, order the stores to index->waiting before the + * loads of index->ctr. + */ smp_mb(); QLIST_FOREACH_SAFE(index, ®istry, node, tmp) { @@ -104,9 +106,6 @@ static void wait_for_readers(void) } } - /* atomic_mb_read has smp_rmb after. */ - smp_rmb(); - if (QLIST_EMPTY(®istry)) { break; } -- 1.8.3.1