@@ -795,6 +795,15 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
*/
char *cpu_model_from_type(const char *typename);
+/**
+ * cpu_is_of_type: Check if a CPU instance implement a QOM type
+ * @cpu: The CPU to be added to the list of CPUs.
+ * @typename: The CPU type.
+ *
+ * Returns: %true if @cpu is a QOM child of type @typename.
+ */
+bool cpu_is_of_type(CPUState *cpu, const char *typename);
+
/**
* cpu_create:
* @typename: The CPU type.
@@ -455,3 +455,8 @@ void cpu_breakpoint_remove_all(CPUState *cpu, int mask)
}
}
}
+
+bool cpu_is_of_type(CPUState *cpu, const char *typename)
+{
+ return !!object_class_dynamic_cast((ObjectClass *)cpu->cc, typename);
+}
Introduce a helper to check whether a vCPU instance is from a certain QOM parent type. We don't need to use the type-safe QOM cast macros and can directly access the cached CPUClass (see commit 6fbdff87062 "cpu: cache CPUClass in CPUState for hot code paths"). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/hw/core/cpu.h | 9 +++++++++ cpu-common.c | 5 +++++ 2 files changed, 14 insertions(+)