mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 17:23:56 -06:00
membarrier: introduce qemu/sys_membarrier.h
This new header file provides heavy-weight "global" memory barriers that enforce memory ordering on each running thread belonging to the current process. For now, use a dummy implementation that issues memory barriers on both sides (matching what QEMU has been doing so far). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
77a8b8462b
commit
c8d3877e48
3 changed files with 26 additions and 7 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "qemu/thread.h"
|
||||
#include "qemu/queue.h"
|
||||
#include "qemu/atomic.h"
|
||||
#include "qemu/sys_membarrier.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -82,7 +83,7 @@ static inline void rcu_read_lock(void)
|
|||
atomic_set(&p_rcu_reader->ctr, ctr);
|
||||
|
||||
/* Write p_rcu_reader->ctr before reading RCU-protected pointers. */
|
||||
smp_mb();
|
||||
smp_mb_placeholder();
|
||||
}
|
||||
|
||||
static inline void rcu_read_unlock(void)
|
||||
|
@ -96,13 +97,13 @@ static inline void rcu_read_unlock(void)
|
|||
|
||||
/* 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
|
||||
* smp_mb_placeholder(), 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();
|
||||
smp_mb_placeholder();
|
||||
if (unlikely(atomic_read(&p_rcu_reader->waiting))) {
|
||||
atomic_set(&p_rcu_reader->waiting, false);
|
||||
qemu_event_set(&rcu_gp_event);
|
||||
|
|
17
include/qemu/sys_membarrier.h
Normal file
17
include/qemu/sys_membarrier.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Process-global memory barriers
|
||||
*
|
||||
* Copyright (c) 2018 Red Hat, Inc.
|
||||
*
|
||||
* Author: Paolo Bonzini <pbonzini@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef QEMU_SYS_MEMBARRIER_H
|
||||
#define QEMU_SYS_MEMBARRIER_H 1
|
||||
|
||||
/* Keep it simple, execute a real memory barrier on both sides. */
|
||||
static inline void smp_mb_global_init(void) {}
|
||||
#define smp_mb_global() smp_mb()
|
||||
#define smp_mb_placeholder() smp_mb()
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue