@@ -37,5 +37,6 @@ int kvm_available(void);
int xen_available(void);
CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
+CpuModelInfo *arch_query_cpu_model(Error **errp);
#endif
@@ -2507,6 +2507,31 @@
##
{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
+##
+# @CpuModelInfo:
+#
+# Virtual CPU model definition.
+#
+# @name: the name of the CPU model definition
+#
+# @accelerator: AccelId (name) of this cpu models acceletaror
+#
+# Since: 2.3
+##
+{ 'type': 'CpuModelInfo',
+ 'data': { 'name': 'str', 'accelerator': 'AccelId' } }
+
+##
+# @query-cpu-model:
+#
+# Return the current virtual CPU model
+#
+# Returns: CpuModelInfo
+#
+# Since: 2.3
+##
+{ 'command': 'query-cpu-model', 'returns': 'CpuModelInfo' }
+
# @AddfdInfo:
#
# Information about a file descriptor that was added to an fd set.
@@ -3392,6 +3392,12 @@ EQMP
},
{
+ .name = "query-cpu-model",
+ .args_type = "",
+ .mhandler.cmd_new = qmp_marshal_input_query_cpu_model,
+ },
+
+ {
.name = "query-target",
.args_type = "",
.mhandler.cmd_new = qmp_marshal_input_query_target,
@@ -573,6 +573,11 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
return arch_query_cpu_definitions(errp);
}
+CpuModelInfo *qmp_query_cpu_model(Error **errp)
+{
+ return arch_query_cpu_model(errp);
+}
+
void qmp_add_client(const char *protocol, const char *fdname,
bool has_skipauth, bool skipauth, bool has_tls, bool tls,
Error **errp)
@@ -1,4 +1,5 @@
stub-obj-y += arch-query-cpu-def.o
+stub-obj-y += arch-query-cpu-mod.o
stub-obj-y += bdrv-commit-all.o
stub-obj-y += chr-baum-init.o
stub-obj-y += chr-msmouse.o
new file mode 100644
@@ -0,0 +1,9 @@
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelInfo *arch_query_cpu_model(Error **errp)
+{
+ error_set(errp, QERR_UNSUPPORTED);
+ return NULL;
+}
@@ -670,3 +670,16 @@ void s390_cpu_model_init(S390CPUClass *cc)
}
}
+/**
+ * s390_cpu_models_used:
+ *
+ * This function indicates if cpus with model properties are in use.
+ *
+ * Returns: a boolean value.
+ *
+ * Since: 2.3
+ */
+bool s390_cpu_models_used(void)
+{
+ return cpu_models_used;
+}
@@ -114,6 +114,7 @@ void s390_cpu_list_entry(gpointer data, gpointer user_data);
bool s390_cpu_classes_initialized(void);
bool s390_probe_mode(void);
void s390_cpu_model_init(S390CPUClass *cc);
+bool s390_cpu_models_used(void);
/*
* bits 0-7 : CMOS generation
@@ -37,6 +37,11 @@
#define CR0_RESET 0xE0UL
#define CR14_RESET 0xC2000000UL;
+static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
+{
+ return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
+}
+
/* generate CPU information for cpu -? */
void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
{
@@ -74,6 +79,30 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
return entry;
}
+
+CpuModelInfo *arch_query_cpu_model(Error **errp)
+{
+ CpuModelInfo *info;
+ S390CPUClass *cc;
+
+ if (!s390_cpu_models_used()) {
+ return NULL;
+ }
+ info = g_try_new0(CpuModelInfo, 1);
+ if (!info) {
+ return NULL;
+ }
+ cc = S390_CPU_GET_CLASS(s390_cpu_addr2state(0));
+ info->name = strdup_s390_cpu_name(cc);
+ if (!info->name) {
+ g_free(info);
+ return NULL;
+ }
+ if (kvm_enabled()) {
+ info->accelerator = ACCEL_ID_KVM;
+ }
+ return info;
+}
#endif
static void s390_cpu_set_pc(CPUState *cs, vaddr value)
This patch implements a new QMP request named 'query-cpu-model'. It returns the cpu model of cpu 0 and its backing accelerator. request: {"execute" : "query-cpu-model" } answer: {"return" : {"name": "2827-ga2", "accelerator": "kvm" }} Alias names are resolved to their respective machine type and GA names already during cpu instantiation. Thus, also a cpu model like 'host' which is implemented as alias will return its normalized cpu model name. Furthermore the patch implements the following functions: - s390_cpu_typename(), returns the currently selected cpu type name or NULL - s390_cpu_models_used(), returns true if S390 cpu models are in use Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com> --- include/sysemu/arch_init.h | 1 + qapi-schema.json | 25 +++++++++++++++++++++++++ qmp-commands.hx | 6 ++++++ qmp.c | 5 +++++ stubs/Makefile.objs | 1 + stubs/arch-query-cpu-mod.c | 9 +++++++++ target-s390x/cpu-models.c | 13 +++++++++++++ target-s390x/cpu-models.h | 1 + target-s390x/cpu.c | 29 +++++++++++++++++++++++++++++ 9 files changed, 90 insertions(+) create mode 100644 stubs/arch-query-cpu-mod.c