[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/7] cpu: Add qemu_for_each_cpu()



From: "Michael S. Tsirkin" <mst@xxxxxxxxxx>

Wrapper to avoid open-coded loops and to make CPUState iteration
independent of CPUArchState.

Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
Signed-off-by: Igor Mammedov <imammedo@xxxxxxxxxx>
Signed-off-by: Andreas FÃrber <afaerber@xxxxxxx>

(cherry picked from QEMU commit d6b9e0d60cc511eca210834428bb74508cff3d33)
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 exec.c             | 10 ++++++++++
 include/qemu/cpu.h |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/exec.c b/exec.c
index 8435de0..9fb6927 100644
--- a/exec.c
+++ b/exec.c
@@ -692,6 +692,16 @@ CPUArchState *qemu_get_cpu(int cpu)
     return env;
 }
 
+void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data)
+{
+    CPUArchState *env = first_cpu;
+
+    while (env) {
+        func(ENV_GET_CPU(env), data);
+        env = env->next_cpu;
+    }
+}
+
 void cpu_exec_init(CPUArchState *env)
 {
 #ifndef CONFIG_USER_ONLY
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 8d2e0cb..23b8b6f 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -138,5 +138,14 @@ bool cpu_is_stopped(CPUState *cpu);
  */
 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
 
+/**
+ * qemu_for_each_cpu:
+ * @func: The function to be executed.
+ * @data: Data to pass to the function.
+ *
+ * Executes @func for each CPU.
+ */
+void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data);
+
 
 #endif
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.