Patchwork [RFC,2/5] cpu: Don't try to pause CPUs if they are already stopped

login
register
mail settings
Submitter Eduardo Habkost
Date April 30, 2014, 8:29 p.m.
Message ID <1398889773-14652-3-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/344316/
State New
Headers show

Comments

Eduardo Habkost - April 30, 2014, 8:29 p.m.
This will make the pause_all_cpus() code not crash in case
qemu_init_vcpu() was not called yet for a CPU (so it doesn't have
cpu->thread set yet).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 cpus.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Patch

diff --git a/cpus.c b/cpus.c
index 69b0530..ca3862b 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1070,6 +1070,14 @@  static int all_vcpus_paused(void)
     return 1;
 }
 
+static void cpu_kick_if_running(CPUState *cpu)
+{
+    if (!cpu->stopped) {
+        assert(cpu->thread);
+        qemu_cpu_kick(cpu);
+    }
+}
+
 void pause_all_vcpus(void)
 {
     CPUState *cpu;
@@ -1077,7 +1085,7 @@  void pause_all_vcpus(void)
     qemu_clock_enable(QEMU_CLOCK_VIRTUAL, false);
     CPU_FOREACH(cpu) {
         cpu->stop = true;
-        qemu_cpu_kick(cpu);
+        cpu_kick_if_running(cpu);
     }
 
     if (qemu_in_vcpu_thread()) {
@@ -1094,7 +1102,7 @@  void pause_all_vcpus(void)
     while (!all_vcpus_paused()) {
         qemu_cond_wait(&qemu_pause_cond, &qemu_global_mutex);
         CPU_FOREACH(cpu) {
-            qemu_cpu_kick(cpu);
+            cpu_kick_if_running(cpu);
         }
     }
 }