Skip to content

Commit b360109

Browse files
committed
hw/loongarch/virt: Improve fdt table creation for CPU object
For CPU object, possible_cpu_arch_ids() function is used rather than smp.cpus. With command -smp x, -device la464-loongarch-cpu, smp.cpus is not accurate for all possible CPU objects, possible_cpu_arch_ids() is used here. Signed-off-by: Bibo Mao <[email protected]> Reviewed-by: Bibo Mao <[email protected]>
1 parent 2f1399b commit b360109

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

hw/loongarch/virt.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -365,26 +365,35 @@ static void create_fdt(LoongArchVirtMachineState *lvms)
365365
static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
366366
{
367367
int num;
368-
const MachineState *ms = MACHINE(lvms);
369-
int smp_cpus = ms->smp.cpus;
368+
MachineState *ms = MACHINE(lvms);
369+
MachineClass *mc = MACHINE_GET_CLASS(ms);
370+
const CPUArchIdList *possible_cpus;
371+
LoongArchCPU *cpu;
372+
CPUState *cs;
373+
char *nodename, *map_path;
370374

371375
qemu_fdt_add_subnode(ms->fdt, "/cpus");
372376
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1);
373377
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0);
374378

375379
/* cpu nodes */
376-
for (num = smp_cpus - 1; num >= 0; num--) {
377-
char *nodename = g_strdup_printf("/cpus/cpu@%d", num);
378-
LoongArchCPU *cpu = LOONGARCH_CPU(qemu_get_cpu(num));
379-
CPUState *cs = CPU(cpu);
380+
possible_cpus = mc->possible_cpu_arch_ids(ms);
381+
for (num = 0; num < possible_cpus->len; num++) {
382+
cs = possible_cpus->cpus[num].cpu;
383+
if (cs == NULL) {
384+
continue;
385+
}
386+
387+
nodename = g_strdup_printf("/cpus/cpu@%d", num);
388+
cpu = LOONGARCH_CPU(cs);
380389

381390
qemu_fdt_add_subnode(ms->fdt, nodename);
382391
qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu");
383392
qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
384393
cpu->dtb_compatible);
385-
if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) {
394+
if (possible_cpus->cpus[num].props.has_node_id) {
386395
qemu_fdt_setprop_cell(ms->fdt, nodename, "numa-node-id",
387-
ms->possible_cpus->cpus[cs->cpu_index].props.node_id);
396+
possible_cpus->cpus[num].props.node_id);
388397
}
389398
qemu_fdt_setprop_cell(ms->fdt, nodename, "reg", num);
390399
qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle",
@@ -394,11 +403,13 @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
394403

395404
/*cpu map */
396405
qemu_fdt_add_subnode(ms->fdt, "/cpus/cpu-map");
406+
for (num = 0; num < possible_cpus->len; num++) {
407+
cs = possible_cpus->cpus[num].cpu;
408+
if (cs == NULL) {
409+
continue;
410+
}
397411

398-
for (num = smp_cpus - 1; num >= 0; num--) {
399-
char *cpu_path = g_strdup_printf("/cpus/cpu@%d", num);
400-
char *map_path;
401-
412+
nodename = g_strdup_printf("/cpus/cpu@%d", num);
402413
if (ms->smp.threads > 1) {
403414
map_path = g_strdup_printf(
404415
"/cpus/cpu-map/socket%d/core%d/thread%d",
@@ -412,10 +423,10 @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
412423
num % ms->smp.cores);
413424
}
414425
qemu_fdt_add_path(ms->fdt, map_path);
415-
qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", cpu_path);
426+
qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", nodename);
416427

417428
g_free(map_path);
418-
g_free(cpu_path);
429+
g_free(nodename);
419430
}
420431
}
421432

0 commit comments

Comments
 (0)