]> git.ipfire.org Git - thirdparty/qemu.git/blame - numa.c
numa: remove node_cpu bitmaps as they are no longer used
[thirdparty/qemu.git] / numa.c
CommitLineData
96d0e26c
WG
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
d38ea87a 25#include "qemu/osdep.h"
e35704ba 26#include "sysemu/numa.h"
96d0e26c 27#include "exec/cpu-common.h"
0987d735 28#include "exec/ramlist.h"
96d0e26c
WG
29#include "qemu/bitmap.h"
30#include "qom/cpu.h"
2b631ec2
WG
31#include "qemu/error-report.h"
32#include "include/exec/cpu-common.h" /* for RAM_ADDR_FMT */
0042109a
WG
33#include "qapi-visit.h"
34#include "qapi/opts-visitor.h"
dfabb8b9 35#include "hw/boards.h"
7febe36f 36#include "sysemu/hostmem.h"
76b5d850 37#include "qmp-commands.h"
5b009e40 38#include "hw/mem/pc-dimm.h"
7dcd1d70
EH
39#include "qemu/option.h"
40#include "qemu/config-file.h"
0042109a
WG
41
42QemuOptsList 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
7febe36f 49static int have_memdevs = -1;
25712ffe
EH
50static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
51 * For all nodes, nodeid < max_numa_nodeid
52 */
de1a7c84 53int nb_numa_nodes;
0f203430 54bool have_numa_distance;
de1a7c84 55NodeInfo numa_info[MAX_NODES];
7febe36f 56
fa9ea81d
BR
57void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node)
58{
672558d2 59 struct numa_addr_range *range;
fa9ea81d 60
abafabd8
BR
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
672558d2 69 range = g_malloc0(sizeof(*range));
fa9ea81d
BR
70 range->mem_start = addr;
71 range->mem_end = addr + size - 1;
72 QLIST_INSERT_HEAD(&numa_info[node].addr, range, entry);
73}
74
75void 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
abafabd8
BR
88static 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
e75e2a14
BR
103/*
104 * Check if @addr falls under NUMA @node.
105 */
106static 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 */
122uint32_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
64c2a8f6
IM
144static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
145 QemuOpts *opts, Error **errp)
96d0e26c 146{
0042109a
WG
147 uint16_t nodenr;
148 uint16List *cpus = NULL;
64c2a8f6 149 MachineClass *mc = MACHINE_GET_CLASS(ms);
96d0e26c 150
0042109a
WG
151 if (node->has_nodeid) {
152 nodenr = node->nodeid;
96d0e26c 153 } else {
0042109a 154 nodenr = nb_numa_nodes;
96d0e26c
WG
155 }
156
0042109a
WG
157 if (nodenr >= MAX_NODES) {
158 error_setg(errp, "Max number of NUMA nodes reached: %"
01bbbcf4 159 PRIu16 "", nodenr);
0042109a 160 return;
96d0e26c
WG
161 }
162
1945b9d8
EH
163 if (numa_info[nodenr].present) {
164 error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
165 return;
166 }
167
64c2a8f6
IM
168 if (!mc->cpu_index_to_instance_props) {
169 error_report("NUMA is not supported by this machine-type");
170 exit(1);
171 }
0042109a 172 for (cpus = node->cpus; cpus; cpus = cpus->next) {
7c88e65d 173 CpuInstanceProperties props;
8979c945
EH
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);
0042109a
WG
179 return;
180 }
7c88e65d
IM
181 props = mc->cpu_index_to_instance_props(ms, cpus->value);
182 props.node_id = nodenr;
183 props.has_node_id = true;
184 machine_set_cpu_numa_node(ms, &props, &error_fatal);
96d0e26c
WG
185 }
186
7febe36f 187 if (node->has_mem && node->has_memdev) {
01bbbcf4 188 error_setg(errp, "qemu: cannot specify both mem= and memdev=");
7febe36f
PB
189 return;
190 }
191
192 if (have_memdevs == -1) {
193 have_memdevs = node->has_memdev;
194 }
195 if (node->has_memdev != have_memdevs) {
196 error_setg(errp, "qemu: memdev option must be specified for either "
01bbbcf4 197 "all or no nodes");
7febe36f
PB
198 return;
199 }
200
0042109a
WG
201 if (node->has_mem) {
202 uint64_t mem_size = node->mem;
203 const char *mem_str = qemu_opt_get(opts, "mem");
204 /* Fix up legacy suffix-less format */
205 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
206 mem_size <<= 20;
207 }
208 numa_info[nodenr].node_mem = mem_size;
209 }
7febe36f
PB
210 if (node->has_memdev) {
211 Object *o;
212 o = object_resolve_path_type(node->memdev, TYPE_MEMORY_BACKEND, NULL);
213 if (!o) {
214 error_setg(errp, "memdev=%s is ambiguous", node->memdev);
215 return;
216 }
217
218 object_ref(o);
219 numa_info[nodenr].node_mem = object_property_get_int(o, "size", NULL);
220 numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
221 }
1af878e0
EH
222 numa_info[nodenr].present = true;
223 max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
96d0e26c
WG
224}
225
0f203430
HC
226static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
227{
228 uint16_t src = dist->src;
229 uint16_t dst = dist->dst;
230 uint8_t val = dist->val;
231
232 if (src >= MAX_NODES || dst >= MAX_NODES) {
233 error_setg(errp,
234 "Invalid node %" PRIu16
235 ", max possible could be %" PRIu16,
236 MAX(src, dst), MAX_NODES);
237 return;
238 }
239
240 if (!numa_info[src].present || !numa_info[dst].present) {
241 error_setg(errp, "Source/Destination NUMA node is missing. "
242 "Please use '-numa node' option to declare it first.");
243 return;
244 }
245
246 if (val < NUMA_DISTANCE_MIN) {
247 error_setg(errp, "NUMA distance (%" PRIu8 ") is invalid, "
248 "it shouldn't be less than %d.",
249 val, NUMA_DISTANCE_MIN);
250 return;
251 }
252
253 if (src == dst && val != NUMA_DISTANCE_MIN) {
254 error_setg(errp, "Local distance of node %d should be %d.",
255 src, NUMA_DISTANCE_MIN);
256 return;
257 }
258
259 numa_info[src].distance[dst] = val;
260 have_numa_distance = true;
261}
262
28d0de7a 263static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
96d0e26c 264{
0042109a 265 NumaOptions *object = NULL;
64c2a8f6 266 MachineState *ms = opaque;
0042109a 267 Error *err = NULL;
96d0e26c 268
0042109a 269 {
09204eac
EB
270 Visitor *v = opts_visitor_new(opts);
271 visit_type_NumaOptions(v, NULL, &object, &err);
272 visit_free(v);
96d0e26c 273 }
96d0e26c 274
0042109a 275 if (err) {
157e94e8 276 goto end;
0042109a 277 }
96d0e26c 278
1fd5d4fe 279 switch (object->type) {
d081a49a 280 case NUMA_OPTIONS_TYPE_NODE:
64c2a8f6 281 parse_numa_node(ms, &object->u.node, opts, &err);
0042109a 282 if (err) {
157e94e8 283 goto end;
96d0e26c 284 }
0042109a
WG
285 nb_numa_nodes++;
286 break;
0f203430
HC
287 case NUMA_OPTIONS_TYPE_DIST:
288 parse_numa_distance(&object->u.dist, &err);
289 if (err) {
290 goto end;
291 }
292 break;
0042109a
WG
293 default:
294 abort();
295 }
96d0e26c 296
157e94e8 297end:
96a1616c 298 qapi_free_NumaOptions(object);
157e94e8
MAL
299 if (err) {
300 error_report_err(err);
301 return -1;
302 }
0042109a 303
157e94e8 304 return 0;
96d0e26c
WG
305}
306
0f203430
HC
307/* If all node pair distances are symmetric, then only distances
308 * in one direction are enough. If there is even one asymmetric
309 * pair, though, then all distances must be provided. The
310 * distance from a node to itself is always NUMA_DISTANCE_MIN,
311 * so providing it is never necessary.
312 */
313static void validate_numa_distance(void)
314{
315 int src, dst;
316 bool is_asymmetrical = false;
317
318 for (src = 0; src < nb_numa_nodes; src++) {
319 for (dst = src; dst < nb_numa_nodes; dst++) {
320 if (numa_info[src].distance[dst] == 0 &&
321 numa_info[dst].distance[src] == 0) {
322 if (src != dst) {
323 error_report("The distance between node %d and %d is "
324 "missing, at least one distance value "
325 "between each nodes should be provided.",
326 src, dst);
327 exit(EXIT_FAILURE);
328 }
329 }
330
331 if (numa_info[src].distance[dst] != 0 &&
332 numa_info[dst].distance[src] != 0 &&
333 numa_info[src].distance[dst] !=
334 numa_info[dst].distance[src]) {
335 is_asymmetrical = true;
336 }
337 }
338 }
339
340 if (is_asymmetrical) {
341 for (src = 0; src < nb_numa_nodes; src++) {
342 for (dst = 0; dst < nb_numa_nodes; dst++) {
343 if (src != dst && numa_info[src].distance[dst] == 0) {
344 error_report("At least one asymmetrical pair of "
345 "distances is given, please provide distances "
346 "for both directions of all node pairs.");
347 exit(EXIT_FAILURE);
348 }
349 }
350 }
351 }
352}
353
354static void complete_init_numa_distance(void)
355{
356 int src, dst;
357
358 /* Fixup NUMA distance by symmetric policy because if it is an
359 * asymmetric distance table, it should be a complete table and
360 * there would not be any missing distance except local node, which
361 * is verified by validate_numa_distance above.
362 */
363 for (src = 0; src < nb_numa_nodes; src++) {
364 for (dst = 0; dst < nb_numa_nodes; dst++) {
365 if (numa_info[src].distance[dst] == 0) {
366 if (src == dst) {
367 numa_info[src].distance[dst] = NUMA_DISTANCE_MIN;
368 } else {
369 numa_info[src].distance[dst] = numa_info[dst].distance[src];
370 }
371 }
372 }
373 }
374}
375
3bfe5716
LV
376void numa_legacy_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
377 int nb_nodes, ram_addr_t size)
378{
379 int i;
380 uint64_t usedmem = 0;
381
382 /* Align each node according to the alignment
383 * requirements of the machine class
384 */
385
386 for (i = 0; i < nb_nodes - 1; i++) {
387 nodes[i].node_mem = (size / nb_nodes) &
388 ~((1 << mc->numa_mem_align_shift) - 1);
389 usedmem += nodes[i].node_mem;
390 }
391 nodes[i].node_mem = size - usedmem;
392}
393
394void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
395 int nb_nodes, ram_addr_t size)
396{
397 int i;
398 uint64_t usedmem = 0, node_mem;
399 uint64_t granularity = size / nb_nodes;
400 uint64_t propagate = 0;
401
402 for (i = 0; i < nb_nodes - 1; i++) {
403 node_mem = (granularity + propagate) &
404 ~((1 << mc->numa_mem_align_shift) - 1);
405 propagate = granularity + propagate - node_mem;
406 nodes[i].node_mem = node_mem;
407 usedmem += node_mem;
408 }
409 nodes[i].node_mem = size - usedmem;
410}
411
ea089eeb 412void parse_numa_opts(MachineState *ms)
96d0e26c 413{
12d6e464 414 int i;
af9b20e8 415 const CPUArchIdList *possible_cpus;
ea089eeb 416 MachineClass *mc = MACHINE_GET_CLASS(ms);
12d6e464 417
64c2a8f6 418 if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, NULL)) {
7dcd1d70
EH
419 exit(1);
420 }
421
12d6e464
EH
422 assert(max_numa_nodeid <= MAX_NODES);
423
424 /* No support for sparse NUMA node IDs yet: */
425 for (i = max_numa_nodeid - 1; i >= 0; i--) {
426 /* Report large node IDs first, to make mistakes easier to spot */
427 if (!numa_info[i].present) {
428 error_report("numa: Node ID missing: %d", i);
429 exit(1);
430 }
431 }
432
433 /* This must be always true if all nodes are present: */
434 assert(nb_numa_nodes == max_numa_nodeid);
435
96d0e26c 436 if (nb_numa_nodes > 0) {
2b631ec2 437 uint64_t numa_total;
96d0e26c
WG
438
439 if (nb_numa_nodes > MAX_NODES) {
440 nb_numa_nodes = MAX_NODES;
441 }
442
9851d0fe 443 /* If no memory size is given for any node, assume the default case
96d0e26c
WG
444 * and distribute the available memory equally across all nodes
445 */
446 for (i = 0; i < nb_numa_nodes; i++) {
8c85901e 447 if (numa_info[i].node_mem != 0) {
96d0e26c
WG
448 break;
449 }
450 }
451 if (i == nb_numa_nodes) {
3bfe5716
LV
452 assert(mc->numa_auto_assign_ram);
453 mc->numa_auto_assign_ram(mc, numa_info, nb_numa_nodes, ram_size);
96d0e26c
WG
454 }
455
2b631ec2
WG
456 numa_total = 0;
457 for (i = 0; i < nb_numa_nodes; i++) {
8c85901e 458 numa_total += numa_info[i].node_mem;
2b631ec2
WG
459 }
460 if (numa_total != ram_size) {
c68233ae
HT
461 error_report("total memory for NUMA nodes (0x%" PRIx64 ")"
462 " should equal RAM size (0x" RAM_ADDR_FMT ")",
2b631ec2
WG
463 numa_total, ram_size);
464 exit(1);
465 }
466
fa9ea81d
BR
467 for (i = 0; i < nb_numa_nodes; i++) {
468 QLIST_INIT(&numa_info[i].addr);
469 }
470
abafabd8
BR
471 numa_set_mem_ranges();
472
ea089eeb 473 /* assign CPUs to nodes using board provided default mapping */
af9b20e8 474 if (!mc->cpu_index_to_instance_props || !mc->possible_cpu_arch_ids) {
ea089eeb
IM
475 error_report("default CPUs to NUMA node mapping isn't supported");
476 exit(1);
477 }
af9b20e8
IM
478
479 possible_cpus = mc->possible_cpu_arch_ids(ms);
480 for (i = 0; i < possible_cpus->len; i++) {
481 if (possible_cpus->cpus[i].props.has_node_id) {
482 break;
483 }
484 }
485
486 /* no CPUs are assigned to NUMA nodes */
487 if (i == possible_cpus->len) {
96d0e26c 488 for (i = 0; i < max_cpus; i++) {
ea089eeb 489 CpuInstanceProperties props;
7c88e65d 490 /* fetch default mapping from board and enable it */
ea089eeb 491 props = mc->cpu_index_to_instance_props(ms, i);
7c88e65d 492 props.has_node_id = true;
57924bcd 493
7c88e65d 494 machine_set_cpu_numa_node(ms, &props, &error_fatal);
96d0e26c
WG
495 }
496 }
3ef71975 497
0f203430
HC
498 /* QEMU needs at least all unique node pair distances to build
499 * the whole NUMA distance table. QEMU treats the distance table
500 * as symmetric by default, i.e. distance A->B == distance B->A.
501 * Thus, QEMU is able to complete the distance table
502 * initialization even though only distance A->B is provided and
503 * distance B->A is not. QEMU knows the distance of a node to
504 * itself is always 10, so A->A distances may be omitted. When
505 * the distances of two nodes of a pair differ, i.e. distance
506 * A->B != distance B->A, then that means the distance table is
507 * asymmetric. In this case, the distances for both directions
508 * of all node pairs are required.
509 */
510 if (have_numa_distance) {
511 /* Validate enough NUMA distance information was provided. */
512 validate_numa_distance();
513
514 /* Validation succeeded, now fill in any missing distances. */
515 complete_init_numa_distance();
516 }
abafabd8
BR
517 } else {
518 numa_set_mem_node_id(0, ram_size, 0);
96d0e26c
WG
519 }
520}
521
7febe36f
PB
522static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
523 const char *name,
524 uint64_t ram_size)
525{
0b183fc8
PB
526 if (mem_path) {
527#ifdef __linux__
7f56e740 528 Error *err = NULL;
dbcb8981 529 memory_region_init_ram_from_file(mr, owner, name, ram_size, false,
7f56e740 530 mem_path, &err);
c3ba3095 531 if (err) {
29b762f5 532 error_report_err(err);
fae947b0
LC
533 if (mem_prealloc) {
534 exit(1);
535 }
536
537 /* Legacy behavior: if allocation failed, fall back to
538 * regular RAM allocation.
539 */
f8ed85ac 540 memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
7f56e740 541 }
0b183fc8
PB
542#else
543 fprintf(stderr, "-mem-path not supported on this host\n");
544 exit(1);
545#endif
546 } else {
f8ed85ac 547 memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
0b183fc8 548 }
7febe36f
PB
549 vmstate_register_ram_global(mr);
550}
551
dfabb8b9
PB
552void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
553 const char *name,
554 uint64_t ram_size)
555{
7febe36f
PB
556 uint64_t addr = 0;
557 int i;
558
559 if (nb_numa_nodes == 0 || !have_memdevs) {
560 allocate_system_memory_nonnuma(mr, owner, name, ram_size);
561 return;
562 }
563
564 memory_region_init(mr, owner, name, ram_size);
565 for (i = 0; i < MAX_NODES; i++) {
7febe36f
PB
566 uint64_t size = numa_info[i].node_mem;
567 HostMemoryBackend *backend = numa_info[i].node_memdev;
568 if (!backend) {
569 continue;
570 }
007b0657
MA
571 MemoryRegion *seg = host_memory_backend_get_memory(backend,
572 &error_fatal);
7febe36f 573
0462faee
HT
574 if (memory_region_is_mapped(seg)) {
575 char *path = object_get_canonical_path_component(OBJECT(backend));
576 error_report("memory backend %s is used multiple times. Each "
577 "-numa option must use a different memdev value.",
578 path);
579 exit(1);
580 }
581
0b217571 582 host_memory_backend_set_mapped(backend, true);
7febe36f
PB
583 memory_region_add_subregion(mr, addr, seg);
584 vmstate_register_ram_global(seg);
585 addr += size;
586 }
dfabb8b9 587}
76b5d850 588
5b009e40
HZ
589static void numa_stat_memory_devices(uint64_t node_mem[])
590{
591 MemoryDeviceInfoList *info_list = NULL;
592 MemoryDeviceInfoList **prev = &info_list;
593 MemoryDeviceInfoList *info;
594
595 qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
596 for (info = info_list; info; info = info->next) {
597 MemoryDeviceInfo *value = info->value;
598
599 if (value) {
1fd5d4fe 600 switch (value->type) {
5b009e40 601 case MEMORY_DEVICE_INFO_KIND_DIMM:
32bafa8f 602 node_mem[value->u.dimm.data->node] += value->u.dimm.data->size;
5b009e40
HZ
603 break;
604 default:
605 break;
606 }
607 }
608 }
609 qapi_free_MemoryDeviceInfoList(info_list);
610}
611
612void query_numa_node_mem(uint64_t node_mem[])
613{
614 int i;
615
616 if (nb_numa_nodes <= 0) {
617 return;
618 }
619
620 numa_stat_memory_devices(node_mem);
621 for (i = 0; i < nb_numa_nodes; i++) {
622 node_mem[i] += numa_info[i].node_mem;
623 }
624}
625
76b5d850
HT
626static int query_memdev(Object *obj, void *opaque)
627{
628 MemdevList **list = opaque;
b0e90181 629 MemdevList *m = NULL;
76b5d850
HT
630
631 if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
b0e90181 632 m = g_malloc0(sizeof(*m));
76b5d850
HT
633
634 m->value = g_malloc0(sizeof(*m->value));
635
e1ff3c67
IM
636 m->value->id = object_property_get_str(obj, "id", NULL);
637 m->value->has_id = !!m->value->id;
638
76b5d850 639 m->value->size = object_property_get_int(obj, "size",
2f6f826e 640 &error_abort);
76b5d850 641 m->value->merge = object_property_get_bool(obj, "merge",
2f6f826e 642 &error_abort);
76b5d850 643 m->value->dump = object_property_get_bool(obj, "dump",
2f6f826e 644 &error_abort);
76b5d850 645 m->value->prealloc = object_property_get_bool(obj,
2f6f826e
MA
646 "prealloc",
647 &error_abort);
76b5d850
HT
648 m->value->policy = object_property_get_enum(obj,
649 "policy",
a3590dac 650 "HostMemPolicy",
2f6f826e 651 &error_abort);
76b5d850 652 object_property_get_uint16List(obj, "host-nodes",
2f6f826e
MA
653 &m->value->host_nodes,
654 &error_abort);
76b5d850
HT
655
656 m->next = *list;
657 *list = m;
658 }
659
660 return 0;
76b5d850
HT
661}
662
663MemdevList *qmp_query_memdev(Error **errp)
664{
2f6f826e 665 Object *obj = object_get_objects_root();
ecaf54a0 666 MemdevList *list = NULL;
76b5d850 667
2f6f826e 668 object_child_foreach(obj, query_memdev, &list);
76b5d850 669 return list;
76b5d850 670}
6bea1ddf 671
0987d735
PB
672void ram_block_notifier_add(RAMBlockNotifier *n)
673{
674 QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next);
675}
676
677void ram_block_notifier_remove(RAMBlockNotifier *n)
678{
679 QLIST_REMOVE(n, next);
680}
681
682void ram_block_notify_add(void *host, size_t size)
683{
684 RAMBlockNotifier *notifier;
685
686 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
687 notifier->ram_block_added(notifier, host, size);
688 }
689}
690
691void ram_block_notify_remove(void *host, size_t size)
692{
693 RAMBlockNotifier *notifier;
694
695 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
696 notifier->ram_block_removed(notifier, host, size);
697 }
698}