xref: /qemu/hw/core/machine-hmp-cmds.c (revision 6f0dd6c5)
1 /*
2  * HMP commands related to machines and CPUs
3  *
4  * Copyright IBM, Corp. 2011
5  *
6  * Authors:
7  *  Anthony Liguori   <aliguori@us.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  *
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.
14  */
15 
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"
26 
27 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
28 {
29     CpuInfoFastList *cpu_list, *cpu;
30 
31     cpu_list = qmp_query_cpus_fast(NULL);
32 
33     for (cpu = cpu_list; cpu; cpu = cpu->next) {
34         int active = ' ';
35 
36         if (cpu->value->cpu_index == monitor_get_cpu_index()) {
37             active = '*';
38         }
39 
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);
43     }
44 
45     qapi_free_CpuInfoFastList(cpu_list);
46 }
47 
48 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
49 {
50     int cpuid;
51     Error *err = NULL;
52 
53     error_report("cpu_add is deprecated, please use device_add instead");
54 
55     cpuid = qdict_get_int(qdict, "id");
56     qmp_cpu_add(cpuid, &err);
57     hmp_handle_error(mon, &err);
58 }
59 
60 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
61 {
62     Error *err = NULL;
63     HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
64     HotpluggableCPUList *saved = l;
65     CpuInstanceProperties *c;
66 
67     if (err != NULL) {
68         hmp_handle_error(mon, &err);
69         return;
70     }
71 
72     monitor_printf(mon, "Hotpluggable CPUs:\n");
73     while (l) {
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);
79         }
80 
81         c = l->value->props;
82         monitor_printf(mon, "  CPUInstance Properties:\n");
83         if (c->has_node_id) {
84             monitor_printf(mon, "    node-id: \"%" PRIu64 "\"\n", c->node_id);
85         }
86         if (c->has_socket_id) {
87             monitor_printf(mon, "    socket-id: \"%" PRIu64 "\"\n", c->socket_id);
88         }
89         if (c->has_die_id) {
90             monitor_printf(mon, "    die-id: \"%" PRIu64 "\"\n", c->die_id);
91         }
92         if (c->has_core_id) {
93             monitor_printf(mon, "    core-id: \"%" PRIu64 "\"\n", c->core_id);
94         }
95         if (c->has_thread_id) {
96             monitor_printf(mon, "    thread-id: \"%" PRIu64 "\"\n", c->thread_id);
97         }
98 
99         l = l->next;
100     }
101 
102     qapi_free_HotpluggableCPUList(saved);
103 }
104 
105 void hmp_info_memdev(Monitor *mon, const QDict *qdict)
106 {
107     Error *err = NULL;
108     MemdevList *memdev_list = qmp_query_memdev(&err);
109     MemdevList *m = memdev_list;
110     Visitor *v;
111     char *str;
112 
113     while (m) {
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);
128 
129         g_free(str);
130         visit_free(v);
131         m = m->next;
132     }
133 
134     monitor_printf(mon, "\n");
135 
136     qapi_free_MemdevList(memdev_list);
137     hmp_handle_error(mon, &err);
138 }
139 
140 void hmp_info_numa(Monitor *mon, const QDict *qdict)
141 {
142     int i;
143     NumaNodeMem *node_mem;
144     CpuInfoList *cpu_list, *cpu;
145 
146     cpu_list = qmp_query_cpus(&error_abort);
147     node_mem = g_new0(NumaNodeMem, nb_numa_nodes);
148 
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);
157             }
158         }
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);
164     }
165     qapi_free_CpuInfoList(cpu_list);
166     g_free(node_mem);
167 }
168