Received: from eggs.gnu.org ([2001:4830:134:3::10]:38097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btb77-0001HX-08 for qemu-devel@nongnu.org; Mon, 10 Oct 2016 09:59:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btb76-000894-4d for qemu-devel@nongnu.org; Mon, 10 Oct 2016 09:59:32 -0400 Received: from mail-qk0-x242.google.com ([2607:f8b0:400d:c09::242]:35600) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btb76-00088s-0l for qemu-devel@nongnu.org; Mon, 10 Oct 2016 09:59:32 -0400 Received: by mail-qk0-x242.google.com with SMTP id v138so5643830qka.2 for ; Mon, 10 Oct 2016 06:59:31 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 10 Oct 2016 15:59:06 +0200 Message-Id: <1476107947-31430-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1476107947-31430-1-git-send-email-pbonzini@redhat.com> References: <1476107947-31430-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 4/5] rcu: simplify memory barriers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: cota@braap.org, alex.bennee@linaro.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; } -- 2.7.4