Skip to content

Commit

Permalink
rcu: simplify memory barriers
Browse files Browse the repository at this point in the history
Thanks to the acquire semantics of qemu_event_reset and qemu_event_wait,
some memory barriers can be removed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Oct 24, 2016
1 parent 374293c commit e11131b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions util/rcu.c
Expand Up @@ -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, &registry, 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, &registry, node, tmp) {
Expand All @@ -104,9 +106,6 @@ static void wait_for_readers(void)
}
}

/* atomic_mb_read has smp_rmb after. */
smp_rmb();

if (QLIST_EMPTY(&registry)) {
break;
}
Expand Down

0 comments on commit e11131b

Please sign in to comment.