yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
Pablo Greco e6a3ae
From e7f11d39d1ef78f47ed6d45ecd278d51c502f131 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
Date: Fri, 22 Nov 2019 11:53:37 +0000
Pablo Greco e6a3ae
Subject: [PATCH 04/16] i386: display known CPUID features linewrapped, in
Pablo Greco e6a3ae
 alphabetical order
Pablo Greco e6a3ae
MIME-Version: 1.0
Pablo Greco e6a3ae
Content-Type: text/plain; charset=UTF-8
Pablo Greco e6a3ae
Content-Transfer-Encoding: 8bit
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
Message-id: <20191122115348.25000-5-pbonzini@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 92605
Pablo Greco e6a3ae
O-Subject: [RHEL8.2/rhel qemu-kvm PATCH 04/15] i386: display known CPUID features linewrapped, in alphabetical order
Pablo Greco e6a3ae
Bugzilla: 1689270
Pablo Greco e6a3ae
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Maxim Levitsky <mlevitsk@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
From: Daniel P. Berrangé <berrange@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
When using '-cpu help' the list of CPUID features is grouped according
Pablo Greco e6a3ae
to the internal low level CPUID grouping. The data printed results in
Pablo Greco e6a3ae
very long lines too.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
This combines to make it hard for users to read the output and identify
Pablo Greco e6a3ae
if QEMU knows about the feature they wish to use.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
This change gets rid of the grouping of features and treats all flags as
Pablo Greco e6a3ae
single list. The list is sorted into alphabetical order and the printing
Pablo Greco e6a3ae
with line wrapping at the 77th column.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Pablo Greco e6a3ae
Message-Id: <20180606165527.17365-4-berrange@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
(cherry picked from commit cc643b1e7898414b56f551bbd42d4ed8c2ae127a)
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 target/i386/cpu.c | 41 +++++++++++++++++++++++++++--------------
Pablo Greco e6a3ae
 1 file changed, 27 insertions(+), 14 deletions(-)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
Pablo Greco e6a3ae
index 52f1f33..d0c48c2 100644
Pablo Greco e6a3ae
--- a/target/i386/cpu.c
Pablo Greco e6a3ae
+++ b/target/i386/cpu.c
Pablo Greco e6a3ae
@@ -3651,17 +3651,21 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 /* Print all cpuid feature names in featureset
Pablo Greco e6a3ae
  */
Pablo Greco e6a3ae
-static void listflags(FILE *f, fprintf_function print, const char **featureset)
Pablo Greco e6a3ae
+static void listflags(FILE *f, fprintf_function print, GList *features)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
-    int bit;
Pablo Greco e6a3ae
-    bool first = true;
Pablo Greco e6a3ae
-
Pablo Greco e6a3ae
-    for (bit = 0; bit < 32; bit++) {
Pablo Greco e6a3ae
-        if (featureset[bit]) {
Pablo Greco e6a3ae
-            print(f, "%s%s", first ? "" : " ", featureset[bit]);
Pablo Greco e6a3ae
-            first = false;
Pablo Greco e6a3ae
+    size_t len = 0;
Pablo Greco e6a3ae
+    GList *tmp;
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
+    for (tmp = features; tmp; tmp = tmp->next) {
Pablo Greco e6a3ae
+        const char *name = tmp->data;
Pablo Greco e6a3ae
+        if ((len + strlen(name) + 1) >= 75) {
Pablo Greco e6a3ae
+            print(f, "\n");
Pablo Greco e6a3ae
+            len = 0;
Pablo Greco e6a3ae
         }
Pablo Greco e6a3ae
+        print(f, "%s%s", len == 0 ? "  " : " ", name);
Pablo Greco e6a3ae
+        len += strlen(name) + 1;
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
+    print(f, "\n");
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 /* Sort alphabetically by type name, respecting X86CPUClass::ordering. */
Pablo Greco e6a3ae
@@ -3708,26 +3712,35 @@ static void x86_cpu_list_entry(gpointer data, gpointer user_data)
Pablo Greco e6a3ae
 /* list available CPU models and flags */
Pablo Greco e6a3ae
 void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
-    int i;
Pablo Greco e6a3ae
+    int i, j;
Pablo Greco e6a3ae
     CPUListState s = {
Pablo Greco e6a3ae
         .file = f,
Pablo Greco e6a3ae
         .cpu_fprintf = cpu_fprintf,
Pablo Greco e6a3ae
     };
Pablo Greco e6a3ae
     GSList *list;
Pablo Greco e6a3ae
+    GList *names = NULL;
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     (*cpu_fprintf)(f, "Available CPUs:\n");
Pablo Greco e6a3ae
     list = get_sorted_cpu_model_list();
Pablo Greco e6a3ae
     g_slist_foreach(list, x86_cpu_list_entry, &s);
Pablo Greco e6a3ae
     g_slist_free(list);
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
-    (*cpu_fprintf)(f, "\nRecognized CPUID flags:\n");
Pablo Greco e6a3ae
+    names = NULL;
Pablo Greco e6a3ae
     for (i = 0; i < ARRAY_SIZE(feature_word_info); i++) {
Pablo Greco e6a3ae
         FeatureWordInfo *fw = &feature_word_info[i];
Pablo Greco e6a3ae
-
Pablo Greco e6a3ae
-        (*cpu_fprintf)(f, "  ");
Pablo Greco e6a3ae
-        listflags(f, cpu_fprintf, fw->feat_names);
Pablo Greco e6a3ae
-        (*cpu_fprintf)(f, "\n");
Pablo Greco e6a3ae
+        for (j = 0; j < 32; j++) {
Pablo Greco e6a3ae
+            if (fw->feat_names[j]) {
Pablo Greco e6a3ae
+                names = g_list_append(names, (gpointer)fw->feat_names[j]);
Pablo Greco e6a3ae
+            }
Pablo Greco e6a3ae
+        }
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
+    names = g_list_sort(names, (GCompareFunc)strcmp);
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
+    (*cpu_fprintf)(f, "\nRecognized CPUID flags:\n");
Pablo Greco e6a3ae
+    listflags(f, cpu_fprintf, names);
Pablo Greco e6a3ae
+    (*cpu_fprintf)(f, "\n");
Pablo Greco e6a3ae
+    g_list_free(names);
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
 static void x86_cpu_definition_entry(gpointer data, gpointer user_data)
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae