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);
- }
-
- if (!bitmap_full(seen_cpus, max_cpus)) {
- char *msg;
- bitmap_complement(seen_cpus, seen_cpus, max_cpus);
- msg = enumerate_cpus(seen_cpus, max_cpus);
- error_report("warning: CPU(s) not present in any NUMA nodes: %s", msg);
- error_report("warning: All CPU(s) up to maxcpus should be described "
- "in NUMA config");
- g_free(msg);
- }
- 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_post_machine_init(void)
+void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
{
- CPUState *cpu;
- int i;
-
- CPU_FOREACH(cpu) {
- for (i = 0; i < nb_numa_nodes; i++) {
- assert(cpu->cpu_index < max_cpus);
- if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) {
- cpu->numa_node = i;
- }
+ 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);
}
}
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",
return list;
}
-int numa_get_node_for_cpu(int idx)
-{
- int i;
-
- assert(idx < max_cpus);
-
- for (i = 0; i < nb_numa_nodes; i++) {
- if (test_bit(idx, numa_info[i].node_cpu)) {
- break;
- }
- }
- return i;
-}
-
void ram_block_notifier_add(RAMBlockNotifier *n)
{
QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next);