2 * HMP commands related to machines and CPUs
4 * Copyright IBM, Corp. 2011
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
17 #include "monitor/hmp.h"
18 #include "monitor/monitor.h"
19 #include "qapi/error.h"
20 #include "qapi/qapi-builtin-visit.h"
21 #include "qapi/qapi-commands-machine.h"
22 #include "qapi/qmp/qdict.h"
23 #include "qapi/string-output-visitor.h"
24 #include "qemu/error-report.h"
25 #include "sysemu/numa.h"
27 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
29 CpuInfoFastList
*cpu_list
, *cpu
;
31 cpu_list
= qmp_query_cpus_fast(NULL
);
33 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
36 if (cpu
->value
->cpu_index
== monitor_get_cpu_index()) {
40 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
,
41 cpu
->value
->cpu_index
);
42 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
45 qapi_free_CpuInfoFastList(cpu_list
);
48 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
53 error_report("cpu_add is deprecated, please use device_add instead");
55 cpuid
= qdict_get_int(qdict
, "id");
56 qmp_cpu_add(cpuid
, &err
);
57 hmp_handle_error(mon
, &err
);
60 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
63 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
64 HotpluggableCPUList
*saved
= l
;
65 CpuInstanceProperties
*c
;
68 hmp_handle_error(mon
, &err
);
72 monitor_printf(mon
, "Hotpluggable CPUs:\n");
74 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
75 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
76 l
->value
->vcpus_count
);
77 if (l
->value
->has_qom_path
) {
78 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
82 monitor_printf(mon
, " CPUInstance Properties:\n");
84 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
86 if (c
->has_socket_id
) {
87 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
90 monitor_printf(mon
, " die-id: \"%" PRIu64
"\"\n", c
->die_id
);
93 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
95 if (c
->has_thread_id
) {
96 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
102 qapi_free_HotpluggableCPUList(saved
);
105 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
108 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
109 MemdevList
*m
= memdev_list
;
114 v
= string_output_visitor_new(false, &str
);
115 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
116 monitor_printf(mon
, "memory backend: %s\n", m
->value
->id
);
117 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
118 monitor_printf(mon
, " merge: %s\n",
119 m
->value
->merge
? "true" : "false");
120 monitor_printf(mon
, " dump: %s\n",
121 m
->value
->dump
? "true" : "false");
122 monitor_printf(mon
, " prealloc: %s\n",
123 m
->value
->prealloc
? "true" : "false");
124 monitor_printf(mon
, " policy: %s\n",
125 HostMemPolicy_str(m
->value
->policy
));
126 visit_complete(v
, &str
);
127 monitor_printf(mon
, " host nodes: %s\n", str
);
134 monitor_printf(mon
, "\n");
136 qapi_free_MemdevList(memdev_list
);
137 hmp_handle_error(mon
, &err
);
140 void hmp_info_numa(Monitor
*mon
, const QDict
*qdict
)
143 NumaNodeMem
*node_mem
;
144 CpuInfoList
*cpu_list
, *cpu
;
146 cpu_list
= qmp_query_cpus(&error_abort
);
147 node_mem
= g_new0(NumaNodeMem
, nb_numa_nodes
);
149 query_numa_node_mem(node_mem
);
150 monitor_printf(mon
, "%d nodes\n", nb_numa_nodes
);
151 for (i
= 0; i
< nb_numa_nodes
; i
++) {
152 monitor_printf(mon
, "node %d cpus:", i
);
153 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
154 if (cpu
->value
->has_props
&& cpu
->value
->props
->has_node_id
&&
155 cpu
->value
->props
->node_id
== i
) {
156 monitor_printf(mon
, " %" PRIi64
, cpu
->value
->CPU
);
159 monitor_printf(mon
, "\n");
160 monitor_printf(mon
, "node %d size: %" PRId64
" MB\n", i
,
161 node_mem
[i
].node_mem
>> 20);
162 monitor_printf(mon
, "node %d plugged: %" PRId64
" MB\n", i
,
163 node_mem
[i
].node_plugged_mem
>> 20);
165 qapi_free_CpuInfoList(cpu_list
);