Skip to contentSkip to conversation

Provide a general purpose way of probing if cpus are stopped

PATCH In review Glauber Costa 2 participants 2 messages Jul 20, 2009 – Jul 22, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Provide a general purpose way of probing if cpus are stopped

We don't have anything that requires that in tree yet, but avi does. So Let's be nice with him, and provide him with those functions that diminish the amount of kvm-specific code.

---
 cpu-all.h |    3 +++
 exec.c    |   22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
cpu-all.h +3 -0
index df3aa2e..6801938 100644
@@ -741,6 +741,9 @@ int page_get_flags(target_ulong address);
 void page_set_flags(target_ulong start, target_ulong end, int flags);
 int page_check_range(target_ulong start, target_ulong len, int flags);
 
+int qemu_cpu_stopped(CPUState *env);
+uint32_t qemu_cpus_running(void);
+
 void cpu_exec_init_all(unsigned long tb_size);
 CPUState *cpu_copy(CPUState *env);
 CPUState *qemu_get_cpu(int cpu);
exec.c +22 -0
index d6e5d3c..2e5f05a 100644
@@ -32,6 +32,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 
+#include "sysemu.h"
 #include "cpu.h"
 #include "exec-all.h"
 #include "qemu-common.h"
@@ -558,6 +559,27 @@ CPUState *qemu_get_cpu(int cpu)
     return env;
 }
 
+int qemu_cpu_stopped(CPUState *env)
+{
+    return !vm_running || env->stopped;
+}
+
+/* Returns the number of cpus that are in the stopped state.
+ * It is a 32-bit value, because if it weren't SGI would */
+uint32_t qemu_cpus_running(void)
+{
+    uint32_t count = 0;
+
+    if (!vm_running)
+        return count;
+
+    CPUState *penv = first_cpu;
+    while (penv) {
+        count += !penv->stopped;
+    }
+    return count;
+}
+
 void cpu_exec_init(CPUState *env)
 {
     CPUState **penv;
Signature · 1 line
1.6.2.2
#1 lore raw
Quoted 6 lines · Glauber Costa

We don't have anything that requires that in tree yet, but avi does. So Let's be nice with him, and provide him with those functions that diminish the amount of kvm-specific code.

Breaks linux-user build as vm_running isn't available.

Regards,

Anthony Liguori