diff mbox series

[RFC] target/arm/arm-powerctl: Restrict to ARM cores

Message ID 20250106182343.35859-1-philmd@linaro.org (mailing list archive)
State New
Headers show
Series [RFC] target/arm/arm-powerctl: Restrict to ARM cores | expand

Commit Message

Philippe Mathieu-Daudé Jan. 6, 2025, 6:23 p.m. UTC
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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/arm-powerctl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Daniel Henrique Barboza Jan. 6, 2025, 7:09 p.m. UTC | #1
On 1/6/25 3:23 PM, Philippe Mathieu-Daudé wrote:
> 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.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---

Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>

>   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..a080a6ab79f 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 (!object_class_dynamic_cast((ObjectClass *)cpu->cc, TYPE_ARM_CPU)) {
> +            continue;
> +        }
>   
> -        if (arm_cpu_mp_affinity(armcpu) == id) {
> +        if (arm_cpu_mp_affinity((ARMCPU *)cpu) == id) {
>               return cpu;
>           }
>       }
Peter Maydell Jan. 6, 2025, 9:45 p.m. UTC | #2
On Mon, 6 Jan 2025 at 18:23, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> 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.
>
> 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..a080a6ab79f 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 (!object_class_dynamic_cast((ObjectClass *)cpu->cc, TYPE_ARM_CPU)) {
> +            continue;
> +        }
>
> -        if (arm_cpu_mp_affinity(armcpu) == id) {
> +        if (arm_cpu_mp_affinity((ARMCPU *)cpu) == id) {
>              return cpu;
>          }
>      }
> --

Makes sense -- the function is "get me a CPU with this MPIDR",
so in a heterogenous system we can happily scan all the Arm CPUs
(even if they're in some other SoC) and trust that the caller
passed us a MPIDR that makes sense. (The callsites might need
some work if we wanted to use those SoC models in a heterogenous
setup where they're not the only SoC -- eg the imx6_src devices
assume the CPUs in the SoC are numbered 0,1,2,3 -- but we don't
need to do that now.)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
diff mbox series

Patch

diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c
index 20c70c7d6bb..a080a6ab79f 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 (!object_class_dynamic_cast((ObjectClass *)cpu->cc, TYPE_ARM_CPU)) {
+            continue;
+        }
 
-        if (arm_cpu_mp_affinity(armcpu) == id) {
+        if (arm_cpu_mp_affinity((ARMCPU *)cpu) == id) {
             return cpu;
         }
     }