All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v2)
@ 2012-12-04 18:58 Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 18:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

Changes v1 -> v2:
 - Coding style changes (patches 1-2)
 - Use "return -1" directly instead of "goto error" on cpu_x86_find_by_name()
   (patch 2)

This series is based on the qom-cpu branch from afaerber's tree. The full
branch can be found in a git tree, at:
  git://github.com/ehabkost/qemu-hacks.git cpu-init-cleanup-short-v2
  https://github.com/ehabkost/qemu-hacks/tree/cpu-init-cleanup-short-v2

References to previous versions:
 v1: http://article.gmane.org/gmane.comp.emulators.qemu/182713
 previous (long) cleanup series:
   http://article.gmane.org/gmane.comp.emulators.qemu/180137


Eduardo Habkost (2):
  target-i386/cpu.c: coding style fixes
  target-i386: cpu: separate feature string parsing from CPU model
    lookup

Igor Mammedov (4):
  target-i386: use define for cpuid vendor string size
  target-i386: postpone cpuid_level update to realize time
  add visitor for parsing hz[KMG] input string
  target-i386: use visit_type_hz to parse tsc_freq property value

 qapi/qapi-visit-core.c      |  11 +++++
 qapi/qapi-visit-core.h      |   2 +
 qapi/string-input-visitor.c |  22 ++++++++++
 target-i386/cpu.c           | 103 ++++++++++++++++++++++++++++----------------
 target-i386/cpu.h           |   2 +
 5 files changed, 102 insertions(+), 38 deletions(-)

-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes
  2012-12-04 18:58 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v2) Eduardo Habkost
