Skip to contentSkip to conversation

target/arm/arm-powerctl: Restrict to ARM cores

PATCH In review Philippe Mathieu-Daudé 2 participants 4 messages Jan 7, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover target/arm/arm-powerctl: Restrict to ARM cores

Since v1:
- Factor cpu_is_of_type() out

Philippe Mathieu-Daudé (2):
cpus: Introduce cpu_is_of_type() helper
target/arm/arm-powerctl: Restrict to ARM cores

 include/hw/core/cpu.h     | 9 +++++++++
 cpu-common.c              | 5 +++++
 target/arm/arm-powerctl.c | 6 ++++--
 3 files changed, 18 insertions(+), 2 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 1/2 cpus: Introduce cpu_is_of_type() helper

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").

---
 include/hw/core/cpu.h | 9 +++++++++
 cpu-common.c          | 5 +++++
 2 files changed, 14 insertions(+)
include/hw/core/cpu.h +9 -0
index c3ca0babcb3..d55d4802ceb 100644
@@ -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.
cpu-common.c +5 -0
index 4248b2d727e..2541a81ef87 100644
@@ -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);
+}
Signature · 1 line
2.47.1
#2 lore raw

PATCH v2 2/2 target/arm/arm-powerctl: Restrict to ARM cores

In reply to Philippe Mathieu-Daudé

When running on a heterogeneous setup, the CPU_FOREACH() macro in arm_get_cpu_by_id() iterates on all vCPUs, regardless they are ARM or not. Check the CPU class type and skip the non-ARM instances.

---
 target/arm/arm-powerctl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/arm/arm-powerctl.c +4 -2
index 20c70c7d6bb..07529ab096e 100644
@@ -36,9 +36,11 @@ CPUState *arm_get_cpu_by_id(uint64_t id)
     DPRINTF("cpu %" PRId64 "\n", id);
 
     CPU_FOREACH(cpu) {
-        ARMCPU *armcpu = ARM_CPU(cpu);
+        if (!cpu_is_of_type(cpu, TYPE_ARM_CPU)) {
+            continue;
+        }
 
-        if (arm_cpu_mp_affinity(armcpu) == id) {
+        if (arm_cpu_mp_affinity((ARMCPU *)cpu) == id) {
             return cpu;
         }
     }
Signature · 1 line
2.47.1
Reviewed-by on the v2 series
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé

Since v1:
- Factor cpu_is_of_type() out

Philippe Mathieu-Daudé (2):
cpus: Introduce cpu_is_of_type() helper
target/arm/arm-powerctl: Restrict to ARM cores

  include/hw/core/cpu.h     | 9 +++++++++
  cpu-common.c              | 5 +++++
  target/arm/arm-powerctl.c | 6 ++++--
  3 files changed, 18 insertions(+), 2 deletions(-)

r~