cpus->value, max_cpus);
return;
}
- bitmap_set(numa_info[nodenr].node_cpu, cpus->value, 1);
props = mc->cpu_index_to_instance_props(ms, cpus->value);
props.node_id = nodenr;
props.has_node_id = true;
}
if (node->has_mem && node->has_memdev) {
- error_setg(errp, "qemu: cannot specify both mem= and memdev=");
+ error_setg(errp, "cannot specify both mem= and memdev=");
return;
}
have_memdevs = node->has_memdev;
}
if (node->has_memdev != have_memdevs) {
- error_setg(errp, "qemu: memdev option must be specified for either "
+ error_setg(errp, "memdev option must be specified for either "
"all or no nodes");
return;
}
}
object_ref(o);
- numa_info[nodenr].node_mem = object_property_get_int(o, "size", NULL);
+ numa_info[nodenr].node_mem = object_property_get_uint(o, "size", NULL);
numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
}
numa_info[nodenr].present = true;
if (src >= MAX_NODES || dst >= MAX_NODES) {
error_setg(errp,
- "Invalid node %" PRIu16
- ", max possible could be %" PRIu16,
+ "Invalid node %d, max possible could be %d",
MAX(src, dst), MAX_NODES);
return;
}
goto end;
}
break;
+ case NUMA_OPTIONS_TYPE_CPU:
+ if (!object->u.cpu.has_node_id) {
+ error_setg(&err, "Missing mandatory node-id property");
+ goto end;
+ }
+ if (!numa_info[object->u.cpu.node_id].present) {
+ error_setg(&err, "Invalid node-id=%" PRId64 ", NUMA node must be "
+ "defined with -numa node,nodeid=ID before it's used with "
+ "-numa cpu,node-id=ID", object->u.cpu.node_id);
+ goto end;
+ }
+
+ machine_set_cpu_numa_node(ms, qapi_NumaCpuOptions_base(&object->u.cpu),
+ &err);
+ break;
default:
abort();
}
return 0;
}
-static char *enumerate_cpus(unsigned long *cpus, int max_cpus)
-{
- int cpu;
- bool first = true;
- GString *s = g_string_new(NULL);
-
- for (cpu = find_first_bit(cpus, max_cpus);
- cpu < max_cpus;
- cpu = find_next_bit(cpus, max_cpus, cpu + 1)) {
- g_string_append_printf(s, "%s%d", first ? "" : " ", cpu);
- first = false;
- }
- return g_string_free(s, FALSE);
-}
-
-static void validate_numa_cpus(void)
-{
- int i;
- unsigned long *seen_cpus = bitmap_new(max_cpus);
-
- for (i = 0; i < nb_numa_nodes; i++) {
- if (bitmap_intersects(seen_cpus, numa_info[i].node_cpu, max_cpus)) {
- bitmap_and(seen_cpus, seen_cpus,
- numa_info[i].node_cpu, max_cpus);
- error_report("CPU(s) present in multiple NUMA nodes: %s",
- enumerate_cpus(seen_cpus, max_cpus));
- g_free(seen_cpus);
- exit(EXIT_FAILURE);
- }
- bitmap_or(seen_cpus, seen_cpus,
- numa_info[i].node_cpu, max_cpus);
- }
- g_free(seen_cpus);
-}
-
/* If all node pair distances are symmetric, then only distances
* in one direction are enough. If there is even one asymmetric
* pair, though, then all distances must be provided. The
void parse_numa_opts(MachineState *ms)
{
int i;
- const CPUArchIdList *possible_cpus;
MachineClass *mc = MACHINE_GET_CLASS(ms);
- for (i = 0; i < MAX_NODES; i++) {
- numa_info[i].node_cpu = bitmap_new(max_cpus);
- }
-
if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, NULL)) {
exit(1);
}
numa_set_mem_ranges();
- /* assign CPUs to nodes using board provided default mapping */
- if (!mc->cpu_index_to_instance_props || !mc->possible_cpu_arch_ids) {
- error_report("default CPUs to NUMA node mapping isn't supported");
- exit(1);
- }
-
- possible_cpus = mc->possible_cpu_arch_ids(ms);
- for (i = 0; i < possible_cpus->len; i++) {
- if (possible_cpus->cpus[i].props.has_node_id) {
- break;
- }
- }
-
- /* no CPUs are assigned to NUMA nodes */
- if (i == possible_cpus->len) {
- for (i = 0; i < max_cpus; i++) {
- CpuInstanceProperties props;
- /* fetch default mapping from board and enable it */
- props = mc->cpu_index_to_instance_props(ms, i);
- props.has_node_id = true;
-
- set_bit(i, numa_info[props.node_id].node_cpu);
- machine_set_cpu_numa_node(ms, &props, &error_fatal);
- }
- }
-
- validate_numa_cpus();
-
/* QEMU needs at least all unique node pair distances to build
* the whole NUMA distance table. QEMU treats the distance table
* as symmetric by default, i.e. distance A->B == distance B->A.
}
}
+void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
+{
+ int node_id = object_property_get_int(OBJECT(dev), "node-id", &error_abort);
+
+ 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 */
+ if (slot->props.has_node_id) {
+ object_property_set_int(OBJECT(dev), slot->props.node_id,
+ "node-id", errp);
+ }
+ } else if (node_id != slot->props.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,
const char *name,
uint64_t ram_size)
/* Legacy behavior: if allocation failed, fall back to
* regular RAM allocation.
*/
- memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
+ memory_region_init_ram_nomigrate(mr, owner, name, ram_size, &error_fatal);
}
#else
fprintf(stderr, "-mem-path not supported on this host\n");
exit(1);
#endif
} else {
- memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
+ memory_region_init_ram_nomigrate(mr, owner, name, ram_size, &error_fatal);
}
vmstate_register_ram_global(mr);
}
}
memory_region_init(mr, owner, name, ram_size);
- for (i = 0; i < MAX_NODES; i++) {
+ for (i = 0; i < nb_numa_nodes; i++) {
uint64_t size = numa_info[i].node_mem;
HostMemoryBackend *backend = numa_info[i].node_memdev;
if (!backend) {
}
}
-static void numa_stat_memory_devices(uint64_t node_mem[])
+static void numa_stat_memory_devices(NumaNodeMem node_mem[])
{
MemoryDeviceInfoList *info_list = NULL;
MemoryDeviceInfoList **prev = &info_list;
MemoryDeviceInfoList *info;
+ PCDIMMDeviceInfo *pcdimm_info;
qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
for (info = info_list; info; info = info->next) {
if (value) {
switch (value->type) {
- case MEMORY_DEVICE_INFO_KIND_DIMM:
- node_mem[value->u.dimm.data->node] += value->u.dimm.data->size;
+ case MEMORY_DEVICE_INFO_KIND_DIMM: {
+ pcdimm_info = value->u.dimm.data;
+ node_mem[pcdimm_info->node].node_mem += pcdimm_info->size;
+ if (pcdimm_info->hotpluggable && pcdimm_info->hotplugged) {
+ node_mem[pcdimm_info->node].node_plugged_mem +=
+ pcdimm_info->size;
+ }
break;
+ }
+
default:
break;
}
qapi_free_MemoryDeviceInfoList(info_list);
}
-void query_numa_node_mem(uint64_t node_mem[])
+void query_numa_node_mem(NumaNodeMem node_mem[])
{
int i;
numa_stat_memory_devices(node_mem);
for (i = 0; i < nb_numa_nodes; i++) {
- node_mem[i] += numa_info[i].node_mem;
+ node_mem[i].node_mem += numa_info[i].node_mem;
}
}
m->value->id = object_property_get_str(obj, "id", NULL);
m->value->has_id = !!m->value->id;
- m->value->size = object_property_get_int(obj, "size",
- &error_abort);
+ m->value->size = object_property_get_uint(obj, "size",
+ &error_abort);
m->value->merge = object_property_get_bool(obj, "merge",
&error_abort);
m->value->dump = object_property_get_bool(obj, "dump",