Skip to content

Commit eb850b6

Browse files
nikunjadlegoater
authored andcommitted
ppc/pnv: fix cores per chip for multiple cpus
When the user does not provide the cpu topology, e.g. "-smp 4", machine fails to initialize 4 cpus. Compute the chip per cores depending on the number of chips and smt threads. Signed-off-by: Nikunj A Dadhania <[email protected]> Signed-off-by: Cédric Le Goater <[email protected]>
1 parent 375a6bd commit eb850b6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

hw/ppc/pnv.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ static void ppc_powernv_init(MachineState *machine)
642642
MemoryRegion *ram;
643643
char *fw_filename;
644644
long fw_size;
645-
int i;
645+
int i, cores_per_chip;
646646
char *chip_typename;
647647
PCIBus *pbus;
648648
bool has_gfx = false;
@@ -714,6 +714,22 @@ static void ppc_powernv_init(MachineState *machine)
714714
}
715715

716716
pnv->chips = g_new0(PnvChip *, pnv->num_chips);
717+
718+
/* If user has specified number of cores, use it. Otherwise, compute it. */
719+
if (smp_cores != 1) {
720+
cores_per_chip = smp_cores;
721+
} else {
722+
cores_per_chip = smp_cpus / (smp_threads * pnv->num_chips);
723+
}
724+
725+
if (smp_cpus != (smp_threads * pnv->num_chips * cores_per_chip)) {
726+
error_report("cpu topology not balanced: "
727+
"chips (%u) * cores (%u) * threads (%u) != "
728+
"number of cpus (%u)",
729+
pnv->num_chips, cores_per_chip, smp_threads, smp_cpus);
730+
exit(1);
731+
}
732+
717733
for (i = 0; i < pnv->num_chips; i++) {
718734
char chip_name[32];
719735
Object *chip = object_new(chip_typename);
@@ -732,7 +748,7 @@ static void ppc_powernv_init(MachineState *machine)
732748
object_property_add_child(OBJECT(pnv), chip_name, chip, &error_fatal);
733749
object_property_set_int(chip, PNV_CHIP_HWID(i), "chip-id",
734750
&error_fatal);
735-
object_property_set_int(chip, smp_cores, "nr-cores", &error_fatal);
751+
object_property_set_int(chip, cores_per_chip, "nr-cores", &error_fatal);
736752
object_property_set_int(chip, 1, "num-phbs", &error_fatal);
737753
object_property_set_bool(chip, true, "realized", &error_fatal);
738754
}

0 commit comments

Comments
 (0)