@ 2012-12-04 18:58 ` Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup Eduardo Habkost
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 18:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

- Use spaces instead of tabs on cpu_x86_cpuid().
- Use braces on 'if' statement cpu_x86_find_by_name().

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index c6c2ca0..7afe839 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1227,9 +1227,11 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
     uint32_t minus_7_0_ebx_features = 0;
     uint32_t numvalue;
 
-    for (def = x86_defs; def; def = def->next)
-        if (name && !strcmp(name, def->name))
+    for (def = x86_defs; def; def = def->next) {
+        if (name && !strcmp(name, def->name)) {
             break;
+        }
+    }
     if (kvm_enabled() && name && strcmp(name, "host") == 0) {
         kvm_cpu_fill_host(x86_cpu_def);
     } else if (!def) {
@@ -1835,17 +1837,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         }
         break;
     case 0x8000000A:
-	if (env->cpuid_ext3_features & CPUID_EXT3_SVM) {
-		*eax = 0x00000001; /* SVM Revision */
-		*ebx = 0x00000010; /* nr of ASIDs */
-		*ecx = 0;
-		*edx = env->cpuid_svm_features; /* optional features */
-	} else {
-		*eax = 0;
-		*ebx = 0;
-		*ecx = 0;
-		*edx = 0;
-	}
+        if (env->cpuid_ext3_features & CPUID_EXT3_SVM) {
+            *eax = 0x00000001; /* SVM Revision */
+            *ebx = 0x00000010; /* nr of ASIDs */
+            *ecx = 0;
+            *edx = env->cpuid_svm_features; /* optional features */
+        } else {
+            *eax = 0;
+            *ebx = 0;
+            *ecx = 0;
+            *edx = 0;
+        }
         break;
     case 0xC0000000:
         *eax = env->cpuid_xlevel2;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup
  2012-12-04 18:58 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v2) Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
@ 2012-12-04 18:58 ` Eduardo Habkost
  2012-12-04 19:13   ` Igor Mammedov
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size Eduardo Habkost
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 18:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

Instead of using parsing the whole cpu_model string inside
cpu_x86_find_by_name(), first split it into the CPU model name and the
full feature string, then parse the feature string into pieces.

When using CPU model classes, those two pieces of information will be
used at different moments (CPU model name will be used to find CPU
class, feature string will be used after CPU object was created), so
making the split in two steps will make it easier to refactor the code
later.

This should also help on the CPU properties work, that will just need to
replace the cpu_x86_parse_featurestr() logic (and can keep the CPU model
lookup code as-is).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
 - Coding style changes
 - Replace "goto error" with "return -1"
---
 target-i386/cpu.c | 67 +++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 45 insertions(+), 22 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 7afe839..4090152 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1208,25 +1208,10 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,
     cpu->env.tsc_khz = value / 1000;
 }
 
-static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
+static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
 {
-    unsigned int i;
     x86_def_t *def;
 
-    char *s = g_strdup(cpu_model);
-    char *featurestr, *name = strtok(s, ",");
-    /* Features to be added*/
-    uint32_t plus_features = 0, plus_ext_features = 0;
-    uint32_t plus_ext2_features = 0, plus_ext3_features = 0;
-    uint32_t plus_kvm_features = kvm_default_features, plus_svm_features = 0;
-    uint32_t plus_7_0_ebx_features = 0;
-    /* Features to be removed */
-    uint32_t minus_features = 0, minus_ext_features = 0;
-    uint32_t minus_ext2_features = 0, minus_ext3_features = 0;
-    uint32_t minus_kvm_features = 0, minus_svm_features = 0;
-    uint32_t minus_7_0_ebx_features = 0;
-    uint32_t numvalue;
-
     for (def = x86_defs; def; def = def->next) {
         if (name && !strcmp(name, def->name)) {
             break;
@@ -1235,16 +1220,37 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
     if (kvm_enabled() && name && strcmp(name, "host") == 0) {
         kvm_cpu_fill_host(x86_cpu_def);
     } else if (!def) {
-        goto error;
+        return -1;
     } else {
         memcpy(x86_cpu_def, def, sizeof(*def));
     }
 
+    return 0;
+}
+
+/* Parse "+feature,-feature,feature=foo" CPU feature string
+ */
+static int cpu_x86_parse_featurestr(x86_def_t *x86_cpu_def, char *features)
+{
+    unsigned int i;
+    char *featurestr; /* Single 'key=value" string being parsed */
+    /* Features to be added*/
+    uint32_t plus_features = 0, plus_ext_features = 0;
+    uint32_t plus_ext2_features = 0, plus_ext3_features = 0;
+    uint32_t plus_kvm_features = kvm_default_features, plus_svm_features = 0;
+    uint32_t plus_7_0_ebx_features = 0;
+    /* Features to be removed */
+    uint32_t minus_features = 0, minus_ext_features = 0;
+    uint32_t minus_ext2_features = 0, minus_ext3_features = 0;
+    uint32_t minus_kvm_features = 0, minus_svm_features = 0;
+    uint32_t minus_7_0_ebx_features = 0;
+    uint32_t numvalue;
+
     add_flagname_to_bitmaps("hypervisor", &plus_features,
             &plus_ext_features, &plus_ext2_features, &plus_ext3_features,
             &plus_kvm_features, &plus_svm_features,  &plus_7_0_ebx_features);
 
-    featurestr = strtok(NULL, ",");
+    featurestr = features ? strtok(features, ",") : NULL;
 
     while (featurestr) {
         char *val;
@@ -1378,11 +1384,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
     if (x86_cpu_def->cpuid_7_0_ebx_features && x86_cpu_def->level < 7) {
         x86_cpu_def->level = 7;
     }
-    g_free(s);
     return 0;
 
 error:
-    g_free(s);
     return -1;
 }
 
@@ -1492,11 +1496,25 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
     CPUX86State *env = &cpu->env;
     x86_def_t def1, *def = &def1;
     Error *error = NULL;
+    char *name, *features;
+    gchar **model_pieces;
 
     memset(def, 0, sizeof(*def));
 
-    if (cpu_x86_find_by_name(def, cpu_model) < 0)
-        return -1;
+    model_pieces = g_strsplit(cpu_model, ",", 2);
+    if (!model_pieces[0]) {
+        goto error;
+    }
+    name = model_pieces[0];
+    features = model_pieces[1];
+
+    if (cpu_x86_find_by_name(def, name) < 0) {
+        goto error;
+    }
+
+    if (cpu_x86_parse_featurestr(def, features) < 0) {
+        goto error;
+    }
     if (def->vendor1) {
         env->cpuid_vendor1 = def->vendor1;
         env->cpuid_vendor2 = def->vendor2;
@@ -1555,7 +1573,12 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
         error_free(error);
         return -1;
     }
+
+    g_strfreev(model_pieces);
     return 0;
+error:
+    g_strfreev(model_pieces);
+    return -1;
 }
 
 #if !defined(CONFIG_USER_ONLY)
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
  2012-12-04 18:58 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v2) Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup Eduardo Habkost
@ 2012-12-04 18:58 ` Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time Eduardo Habkost
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 18:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 target-i386/cpu.c | 6 +++---
 target-i386/cpu.h | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 4090152..86d7a61 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1106,13 +1106,13 @@ static char *x86_cpuid_get_vendor(Object *obj, Error **errp)
     char *value;
     int i;
 
