Patchwork [1/8] Introduce proper compiler barrier

login
register
mail settings
Submitter Jan Kiszka
Date June 25, 2010, 2:56 p.m.
Message ID <9a37eceacb7bb54e123bab9a31094d464d3c9040.1277477810.git.jan.kiszka@siemens.com>
Download mbox | patch
Permalink /patch/56948/
State New
Headers show

Comments

Jan Kiszka - June 25, 2010, 2:56 p.m.
Define barrier() as optimization barrier and replace (potentially
unreliable) asm("") fences.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 cpu-exec.c     |    5 +++--
 qemu-barrier.h |    3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)

Patch

diff --git a/cpu-exec.c b/cpu-exec.c
index 026980a..525b3b4 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -21,6 +21,7 @@ 
 #include "disas.h"
 #include "tcg.h"
 #include "kvm.h"
+#include "qemu-barrier.h"
 
 #if !defined(CONFIG_SOFTMMU)
 #undef EAX
@@ -233,7 +234,7 @@  int cpu_exec(CPUState *env1)
        use it.  */
     QEMU_BUILD_BUG_ON (sizeof (saved_env_reg) != sizeof (env));
     saved_env_reg = (host_reg_t) env;
-    asm("");
+    barrier();
     env = env1;
 
     if (exit_request) {
@@ -669,7 +670,7 @@  int cpu_exec(CPUState *env1)
 #endif
 
     /* restore global registers */
-    asm("");
+    barrier();
     env = (void *) saved_env_reg;
 
     /* fail safe : never use cpu_single_env outside cpu_exec() */
diff --git a/qemu-barrier.h b/qemu-barrier.h
index 3bd1075..b77fce2 100644
--- a/qemu-barrier.h
+++ b/qemu-barrier.h
@@ -4,4 +4,7 @@ 
 /* FIXME: arch dependant, x86 version */
 #define smp_wmb()   asm volatile("" ::: "memory")
 
+/* Compiler barrier */
+#define barrier()   asm volatile("" ::: "memory")
+
 #endif