From patchwork Wed Oct 2 11:33:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Mueller X-Patchwork-Id: 279702 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 342782C00BA for ; Wed, 2 Oct 2013 21:41:04 +1000 (EST) Received: from localhost ([::1]:35457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRKne-0003Io-3Z for incoming@patchwork.ozlabs.org; Wed, 02 Oct 2013 07:41:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRKgt-0000Yo-Tb for qemu-devel@nongnu.org; Wed, 02 Oct 2013 07:34:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VRKgk-000270-GP for qemu-devel@nongnu.org; Wed, 02 Oct 2013 07:34:03 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:45591) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRKgk-00026D-8E for qemu-devel@nongnu.org; Wed, 02 Oct 2013 07:33:54 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 2 Oct 2013 12:33:53 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 2 Oct 2013 12:33:51 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 07AD31B0806B for ; Wed, 2 Oct 2013 12:33:53 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r92BXcwj53608610 for ; Wed, 2 Oct 2013 11:33:38 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r92BXoDX022978 for ; Wed, 2 Oct 2013 05:33:50 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r92BXkeY022802; Wed, 2 Oct 2013 05:33:50 -0600 From: Michael Mueller To: qemu-devel@nongnu.org Date: Wed, 2 Oct 2013 13:33:40 +0200 Message-Id: <1380713622-22325-10-git-send-email-mimu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1380713622-22325-1-git-send-email-mimu@linux.vnet.ibm.com> References: <1380713622-22325-1-git-send-email-mimu@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13100211-0542-0000-0000-0000069FF7BC X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.113 Cc: Michael Mueller Subject: [Qemu-devel] [PATCH RFC 09/11] s390/qemu: cpu model QMP 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 descending sorted list of cpu model names derived from the currently (in the current host context) supported set of cpu classes. That means a consumer can successfully request each reported cpu model. Implicitly, the first reported cpu model is the host cpu model. request: {"execute": "query-cpu-definitions"} answer: {"return": [{"name": "2827-ga1"}, {"name": "2818-ga1"}, {"name": "2817-ga2"}, {"name": "2817-ga1"}, {"name": "2098-ga2"}, {"name": "2098-ga1"}, {"name": "2097-ga3"}, {"name": "2097-ga2"}, {"name": "2097-ga1"}, {"name": "2096-ga2"}, {"name": "2096-ga1"}, {"name": "2094-ga3"}, {"name": "2094-ga2"}, {"name": "2094-ga1"}, {"name": "2086-ga3"}, {"name": "2086-ga2"}, {"name": "2086-ga1"}, {"name": "2084-ga5"}, {"name": "2084-ga4"}, {"name": "2084-ga3"}, {"name": "2084-ga2"}, {"name": "2084-ga1"}, {"name": "2068-ga1"}, {"name": "2064-ga3"}, {"name": "2064-ga2"}, {"name": "2064-ga1"}]} Signed-off-by: Michael Mueller --- target-s390x/cpu-models.c | 15 +++++++++++ target-s390x/cpu-models.h | 1 + target-s390x/cpu.c | 69 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c index 68b978a..f07ff17 100644 --- a/target-s390x/cpu-models.c +++ b/target-s390x/cpu-models.c @@ -249,6 +249,21 @@ gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b) 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->order < cc_b->order) { + return 1; + } + if (cc_a->order > cc_b->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 fd01876..9d02ce6 100644 --- a/target-s390x/cpu-models.h +++ b/target-s390x/cpu-models.h @@ -51,6 +51,7 @@ struct S390HostProps { int s390_fetch_kvm_host_props(struct S390HostProps *prop); int s390_request_kvm_cpu_config(S390CPUClass *cc); gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b); +gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b); int s390_setup_cpu_classes(struct S390HostProps *prop); ObjectClass *s390_cpu_class_by_name(const char *name); void s390_cpu_list_entry(gpointer data, gpointer user_data); diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c index 0fccc72..b790905 100644 --- a/target-s390x/cpu.c +++ b/target-s390x/cpu.c @@ -57,18 +57,77 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf) } #ifndef CONFIG_USER_ONLY -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) -{ - CpuDefinitionInfoList *entry; +static void s390_query_cpu_definition(gpointer data, gpointer user_data) { + S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data); + char model[16]; CpuDefinitionInfo *info; + CpuDefinitionInfoList *entry; + struct { + CpuDefinitionInfoList *head; + CpuDefinitionInfoList *tail; + } *cpu_definition = user_data; + + if (!cc->is_active) { + return; + } + info = g_malloc0(sizeof(*info)); - info->name = g_strdup("host"); + if (!info) { + return; + } + + snprintf(model, sizeof(model), "%04x-ga%u", cc->type, cc->ga); + info->name = g_strdup(model); + if (!info->name) { + return; + g_free(info); + } entry = g_malloc0(sizeof(*entry)); + if (!entry) { + g_free(info->name); + g_free(info); + return; + } entry->value = info; + entry->next = NULL; - return entry; + if (cpu_definition->tail) { + cpu_definition->tail->next = entry; + cpu_definition->tail = cpu_definition->tail->next; + } else { + cpu_definition->head = cpu_definition->tail = entry; + } +} + +CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +{ + if (kvm_enabled()) { + GSList *list; + + list = object_class_get_list(TYPE_S390_CPU, false); + list = g_slist_sort(list, s390_cpu_class_desc_order_compare); + struct { + CpuDefinitionInfoList *head; + CpuDefinitionInfoList *tail; + } cpu_definition = { + .head = NULL, + .tail = NULL, + }; + g_slist_foreach(list, s390_query_cpu_definition, &cpu_definition); + g_slist_free(list); + return cpu_definition.head; + } else { + CpuDefinitionInfoList *entry; + CpuDefinitionInfo *info; + + info = g_malloc0(sizeof(*info)); + info->name = g_strdup("host"); + entry = g_malloc0(sizeof(*entry)); + entry->value = info; + return entry; + } } #endif