-    value = (char *)g_malloc(12 + 1);
+    value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
     for (i = 0; i < 4; i++) {
         value[i    ] = env->cpuid_vendor1 >> (8 * i);
         value[i + 4] = env->cpuid_vendor2 >> (8 * i);
         value[i + 8] = env->cpuid_vendor3 >> (8 * i);
     }
-    value[12] = '\0';
+    value[CPUID_VENDOR_SZ] = '\0';
     return value;
 }
 
@@ -1123,7 +1123,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value,
     CPUX86State *env = &cpu->env;
     int i;
 
-    if (strlen(value) != 12) {
+    if (strlen(value) != CPUID_VENDOR_SZ) {
         error_set(errp, QERR_PROPERTY_VALUE_BAD, "",
                   "vendor", value);
         return;
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 90ef1ff..386c4f6 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -510,6 +510,8 @@
 #define CPUID_7_0_EBX_ADX      (1 << 19)
 #define CPUID_7_0_EBX_SMAP     (1 << 20)
 
+#define CPUID_VENDOR_SZ      12
+
 #define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */
 #define CPUID_VENDOR_INTEL_2 0x49656e69 /* "ineI" */
 #define CPUID_VENDOR_INTEL_3 0x6c65746e /* "ntel" */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time
  2012-12-04 18:58 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v2) Eduardo Habkost
                   ` (2 preceding siblings ...)
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size Eduardo Habkost
@ 2012-12-04 18:58 ` Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value Eduardo Habkost
  5 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 18:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

From: Igor Mammedov <imammedo@redhat.com>

delay capping cpuid_level to 7 to realize time so property setters
for cpuid_7_0_ebx_features and "level" could be used in any order/time
between x86_cpu_initfn() and x86_cpu_realize().

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 target-i386/cpu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 86d7a61..a56a130 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1381,9 +1381,6 @@ static int cpu_x86_parse_featurestr(x86_def_t *x86_cpu_def, char *features)
         if (kvm_check_features_against_host(x86_cpu_def) && enforce_cpuid)
             goto error;
     }
-    if (x86_cpu_def->cpuid_7_0_ebx_features && x86_cpu_def->level < 7) {
-        x86_cpu_def->level = 7;
-    }
     return 0;
 
 error:
