@@ -233,6 +233,16 @@ void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data);
*/
CPUState *qemu_get_cpu(int index);
+/**
+ * cpu_exists:
+ * @id - guest exposed CPU ID to lookup
+ *
+ * Search for CPU with specified ID.
+ *
+ * Returns: true - CPU is found, false - CPU isn't found
+ */
+bool cpu_exists(int64_t id);
+
#ifndef CONFIG_USER_ONLY
typedef void (*CPUInterruptHandler)(CPUState *, int);
@@ -24,6 +24,32 @@
#include "qemu/notify.h"
#include "sysemu/sysemu.h"
+typedef struct CPU_exists_args {
+ int64_t id;
+ bool found;
+} CPU_exists_args;
+
+static void cpu_exist_cb(CPUState *cpu, void *data)
+{
+ CPUClass *klass = CPU_GET_CLASS(cpu);
+ CPU_exists_args *arg = data;
+
+ if (klass->get_arch_id(cpu) == arg->id) {
+ arg->found = true;
+ }
+}
+
+bool cpu_exists(int64_t id)
+{
+ CPU_exists_args data = {
+ .id = id,
+ .found = false,
+ };
+
+ qemu_for_each_cpu(cpu_exist_cb, &data);
+ return data.found;
+}
+
/* CPU hot-plug notifiers */
static NotifierList cpu_added_notifiers =
NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
Signed-off-by: Igor Mammedov <imammedo@redhat.com> --- v3: * use qemu_for_each_cpu() instead of recursion v2: * s/get_firmware_id()/get_arch_id()/ rebase fixup * remove check for get_arch_id being NULL, since it's always defined --- include/qom/cpu.h | 10 ++++++++++ qom/cpu.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-)