@@ -36,6 +36,20 @@ static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
core->nr_threads = value;
}
+static void core_prop_set_plugged_threads(Object *obj, Visitor *v,
+ const char *name, void *opaque,
+ Error **errp)
+{
+ CPUCore *core = CPU_CORE(obj);
+ int64_t value;
+
+ if (!visit_type_int(v, name, &value, errp)) {
+ return;
+ }
+
+ core->plugged_threads = value;
+}
+
static void cpu_core_instance_init(Object *obj)
{
CPUCore *core = CPU_CORE(obj);
@@ -48,6 +62,22 @@ static void cpu_core_instance_init(Object *obj)
if (current_machine) {
core->nr_threads = current_machine->smp.threads;
}
+
+ core->plugged_threads = -1;
+}
+
+static void cpu_core_realize(DeviceState *dev, Error **errp)
+{
+ CPUCore *core = CPU_CORE(dev);
+
+ if (core->plugged_threads > core->nr_threads) {
+ error_setg(errp, "Plugged threads (plugged-threads: %d) must "
+ "not be more than max threads (nr-threads: %d)",
+ core->plugged_threads, core->nr_threads);
+ return;
+ } else if (core->plugged_threads == -1) {
+ core->plugged_threads = core->nr_threads;
+ }
}
static void cpu_core_class_init(ObjectClass *oc, void *data)
@@ -57,6 +87,9 @@ static void cpu_core_class_init(ObjectClass *oc, void *data)
set_bit(DEVICE_CATEGORY_CPU, dc->categories);
object_class_property_add(oc, "nr-threads", "int", core_prop_get_nr_threads,
core_prop_set_nr_threads, NULL, NULL);
+ object_class_property_add(oc, "plugged-threads", "int", NULL,
+ core_prop_set_plugged_threads, NULL, NULL);
+ dc->realize = cpu_core_realize;
}
static const TypeInfo cpu_core_type_info = {
@@ -276,6 +276,8 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)
assert(pc->chip);
+ pcc->parent_realize(dev, errp);
+
pc->threads = g_new(PowerPCCPU *, cc->nr_threads);
for (i = 0; i < cc->nr_threads; i++) {
PowerPCCPU *cpu;
@@ -376,11 +378,13 @@ static void pnv_core_power10_class_init(ObjectClass *oc, void *data)
static void pnv_core_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
+ PnvCoreClass *pcc = PNV_CORE_CLASS(oc);
- dc->realize = pnv_core_realize;
dc->unrealize = pnv_core_unrealize;
device_class_set_props(dc, pnv_core_properties);
dc->user_creatable = false;
+ device_class_set_parent_realize(dc, pnv_core_realize,
+ &pcc->parent_realize);
}
#define DEFINE_PNV_CORE_TYPE(family, cpu_model) \
@@ -331,6 +331,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
(SpaprMachineState *) object_dynamic_cast(qdev_get_machine(),
TYPE_SPAPR_MACHINE);
SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
+ SpaprCpuCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(sc);
CPUCore *cc = CPU_CORE(OBJECT(dev));
int i;
@@ -339,6 +340,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
return;
}
+ scc->parent_realize(dev, errp);
+
qemu_register_reset(spapr_cpu_core_reset_handler, sc);
sc->threads = g_new0(PowerPCCPU *, cc->nr_threads);
for (i = 0; i < cc->nr_threads; i++) {
@@ -363,11 +366,12 @@ static void spapr_cpu_core_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
SpaprCpuCoreClass *scc = SPAPR_CPU_CORE_CLASS(oc);
- dc->realize = spapr_cpu_core_realize;
dc->unrealize = spapr_cpu_core_unrealize;
dc->reset = spapr_cpu_core_reset;
device_class_set_props(dc, spapr_cpu_core_properties);
scc->cpu_type = data;
+ device_class_set_parent_realize(dc, spapr_cpu_core_realize,
+ &scc->parent_realize);
}
#define DEFINE_SPAPR_CPU_CORE_TYPE(cpu_model) \
@@ -21,7 +21,16 @@ struct CPUCore {
DeviceState parent_obj;
/*< public >*/
+ int core_id;
+
+ /* Maximum number of threads contained in this core. */
int nr_threads;
+
+ /*
+ * How many threads should be plugged in this core via
+ * "-device"/"device_add"?
+ */
+ int plugged_threads;
};
#endif
@@ -49,6 +49,8 @@ struct PnvCoreClass {
/*< public >*/
const MemoryRegionOps *xscom_ops;
uint64_t xscom_size;
+
+ DeviceRealize parent_realize;
};
#define PNV_CORE_TYPE_SUFFIX "-" TYPE_PNV_CORE
@@ -37,6 +37,8 @@ struct SpaprCpuCoreClass {
/*< public >*/
const char *cpu_type;
+
+ DeviceRealize parent_realize;
};
const char *spapr_get_cpu_core_type(const char *cpu_type);