@@ -2074,6 +2071,11 @@ static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
 void x86_cpu_realize(Object *obj, Error **errp)
 {
     X86CPU *cpu = X86_CPU(obj);
+    CPUX86State *env = &cpu->env;
+
+    if (env->cpuid_7_0_ebx_features && env->cpuid_level < 7) {
+        env->cpuid_level = 7;
+    }
 
 #ifndef CONFIG_USER_ONLY
     qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
  2012-12-04 18:58 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v2) Eduardo Habkost
                   ` (3 preceding siblings ...)
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time Eduardo Habkost
@ 2012-12-04 18:58 ` Eduardo Habkost
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value Eduardo Habkost
  5 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 18:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Andreas Färber <afaerber@suse.de>
---
 qapi/qapi-visit-core.c      | 11 +++++++++++
 qapi/qapi-visit-core.h      |  2 ++
 qapi/string-input-visitor.c | 22 ++++++++++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 7a82b63..5c8705e 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -311,3 +311,14 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],
     g_free(enum_str);
     *obj = value;
 }
+
+void visit_type_freq(Visitor *v, int64_t *obj, const char *name, Error **errp)
+{
+    if (!error_is_set(errp)) {
+        if (v->type_freq) {
+            v->type_freq(v, obj, name, errp);
+        } else {
+            v->type_int(v, obj, name, errp);
+        }
+    }
+}
diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h
index 60aceda..e5e7dd7 100644
--- a/qapi/qapi-visit-core.h
+++ b/qapi/qapi-visit-core.h
@@ -62,6 +62,7 @@ struct Visitor
     void (*type_int64)(Visitor *v, int64_t *obj, const char *name, Error **errp);
     /* visit_type_size() falls back to (*type_uint64)() if type_size is unset */
     void (*type_size)(Visitor *v, uint64_t *obj, const char *name, Error **errp);
+    void (*type_freq)(Visitor *v, int64_t *obj, const char *name, Error **errp);
 };
 
 void visit_start_handle(Visitor *v, void **obj, const char *kind,
@@ -91,5 +92,6 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp);
+void visit_type_freq(Visitor *v, int64_t *obj, const char *name, Error **errp);
 
 #endif
diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index 497eb9a..74fe395 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present,
     *present = true;
 }
 
+static void parse_type_freq(Visitor *v, int64_t *obj, const char *name,
+                            Error **errp)
+{
+    StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
+    char *endp = (char *) siv->string;
+    long long val = 0;
+
+    errno = 0;
+    if (siv->string) {
+        val = strtosz_suffix_unit(siv->string, &endp,
+                             STRTOSZ_DEFSUFFIX_B, 1000);
+    }
+    if (!siv->string || val == -1 || *endp) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, name,
+              "a value representable as a non-negative int64");
+        return;
+    }
+
+    *obj = val;
+}
+
 Visitor *string_input_get_visitor(StringInputVisitor *v)
 {
     return &v->visitor;
@@ -132,6 +153,7 @@ StringInputVisitor *string_input_visitor_new(const char *str)
     v->visitor.type_str = parse_type_str;
     v->visitor.type_number = parse_type_number;
     v->visitor.start_optional = parse_start_optional;
+    v->visitor.type_freq = parse_type_freq;
 
     v->string = str;
     return v;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value
  2012-12-04 18:58 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v2) Eduardo Habkost
                   ` (4 preceding siblings ...)
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
@ 2012-12-04 18:58 ` Eduardo Habkost
  5 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 18:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
---
 target-i386/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index a56a130..f8ba569 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1195,7 +1195,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,
     const int64_t max = INT64_MAX;
     int64_t value;
 
-    visit_type_int(v, &value, name, errp);
+    visit_type_freq(v, &value, name, errp);
     if (error_is_set(errp)) {
         return;
     }
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup
  2012-12-04 18:58 ` [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup Eduardo Habkost
@ 2012-12-04 19:13   ` Igor Mammedov
  0 siblings, 0 replies; 13+ messages in thread
From: Igor Mammedov @ 2012-12-04 19:13 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Don Slutz, qemu-devel, Andreas Färber

On Tue,  4 Dec 2012 16:58:19 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Instead of using parsing the whole cpu_model string inside
> cpu_x86_find_by_name(), first split it into the CPU model name and the
> full feature string, then parse the feature string into pieces.
> 
> When using CPU model classes, those two pieces of information will be
> used at different moments (CPU model name will be used to find CPU
> class, feature string will be used after CPU object was created), so
> making the split in two steps will make it easier to refactor the code
> later.
> 
> This should also help on the CPU properties work, that will just need to
> replace the cpu_x86_parse_featurestr() logic (and can keep the CPU model
> lookup code as-is).
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Changes v1 -> v2:
>  - Coding style changes
>  - Replace "goto error" with "return -1"
> ---
>  target-i386/cpu.c | 67 +++++++++++++++++++++++++++++++++++++------------------
>  1 file changed, 45 insertions(+), 22 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 7afe839..4090152 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1208,25 +1208,10 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque,
>      cpu->env.tsc_khz = value / 1000;
>  }
>  
> -static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
> +static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
>  {
> -    unsigned int i;
>      x86_def_t *def;
>  
> -    char *s = g_strdup(cpu_model);
> -    char *featurestr, *name = strtok(s, ",");
> -    /* Features to be added*/
> -    uint32_t plus_features = 0, plus_ext_features = 0;
> -    uint32_t plus_ext2_features = 0, plus_ext3_features = 0;
> -    uint32_t plus_kvm_features = kvm_default_features, plus_svm_features = 0;
> -    uint32_t plus_7_0_ebx_features = 0;
> -    /* Features to be removed */
> -    uint32_t minus_features = 0, minus_ext_features = 0;
> -    uint32_t minus_ext2_features = 0, minus_ext3_features = 0;
> -    uint32_t minus_kvm_features = 0, minus_svm_features = 0;
> -    uint32_t minus_7_0_ebx_features = 0;
> -    uint32_t numvalue;
> -
>      for (def = x86_defs; def; def = def->next) {
>          if (name && !strcmp(name, def->name)) {
>              break;
> @@ -1235,16 +1220,37 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
>      if (kvm_enabled() && name && strcmp(name, "host") == 0) {
>          kvm_cpu_fill_host(x86_cpu_def);
>      } else if (!def) {
> -        goto error;
> +        return -1;
>      } else {
>          memcpy(x86_cpu_def, def, sizeof(*def));
>      }
>  
> +    return 0;
> +}
> +
> +/* Parse "+feature,-feature,feature=foo" CPU feature string
> + */
> +static int cpu_x86_parse_featurestr(x86_def_t *x86_cpu_def, char *features)
> +{
> +    unsigned int i;
> +    char *featurestr; /* Single 'key=value" string being parsed */
> +    /* Features to be added*/
> +    uint32_t plus_features = 0, plus_ext_features = 0;
> +    uint32_t plus_ext2_features = 0, plus_ext3_features = 0;
> +    uint32_t plus_kvm_features = kvm_default_features, plus_svm_features = 0;
> +    uint32_t plus_7_0_ebx_features = 0;
> +    /* Features to be removed */
> +    uint32_t minus_features = 0, minus_ext_features = 0;
> +    uint32_t minus_ext2_features = 0, minus_ext3_features = 0;
> +    uint32_t minus_kvm_features = 0, minus_svm_features = 0;
> +    uint32_t minus_7_0_ebx_features = 0;
> +    uint32_t numvalue;
> +
>      add_flagname_to_bitmaps("hypervisor", &plus_features,
>              &plus_ext_features, &plus_ext2_features, &plus_ext3_features,
>              &plus_kvm_features, &plus_svm_features,  &plus_7_0_ebx_features);
>  
> -    featurestr = strtok(NULL, ",");
> +    featurestr = features ? strtok(features, ",") : NULL;
>  
>      while (featurestr) {
>          char *val;
> @@ -1378,11 +1384,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)
>      if (x86_cpu_def->cpuid_7_0_ebx_features && x86_cpu_def->level < 7) {
>          x86_cpu_def->level = 7;
>      }
> -    g_free(s);
>      return 0;
>  
>  error:
> -    g_free(s);
>      return -1;
>  }
>  
> @@ -1492,11 +1496,25 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
>      CPUX86State *env = &cpu->env;
>      x86_def_t def1, *def = &def1;
>      Error *error = NULL;
> +    char *name, *features;
> +    gchar **model_pieces;
>  
>      memset(def, 0, sizeof(*def));
>  
> -    if (cpu_x86_find_by_name(def, cpu_model) < 0)
> -        return -1;
> +    model_pieces = g_strsplit(cpu_model, ",", 2);
> +    if (!model_pieces[0]) {
> +        goto error;
> +    }
> +    name = model_pieces[0];
> +    features = model_pieces[1];
> +
> +    if (cpu_x86_find_by_name(def, name) < 0) {
> +        goto error;
> +    }
> +
> +    if (cpu_x86_parse_featurestr(def, features) < 0) {
> +        goto error;
> +    }
>      if (def->vendor1) {
>          env->cpuid_vendor1 = def->vendor1;
>          env->cpuid_vendor2 = def->vendor2;
> @@ -1555,7 +1573,12 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
>          error_free(error);
model_pieces is leaked,
s/return -1/goto error/

>          return -1;
>      }
> +
> +    g_strfreev(model_pieces);
>      return 0;
> +error:
> +    g_strfreev(model_pieces);
> +    return -1;
>  }
>  
>  #if !defined(CONFIG_USER_ONLY)
> -- 
> 1.7.11.7
> 
> 


-- 
Regards,
  Igor

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
  2012-12-05 11:51       ` Eduardo Habkost
@ 2012-12-05 12:03         ` Igor Mammedov
  0 siblings, 0 replies; 13+ messages in thread
From: Igor Mammedov @ 2012-12-05 12:03 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Don Slutz, Andreas Färber, qemu-devel

On Wed, 5 Dec 2012 09:51:25 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Wed, Dec 05, 2012 at 12:29:06PM +0100, Andreas Färber wrote:
> > Am 04.12.2012 20:38, schrieb Eduardo Habkost:
> > > On Tue, Dec 04, 2012 at 05:34:40PM -0200, Eduardo Habkost wrote:
> > >> From: Igor Mammedov <imammedo@redhat.com>
> > >>
> > >> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > > 
> > > Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
> > 
> > As a reminder, when you submit patches, I need your Sob added.
> > In these particular cases, I can usually search the list for an earlier
> > submission by Igor and take that, but it would be more time-efficient if
> > I could just apply the latest submitted version with Sobs.
> > 
> > If you cherry-pick patches from your colleague's branch, you can use
> > git-cherry-pick's -s option to facilitate this.
> 
> Sorry, I'll do that next time.
> 
> BTW, I cherry-picked the patches from igor's tree directly (after
> discussing with him), so I don't know if all of them have been submitted
> to the list before.
They were submitted in v5 cpu properties series.
Message-Id: <1350918203-25198-7-git-send-email-imammedo@redhat.com>
Message-Id: <1350918203-25198-8-git-send-email-imammedo@redhat.com>
Message-Id: <1350918203-25198-25-git-send-email-imammedo@redhat.com>
Message-Id: <1350918203-25198-15-git-send-email-imammedo@redhat.com>

> 
> For reference, they are:
> https://github.com/imammedo/qemu/commit/b515a509d6e175681bbd85d2833400b1d5368877
> https://github.com/imammedo/qemu/commit/4c9d836d4e6589493c82c21dd9b48ddc244c0a3d
> https://github.com/imammedo/qemu/commit/cf301a2013c99e22cab55f9e840c3885b6130c38
> https://github.com/imammedo/qemu/commit/dc70027e0bd190832527b68579704384fd8b950b
> 
> > 
> > Regards,
> > Andreas
> > 
> > -- 
> > SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> > GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
  2012-12-05 11:29     ` Andreas Färber
@ 2012-12-05 11:51       ` Eduardo Habkost
  2012-12-05 12:03         ` Igor Mammedov
  0 siblings, 1 reply; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-05 11:51 UTC (permalink / raw)
  To: Andreas Färber; +Cc: Igor Mammedov, Don Slutz, qemu-devel

On Wed, Dec 05, 2012 at 12:29:06PM +0100, Andreas Färber wrote:
> Am 04.12.2012 20:38, schrieb Eduardo Habkost:
> > On Tue, Dec 04, 2012 at 05:34:40PM -0200, Eduardo Habkost wrote:
> >> From: Igor Mammedov <imammedo@redhat.com>
> >>
> >> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > 
> > Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
> 
> As a reminder, when you submit patches, I need your Sob added.
> In these particular cases, I can usually search the list for an earlier
> submission by Igor and take that, but it would be more time-efficient if
> I could just apply the latest submitted version with Sobs.
> 
> If you cherry-pick patches from your colleague's branch, you can use
> git-cherry-pick's -s option to facilitate this.

Sorry, I'll do that next time.

BTW, I cherry-picked the patches from igor's tree directly (after
discussing with him), so I don't know if all of them have been submitted
to the list before.

For reference, they are:
https://github.com/imammedo/qemu/commit/b515a509d6e175681bbd85d2833400b1d5368877
https://github.com/imammedo/qemu/commit/4c9d836d4e6589493c82c21dd9b48ddc244c0a3d
https://github.com/imammedo/qemu/commit/cf301a2013c99e22cab55f9e840c3885b6130c38
https://github.com/imammedo/qemu/commit/dc70027e0bd190832527b68579704384fd8b950b

> 
> Regards,
> Andreas
> 
> -- 
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

-- 
Eduardo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
  2012-12-04 19:38   ` Eduardo Habkost
