qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] target/arm/arm-powerctl: Restrict to ARM cores
@ 2025-01-07 13:57 Philippe Mathieu-Daudé
  2025-01-07 13:57 ` [PATCH v2 1/2] cpus: Introduce cpu_is_of_type() helper Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-07 13:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Marcel Apfelbaum, Daniel Henrique Barboza,
	Anton Johansson, Alistair Francis, Philippe Mathieu-Daudé,
	qemu-arm, Yanan Wang, Zhao Liu, Thomas Huth, Edgar E . Iglesias,
	Paolo Bonzini, Eduardo Habkost, Peter Maydell

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(-)

-- 
2.47.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] cpus: Introduce cpu_is_of_type() helper
  2025-01-07 13:57 [PATCH v2 0/2] target/arm/arm-powerctl: Restrict to ARM cores Philippe Mathieu-Daudé
@ 2025-01-07 13:57 ` Philippe Mathieu-Daudé
  2025-01-07 13:57 ` [PATCH v2 2/2] target/arm/arm-powerctl: Restrict to ARM cores Philippe Mathieu-Daudé
  2025-01-07 15:34 ` [PATCH v2 0/2] " Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-07 13:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Marcel Apfelbaum, Daniel Henrique Barboza,
	Anton Johansson, Alistair Francis, Philippe Mathieu-Daudé,
	qemu-arm, Yanan Wang, Zhao Liu, Thomas Huth, Edgar E . Iglesias,
	Paolo Bonzini, Eduardo Habkost, Peter Maydell

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(+)

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] target/arm/arm-powerctl: Restrict to ARM cores
  2025-01-07 13:57 [PATCH v2 0/2] target/arm/arm-powerctl: Restrict to ARM cores Philippe Mathieu-Daudé
  2025-01-07 13:57 ` [PATCH v2 1/2] cpus: Introduce cpu_is_of_type() helper Philippe Mathieu-Daudé
@ 2025-01-07 13:57 ` Philippe Mathieu-Daudé
  2025-01-07 15:34 ` [PATCH v2 0/2] " Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-07 13:57 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Marcel Apfelbaum, Daniel Henrique Barboza,
	Anton Johansson, Alistair Francis, Philippe Mathieu-Daudé,
	qemu-arm, Yanan Wang, Zhao Liu, Thomas Huth, Edgar E . Iglesias,
	Paolo Bonzini, Eduardo Habkost, Peter Maydell

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.

Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/arm-powerctl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c
index 20c70c7d6bb..07529ab096e 100644
--- a/target/arm/arm-powerctl.c
+++ b/target/arm/arm-powerctl.c
@@ -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;
         }
     }
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] target/arm/arm-powerctl: Restrict to ARM cores
  2025-01-07 13:57 [PATCH v2 0/2] target/arm/arm-powerctl: Restrict to ARM cores Philippe Mathieu-Daudé
  2025-01-07 13:57 ` [PATCH v2 1/2] cpus: Introduce cpu_is_of_type() helper Philippe Mathieu-Daudé
  2025-01-07 13:57 ` [PATCH v2 2/2] target/arm/arm-powerctl: Restrict to ARM cores Philippe Mathieu-Daudé
@ 2025-01-07 15:34 ` Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2025-01-07 15:34 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Marcel Apfelbaum, Daniel Henrique Barboza, Anton Johansson,
	Alistair Francis, qemu-arm, Yanan Wang, Zhao Liu, Thomas Huth,
	Edgar E . Iglesias, Paolo Bonzini, Eduardo Habkost, Peter Maydell

On 1/7/25 05:57, Philippe Mathieu-Daudé wrote:
> 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(-)
> 

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-07 15:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-07 13:57 [PATCH v2 0/2] target/arm/arm-powerctl: Restrict to ARM cores Philippe Mathieu-Daudé
2025-01-07 13:57 ` [PATCH v2 1/2] cpus: Introduce cpu_is_of_type() helper Philippe Mathieu-Daudé
2025-01-07 13:57 ` [PATCH v2 2/2] target/arm/arm-powerctl: Restrict to ARM cores Philippe Mathieu-Daudé
2025-01-07 15:34 ` [PATCH v2 0/2] " Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).