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é <phi...@linaro.org> --- include/hw/core/cpu.h | 9 +++++++++ cpu-common.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index c3ca0babcb3..d55d4802ceb 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -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. diff --git a/cpu-common.c b/cpu-common.c index 4248b2d727e..2541a81ef87 100644 --- a/cpu-common.c +++ b/cpu-common.c @@ -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); +} -- 2.47.1