diff mbox

[9/9] target-i386: Return runnability information on query-cpu-definitions

Message ID 1462558292-2126-10-git-send-email-ehabkost@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eduardo Habkost May 6, 2016, 6:11 p.m. UTC
Fill the "runnable" and "unavailable-features" fields on the x86
implementation of query-cpu-definitions.

Example command output:

  {
      "return": [
          { "runnable": true, "name": "host"},
          { "runnable": true, "name": "qemu64"},
          { "runnable": true, "name": "qemu32"},
          { "runnable": false, "name": "phenom",
            "unavailable-features": ["npt", "sse4a", "3dnow", "3dnowext", "fxsr-opt", "mmxext"] },
          { "runnable": true, "name": "pentium3"},
          { "runnable": true, "name": "pentium2"},
          { "runnable": true, "name": "pentium"},
          { "runnable": true, "name": "n270"},
          { "runnable": true, "name": "kvm64"},
          { "runnable": true, "name": "kvm32"},
          { "runnable": true, "name": "coreduo"},
          { "runnable": true, "name": "core2duo"},
          { "runnable": false, "name": "athlon",
            "unavailable-features": ["3dnow", "3dnowext", "mmxext"] },
          { "runnable": true, "name": "Westmere"},
          { "runnable": true, "name": "SandyBridge"},
          { "runnable": true, "name": "Penryn"},
          { "runnable": false, "name": "Opteron_G5",
            "unavailable-features": ["tbm", "fma4", "xop", "3dnowprefetch", "misalignsse", "sse4a"] },
          { "runnable": false, "name": "Opteron_G4",
            "unavailable-features": ["fma4", "xop", "3dnowprefetch", "misalignsse", "sse4a"] },
          { "runnable": false, "name": "Opteron_G3",
            "unavailable-features": ["misalignsse", "sse4a"] },
          { "runnable": true, "name": "Opteron_G2"},
          { "runnable": true, "name": "Opteron_G1"},
          { "runnable": true, "name": "Nehalem"},
          { "runnable": true, "name": "IvyBridge"},
          { "runnable": false, "name": "Haswell",
            "unavailable-features": ["rtm", "hle"] },
          { "runnable": true, "name": "Haswell-noTSX"},
          { "runnable": true, "name": "Conroe"},
          { "runnable": false, "name": "Broadwell",
            "unavailable-features": ["3dnowprefetch", "smap", "adx", "rdseed", "rtm", "hle"] },
          { "runnable": false, "name": "Broadwell-noTSX",
            "unavailable-features": ["3dnowprefetch", "smap", "adx", "rdseed"] },
          { "runnable": true, "name": "486"}
      ]
  }

Cc: Jiri Denemark <jdenemar@redhat.com>
Cc: libvir-list@redhat.com
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
diff mbox

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e7365d1..f6f0f83 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2041,6 +2041,41 @@  static void x86_cpu_report_filtered_features(X86CPU *cpu)
     }
 }
 
+static bool x86_cpu_class_is_runnable(X86CPUClass *xcc, strList **missing_feats)
+{
+    X86CPU *xc;
+    bool r;
+    FeatureWord w;
+
+    if (xcc->kvm_required && !kvm_enabled()) {
+        return false;
+    }
+
+    xc = X86_CPU(object_new(object_class_get_name(OBJECT_CLASS(xcc))));
+    r = !x86_cpu_filter_features(xc);
+    if (!r) {
+        for (w = 0; w < FEATURE_WORDS; w++) {
+            FeatureWordInfo *fi = &feature_word_info[w];
+            uint32_t filtered = xc->filtered_features[w];
+            int i;
+            for (i = 0; i < 32; i++) {
+                if (filtered & (1UL << i)) {
+                    char **parts = g_strsplit(fi->feat_names[i], "|", 2);
+                    strList *new = g_new0(strList, 1);
+                    new->value = g_strdup(parts[0]);
+                    feat2prop(new->value);
+                    new->next = *missing_feats;
+                    *missing_feats = new;
+                    g_strfreev(parts);
+                }
+            }
+        }
+    }
+
+    object_unref(OBJECT(xc));
+    return r;
+}
+
 /* Print all cpuid feature names in featureset
  */
 static void listflags(FILE *f, fprintf_function print, const char **featureset)
@@ -2133,6 +2168,11 @@  static void x86_cpu_definition_entry(gpointer data, gpointer user_data)
 
     info = g_malloc0(sizeof(*info));
     info->name = x86_cpu_class_get_model_name(cc);
+    info->has_runnable = true;
+    info->runnable = x86_cpu_class_is_runnable(cc, &info->unavailable_features);
+    if (!info->runnable) {
+        info->has_unavailable_features = true;
+    }
 
     entry = g_malloc0(sizeof(*entry));
     entry->value = info;