diff mbox series

[RFC,13/52] cpu/core: Use generic topology helper for "help" to set nr_threads

Message ID 20230213095035.158240-14-zhao1.liu@linux.intel.com
State New
Headers show
Series Introduce hybrid CPU topology | expand

Commit Message

Zhao Liu Feb. 13, 2023, 9:49 a.m. UTC
From: Zhao Liu <zhao1.liu@intel.com>

The commit 0b47ec4 (cpu/core: Fix "help" of CPU core device types) sets
nr_threads with current_machine's smp.threads for "help".

This will break if current_machine has hybrid topology. Though core
device now is only used by PPC, as the general code, hybrid topology
deserves to be handled more gracefully and does not depend on whether
the specific architecture supports hybrid topology.

So use a generic topology helper to get threads info (of CPU 0) from
current_machine. For smp case, this helper returns "threads per core"
as the original smp.threads, and for hybrid case, it returns threads of
the core that CPU 0 is located.

Since that nr_threads is just to make "help" happy and it isn't used
afterwards, give it the threads of CPU 0 can work.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 hw/cpu/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/hw/cpu/core.c b/hw/cpu/core.c
index 987607515574..bc5ab4e01038 100644
--- a/hw/cpu/core.c
+++ b/hw/cpu/core.c
@@ -71,10 +71,12 @@  static void cpu_core_instance_init(Object *obj)
     /*
      * Only '-device something-cpu-core,help' can get us there before
      * the machine has been created. We don't care to set nr_threads
-     * in this case since it isn't used afterwards.
+     * in this case since it isn't used afterwards, so we fetch the
+     * threads of the core where the CPU 0 is located, no matter whether
+     * the topology is smp or hybrid.
      */
     if (current_machine) {
-        core->nr_threads = current_machine->smp.threads;
+        core->nr_threads = machine_topo_get_threads_by_idx(current_machine, 0);
     }
 }