[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 24/69] rcu: make memory barriers more explicit
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 24/69] rcu: make memory barriers more explicit |
Date: |
Tue, 13 Mar 2018 23:46:34 +0100 |
Prepare for introducing smp_mb_placeholder() and smp_mb_global().
The new smp_mb() in synchronize_rcu() is not strictly necessary, since
the first atomic_mb_set for rcu_gp_ctr provides the required ordering.
However, synchronize_rcu is not performance critical, and it *will* be
necessary to introduce a smp_mb_global before calling wait_for_readers().
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/qemu/rcu.h | 15 +++++++++++++--
util/rcu.c | 12 +++++++++---
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h
index f19413d649..625f09ac09 100644
--- a/include/qemu/rcu.h
+++ b/include/qemu/rcu.h
@@ -79,7 +79,10 @@ static inline void rcu_read_lock(void)
}
ctr = atomic_read(&rcu_gp_ctr);
- atomic_xchg(&p_rcu_reader->ctr, ctr);
+ atomic_set(&p_rcu_reader->ctr, ctr);
+
+ /* Write p_rcu_reader->ctr before reading RCU-protected pointers. */
+ smp_mb();
}
static inline void rcu_read_unlock(void)
@@ -91,7 +94,15 @@ static inline void rcu_read_unlock(void)
return;
}
- atomic_xchg(&p_rcu_reader->ctr, 0);
+ /* Ensure that the critical section is seen to precede the
+ * store to p_rcu_reader->ctr. Together with the following
+ * smp_mb(), this ensures writes to p_rcu_reader->ctr
+ * are sequentially consistent.
+ */
+ atomic_store_release(&p_rcu_reader->ctr, 0);
+
+ /* Write p_rcu_reader->ctr before reading p_rcu_reader->waiting. */
+ smp_mb();
if (unlikely(atomic_read(&p_rcu_reader->waiting))) {
atomic_set(&p_rcu_reader->waiting, false);
qemu_event_set(&rcu_gp_event);
diff --git a/util/rcu.c b/util/rcu.c
index f4d09c8304..7366dc50dd 100644
--- a/util/rcu.c
+++ b/util/rcu.c
@@ -92,8 +92,9 @@ static void wait_for_readers(void)
atomic_set(&index->waiting, true);
}
- /* Here, order the stores to index->waiting before the
- * loads of index->ctr.
+ /* Here, order the stores to index->waiting before the loads of
+ * index->ctr. Pairs with smp_mb() in rcu_read_unlock(),
+ * ensuring that the loads of index->ctr are sequentially consistent.
*/
smp_mb();
@@ -142,8 +143,13 @@ static void wait_for_readers(void)
void synchronize_rcu(void)
{
qemu_mutex_lock(&rcu_sync_lock);
- qemu_mutex_lock(&rcu_registry_lock);
+ /* Write RCU-protected pointers before reading p_rcu_reader->ctr.
+ * Pairs with smp_mb() in rcu_read_lock().
+ */
+ smp_mb();
+
+ qemu_mutex_lock(&rcu_registry_lock);
if (!QLIST_EMPTY(®istry)) {
/* In either case, the atomic_mb_set below blocks stores that free
* old RCU-protected pointers.
--
2.14.3
- [Qemu-devel] [PULL 15/69] chardev: use chardev's gcontext for async connect, (continued)
- [Qemu-devel] [PULL 15/69] chardev: use chardev's gcontext for async connect, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 12/69] chardev: update net listener gcontext, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 14/69] chardev: introduce chr_machine_done hook, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 16/69] chardev: tcp: postpone async connection setup, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 19/69] hw/i386: make IOMMUs configurable via default-configs/, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 18/69] scsi: support NDOB (no data-out buffer) for WRITE SAME commands, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 22/69] rcutorture: remove synchronize_rcu from readers, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 21/69] hw/mips/jazz: Fix implicit creation of "-drive if=scsi" devices, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 17/69] chardev: tcp: let TLS run on chardev context, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 20/69] Polish the version strings containing the package version, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 24/69] rcu: make memory barriers more explicit,
Paolo Bonzini <=
- [Qemu-devel] [PULL 23/69] docs: document atomic_load_acquire and atomic_store_release, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 25/69] membarrier: introduce qemu/sys_membarrier.h, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 26/69] membarrier: add --enable-membarrier, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 28/69] hw/dma/i8257: Rename DMA_init() to i8257_dma_init(), Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 27/69] hw/isa: Move parallel_hds_isa_init() to hw/char/parallel-isa.c, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 30/69] MAINTAINERS: Fix the PC87312 include path, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 29/69] hw/input/i8042: Extract declarations from i386/pc.h into input/i8042.h, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 31/69] hw/isa/pc87312: Rename the device type as TYPE_PC87312_SUPERIO, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 32/69] hw/isa/pc87312: Use uint16_t for the ISA I/O base address, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 33/69] hw/isa/pc87312: Use 'unsigned int' for the irq value, Paolo Bonzini, 2018/03/13