@ 2012-12-05 11:29     ` Andreas Färber
  2012-12-05 11:51       ` Eduardo Habkost
  0 siblings, 1 reply; 13+ messages in thread
From: Andreas Färber @ 2012-12-05 11:29 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Igor Mammedov, Don Slutz, qemu-devel

Am 04.12.2012 20:38, schrieb Eduardo Habkost:
> On Tue, Dec 04, 2012 at 05:34:40PM -0200, Eduardo Habkost wrote:
>> From: Igor Mammedov <imammedo@redhat.com>
>>
>> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> 
> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

As a reminder, when you submit patches, I need your Sob added.
In these particular cases, I can usually search the list for an earlier
submission by Igor and take that, but it would be more time-efficient if
I could just apply the latest submitted version with Sobs.

If you cherry-pick patches from your colleague's branch, you can use
git-cherry-pick's -s option to facilitate this.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size Eduardo Habkost
@ 2012-12-04 19:38   ` Eduardo Habkost
  2012-12-05 11:29     ` Andreas Färber
  0 siblings, 1 reply; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 19:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

On Tue, Dec 04, 2012 at 05:34:40PM -0200, Eduardo Habkost wrote:
> From: Igor Mammedov <imammedo@redhat.com>
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

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

> ---
>  target-i386/cpu.c | 6 +++---
>  target-i386/cpu.h | 2 ++
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 70ba323..05ac79a 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1106,13 +1106,13 @@ static char *x86_cpuid_get_vendor(Object *obj, Error **errp)
>      char *value;
>      int i;
>  
> -    value = (char *)g_malloc(12 + 1);
> +    value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
>      for (i = 0; i < 4; i++) {
>          value[i    ] = env->cpuid_vendor1 >> (8 * i);
>          value[i + 4] = env->cpuid_vendor2 >> (8 * i);
>          value[i + 8] = env->cpuid_vendor3 >> (8 * i);
>      }
> -    value[12] = '\0';
> +    value[CPUID_VENDOR_SZ] = '\0';
>      return value;
>  }
>  
> @@ -1123,7 +1123,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value,
>      CPUX86State *env = &cpu->env;
>      int i;
>  
> -    if (strlen(value) != 12) {
> +    if (strlen(value) != CPUID_VENDOR_SZ) {
>          error_set(errp, QERR_PROPERTY_VALUE_BAD, "",
>                    "vendor", value);
>          return;
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index 90ef1ff..386c4f6 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -510,6 +510,8 @@
>  #define CPUID_7_0_EBX_ADX      (1 << 19)
>  #define CPUID_7_0_EBX_SMAP     (1 << 20)
>  
> +#define CPUID_VENDOR_SZ      12
> +
>  #define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */
>  #define CPUID_VENDOR_INTEL_2 0x49656e69 /* "ineI" */
>  #define CPUID_VENDOR_INTEL_3 0x6c65746e /* "ntel" */
> -- 
> 1.7.11.7
> 
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
  2012-12-04 19:34 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Eduardo Habkost
@ 2012-12-04 19:34 ` Eduardo Habkost
  2012-12-04 19:38   ` Eduardo Habkost
  0 siblings, 1 reply; 13+ messages in thread
From: Eduardo Habkost @ 2012-12-04 19:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 target-i386/cpu.c | 6 +++---
 target-i386/cpu.h | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 70ba323..05ac79a 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1106,13 +1106,13 @@ static char *x86_cpuid_get_vendor(Object *obj, Error **errp)
     char *value;
     int i;
 
-    value = (char *)g_malloc(12 + 1);
+    value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
     for (i = 0; i < 4; i++) {
         value[i    ] = env->cpuid_vendor1 >> (8 * i);
         value[i + 4] = env->cpuid_vendor2 >> (8 * i);
         value[i + 8] = env->cpuid_vendor3 >> (8 * i);
     }
-    value[12] = '\0';
+    value[CPUID_VENDOR_SZ] = '\0';
     return value;
 }
 
@@ -1123,7 +1123,7 @@ static void x86_cpuid_set_vendor(Object *obj, const char *value,
     CPUX86State *env = &cpu->env;
     int i;
 
-    if (strlen(value) != 12) {
+    if (strlen(value) != CPUID_VENDOR_SZ) {
         error_set(errp, QERR_PROPERTY_VALUE_BAD, "",
                   "vendor", value);
         return;
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 90ef1ff..386c4f6 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -510,6 +510,8 @@
 #define CPUID_7_0_EBX_ADX      (1 << 19)
 #define CPUID_7_0_EBX_SMAP     (1 << 20)
 
+#define CPUID_VENDOR_SZ      12
+
 #define CPUID_VENDOR_INTEL_1 0x756e6547 /* "Genu" */
 #define CPUID_VENDOR_INTEL_2 0x49656e69 /* "ineI" */
 #define CPUID_VENDOR_INTEL_3 0x6c65746e /* "ntel" */
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-12-05 12:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-04 18:58 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v2) Eduardo Habkost
2012-12-04 18:58 ` [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
2012-12-04 18:58 ` [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup Eduardo Habkost
2012-12-04 19:13   ` Igor Mammedov
2012-12-04 18:58 ` [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size Eduardo Habkost
2012-12-04 18:58 ` [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time Eduardo Habkost
2012-12-04 18:58 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
2012-12-04 18:58 ` [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value Eduardo Habkost
2012-12-04 19:34 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Eduardo Habkost
2012-12-04 19:34 ` [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size Eduardo Habkost
2012-12-04 19:38   ` Eduardo Habkost
2012-12-05 11:29     ` Andreas Färber
2012-12-05 11:51       ` Eduardo Habkost
2012-12-05 12:03         ` Igor Mammedov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.