Patchwork [qom-cpu,2/4] target-i386: Drop redundant list of CPU definitions

login
register
mail settings
Submitter Andreas Färber
Date Dec. 9, 2012, 7:45 p.m.
Message ID <1355082353-322-3-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/204781/
State New
Headers show

Comments

Andreas Färber - Dec. 9, 2012, 7:45 p.m.
Since we are no longer parsing cpudefs from config files, only the array
of built-in definitions remains.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-i386/cpu.c |   37 ++++++++++++++-----------------------
 1 Datei geändert, 14 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-)
Eduardo Habkost - Dec. 10, 2012, 6:22 p.m.
On Sun, Dec 09, 2012 at 08:45:51PM +0100, Andreas Färber wrote:
> Since we are no longer parsing cpudefs from config files, only the array
> of built-in definitions remains.
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

But this probably has to be redone if you remove patch 1/4.

I believe the code in cpu_x86_find_by_name() will get much simpler and
friendlier to change if we simply move the strcmp(name, "host") check
above the model list lookup (instead of moving it to
cpu_x86_register()).


> ---
>  target-i386/cpu.c |   37 ++++++++++++++-----------------------
>  1 Datei geändert, 14 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index a46faa2..e265317 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -330,11 +330,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[] = {
>      {
> @@ -1210,20 +1206,17 @@ 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;
>  
> -    for (def = x86_defs; def; def = def->next) {
> -        if (name && !strcmp(name, def->name)) {
> -            break;
> +    for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
> +        x86_def_t *def = &builtin_x86_defs[i];
> +        if (strcmp(name, def->name) == 0) {
> +            memcpy(x86_cpu_def, def, sizeof(*def));
> +            return 0;
>          }
>      }
> -    if (!def) {
> -        return -1;
> -    } else {
> -        memcpy(x86_cpu_def, def, sizeof(*def));
> -    }
>  
> -    return 0;
> +    return -1;
>  }
>  
>  /* Parse "+feature,-feature,feature=foo" CPU feature string
> @@ -1418,10 +1411,11 @@ static void listflags(char *buf, int bufsize, uint32_t fbits,
>  /* generate CPU information. */
>  void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
>  {
> -    x86_def_t *def;
> +    int i;
>      char buf[256];
>  
> -    for (def = x86_defs; def; def = def->next) {
> +    for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
> +        x86_def_t *def = &builtin_x86_defs[i];
>          snprintf(buf, sizeof(buf), "%s", def->name);
>          (*cpu_fprintf)(f, "x86 %16s  %-48s\n", buf, def->model_id);
>      }
> @@ -1442,14 +1436,14 @@ void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
>  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;
>  
>          info = g_malloc0(sizeof(*info));
> -        info->name = g_strdup(def->name);
> +        info->name = g_strdup(builtin_x86_defs[i].name);
>  
>          entry = g_malloc0(sizeof(*entry));
>          entry->value = info;
> @@ -1598,7 +1592,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 */
> @@ -1611,8 +1604,6 @@ void x86_cpudef_setup(void)
>                  break;
>              }
>          }
> -
> -        x86_defs = def;
>      }
>  }
>  
> -- 
> 1.7.10.4
> 
>

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index a46faa2..e265317 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -330,11 +330,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[] = {
     {
@@ -1210,20 +1206,17 @@  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;
 
-    for (def = x86_defs; def; def = def->next) {
-        if (name && !strcmp(name, def->name)) {
-            break;
+    for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
+        x86_def_t *def = &builtin_x86_defs[i];
+        if (strcmp(name, def->name) == 0) {
+            memcpy(x86_cpu_def, def, sizeof(*def));
+            return 0;
         }
     }
-    if (!def) {
-        return -1;
-    } else {
-        memcpy(x86_cpu_def, def, sizeof(*def));
-    }
 
-    return 0;
+    return -1;
 }
 
 /* Parse "+feature,-feature,feature=foo" CPU feature string
@@ -1418,10 +1411,11 @@  static void listflags(char *buf, int bufsize, uint32_t fbits,
 /* generate CPU information. */
 void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 {
-    x86_def_t *def;
+    int i;
     char buf[256];
 
-    for (def = x86_defs; def; def = def->next) {
+    for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) {
+        x86_def_t *def = &builtin_x86_defs[i];
         snprintf(buf, sizeof(buf), "%s", def->name);
         (*cpu_fprintf)(f, "x86 %16s  %-48s\n", buf, def->model_id);
     }
@@ -1442,14 +1436,14 @@  void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 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;
 
         info = g_malloc0(sizeof(*info));
-        info->name = g_strdup(def->name);
+        info->name = g_strdup(builtin_x86_defs[i].name);
 
         entry = g_malloc0(sizeof(*entry));
         entry->value = info;
@@ -1598,7 +1592,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 */
@@ -1611,8 +1604,6 @@  void x86_cpudef_setup(void)
                 break;
             }
         }
-
-        x86_defs = def;
     }
 }