Blame SOURCES/kvm-s390x-print-CPU-definitions-in-sorted-order.patch

4a2fec
From a009d0254cdfd6deb532ef654a3f2811cb8b9c15 Mon Sep 17 00:00:00 2001
4a2fec
From: David Hildenbrand <david@redhat.com>
4a2fec
Date: Fri, 10 Nov 2017 14:49:03 +0100
4a2fec
Subject: [PATCH 6/7] s390x: print CPU definitions in sorted order
4a2fec
4a2fec
RH-Author: David Hildenbrand <david@redhat.com>
4a2fec
Message-id: <20171110144904.7026-2-david@redhat.com>
4a2fec
Patchwork-id: 77647
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-ma PATCH v3 1/2] s390x: print CPU definitions in sorted order
4a2fec
Bugzilla: 1504138
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
4a2fec
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
4a2fec
4a2fec
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1504138
4a2fec
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=14527097
4a2fec
Upstream-status: 99aa6bf29b87052d9603c5bf5c23d0db960f30ce
4a2fec
4a2fec
Other architectures provide nicely sorted lists, let's do it similarly on
4a2fec
s390x.
4a2fec
4a2fec
While at it, clean up the code we have to touch either way.
4a2fec
4a2fec
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
4a2fec
Signed-off-by: David Hildenbrand <david@redhat.com>
4a2fec
Message-Id: <20170913132417.24384-16-david@redhat.com>
4a2fec
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
4a2fec
(cherry picked from commit 99aa6bf29b87052d9603c5bf5c23d0db960f30ce)
4a2fec
Signed-off-by: David Hildenbrand <david@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 target/s390x/cpu_models.c | 56 ++++++++++++++++++++++++++++++++++-------------
4a2fec
 1 file changed, 41 insertions(+), 15 deletions(-)
4a2fec
4a2fec
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
4a2fec
index fa1338f..e055852 100644
4a2fec
--- a/target/s390x/cpu_models.c
4a2fec
+++ b/target/s390x/cpu_models.c
4a2fec
@@ -267,16 +267,11 @@ const S390CPUDef *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
4a2fec
     return last_compatible;
4a2fec
 }
4a2fec
 
4a2fec
-struct S390PrintCpuListInfo {
4a2fec
-    FILE *f;
4a2fec
-    fprintf_function print;
4a2fec
-};
4a2fec
-
4a2fec
-static void print_cpu_model_list(ObjectClass *klass, void *opaque)
4a2fec
+static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data)
4a2fec
 {
4a2fec
-    struct S390PrintCpuListInfo *info = opaque;
4a2fec
-    S390CPUClass *scc = S390_CPU_CLASS(klass);
4a2fec
-    char *name = g_strdup(object_class_get_name(klass));
4a2fec
+    CPUListState *s = user_data;
4a2fec
+    const S390CPUClass *scc = S390_CPU_CLASS((ObjectClass *)data);
4a2fec
+    char *name = g_strdup(object_class_get_name((ObjectClass *)data));
4a2fec
     const char *details = "";
4a2fec
 
4a2fec
     if (scc->is_static) {
4a2fec
@@ -287,21 +282,52 @@ static void print_cpu_model_list(ObjectClass *klass, void *opaque)
4a2fec
 
4a2fec
     /* strip off the -s390-cpu */
4a2fec
     g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
4a2fec
-    (*info->print)(info->f, "s390 %-15s %-35s %s\n", name, scc->desc,
4a2fec
-                   details);
4a2fec
+    (*s->cpu_fprintf)(s->file, "s390 %-15s %-35s %s\n", name, scc->desc,
4a2fec
+                      details);
4a2fec
     g_free(name);
4a2fec
 }
4a2fec
 
4a2fec
+static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b)
4a2fec
+{
4a2fec
+    const S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *)a);
4a2fec
+    const S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *)b);
4a2fec
+    const char *name_a = object_class_get_name((ObjectClass *)a);
4a2fec
+    const char *name_b = object_class_get_name((ObjectClass *)b);
4a2fec
+
4a2fec
+    /* move qemu and host to the top of the list, qemu first, host second */
4a2fec
+    if (name_a[0] == 'q') {
4a2fec
+        return -1;
4a2fec
+    } else if (name_b[0] == 'q') {
4a2fec
+        return 1;
4a2fec
+    } else if (name_a[0] == 'h') {
4a2fec
+        return -1;
4a2fec
+    } else if (name_b[0] == 'h') {
4a2fec
+        return 1;
4a2fec
+    }
4a2fec
+
4a2fec
+    /* keep the same order we have in our table (sorted by release date) */
4a2fec
+    if (cc_a->cpu_def != cc_b->cpu_def) {
4a2fec
+        return cc_a->cpu_def - cc_b->cpu_def;
4a2fec
+    }
4a2fec
+
4a2fec
+    /* exact same definition - list base model first */
4a2fec
+    return cc_a->is_static ? -1 : 1;
4a2fec
+}
4a2fec
+
4a2fec
 void s390_cpu_list(FILE *f, fprintf_function print)
4a2fec
 {
4a2fec
-    struct S390PrintCpuListInfo info = {
4a2fec
-        .f = f,
4a2fec
-        .print = print,
4a2fec
+    CPUListState s = {
4a2fec
+        .file = f,
4a2fec
+        .cpu_fprintf = print,
4a2fec
     };
4a2fec
     S390FeatGroup group;
4a2fec
     S390Feat feat;
4a2fec
+    GSList *list;
4a2fec
 
4a2fec
-    object_class_foreach(print_cpu_model_list, TYPE_S390_CPU, false, &info;;
4a2fec
+    list = object_class_get_list(TYPE_S390_CPU, false);
4a2fec
+    list = g_slist_sort(list, s390_cpu_list_compare);
4a2fec
+    g_slist_foreach(list, s390_print_cpu_model_list_entry, &s);
4a2fec
+    g_slist_free(list);
4a2fec
 
4a2fec
     (*print)(f, "\nRecognized feature flags:\n");
4a2fec
     for (feat = 0; feat < S390_FEAT_MAX; feat++) {
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec