2 * QMP commands related to machines and CPUs
4 * Copyright (C) 2014 Red Hat Inc
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
10 #include "qemu/osdep.h"
11 #include "hw/boards.h"
12 #include "qapi/error.h"
13 #include "qapi/qapi-builtin-visit.h"
14 #include "qapi/qapi-commands-machine.h"
15 #include "qapi/qmp/qerror.h"
16 #include "qapi/qmp/qobject.h"
17 #include "qapi/qobject-input-visitor.h"
18 #include "qemu/main-loop.h"
19 #include "qom/qom-qobject.h"
20 #include "sysemu/hostmem.h"
21 #include "sysemu/hw_accel.h"
22 #include "sysemu/numa.h"
23 #include "sysemu/runstate.h"
25 static void cpustate_to_cpuinfo_s390(CpuInfoS390
*info
, const CPUState
*cpu
)
28 S390CPU
*s390_cpu
= S390_CPU(cpu
);
29 CPUS390XState
*env
= &s390_cpu
->env
;
31 info
->cpu_state
= env
->cpu_state
;
38 * fast means: we NEVER interrupt vCPU threads to retrieve
39 * information from KVM.
41 CpuInfoFastList
*qmp_query_cpus_fast(Error
**errp
)
43 MachineState
*ms
= MACHINE(qdev_get_machine());
44 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
45 CpuInfoFastList
*head
= NULL
, **tail
= &head
;
46 SysEmuTarget target
= qapi_enum_parse(&SysEmuTarget_lookup
, TARGET_NAME
,
51 CpuInfoFast
*value
= g_malloc0(sizeof(*value
));
53 value
->cpu_index
= cpu
->cpu_index
;
54 value
->qom_path
= object_get_canonical_path(OBJECT(cpu
));
55 value
->thread_id
= cpu
->thread_id
;
57 value
->has_props
= !!mc
->cpu_index_to_instance_props
;
58 if (value
->has_props
) {
59 CpuInstanceProperties
*props
;
60 props
= g_malloc0(sizeof(*props
));
61 *props
= mc
->cpu_index_to_instance_props(ms
, cpu
->cpu_index
);
65 value
->target
= target
;
66 if (target
== SYS_EMU_TARGET_S390X
) {
67 cpustate_to_cpuinfo_s390(&value
->u
.s390x
, cpu
);
70 QAPI_LIST_APPEND(tail
, value
);
76 MachineInfoList
*qmp_query_machines(Error
**errp
)
78 GSList
*el
, *machines
= object_class_get_list(TYPE_MACHINE
, false);
79 MachineInfoList
*mach_list
= NULL
;
81 for (el
= machines
; el
; el
= el
->next
) {
82 MachineClass
*mc
= el
->data
;
85 info
= g_malloc0(sizeof(*info
));
87 info
->has_is_default
= true;
88 info
->is_default
= true;
92 info
->has_alias
= true;
93 info
->alias
= g_strdup(mc
->alias
);
96 info
->name
= g_strdup(mc
->name
);
97 info
->cpu_max
= !mc
->max_cpus
? 1 : mc
->max_cpus
;
98 info
->hotpluggable_cpus
= mc
->has_hotpluggable_cpus
;
99 info
->numa_mem_supported
= mc
->numa_mem_supported
;
100 info
->deprecated
= !!mc
->deprecation_reason
;
101 if (mc
->default_cpu_type
) {
102 info
->default_cpu_type
= g_strdup(mc
->default_cpu_type
);
103 info
->has_default_cpu_type
= true;
105 if (mc
->default_ram_id
) {
106 info
->default_ram_id
= g_strdup(mc
->default_ram_id
);
107 info
->has_default_ram_id
= true;
110 QAPI_LIST_PREPEND(mach_list
, info
);
113 g_slist_free(machines
);
117 CurrentMachineParams
*qmp_query_current_machine(Error
**errp
)
119 CurrentMachineParams
*params
= g_malloc0(sizeof(*params
));
120 params
->wakeup_suspend_support
= qemu_wakeup_suspend_enabled();
125 TargetInfo
*qmp_query_target(Error
**errp
)
127 TargetInfo
*info
= g_malloc0(sizeof(*info
));
129 info
->arch
= qapi_enum_parse(&SysEmuTarget_lookup
, TARGET_NAME
, -1,
135 HotpluggableCPUList
*qmp_query_hotpluggable_cpus(Error
**errp
)
137 MachineState
*ms
= MACHINE(qdev_get_machine());
138 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
140 if (!mc
->has_hotpluggable_cpus
) {
141 error_setg(errp
, QERR_FEATURE_DISABLED
, "query-hotpluggable-cpus");
145 return machine_query_hotpluggable_cpus(ms
);
148 void qmp_set_numa_node(NumaOptions
*cmd
, Error
**errp
)
150 if (phase_check(PHASE_MACHINE_INITIALIZED
)) {
151 error_setg(errp
, "The command is permitted only before the machine has been created");
155 set_numa_options(MACHINE(qdev_get_machine()), cmd
, errp
);
158 static int query_memdev(Object
*obj
, void *opaque
)
160 MemdevList
**list
= opaque
;
165 if (object_dynamic_cast(obj
, TYPE_MEMORY_BACKEND
)) {
166 m
= g_malloc0(sizeof(*m
));
168 m
->id
= g_strdup(object_get_canonical_path_component(obj
));
171 m
->size
= object_property_get_uint(obj
, "size", &error_abort
);
172 m
->merge
= object_property_get_bool(obj
, "merge", &error_abort
);
173 m
->dump
= object_property_get_bool(obj
, "dump", &error_abort
);
174 m
->prealloc
= object_property_get_bool(obj
, "prealloc", &error_abort
);
175 m
->policy
= object_property_get_enum(obj
, "policy", "HostMemPolicy",
177 host_nodes
= object_property_get_qobject(obj
,
180 v
= qobject_input_visitor_new(host_nodes
);
181 visit_type_uint16List(v
, NULL
, &m
->host_nodes
, &error_abort
);
183 qobject_unref(host_nodes
);
185 QAPI_LIST_PREPEND(*list
, m
);
191 MemdevList
*qmp_query_memdev(Error
**errp
)
193 Object
*obj
= object_get_objects_root();
194 MemdevList
*list
= NULL
;
196 object_child_foreach(obj
, query_memdev
, &list
);