qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: mttcg@greensocs.com, cota@braap.org, rth@twiddle.net
Subject: [Qemu-devel] [PATCH 7/9] tcg: synchronize exit_request and tcg_current_cpu accesses
Date: Wed, 26 Aug 2015 02:17:43 +0200	[thread overview]
Message-ID: <1440548265-4755-8-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1440548265-4755-1-git-send-email-pbonzini@redhat.com>

Synchronize the remaining pair of accesses in cpu_signal.  The
wrongly-ordered accesses in cpu_signal are currently not an issue on
Windows because they execute atomically between SuspendProcess and
ResumeProcess.  Only cpu_exec can be split (and the newly introduced
atomic_mb_read would be needed on Windows too, but the compiler
must not be doing strange optimizations).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpu-exec.c |  2 +-
 cpus.c     | 14 ++++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 2128bf1..b337506 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -409,7 +409,7 @@ int cpu_exec(CPUState *cpu)
     atomic_mb_set(&tcg_current_cpu, cpu);
     rcu_read_lock();
 
-    if (unlikely(exit_request)) {
+    if (unlikely(atomic_mb_read(&exit_request))) {
         cpu->exit_request = 1;
     }
 
diff --git a/cpus.c b/cpus.c
index ec8168c..783ef00 100644
--- a/cpus.c
+++ b/cpus.c
@@ -663,11 +663,15 @@ static void cpu_handle_guest_debug(CPUState *cpu)
 
 static void cpu_signal(int sig)
 {
-    CPUState *cpu = atomic_mb_read(&tcg_current_cpu);
+    CPUState *cpu;
+    /* Ensure whatever caused the exit has reached the CPU threads before
+     * writing exit_request.
+     */
+    atomic_mb_set(&exit_request, 1);
+    cpu = atomic_mb_read(&tcg_current_cpu);
     if (cpu) {
         cpu_exit(cpu);
     }
-    exit_request = 1;
 }
 
 #ifdef CONFIG_LINUX
@@ -1074,7 +1078,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
     }
 
     /* process any pending work */
-    exit_request = 1;
+    atomic_mb_set(&exit_request, 1);
 
     while (1) {
         tcg_exec_all();
@@ -1453,7 +1457,9 @@ static void tcg_exec_all(void)
             break;
         }
     }
-    exit_request = 0;
+
+    /* Pairs with smp_wmb in qemu_cpu_kick.  */
+    atomic_mb_set(&exit_request, 0);
 }
 
 void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
-- 
2.4.3

  parent reply	other threads:[~2015-08-26  0:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-26  0:17 [Qemu-devel] [PATCH v2 0/9] tcg: signal-free qemu_cpu_kick Paolo Bonzini
2015-08-26  0:17 ` [Qemu-devel] [PATCH 1/9] i8257: rewrite DMA_schedule to avoid hooking into the CPU loop Paolo Bonzini
2015-08-26  0:17 ` [Qemu-devel] [PATCH 2/9] i8257: remove cpu_request_exit irq Paolo Bonzini
2015-08-26  0:17 ` [Qemu-devel] [PATCH 3/9] tcg: introduce tcg_current_cpu Paolo Bonzini
2015-08-26  0:17 ` [Qemu-devel] [PATCH 4/9] remove qemu/tls.h Paolo Bonzini
2015-08-26  0:17 ` [Qemu-devel] [PATCH 5/9] tcg: assign cpu->current_tb in a simpler place Paolo Bonzini
2015-08-26  0:17 ` [Qemu-devel] [PATCH 6/9] tcg: synchronize cpu->exit_request and cpu->tcg_exit_req accesses Paolo Bonzini
2015-08-28  2:19   ` Emilio G. Cota
2015-08-28  8:50     ` Paolo Bonzini
2015-08-26  0:17 ` Paolo Bonzini [this message]
2015-08-26  0:17 ` [Qemu-devel] [PATCH 8/9] use qemu_cpu_kick instead of cpu_exit or qemu_cpu_kick_thread Paolo Bonzini
2015-08-26  0:17 ` [Qemu-devel] [PATCH 9/9] tcg: signal-free qemu_cpu_kick Paolo Bonzini
2015-08-28  4:21 ` [Qemu-devel] [PATCH v2 0/9] " Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440548265-4755-8-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=cota@braap.org \
    --cc=mttcg@greensocs.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).