On 5/29/2026 7:18 AM, [email protected] wrote:
From: Xuemei Liu <[email protected]>

Supplement RISC-V cpu topology arguments, including support socket
cluster and threads per core.

Signed-off-by: Xuemei Liu <[email protected]>
---

Seems like we can't set clusters/cores/threads as 0 from the command line:

u$ ./build/qemu-system-riscv64 -M virt -smp cores=0
qemu-system-riscv64: Invalid CPU topology: CPU topology parameters must be 
greater than zero

And any missing SMP values from the cmd line is filled with '1' during
machine_parse_smp_config().  So we're not generating div by zero with
this patch.


Reviewed-by: Daniel Henrique Barboza <[email protected]>



  hw/riscv/numa.c | 12 +++++++++++-
  1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/hw/riscv/numa.c b/hw/riscv/numa.c
index 24a803f7fa..8a144925c1 100644
--- a/hw/riscv/numa.c
+++ b/hw/riscv/numa.c
@@ -239,8 +239,18 @@ const CPUArchIdList 
*riscv_numa_possible_cpu_arch_ids(MachineState *ms)
      for (n = 0; n < ms->possible_cpus->len; n++) {
          ms->possible_cpus->cpus[n].type = ms->cpu_type;
          ms->possible_cpus->cpus[n].arch_id = n;
+        ms->possible_cpus->cpus[n].props.has_socket_id = true;
+        ms->possible_cpus->cpus[n].props.socket_id =
+            n / (ms->smp.clusters * ms->smp.cores * ms->smp.threads);
+        ms->possible_cpus->cpus[n].props.has_cluster_id = true;
+        ms->possible_cpus->cpus[n].props.cluster_id =
+            (n / (ms->smp.cores * ms->smp.threads)) % ms->smp.clusters;
          ms->possible_cpus->cpus[n].props.has_core_id = true;
-        ms->possible_cpus->cpus[n].props.core_id = n;
+        ms->possible_cpus->cpus[n].props.core_id =
+            (n / ms->smp.threads) % ms->smp.cores;
+        ms->possible_cpus->cpus[n].props.has_thread_id = true;
+        ms->possible_cpus->cpus[n].props.thread_id =
+            n % ms->smp.threads;
      }

      return ms->possible_cpus;


Reply via email to