pnv_core: Allocate cpu thread objects individually
Currently, we allocate space for all the cpu objects within a single core in one big block. This was copied from an older version of the spapr code and requires some ugly pointer manipulation to extract the individual objects. This design was due to a misunderstanding of qemu lifetime conventions and has already been changed in spapr (in 94ad93bd "spapr_cpu_core: instantiate CPUs separately". Make an equivalent change in pnv_core to get rid of the nasty pointer arithmetic. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Cédric Le Goater <clg@kaod.org> Reviewed-by: Greg Kurz <groug@kaod.org>
This commit is contained in:
parent
937c2146a6
commit
08304a8689
@ -121,9 +121,9 @@ static int get_cpus_node(void *fdt)
|
|||||||
*/
|
*/
|
||||||
static void pnv_dt_core(PnvChip *chip, PnvCore *pc, void *fdt)
|
static void pnv_dt_core(PnvChip *chip, PnvCore *pc, void *fdt)
|
||||||
{
|
{
|
||||||
CPUState *cs = CPU(DEVICE(pc->threads));
|
PowerPCCPU *cpu = pc->threads[0];
|
||||||
|
CPUState *cs = CPU(cpu);
|
||||||
DeviceClass *dc = DEVICE_GET_CLASS(cs);
|
DeviceClass *dc = DEVICE_GET_CLASS(cs);
|
||||||
PowerPCCPU *cpu = POWERPC_CPU(cs);
|
|
||||||
int smt_threads = CPU_CORE(pc)->nr_threads;
|
int smt_threads = CPU_CORE(pc)->nr_threads;
|
||||||
CPUPPCState *env = &cpu->env;
|
CPUPPCState *env = &cpu->env;
|
||||||
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs);
|
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cs);
|
||||||
|
@ -151,7 +151,6 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)
|
|||||||
PnvCore *pc = PNV_CORE(OBJECT(dev));
|
PnvCore *pc = PNV_CORE(OBJECT(dev));
|
||||||
CPUCore *cc = CPU_CORE(OBJECT(dev));
|
CPUCore *cc = CPU_CORE(OBJECT(dev));
|
||||||
const char *typename = pnv_core_cpu_typename(pc);
|
const char *typename = pnv_core_cpu_typename(pc);
|
||||||
size_t size = object_type_get_instance_size(typename);
|
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
void *obj;
|
void *obj;
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -165,11 +164,11 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pc->threads = g_malloc0(size * cc->nr_threads);
|
pc->threads = g_new(PowerPCCPU *, cc->nr_threads);
|
||||||
for (i = 0; i < cc->nr_threads; i++) {
|
for (i = 0; i < cc->nr_threads; i++) {
|
||||||
obj = pc->threads + i * size;
|
obj = object_new(typename);
|
||||||
|
|
||||||
object_initialize(obj, size, typename);
|
pc->threads[i] = POWERPC_CPU(obj);
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "thread[%d]", i);
|
snprintf(name, sizeof(name), "thread[%d]", i);
|
||||||
object_property_add_child(OBJECT(pc), name, obj, &error_abort);
|
object_property_add_child(OBJECT(pc), name, obj, &error_abort);
|
||||||
@ -179,7 +178,7 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < cc->nr_threads; j++) {
|
for (j = 0; j < cc->nr_threads; j++) {
|
||||||
obj = pc->threads + j * size;
|
obj = OBJECT(pc->threads[j]);
|
||||||
|
|
||||||
pnv_core_realize_child(obj, XICS_FABRIC(xi), &local_err);
|
pnv_core_realize_child(obj, XICS_FABRIC(xi), &local_err);
|
||||||
if (local_err) {
|
if (local_err) {
|
||||||
@ -194,7 +193,7 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
while (--i >= 0) {
|
while (--i >= 0) {
|
||||||
obj = pc->threads + i * size;
|
obj = OBJECT(pc->threads[i]);
|
||||||
object_unparent(obj);
|
object_unparent(obj);
|
||||||
}
|
}
|
||||||
g_free(pc->threads);
|
g_free(pc->threads);
|
||||||
|
@ -34,7 +34,7 @@ typedef struct PnvCore {
|
|||||||
CPUCore parent_obj;
|
CPUCore parent_obj;
|
||||||
|
|
||||||
/*< public >*/
|
/*< public >*/
|
||||||
void *threads;
|
PowerPCCPU **threads;
|
||||||
uint32_t pir;
|
uint32_t pir;
|
||||||
|
|
||||||
MemoryRegion xscom_regs;
|
MemoryRegion xscom_regs;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user