Skip to contentSkip to conversation

target-i386: x86_defs cleanup

PATCH New Andreas Färber 1 participant 3 messages Jan 21, 2013

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/2 target-i386: Simplify cpu_x86_find_by_name()

In reply to Andreas Färber

Catch NULL name argument early to avoid repeated checks. Similarly, check for -cpu host early and untangle from iterating through model definitions.

---
 target-i386/cpu.c |   22 ++++++++++++----------

1 Datei geändert, 12 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-)

target-i386/cpu.c +12 -10
index 333745b..a072712 100644
@@ -1321,20 +1321,22 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
 {
     x86_def_t *def;
 
-    for (def = x86_defs; def; def = def->next) {
-        if (name && !strcmp(name, def->name)) {
-            break;
-        }
+    if (name == NULL) {
+        return -1;
     }
-    if (kvm_enabled() && name && strcmp(name, "host") == 0) {
+    if (kvm_enabled() && strcmp(name, "host") == 0) {
         kvm_cpu_fill_host(x86_cpu_def);
-    } else if (!def) {
-        return -1;
-    } else {
-        memcpy(x86_cpu_def, def, sizeof(*def));
+        return 0;
     }
 
-    return 0;
+    for (def = x86_defs; def; def = def->next) {
+        if (strcmp(name, def->name) == 0) {
+            memcpy(x86_cpu_def, def, sizeof(*def));
+            return 0;
+        }
+    }
+
+    return -1;
 }
 
 /* Parse "+feature,-feature,feature=foo" CPU feature string
Signature · 1 line
1.7.10.4
#0 lore raw

v2 cover target-i386: x86_defs cleanup

Hello,

Here's a revamped mini-series doing cleanups of x86_defs for v1.4 before we proceed with X86CPU subclasses for v1.5.

v2 leaves the cpudef hooks in place and refactors only within functions.

Intended to catch this week's qom-cpu pull if there are no more objections.

Regards,
Andreas

v1 -> v2:
* MAINTAINERS patch was applied already.
* Redone on master.
* Actually removed x86_def_t next pointer this time.
* Instead of pulling -cpu host handling out of cpu_x86_find_by_name(), moved it to the front of that function.
* Deferred cleanup of cpudef_setup() hooks.

Cc Eduardo Habkost <[email protected]>
Cc Igor Mammedov <[email protected]>

Andreas Färber (2):
target-i386: Simplify cpu_x86_find_by_name()
target-i386: Drop redundant list of CPU definitions

 target-i386/cpu.c |   42 +++++++++++++++++++++---------------------

1 Datei geändert, 21 Zeilen hinzugefügt(+), 21 Zeilen entfernt(-)

Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v2 2/2 target-i386: Drop redundant list of CPU definitions

It is no longer needed since dropping cpudef config file support. Cleaning this up removes knowledge about other models from x86_def_t, in preparation for reusing x86_def_t as intermediate step towards pure QOM X86CPU subclasses.

---
 target-i386/cpu.c |   22 ++++++++++------------

1 Datei geändert, 10 Zeilen hinzugefügt(+), 12 Zeilen entfernt(-)

target-i386/cpu.c +10 -12
index a072712..ddd7b98 100644
@@ -338,7 +338,6 @@ static void add_flagname_to_bitmaps(const char *flagname,
 }
 
 typedef struct x86_def_t {
-    struct x86_def_t *next;
     const char *name;
     uint32_t level;
     uint32_t vendor1, vendor2, vendor3;
@@ -396,11 +395,7 @@ typedef struct x86_def_t {
 #define TCG_SVM_FEATURES 0
 #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP)
 
-/* maintains list of cpu model definitions
- */
-static x86_def_t *x86_defs = {NULL};
-
-/* built-in cpu model definitions (deprecated)
+/* built-in CPU model definitions
  */
 static x86_def_t builtin_x86_defs[] = {
     {
@@ -1320,6 +1315,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,
 static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
 {
     x86_def_t *def;
+    int i;
 
     if (name == NULL) {
         return -1;
@@ -1329,7 +1325,8 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
         return 0;
     }
 
-    for (def = x86_defs; def; def = def->next) {
+    for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
+        def = &builtin_x86_defs[i];
         if (strcmp(name, def->name) == 0) {
             memcpy(x86_cpu_def, def, sizeof(*def));
             return 0;
@@ -1515,8 +1512,10 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 {
     x86_def_t *def;
     char buf[256];
+    int i;
 
-    for (def = x86_defs; def; def = def->next) {
+    for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
+        def = &builtin_x86_defs[i];
         snprintf(buf, sizeof(buf), "%s", def->name);
         (*cpu_fprintf)(f, "x86 %16s  %-48s\n", buf, def->model_id);
     }
@@ -1538,11 +1537,13 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
 {
     CpuDefinitionInfoList *cpu_list = NULL;
     x86_def_t *def;
+    int i;
 
-    for (def = x86_defs; def; def = def->next) {
+    for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
         CpuDefinitionInfoList *entry;
         CpuDefinitionInfo *info;
 
+        def = &builtin_x86_defs[i];
         info = g_malloc0(sizeof(*info));
         info->name = g_strdup(def->name);
 
@@ -1663,7 +1664,6 @@ void x86_cpudef_setup(void)
 
     for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); ++i) {
         x86_def_t *def = &builtin_x86_defs[i];
-        def->next = x86_defs;
 
         /* Look for specific "cpudef" models that */
         /* have the QEMU version in .model_id */
@@ -1676,8 +1676,6 @@ void x86_cpudef_setup(void)
                 break;
             }
         }
-
-        x86_defs = def;
     }
 }
 
Signature · 1 line
1.7.10.4