]> git.proxmox.com Git - mirror_qemu.git/blob - numa.c
tests: numa: add case for QMP command query-cpus
[mirror_qemu.git] / numa.c
1 /*
2 * NUMA parameter parsing routines
3 *
4 * Copyright (c) 2014 Fujitsu Ltd.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #include "qemu/osdep.h"
26 #include "sysemu/numa.h"
27 #include "exec/cpu-common.h"
28 #include "exec/ramlist.h"
29 #include "qemu/bitmap.h"
30 #include "qom/cpu.h"
31 #include "qemu/error-report.h"
32 #include "include/exec/cpu-common.h" /* for RAM_ADDR_FMT */
33 #include "qapi-visit.h"
34 #include "qapi/opts-visitor.h"
35 #include "hw/boards.h"
36 #include "sysemu/hostmem.h"
37 #include "qmp-commands.h"
38 #include "hw/mem/pc-dimm.h"
39 #include "qemu/option.h"
40 #include "qemu/config-file.h"
41
42 QemuOptsList qemu_numa_opts = {
43 .name = "numa",
44 .implied_opt_name = "type",
45 .head = QTAILQ_HEAD_INITIALIZER(qemu_numa_opts.head),
46 .desc = { { 0 } } /* validated with OptsVisitor */
47 };
48
49 static int have_memdevs = -1;
50 static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
51 * For all nodes, nodeid < max_numa_nodeid
52 */
53 int nb_numa_nodes;
54 bool have_numa_distance;
55 NodeInfo numa_info[MAX_NODES];
56
57 void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node)
58 {
59 struct numa_addr_range *range;
60
61 /*
62 * Memory-less nodes can come here with 0 size in which case,
63 * there is nothing to do.
64 */
65 if (!size) {
66 return;
67 }
68
69 range = g_malloc0(sizeof(*range));
70 range->mem_start = addr;
71 range->mem_end = addr + size - 1;
72 QLIST_INSERT_HEAD(&numa_info[node].addr, range, entry);
73 }
74
75 void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node)
76 {
77 struct numa_addr_range *range, *next;
78
79 QLIST_FOREACH_SAFE(range, &numa_info[node].addr, entry, next) {
80 if (addr == range->mem_start && (addr + size - 1) == range->mem_end) {
81 QLIST_REMOVE(range, entry);
82 g_free(range);
83 return;
84 }
85 }
86 }
87
88 static void numa_set_mem_ranges(void)
89 {
90 int i;
91 ram_addr_t mem_start = 0;
92
93 /*
94 * Deduce start address of each node and use it to store
95 * the address range info in numa_info address range list
96 */
97 for (i = 0; i < nb_numa_nodes; i++) {
98 numa_set_mem_node_id(mem_start, numa_info[i].node_mem, i);
99 mem_start += numa_info[i].node_mem;
100 }
101 }
102
103 /*
104 * Check if @addr falls under NUMA @node.
105 */
106 static bool numa_addr_belongs_to_node(ram_addr_t addr, uint32_t node)
107 {
108 struct numa_addr_range *range;
109
110 QLIST_FOREACH(range, &numa_info[node].addr, entry) {
111 if (addr >= range->mem_start && addr <= range->mem_end) {
112 return true;
113 }
114 }
115 return false;
116 }
117
118 /*
119 * Given an address, return the index of the NUMA node to which the
120 * address belongs to.
121 */
122 uint32_t numa_get_node(ram_addr_t addr, Error **errp)
123 {
124 uint32_t i;
125
126 /* For non NUMA configurations, check if the addr falls under node 0 */
127 if (!nb_numa_nodes) {
128 if (numa_addr_belongs_to_node(addr, 0)) {
129 return 0;
130 }
131 }
132
133 for (i = 0; i < nb_numa_nodes; i++) {
134 if (numa_addr_belongs_to_node(addr, i)) {
135 return i;
136 }
137 }
138
139 error_setg(errp, "Address 0x" RAM_ADDR_FMT " doesn't belong to any "
140 "NUMA node", addr);
141 return -1;
142 }
143
144 static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
145 QemuOpts *opts, Error **errp)
146 {
147 uint16_t nodenr;
148 uint16List *cpus = NULL;
149 MachineClass *mc = MACHINE_GET_CLASS(ms);
150
151 if (node->has_nodeid) {
152 nodenr = node->nodeid;
153 } else {
154 nodenr = nb_numa_nodes;
155 }
156
157 if (nodenr >= MAX_NODES) {
158 error_setg(errp, "Max number of NUMA nodes reached: %"
159 PRIu16 "", nodenr);
160 return;
161 }
162
163 if (numa_info[nodenr].present) {
164 error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
165 return;
166 }
167
168 if (!mc->cpu_index_to_instance_props) {
169 error_report("NUMA is not supported by this machine-type");
170 exit(1);
171 }
172 for (cpus = node->cpus; cpus; cpus = cpus->next) {
173 CpuInstanceProperties props;
174 if (cpus->value >= max_cpus) {
175 error_setg(errp,
176 "CPU index (%" PRIu16 ")"
177 " should be smaller than maxcpus (%d)",
178 cpus->value, max_cpus);
179 return;
180 }
181 bitmap_set(numa_info[nodenr].node_cpu, cpus->value, 1);
182 props = mc->cpu_index_to_instance_props(ms, cpus->value);
183 props.node_id = nodenr;
184 props.has_node_id = true;
185 machine_set_cpu_numa_node(ms, &props, &error_fatal);
186 }
187
188 if (node->has_mem && node->has_memdev) {
189 error_setg(errp, "qemu: cannot specify both mem= and memdev=");
190 return;
191 }
192
193 if (have_memdevs == -1) {
194 have_memdevs = node->has_memdev;
195 }
196 if (node->has_memdev != have_memdevs) {
197 error_setg(errp, "qemu: memdev option must be specified for either "
198 "all or no nodes");
199 return;
200 }
201
202 if (node->has_mem) {
203 uint64_t mem_size = node->mem;
204 const char *mem_str = qemu_opt_get(opts, "mem");
205 /* Fix up legacy suffix-less format */
206 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
207 mem_size <<= 20;
208 }
209 numa_info[nodenr].node_mem = mem_size;
210 }
211 if (node->has_memdev) {
212 Object *o;
213 o = object_resolve_path_type(node->memdev, TYPE_MEMORY_BACKEND, NULL);
214 if (!o) {
215 error_setg(errp, "memdev=%s is ambiguous", node->memdev);
216 return;
217 }
218
219 object_ref(o);
220 numa_info[nodenr].node_mem = object_property_get_int(o, "size", NULL);
221 numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
222 }
223 numa_info[nodenr].present = true;
224 max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
225 }
226
227 static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
228 {
229 uint16_t src = dist->src;
230 uint16_t dst = dist->dst;
231 uint8_t val = dist->val;
232
233 if (src >= MAX_NODES || dst >= MAX_NODES) {
234 error_setg(errp,
235 "Invalid node %" PRIu16
236 ", max possible could be %" PRIu16,
237 MAX(src, dst), MAX_NODES);
238 return;
239 }
240
241 if (!numa_info[src].present || !numa_info[dst].present) {
242 error_setg(errp, "Source/Destination NUMA node is missing. "
243 "Please use '-numa node' option to declare it first.");
244 return;
245 }
246
247 if (val < NUMA_DISTANCE_MIN) {
248 error_setg(errp, "NUMA distance (%" PRIu8 ") is invalid, "
249 "it shouldn't be less than %d.",
250 val, NUMA_DISTANCE_MIN);
251 return;
252 }
253
254 if (src == dst && val != NUMA_DISTANCE_MIN) {
255 error_setg(errp, "Local distance of node %d should be %d.",
256 src, NUMA_DISTANCE_MIN);
257 return;
258 }
259
260 numa_info[src].distance[dst] = val;
261 have_numa_distance = true;
262 }
263
264 static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
265 {
266 NumaOptions *object = NULL;
267 MachineState *ms = opaque;
268 Error *err = NULL;
269
270 {
271 Visitor *v = opts_visitor_new(opts);
272 visit_type_NumaOptions(v, NULL, &object, &err);
273 visit_free(v);
274 }
275
276 if (err) {
277 goto end;
278 }
279
280 switch (object->type) {
281 case NUMA_OPTIONS_TYPE_NODE:
282 parse_numa_node(ms, &object->u.node, opts, &err);
283 if (err) {
284 goto end;
285 }
286 nb_numa_nodes++;
287 break;
288 case NUMA_OPTIONS_TYPE_DIST:
289 parse_numa_distance(&object->u.dist, &err);
290 if (err) {
291 goto end;
292 }
293 break;
294 default:
295 abort();
296 }
297
298 end:
299 qapi_free_NumaOptions(object);
300 if (err) {
301 error_report_err(err);
302 return -1;
303 }
304
305 return 0;
306 }
307
308 static char *enumerate_cpus(unsigned long *cpus, int max_cpus)
309 {
310 int cpu;
311 bool first = true;
312 GString *s = g_string_new(NULL);
313
314 for (cpu = find_first_bit(cpus, max_cpus);
315 cpu < max_cpus;
316 cpu = find_next_bit(cpus, max_cpus, cpu + 1)) {
317 g_string_append_printf(s, "%s%d", first ? "" : " ", cpu);
318 first = false;
319 }
320 return g_string_free(s, FALSE);
321 }
322
323 static void validate_numa_cpus(void)
324 {
325 int i;
326 unsigned long *seen_cpus = bitmap_new(max_cpus);
327
328 for (i = 0; i < nb_numa_nodes; i++) {
329 if (bitmap_intersects(seen_cpus, numa_info[i].node_cpu, max_cpus)) {
330 bitmap_and(seen_cpus, seen_cpus,
331 numa_info[i].node_cpu, max_cpus);
332 error_report("CPU(s) present in multiple NUMA nodes: %s",
333 enumerate_cpus(seen_cpus, max_cpus));
334 g_free(seen_cpus);
335 exit(EXIT_FAILURE);
336 }
337 bitmap_or(seen_cpus, seen_cpus,
338 numa_info[i].node_cpu, max_cpus);
339 }
340
341 if (!bitmap_full(seen_cpus, max_cpus)) {
342 char *msg;
343 bitmap_complement(seen_cpus, seen_cpus, max_cpus);
344 msg = enumerate_cpus(seen_cpus, max_cpus);
345 error_report("warning: CPU(s) not present in any NUMA nodes: %s", msg);
346 error_report("warning: All CPU(s) up to maxcpus should be described "
347 "in NUMA config");
348 g_free(msg);
349 }
350 g_free(seen_cpus);
351 }
352
353 /* If all node pair distances are symmetric, then only distances
354 * in one direction are enough. If there is even one asymmetric
355 * pair, though, then all distances must be provided. The
356 * distance from a node to itself is always NUMA_DISTANCE_MIN,
357 * so providing it is never necessary.
358 */
359 static void validate_numa_distance(void)
360 {
361 int src, dst;
362 bool is_asymmetrical = false;
363
364 for (src = 0; src < nb_numa_nodes; src++) {
365 for (dst = src; dst < nb_numa_nodes; dst++) {
366 if (numa_info[src].distance[dst] == 0 &&
367 numa_info[dst].distance[src] == 0) {
368 if (src != dst) {
369 error_report("The distance between node %d and %d is "
370 "missing, at least one distance value "
371 "between each nodes should be provided.",
372 src, dst);
373 exit(EXIT_FAILURE);
374 }
375 }
376
377 if (numa_info[src].distance[dst] != 0 &&
378 numa_info[dst].distance[src] != 0 &&
379 numa_info[src].distance[dst] !=
380 numa_info[dst].distance[src]) {
381 is_asymmetrical = true;
382 }
383 }
384 }
385
386 if (is_asymmetrical) {
387 for (src = 0; src < nb_numa_nodes; src++) {
388 for (dst = 0; dst < nb_numa_nodes; dst++) {
389 if (src != dst && numa_info[src].distance[dst] == 0) {
390 error_report("At least one asymmetrical pair of "
391 "distances is given, please provide distances "
392 "for both directions of all node pairs.");
393 exit(EXIT_FAILURE);
394 }
395 }
396 }
397 }
398 }
399
400 static void complete_init_numa_distance(void)
401 {
402 int src, dst;
403
404 /* Fixup NUMA distance by symmetric policy because if it is an
405 * asymmetric distance table, it should be a complete table and
406 * there would not be any missing distance except local node, which
407 * is verified by validate_numa_distance above.
408 */
409 for (src = 0; src < nb_numa_nodes; src++) {
410 for (dst = 0; dst < nb_numa_nodes; dst++) {
411 if (numa_info[src].distance[dst] == 0) {
412 if (src == dst) {
413 numa_info[src].distance[dst] = NUMA_DISTANCE_MIN;
414 } else {
415 numa_info[src].distance[dst] = numa_info[dst].distance[src];
416 }
417 }
418 }
419 }
420 }
421
422 void numa_legacy_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
423 int nb_nodes, ram_addr_t size)
424 {
425 int i;
426 uint64_t usedmem = 0;
427
428 /* Align each node according to the alignment
429 * requirements of the machine class
430 */
431
432 for (i = 0; i < nb_nodes - 1; i++) {
433 nodes[i].node_mem = (size / nb_nodes) &
434 ~((1 << mc->numa_mem_align_shift) - 1);
435 usedmem += nodes[i].node_mem;
436 }
437 nodes[i].node_mem = size - usedmem;
438 }
439
440 void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
441 int nb_nodes, ram_addr_t size)
442 {
443 int i;
444 uint64_t usedmem = 0, node_mem;
445 uint64_t granularity = size / nb_nodes;
446 uint64_t propagate = 0;
447
448 for (i = 0; i < nb_nodes - 1; i++) {
449 node_mem = (granularity + propagate) &
450 ~((1 << mc->numa_mem_align_shift) - 1);
451 propagate = granularity + propagate - node_mem;
452 nodes[i].node_mem = node_mem;
453 usedmem += node_mem;
454 }
455 nodes[i].node_mem = size - usedmem;
456 }
457
458 void parse_numa_opts(MachineState *ms)
459 {
460 int i;
461 const CPUArchIdList *possible_cpus;
462 MachineClass *mc = MACHINE_GET_CLASS(ms);
463
464 for (i = 0; i < MAX_NODES; i++) {
465 numa_info[i].node_cpu = bitmap_new(max_cpus);
466 }
467
468 if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, NULL)) {
469 exit(1);
470 }
471
472 assert(max_numa_nodeid <= MAX_NODES);
473
474 /* No support for sparse NUMA node IDs yet: */
475 for (i = max_numa_nodeid - 1; i >= 0; i--) {
476 /* Report large node IDs first, to make mistakes easier to spot */
477 if (!numa_info[i].present) {
478 error_report("numa: Node ID missing: %d", i);
479 exit(1);
480 }
481 }
482
483 /* This must be always true if all nodes are present: */
484 assert(nb_numa_nodes == max_numa_nodeid);
485
486 if (nb_numa_nodes > 0) {
487 uint64_t numa_total;
488
489 if (nb_numa_nodes > MAX_NODES) {
490 nb_numa_nodes = MAX_NODES;
491 }
492
493 /* If no memory size is given for any node, assume the default case
494 * and distribute the available memory equally across all nodes
495 */
496 for (i = 0; i < nb_numa_nodes; i++) {
497 if (numa_info[i].node_mem != 0) {
498 break;
499 }
500 }
501 if (i == nb_numa_nodes) {
502 assert(mc->numa_auto_assign_ram);
503 mc->numa_auto_assign_ram(mc, numa_info, nb_numa_nodes, ram_size);
504 }
505
506 numa_total = 0;
507 for (i = 0; i < nb_numa_nodes; i++) {
508 numa_total += numa_info[i].node_mem;
509 }
510 if (numa_total != ram_size) {
511 error_report("total memory for NUMA nodes (0x%" PRIx64 ")"
512 " should equal RAM size (0x" RAM_ADDR_FMT ")",
513 numa_total, ram_size);
514 exit(1);
515 }
516
517 for (i = 0; i < nb_numa_nodes; i++) {
518 QLIST_INIT(&numa_info[i].addr);
519 }
520
521 numa_set_mem_ranges();
522
523 /* assign CPUs to nodes using board provided default mapping */
524 if (!mc->cpu_index_to_instance_props || !mc->possible_cpu_arch_ids) {
525 error_report("default CPUs to NUMA node mapping isn't supported");
526 exit(1);
527 }
528
529 possible_cpus = mc->possible_cpu_arch_ids(ms);
530 for (i = 0; i < possible_cpus->len; i++) {
531 if (possible_cpus->cpus[i].props.has_node_id) {
532 break;
533 }
534 }
535
536 /* no CPUs are assigned to NUMA nodes */
537 if (i == possible_cpus->len) {
538 for (i = 0; i < max_cpus; i++) {
539 CpuInstanceProperties props;
540 /* fetch default mapping from board and enable it */
541 props = mc->cpu_index_to_instance_props(ms, i);
542 props.has_node_id = true;
543
544 set_bit(i, numa_info[props.node_id].node_cpu);
545 machine_set_cpu_numa_node(ms, &props, &error_fatal);
546 }
547 }
548
549 validate_numa_cpus();
550
551 /* QEMU needs at least all unique node pair distances to build
552 * the whole NUMA distance table. QEMU treats the distance table
553 * as symmetric by default, i.e. distance A->B == distance B->A.
554 * Thus, QEMU is able to complete the distance table
555 * initialization even though only distance A->B is provided and
556 * distance B->A is not. QEMU knows the distance of a node to
557 * itself is always 10, so A->A distances may be omitted. When
558 * the distances of two nodes of a pair differ, i.e. distance
559 * A->B != distance B->A, then that means the distance table is
560 * asymmetric. In this case, the distances for both directions
561 * of all node pairs are required.
562 */
563 if (have_numa_distance) {
564 /* Validate enough NUMA distance information was provided. */
565 validate_numa_distance();
566
567 /* Validation succeeded, now fill in any missing distances. */
568 complete_init_numa_distance();
569 }
570 } else {
571 numa_set_mem_node_id(0, ram_size, 0);
572 }
573 }
574
575 void numa_post_machine_init(void)
576 {
577 CPUState *cpu;
578 int i;
579
580 CPU_FOREACH(cpu) {
581 for (i = 0; i < nb_numa_nodes; i++) {
582 assert(cpu->cpu_index < max_cpus);
583 if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) {
584 cpu->numa_node = i;
585 }
586 }
587 }
588 }
589
590 static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
591 const char *name,
592 uint64_t ram_size)
593 {
594 if (mem_path) {
595 #ifdef __linux__
596 Error *err = NULL;
597 memory_region_init_ram_from_file(mr, owner, name, ram_size, false,
598 mem_path, &err);
599 if (err) {
600 error_report_err(err);
601 if (mem_prealloc) {
602 exit(1);
603 }
604
605 /* Legacy behavior: if allocation failed, fall back to
606 * regular RAM allocation.
607 */
608 memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
609 }
610 #else
611 fprintf(stderr, "-mem-path not supported on this host\n");
612 exit(1);
613 #endif
614 } else {
615 memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
616 }
617 vmstate_register_ram_global(mr);
618 }
619
620 void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
621 const char *name,
622 uint64_t ram_size)
623 {
624 uint64_t addr = 0;
625 int i;
626
627 if (nb_numa_nodes == 0 || !have_memdevs) {
628 allocate_system_memory_nonnuma(mr, owner, name, ram_size);
629 return;
630 }
631
632 memory_region_init(mr, owner, name, ram_size);
633 for (i = 0; i < MAX_NODES; i++) {
634 uint64_t size = numa_info[i].node_mem;
635 HostMemoryBackend *backend = numa_info[i].node_memdev;
636 if (!backend) {
637 continue;
638 }
639 MemoryRegion *seg = host_memory_backend_get_memory(backend,
640 &error_fatal);
641
642 if (memory_region_is_mapped(seg)) {
643 char *path = object_get_canonical_path_component(OBJECT(backend));
644 error_report("memory backend %s is used multiple times. Each "
645 "-numa option must use a different memdev value.",
646 path);
647 exit(1);
648 }
649
650 host_memory_backend_set_mapped(backend, true);
651 memory_region_add_subregion(mr, addr, seg);
652 vmstate_register_ram_global(seg);
653 addr += size;
654 }
655 }
656
657 static void numa_stat_memory_devices(uint64_t node_mem[])
658 {
659 MemoryDeviceInfoList *info_list = NULL;
660 MemoryDeviceInfoList **prev = &info_list;
661 MemoryDeviceInfoList *info;
662
663 qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
664 for (info = info_list; info; info = info->next) {
665 MemoryDeviceInfo *value = info->value;
666
667 if (value) {
668 switch (value->type) {
669 case MEMORY_DEVICE_INFO_KIND_DIMM:
670 node_mem[value->u.dimm.data->node] += value->u.dimm.data->size;
671 break;
672 default:
673 break;
674 }
675 }
676 }
677 qapi_free_MemoryDeviceInfoList(info_list);
678 }
679
680 void query_numa_node_mem(uint64_t node_mem[])
681 {
682 int i;
683
684 if (nb_numa_nodes <= 0) {
685 return;
686 }
687
688 numa_stat_memory_devices(node_mem);
689 for (i = 0; i < nb_numa_nodes; i++) {
690 node_mem[i] += numa_info[i].node_mem;
691 }
692 }
693
694 static int query_memdev(Object *obj, void *opaque)
695 {
696 MemdevList **list = opaque;
697 MemdevList *m = NULL;
698
699 if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
700 m = g_malloc0(sizeof(*m));
701
702 m->value = g_malloc0(sizeof(*m->value));
703
704 m->value->id = object_property_get_str(obj, "id", NULL);
705 m->value->has_id = !!m->value->id;
706
707 m->value->size = object_property_get_int(obj, "size",
708 &error_abort);
709 m->value->merge = object_property_get_bool(obj, "merge",
710 &error_abort);
711 m->value->dump = object_property_get_bool(obj, "dump",
712 &error_abort);
713 m->value->prealloc = object_property_get_bool(obj,
714 "prealloc",
715 &error_abort);
716 m->value->policy = object_property_get_enum(obj,
717 "policy",
718 "HostMemPolicy",
719 &error_abort);
720 object_property_get_uint16List(obj, "host-nodes",
721 &m->value->host_nodes,
722 &error_abort);
723
724 m->next = *list;
725 *list = m;
726 }
727
728 return 0;
729 }
730
731 MemdevList *qmp_query_memdev(Error **errp)
732 {
733 Object *obj = object_get_objects_root();
734 MemdevList *list = NULL;
735
736 object_child_foreach(obj, query_memdev, &list);
737 return list;
738 }
739
740 void ram_block_notifier_add(RAMBlockNotifier *n)
741 {
742 QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next);
743 }
744
745 void ram_block_notifier_remove(RAMBlockNotifier *n)
746 {
747 QLIST_REMOVE(n, next);
748 }
749
750 void ram_block_notify_add(void *host, size_t size)
751 {
752 RAMBlockNotifier *notifier;
753
754 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
755 notifier->ram_block_added(notifier, host, size);
756 }
757 }
758
759 void ram_block_notify_remove(void *host, size_t size)
760 {
761 RAMBlockNotifier *notifier;
762
763 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
764 notifier->ram_block_removed(notifier, host, size);
765 }
766 }