From patchwork Mon Mar 2 12:44:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Mueller X-Patchwork-Id: 445115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6AB331400EA for ; Tue, 3 Mar 2015 00:02:35 +1100 (AEDT) Received: from localhost ([::1]:56691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSPnT-0005MI-Fn for incoming@patchwork.ozlabs.org; Mon, 02 Mar 2015 07:50:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSPiN-0005QQ-HO for qemu-devel@nongnu.org; Mon, 02 Mar 2015 07:44:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSPiJ-00048r-0R for qemu-devel@nongnu.org; Mon, 02 Mar 2015 07:44:51 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:57312) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSPiI-00048b-L6 for qemu-devel@nongnu.org; Mon, 02 Mar 2015 07:44:46 -0500 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Mar 2015 12:44:45 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 2 Mar 2015 12:44:43 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6EF1617D8063 for ; Mon, 2 Mar 2015 12:45:01 +0000 (GMT) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t22CigtM3277300 for ; Mon, 2 Mar 2015 12:44:42 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t22Cie1E003813 for ; Mon, 2 Mar 2015 05:44:42 -0700 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t22CiTj0003352; Mon, 2 Mar 2015 05:44:39 -0700 From: Michael Mueller To: qemu-devel@nongnu.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 2 Mar 2015 13:44:06 +0100 Message-Id: <1425300248-40277-15-git-send-email-mimu@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1425300248-40277-1-git-send-email-mimu@linux.vnet.ibm.com> References: <1425300248-40277-1-git-send-email-mimu@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15030212-0021-0000-0000-0000030F28F3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.111 Cc: Eduardo Habkost , Gleb Natapov , Alexander Graf , Christian Borntraeger , "Jason J. Herne" , Cornelia Huck , Paolo Bonzini , Michael Mueller , Andreas Faerber , Richard Henderson Subject: [Qemu-devel] [PATCH v3 14/16] target-s390x: Extend QMP command query-cpu-definitions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch implements the QMP command 'query-cpu-definitions' in the S390 context. The command returns a list of cpu model names in the current host context. A consumer may successfully request each listed cpu model as long for a given accelerator this model is runnable. The QMP type AccelCpuModelInfo is introduced and the type CpuDefinitionInfo is extended by the optional field 'accelerators'. It contains a list of named accelerators and some indication whether the associated cpu model is runnable or the default cpu model. The default cpu model is used if either no specific cpu model is requested during QEMU startup or if the cpu model with name 'host' is requested. request: {"execute": "query-cpu-definitions"} answer: {"return": [{"name":"2964-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]}, {"name":"2828-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]}, {"name":"2827-ga2","accelerators":[{"name":"kvm","runnable":true,"default":true}]}, {"name":"2827-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]}, {"name":"2818-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]}, ... {"name":"2064-ga1","accelerators":[{"runnable":true,"name":"kvm","default":false}]} ] } Signed-off-by: Michael Mueller --- qapi-schema.json | 21 +++++++++- target-s390x/cpu-models.c | 15 +++++++ target-s390x/cpu-models.h | 1 + target-s390x/cpu.c | 100 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 130 insertions(+), 7 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index e9b213f..44863e5 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2485,16 +2485,35 @@ 'data': ['qtest', 'tcg', 'kvm', 'xen' ] } ## +# @AccelCpuModelInfo: +# +# Accelerator specific CPU model data +# +# @name: the accelerator name +# +# @default: cpu model for 'host' +# +# @runnable: cpu model can be activated on hosting machine +# +# Since: 2.3 +# +## +{ 'type': 'AccelCpuModelInfo', + 'data': { 'name': 'AccelId', 'default': 'bool', 'runnable': 'bool' } } + +## # @CpuDefinitionInfo: # # Virtual CPU definition. # # @name: the name of the CPU definition # +# @accelerators: #optional cpu model offered per accelerator (since 2.3) +# # Since: 1.2.0 ## { 'type': 'CpuDefinitionInfo', - 'data': { 'name': 'str' } } + 'data': { 'name': 'str', '*accelerators': ['AccelCpuModelInfo'] } } ## # @query-cpu-definitions: diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c index 116dbcc..7ad61df 100644 --- a/target-s390x/cpu-models.c +++ b/target-s390x/cpu-models.c @@ -211,6 +211,21 @@ int set_s390_cpu_alias(const char *name, const char *model) return 0; } +/* compare order of two cpu classes for descending sort */ +gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b) +{ + S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a); + S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b); + + if (cc_a->mach.order < cc_b->mach.order) { + return 1; + } + if (cc_a->mach.order > cc_b->mach.order) { + return -1; + } + return 0; +} + /* return machine class for specific machine type */ static void s390_machine_class_test_cpu_class(gpointer data, gpointer user_data) { diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h index 51db298..3605aa4 100644 --- a/target-s390x/cpu-models.h +++ b/target-s390x/cpu-models.h @@ -110,6 +110,7 @@ static inline bool kvm_s390_probe_mode(void) int s390_setup_cpu_classes(AccelId accel, S390MachineProps *prop); gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b); +gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b); void s390_cpu_list_entry(gpointer data, gpointer user_data); bool s390_cpu_classes_initialized(void); bool s390_probe_mode(void); diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c index cefaff1..6bf6554 100644 --- a/target-s390x/cpu.c +++ b/target-s390x/cpu.c @@ -66,18 +66,106 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf) } #ifndef CONFIG_USER_ONLY -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +static AccelCpuModelInfoList *qmp_query_accel_entry(AccelId accel, + S390CPUClass *cc, + AccelCpuModelInfoList *prev) +{ + AccelCpuModelInfoList *list; + AccelCpuModelInfo *info; + + info = g_try_new0(AccelCpuModelInfo, 1); + if (!info) { + goto out; + } + info->name = accel; + info->runnable = cc->is_active[accel]; + info->q_default = cc->is_host[accel]; + list = g_try_new0(AccelCpuModelInfoList, 1); + if (!list) { + goto out; + } + list->value = info; + list->next = prev; + + return list; +out: + g_free(info); + return prev; +} + +static void qmp_query_cpu_definition_entry(gpointer data, gpointer user_data) +{ + ObjectClass *oc = (ObjectClass *) data; + S390CPUClass *cc = S390_CPU_CLASS(oc); + CpuDefinitionInfoList *list, **prev = user_data; + CpuDefinitionInfo *info; + + if (!strcmp(object_class_get_name(oc), TYPE_S390_CPU)) { + return; + } + info = g_try_new0(CpuDefinitionInfo, 1); + if (!info) { + goto out; + } + info->name = strdup_s390_cpu_name(cc); + if (kvm_enabled()) { + info->accelerators = + qmp_query_accel_entry(ACCEL_ID_KVM, cc, info->accelerators); + } + info->has_accelerators = (info->accelerators) ? true : false; + list = g_try_new0(CpuDefinitionInfoList, 1); + if (!list) { + goto out; + } + list->value = info; + list->next = *prev; + *prev = list; + return; +out: + if (info) { + g_free(info->name); + g_free(info); + } +} + +static CpuDefinitionInfoList *qmp_query_cpu_definition_host(void) { - CpuDefinitionInfoList *entry; + CpuDefinitionInfoList *host = NULL; CpuDefinitionInfo *info; - info = g_malloc0(sizeof(*info)); + info = g_try_new0(CpuDefinitionInfo, 1); + if (!info) { + goto out; + } info->name = g_strdup("host"); - entry = g_malloc0(sizeof(*entry)); - entry->value = info; + host = g_try_new0(CpuDefinitionInfoList, 1); + if (!host) { + g_free(info->name); + g_free(info); + goto out; + } + host->value = info; +out: + return host; +} + +CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +{ + CpuDefinitionInfoList *list = NULL; + GSList *class_list; + + if (!s390_probe_mode()) { + if (!s390_cpu_models_used()) { + return qmp_query_cpu_definition_host(); + } + } + class_list = object_class_get_list(TYPE_S390_CPU, false); + class_list = g_slist_sort(class_list, s390_cpu_class_asc_order_compare); + g_slist_foreach(class_list, qmp_query_cpu_definition_entry, &list); + g_slist_free(class_list); - return entry; + return list; } CpuModelInfo *arch_query_cpu_model(Error **errp)