numa: consolidate cpu_preplug fixups/checks for pc/arm/spapr

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Message-Id: <1496161442-96665-2-git-send-email-imammedo@redhat.com>
[ehabkost: Fix indentation]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
Igor Mammedov 2017-05-30 18:23:56 +02:00 committed by Eduardo Habkost
parent 1f43571604
commit a0ceb640d0
5 changed files with 28 additions and 46 deletions

View File

@ -1372,7 +1372,6 @@ static void machvirt_init(MachineState *machine)
for (n = 0; n < possible_cpus->len; n++) { for (n = 0; n < possible_cpus->len; n++) {
Object *cpuobj; Object *cpuobj;
CPUState *cs; CPUState *cs;
int node_id;
if (n >= smp_cpus) { if (n >= smp_cpus) {
break; break;
@ -1385,19 +1384,8 @@ static void machvirt_init(MachineState *machine)
cs = CPU(cpuobj); cs = CPU(cpuobj);
cs->cpu_index = n; cs->cpu_index = n;
node_id = possible_cpus->cpus[cs->cpu_index].props.node_id; numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index], DEVICE(cpuobj),
if (!possible_cpus->cpus[cs->cpu_index].props.has_node_id) { &error_fatal);
/* by default CPUState::numa_node was 0 if it's not set via CLI
* keep it this way for now but in future we probably should
* refuse to start up with incomplete numa mapping */
node_id = 0;
}
if (cs->numa_node == CPU_UNSET_NUMA_NODE_ID) {
cs->numa_node = node_id;
} else {
/* CPU isn't device_add compatible yet, this shouldn't happen */
error_setg(&error_abort, "user set node-id not implemented");
}
if (!vms->secure) { if (!vms->secure) {
object_property_set_bool(cpuobj, false, "has_el3", NULL); object_property_set_bool(cpuobj, false, "has_el3", NULL);

View File

@ -1893,7 +1893,6 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp) DeviceState *dev, Error **errp)
{ {
int idx; int idx;
int node_id;
CPUState *cs; CPUState *cs;
CPUArchId *cpu_slot; CPUArchId *cpu_slot;
X86CPUTopoInfo topo; X86CPUTopoInfo topo;
@ -1984,21 +1983,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
cs = CPU(cpu); cs = CPU(cpu);
cs->cpu_index = idx; cs->cpu_index = idx;
node_id = cpu_slot->props.node_id; numa_cpu_pre_plug(cpu_slot, dev, errp);
if (!cpu_slot->props.has_node_id) {
/* by default CPUState::numa_node was 0 if it's not set via CLI
* keep it this way for now but in future we probably should
* refuse to start up with incomplete numa mapping */
node_id = 0;
}
if (cs->numa_node == CPU_UNSET_NUMA_NODE_ID) {
cs->numa_node = node_id;
} else if (cs->numa_node != node_id) {
error_setg(errp, "node-id %d must match numa node specified"
"with -numa option for cpu-index %d",
cs->numa_node, cs->cpu_index);
return;
}
} }
static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,

View File

@ -2922,11 +2922,9 @@ static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
MachineClass *mc = MACHINE_GET_CLASS(hotplug_dev); MachineClass *mc = MACHINE_GET_CLASS(hotplug_dev);
Error *local_err = NULL; Error *local_err = NULL;
CPUCore *cc = CPU_CORE(dev); CPUCore *cc = CPU_CORE(dev);
sPAPRCPUCore *sc = SPAPR_CPU_CORE(dev);
char *base_core_type = spapr_get_cpu_core_type(machine->cpu_model); char *base_core_type = spapr_get_cpu_core_type(machine->cpu_model);
const char *type = object_get_typename(OBJECT(dev)); const char *type = object_get_typename(OBJECT(dev));
CPUArchId *core_slot; CPUArchId *core_slot;
int node_id;
int index; int index;
if (dev->hotplugged && !mc->has_hotpluggable_cpus) { if (dev->hotplugged && !mc->has_hotpluggable_cpus) {
@ -2967,20 +2965,7 @@ static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
goto out; goto out;
} }
node_id = core_slot->props.node_id; numa_cpu_pre_plug(core_slot, dev, &local_err);
if (!core_slot->props.has_node_id) {
/* by default CPUState::numa_node was 0 if it's not set via CLI
* keep it this way for now but in future we probably should
* refuse to start up with incomplete numa mapping */
node_id = 0;
}
if (sc->node_id == CPU_UNSET_NUMA_NODE_ID) {
sc->node_id = node_id;
} else if (sc->node_id != node_id) {
error_setg(&local_err, "node-id %d must match numa node specified"
"with -numa option for cpu-index %d", sc->node_id, cc->core_id);
goto out;
}
out: out:
g_free(base_core_type); g_free(base_core_type);

View File

@ -35,4 +35,5 @@ void numa_legacy_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
int nb_nodes, ram_addr_t size); int nb_nodes, ram_addr_t size);
void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes, void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
int nb_nodes, ram_addr_t size); int nb_nodes, ram_addr_t size);
void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp);
#endif #endif

23
numa.c
View File

@ -533,6 +533,29 @@ void parse_numa_opts(MachineState *ms)
} }
} }
void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
{
int mapped_node_id; /* set by -numa option */
int node_id = object_property_get_int(OBJECT(dev), "node-id", &error_abort);
/* by default CPUState::numa_node was 0 if it wasn't set explicitly
* TODO: make it error when incomplete numa mapping support is removed
*/
mapped_node_id = slot->props.node_id;
if (!slot->props.has_node_id) {
mapped_node_id = 0;
}
if (node_id == CPU_UNSET_NUMA_NODE_ID) {
/* due to bug in libvirt, it doesn't pass node-id from props on
* device_add as expected, so we have to fix it up here */
object_property_set_int(OBJECT(dev), mapped_node_id, "node-id", errp);
} else if (node_id != mapped_node_id) {
error_setg(errp, "node-id=%d must match numa node specified "
"with -numa option", node_id);
}
}
static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner, static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
const char *name, const char *name,
uint64_t ram_size) uint64_t ram_size)