X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=numa.c;h=6fc2393ddd803726bed28af7415d8276f0c34941;hb=5b12c163c830081cbb78e2de3b42c5fe1b73e74e;hp=f5fc7da3e9cc5d24439b627d114115fa118db2bc;hpb=e1ff3c67e8544f41f1bea76ba76385faee0d2bb7;p=mirror_qemu.git diff --git a/numa.c b/numa.c index f5fc7da3e9..6fc2393ddd 100644 --- a/numa.c +++ b/numa.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "sysemu/numa.h" #include "exec/cpu-common.h" +#include "exec/ramlist.h" #include "qemu/bitmap.h" #include "qom/cpu.h" #include "qemu/error-report.h" @@ -227,8 +228,8 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp) } switch (object->type) { - case NUMA_OPTIONS_KIND_NODE: - numa_node_parse(object->u.node.data, opts, &err); + case NUMA_OPTIONS_TYPE_NODE: + numa_node_parse(&object->u.node, opts, &err); if (err) { goto end; } @@ -266,20 +267,19 @@ static char *enumerate_cpus(unsigned long *cpus, int max_cpus) static void validate_numa_cpus(void) { int i; - DECLARE_BITMAP(seen_cpus, MAX_CPUMASK_BITS); + unsigned long *seen_cpus = bitmap_new(max_cpus); - bitmap_zero(seen_cpus, MAX_CPUMASK_BITS); for (i = 0; i < nb_numa_nodes; i++) { - if (bitmap_intersects(seen_cpus, numa_info[i].node_cpu, - MAX_CPUMASK_BITS)) { + if (bitmap_intersects(seen_cpus, numa_info[i].node_cpu, max_cpus)) { bitmap_and(seen_cpus, seen_cpus, - numa_info[i].node_cpu, MAX_CPUMASK_BITS); + 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_CPUMASK_BITS); + numa_info[i].node_cpu, max_cpus); } if (!bitmap_full(seen_cpus, max_cpus)) { @@ -291,12 +291,17 @@ static void validate_numa_cpus(void) "in NUMA config"); g_free(msg); } + g_free(seen_cpus); } void parse_numa_opts(MachineClass *mc) { int i; + 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, NULL, NULL)) { exit(1); } @@ -333,12 +338,12 @@ void parse_numa_opts(MachineClass *mc) if (i == nb_numa_nodes) { uint64_t usedmem = 0; - /* On Linux, each node's border has to be 8MB aligned, - * the final node gets the rest. + /* Align each node according to the alignment + * requirements of the machine class */ for (i = 0; i < nb_numa_nodes - 1; i++) { numa_info[i].node_mem = (ram_size / nb_numa_nodes) & - ~((1 << 23UL) - 1); + ~((1 << mc->numa_mem_align_shift) - 1); usedmem += numa_info[i].node_mem; } numa_info[i].node_mem = ram_size - usedmem; @@ -362,7 +367,7 @@ void parse_numa_opts(MachineClass *mc) numa_set_mem_ranges(); for (i = 0; i < nb_numa_nodes; i++) { - if (!bitmap_empty(numa_info[i].node_cpu, MAX_CPUMASK_BITS)) { + if (!bitmap_empty(numa_info[i].node_cpu, max_cpus)) { break; } } @@ -397,6 +402,7 @@ void numa_post_machine_init(void) 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; } @@ -558,6 +564,8 @@ 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; @@ -565,3 +573,31 @@ int numa_get_node_for_cpu(int idx) } return i; } + +void ram_block_notifier_add(RAMBlockNotifier *n) +{ + QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next); +} + +void ram_block_notifier_remove(RAMBlockNotifier *n) +{ + QLIST_REMOVE(n, next); +} + +void ram_block_notify_add(void *host, size_t size) +{ + RAMBlockNotifier *notifier; + + QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) { + notifier->ram_block_added(notifier, host, size); + } +} + +void ram_block_notify_remove(void *host, size_t size) +{ + RAMBlockNotifier *notifier; + + QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) { + notifier->ram_block_removed(notifier, host, size); + } +}