qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [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 ` Eduardo Habkost
  0 siblings, 0 replies; 24+ 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] 24+ messages in thread

* [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3)
@ 2012-12-04 19:34 Eduardo Habkost
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
                   ` (6 more replies)
  0 siblings, 7 replies; 24+ 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

Changes v3:
 - Fix memory leak spotted by Igor, on patch 2

Changes 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-v3
  https://github.com/ehabkost/qemu-hacks/tree/cpu-init-cleanup-short-v3

References to previous versions:
 v2: http://marc.info/?l=qemu-devel&m=135464803607329
 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           | 105 ++++++++++++++++++++++++++++----------------
 target-i386/cpu.h           |   2 +
 5 files changed, 103 insertions(+), 39 deletions(-)

-- 
1.7.11.7

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

* [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes
  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:40   ` Igor Mammedov
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup Eduardo Habkost
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 24+ 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

- 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] 24+ messages in thread

* [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup
  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 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
@ 2012-12-04 19:34 ` Eduardo Habkost
  2012-12-04 19:47   ` Igor Mammedov
  2012-12-05 15:58   ` Andreas Färber
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size Eduardo Habkost
                   ` (4 subsequent siblings)
  6 siblings, 2 replies; 24+ 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

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"

Changes v2 -> v3:
 - Fix memory leak on handling of errors form object_property_set_str()
---
 target-i386/cpu.c | 69 ++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 23 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 7afe839..70ba323 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;
@@ -1553,9 +1571,14 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model)
     if (error) {
         fprintf(stderr, "%s\n", error_get_pretty(error));
         error_free(error);
-        return -1;
+        goto error;
     }
+
+    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] 24+ 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 ` [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup Eduardo Habkost
@ 2012-12-04 19:34 ` Eduardo Habkost
  2012-12-04 19:38   ` Eduardo Habkost
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time Eduardo Habkost
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 24+ 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] 24+ messages in thread

* [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time
  2012-12-04 19:34 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Eduardo Habkost
                   ` (2 preceding siblings ...)
  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:34 ` Eduardo Habkost
  2012-12-04 19:36   ` Eduardo Habkost
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 24+ 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>

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 05ac79a..56a5646 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] 24+ messages in thread

* [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
  2012-12-04 19:34 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Eduardo Habkost
                   ` (3 preceding siblings ...)
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time Eduardo Habkost
@ 2012-12-04 19:34 ` Eduardo Habkost
  2012-12-04 19:41   ` Eduardo Habkost
                     ` (2 more replies)
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value Eduardo Habkost
  2012-12-05 16:24 ` [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Andreas Färber
  6 siblings, 3 replies; 24+ 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>
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] 24+ messages in thread

* [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value
  2012-12-04 19:34 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Eduardo Habkost
                   ` (4 preceding siblings ...)
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
@ 2012-12-04 19:34 ` Eduardo Habkost
  2012-12-04 19:55   ` Eduardo Habkost
  2012-12-05 16:24 ` [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Andreas Färber
  6 siblings, 1 reply; 24+ 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>
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 56a5646..5d11180 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] 24+ messages in thread

* Re: [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time Eduardo Habkost
@ 2012-12-04 19:36   ` Eduardo Habkost
  0 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-04 19:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

On Tue, Dec 04, 2012 at 05:34:41PM -0200, Eduardo Habkost wrote:
> 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>

Reviewed-by: Eduardo Habkost <ehabkost@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 05ac79a..56a5646 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
> 
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 24+ 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; 24+ 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] 24+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
@ 2012-12-04 19:40   ` Igor Mammedov
  0 siblings, 0 replies; 24+ messages in thread
From: Igor Mammedov @ 2012-12-04 19:40 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Don Slutz, qemu-devel, Andreas Färber

On Tue,  4 Dec 2012 17:34:38 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> - 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
> 
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

-- 
Regards,
  Igor

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

* Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
@ 2012-12-04 19:41   ` Eduardo Habkost
  2012-12-04 23:43   ` Andreas Färber
  2012-12-05 17:52   ` mdroth
  2 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-04 19:41 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote:
> From: Igor Mammedov <imammedo@redhat.com>
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> Acked-by: Andreas Färber <afaerber@suse.de>

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


> ---
>  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
> 
> 

-- 
Eduardo

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

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

On Tue,  4 Dec 2012 17:34:39 -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"
> 
> Changes v2 -> v3:
>  - Fix memory leak on handling of errors form object_property_set_str()
> ---
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

-- 
Regards,
  Igor

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

* Re: [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value Eduardo Habkost
@ 2012-12-04 19:55   ` Eduardo Habkost
  0 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-04 19:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Don Slutz, Andreas Färber

On Tue, Dec 04, 2012 at 05:34:43PM -0200, Eduardo Habkost wrote:
> From: Igor Mammedov <imammedo@redhat.com>
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> Reviewed-by: Andreas Färber <afaerber@suse.de>

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

> ---
>  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 56a5646..5d11180 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
> 
> 
> 
> 

-- 
Eduardo

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

* Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
  2012-12-04 19:41   ` Eduardo Habkost
@ 2012-12-04 23:43   ` Andreas Färber
  2012-12-05 17:52   ` mdroth
  2 siblings, 0 replies; 24+ messages in thread
From: Andreas Färber @ 2012-12-04 23:43 UTC (permalink / raw)
  To: Michael Roth; +Cc: Igor Mammedov, Don Slutz, Eduardo Habkost, qemu-devel

Am 04.12.2012 20:34, schrieb Eduardo Habkost:
> From: Igor Mammedov <imammedo@redhat.com>
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> Acked-by: Andreas Färber <afaerber@suse.de>

Mike, do we need to do anything here wrt deallocation visitors?
Or can you ack?

Thanks,
Andreas

> ---
>  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;
> 


-- 
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] 24+ 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; 24+ 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] 24+ 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; 24+ 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] 24+ 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; 24+ 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] 24+ messages in thread

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

Am 04.12.2012 20:34, schrieb Eduardo Habkost:
> Instead of using parsing the whole cpu_model string inside

Dropped "using".

> 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.
[...]
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 7afe839..70ba323 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*/
[...]
> @@ -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*/

I took the liberty of adding a space above by editing patches 1 & 2.

Also, in Linux, multi-level topics such as "PPC: KVM: " seem to be
common, whereas in QEMU we've been using paths ("tcg/ppc: "); Anthony
has once used "isa: pic: " when he meant affecting both isa and pic
(8f04ee0882aec9fe91fb70f767edf5dacff59835), so since this does not touch
on the QOM cpu.c that I usually label "cpu: ", in a previous case I have
edited your patch as "target-i386/cpu: ", but since this subject
redundantly mentions CPU later on I'm dropping it. Hope this explains
the rationale! Generally I found the GNOME guidelines pretty convincing:
https://live.gnome.org/Git/CommitMessages
(capitalizing after the lowercase topic makes the main message stand out
when reading through shortlogs IMO)

Thanks, applied patches 1-2 to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

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] 24+ messages in thread

* Re: [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3)
  2012-12-04 19:34 [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Eduardo Habkost
                   ` (5 preceding siblings ...)
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value Eduardo Habkost
@ 2012-12-05 16:24 ` Andreas Färber
  6 siblings, 0 replies; 24+ messages in thread
From: Andreas Färber @ 2012-12-05 16:24 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Igor Mammedov, Don Slutz, qemu-devel, Michael Roth

Am 04.12.2012 20:34, schrieb Eduardo Habkost:
> Igor Mammedov (4):
>   target-i386: use define for cpuid vendor string size
>   target-i386: postpone cpuid_level update to realize time

Applied Igor's earlier signed off versions of these to qom-cpu, spotting
no semantic difference:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Still waiting on an ack for the new freq visitor.

Andreas

>   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           | 105 ++++++++++++++++++++++++++++----------------
>  target-i386/cpu.h           |   2 +
>  5 files changed, 103 insertions(+), 39 deletions(-)

-- 
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] 24+ messages in thread

* Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
  2012-12-04 19:34 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
  2012-12-04 19:41   ` Eduardo Habkost
  2012-12-04 23:43   ` Andreas Färber
@ 2012-12-05 17:52   ` mdroth
  2012-12-05 19:21     ` Eduardo Habkost
  2 siblings, 1 reply; 24+ messages in thread
From: mdroth @ 2012-12-05 17:52 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Igor Mammedov, Don Slutz, qemu-devel, Andreas Färber

On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote:
> 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 this is for strtosz_suffix_unit(), it looks like this is already
handled internally and can be dropped. Relic from a previous version
that called strtod() directly maybe?

If that's not the case, I think it should be fixed in the called function[s]
rather than for each caller.

> +    if (siv->string) {
> +        val = strtosz_suffix_unit(siv->string, &endp,
> +                             STRTOSZ_DEFSUFFIX_B, 1000);

Specifying 1000 as the unit size will make "1M" == 1000^2 as opposed to
1024^2. Is this intentional?

> +    }
> +    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;

This seems applicable for stuff like -m 1G and potentionally some other
properties. We can make it generic later, but if we do end up re-spinning
consider something like ->type_unit_suffixed_int(). But I'm not against
leaving as is for now since I can't think of a better name for it atm :)

Whatever we call it, based on a recent discussion here:

http://lists.gnu.org/archive/html/qemu-devel/2012-11/msg02872.html

we should have a corresponding implementation in qapi-dealloc-visitor.c.
In this case You can just do:

v->visitor.type_freq = qapi_dealloc_type_int;

There aren't any problems in the current code, we just want to avoid relying on
fallbacks for the dealloc case in general because in some situations the
underlying sizes of the C types don't match and this can cause problems down
the road for the dealloc visitor even though it's okay for other visitor
implementations.

>  
>      v->string = str;
>      return v;
> -- 
> 1.7.11.7
> 
> 

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

* Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
  2012-12-05 17:52   ` mdroth
@ 2012-12-05 19:21     ` Eduardo Habkost
  2012-12-05 21:00       ` mdroth
  0 siblings, 1 reply; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-05 19:21 UTC (permalink / raw)
  To: mdroth; +Cc: Igor Mammedov, Don Slutz, qemu-devel, Andreas Färber

On Wed, Dec 05, 2012 at 11:52:29AM -0600, mdroth wrote:
> On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote:
[...]
> > 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 this is for strtosz_suffix_unit(), it looks like this is already
> handled internally and can be dropped. Relic from a previous version
> that called strtod() directly maybe?
> 
> If that's not the case, I think it should be fixed in the called function[s]
> rather than for each caller.
> 
> > +    if (siv->string) {
> > +        val = strtosz_suffix_unit(siv->string, &endp,
> > +                             STRTOSZ_DEFSUFFIX_B, 1000);
> 
> Specifying 1000 as the unit size will make "1M" == 1000^2 as opposed to
> 1024^2. Is this intentional?

I don't know if this is a good idea for a generalx-use visitor, but this is the
current behavior of "-cpu ...,tsc_freq=1M", that we need to keep for
compatibility, somehow.

> 
> > +    }
> > +    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;
> 
> This seems applicable for stuff like -m 1G and potentionally some other
> properties. We can make it generic later, but if we do end up re-spinning
> consider something like ->type_unit_suffixed_int(). But I'm not against
> leaving as is for now since I can't think of a better name for it atm :)

I thought the visitor was going to support things like "1GHz", but if it's just
a "suffixed int" with no unit, the name could be changed, I guess.

But we still have the 1000 vs 1024 problem. On the one hand, it would be
interesting to make make it consistent and use the same base everywhere.
On the other hand, I assume we have different command-line options using
different bases and we'll need to keep compatibility.

Must all visitor functions have the
"function(Visitor *v, obj, const char *name, Error **errp)" signature,
or can we add additional type-specific arguments? (so we could tell
the visitor if the default base should be 1000 or 1024)

-- 
Eduardo

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

* Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
  2012-12-05 19:21     ` Eduardo Habkost
@ 2012-12-05 21:00       ` mdroth
  2012-12-06 20:49         ` Igor Mammedov
  0 siblings, 1 reply; 24+ messages in thread
From: mdroth @ 2012-12-05 21:00 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: Igor Mammedov, Don Slutz, qemu-devel, Andreas Färber

On Wed, Dec 05, 2012 at 05:21:50PM -0200, Eduardo Habkost wrote:
> On Wed, Dec 05, 2012 at 11:52:29AM -0600, mdroth wrote:
> > On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote:
> [...]
> > > 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 this is for strtosz_suffix_unit(), it looks like this is already
> > handled internally and can be dropped. Relic from a previous version
> > that called strtod() directly maybe?
> > 
> > If that's not the case, I think it should be fixed in the called function[s]
> > rather than for each caller.
> > 
> > > +    if (siv->string) {
> > > +        val = strtosz_suffix_unit(siv->string, &endp,
> > > +                             STRTOSZ_DEFSUFFIX_B, 1000);
> > 
> > Specifying 1000 as the unit size will make "1M" == 1000^2 as opposed to
> > 1024^2. Is this intentional?
> 
> I don't know if this is a good idea for a generalx-use visitor, but this is the
> current behavior of "-cpu ...,tsc_freq=1M", that we need to keep for
> compatibility, somehow.
> 
> > 
> > > +    }
> > > +    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;
> > 
> > This seems applicable for stuff like -m 1G and potentionally some other
> > properties. We can make it generic later, but if we do end up re-spinning
> > consider something like ->type_unit_suffixed_int(). But I'm not against
> > leaving as is for now since I can't think of a better name for it atm :)
> 
> I thought the visitor was going to support things like "1GHz", but if it's just
> a "suffixed int" with no unit, the name could be changed, I guess.
> 
> But we still have the 1000 vs 1024 problem. On the one hand, it would be
> interesting to make make it consistent and use the same base everywhere.
> On the other hand, I assume we have different command-line options using
> different bases and we'll need to keep compatibility.

If we were to map it to a QAPI schema definition at some point, I'd
imagine it looking something like:

{ 'field_name': { 'type': 'suffixed_int', 'unit': 1000 } }

with 'unit' defaulting to 1024 if unspecified. (I have some patches
floating around as part of the QIDL series for doing more descriptive
QAPI definitions) 

> 
> Must all visitor functions have the
> "function(Visitor *v, obj, const char *name, Error **errp)" signature,
> or can we add additional type-specific arguments? (so we could tell
> the visitor if the default base should be 1000 or 1024)

Visitor functions don't necessarilly have to follow the same basic
signature, so it would be okay to declare it with an extra 'unit' param
and pass that in. We could still hide this behind a visit_type_freq()
wrapper in open-coded visitors as well, I'd just prefer to make the bits
we add to qapi-visit-core.c more general where possible to keep unit
tests and code generation stuff somewhat sane for the core api.

> 
> -- 
> Eduardo
> 

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

* Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
  2012-12-05 21:00       ` mdroth
@ 2012-12-06 20:49         ` Igor Mammedov
  0 siblings, 0 replies; 24+ messages in thread
From: Igor Mammedov @ 2012-12-06 20:49 UTC (permalink / raw)
  To: mdroth; +Cc: Don Slutz, Eduardo Habkost, Andreas Färber, qemu-devel

On Wed, 5 Dec 2012 15:00:59 -0600
mdroth <mdroth@linux.vnet.ibm.com> wrote:

> On Wed, Dec 05, 2012 at 05:21:50PM -0200, Eduardo Habkost wrote:
> > On Wed, Dec 05, 2012 at 11:52:29AM -0600, mdroth wrote:
> > > On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote:
> > [...]
> > > > 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 this is for strtosz_suffix_unit(), it looks like this is already
> > > handled internally and can be dropped. Relic from a previous version
> > > that called strtod() directly maybe?
> > > 
> > > If that's not the case, I think it should be fixed in the called function[s]
> > > rather than for each caller.
> > > 
> > > > +    if (siv->string) {
> > > > +        val = strtosz_suffix_unit(siv->string, &endp,
> > > > +                             STRTOSZ_DEFSUFFIX_B, 1000);
> > > 
> > > Specifying 1000 as the unit size will make "1M" == 1000^2 as opposed to
> > > 1024^2. Is this intentional?
> > 
> > I don't know if this is a good idea for a generalx-use visitor, but this is the
> > current behavior of "-cpu ...,tsc_freq=1M", that we need to keep for
> > compatibility, somehow.
> > 
> > > 
> > > > +    }
> > > > +    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;
> > > 
> > > This seems applicable for stuff like -m 1G and potentionally some other
> > > properties. We can make it generic later, but if we do end up re-spinning
> > > consider something like ->type_unit_suffixed_int(). But I'm not against
> > > leaving as is for now since I can't think of a better name for it atm :)
> > 
> > I thought the visitor was going to support things like "1GHz", but if it's just
> > a "suffixed int" with no unit, the name could be changed, I guess.
> > 
> > But we still have the 1000 vs 1024 problem. On the one hand, it would be
> > interesting to make make it consistent and use the same base everywhere.
> > On the other hand, I assume we have different command-line options using
> > different bases and we'll need to keep compatibility.
> 
> If we were to map it to a QAPI schema definition at some point, I'd
> imagine it looking something like:
> 
> { 'field_name': { 'type': 'suffixed_int', 'unit': 1000 } }
> 
> with 'unit' defaulting to 1024 if unspecified. (I have some patches
> floating around as part of the QIDL series for doing more descriptive
> QAPI definitions) 
> 
> > 
> > Must all visitor functions have the
> > "function(Visitor *v, obj, const char *name, Error **errp)" signature,
> > or can we add additional type-specific arguments? (so we could tell
> > the visitor if the default base should be 1000 or 1024)
> 
> Visitor functions don't necessarilly have to follow the same basic
> signature, so it would be okay to declare it with an extra 'unit' param
> and pass that in. We could still hide this behind a visit_type_freq()
> wrapper in open-coded visitors as well, I'd just prefer to make the bits
> we add to qapi-visit-core.c more general where possible to keep unit
> tests and code generation stuff somewhat sane for the core api.
Lets try to do it this way and if people don't like idea fall back to fixed
type_freq. I'll post patches in a momment

> 
> > 
> > -- 
> > Eduardo
> > 


-- 
Regards,
  Igor

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

end of thread, other threads:[~2012-12-06 20:50 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 1/6] target-i386/cpu.c: coding style fixes Eduardo Habkost
2012-12-04 19:40   ` Igor Mammedov
2012-12-04 19:34 ` [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup Eduardo Habkost
2012-12-04 19:47   ` Igor Mammedov
2012-12-05 15:58   ` Andreas Färber
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
2012-12-04 19:34 ` [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time Eduardo Habkost
2012-12-04 19:36   ` Eduardo Habkost
2012-12-04 19:34 ` [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string Eduardo Habkost
2012-12-04 19:41   ` Eduardo Habkost
2012-12-04 23:43   ` Andreas Färber
2012-12-05 17:52   ` mdroth
2012-12-05 19:21     ` Eduardo Habkost
2012-12-05 21:00       ` mdroth
2012-12-06 20:49         ` Igor Mammedov
2012-12-04 19:34 ` [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value Eduardo Habkost
2012-12-04 19:55   ` Eduardo Habkost
2012-12-05 16:24 ` [Qemu-devel] [PATCH 0/6] short x86 CPU init cleanup (v3) Andreas Färber
  -- strict thread matches above, loose matches on Subject: below --
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 3/6] target-i386: use define for cpuid vendor string size Eduardo Habkost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).