Patchwork [02/10] target-i386: cpu: convert existing dynamic properties into static properties

login
register
mail settings
Submitter Andreas Färber
Date April 26, 2013, 4:20 p.m.
Message ID <517AA94D.5080104@suse.de>
Download mbox | patch
Permalink /patch/239887/
State New
Headers show

Comments

Andreas Färber - April 26, 2013, 4:20 p.m.
Am 25.02.2013 02:03, schrieb Igor Mammedov:
> Following properties are converted:
>     * vendor
>     * xlevel
>         * custom setter/getter replaced by qdev's DEFINE_PROP_UINT32
>     * level
>         * custom setter/getter replaced by qdev's DEFINE_PROP_UINT32
>     * tsc-frequency
>     * stepping
>     * model
>     * family
>     * model-id
>         * check "if (model_id == NULL)" looks unnecessary now, since all
>         builtin model-ids are not NULL and user shouldn't be able to set
>         it NULL (cpumodel string parsing code takes care of it, if feature
>         is specified as "model-id=" on command line, its parsing will
>         result in an empty string as value).
> 
> Common changes to all properties:
>     * string properties: changed function signature to conform to form used in
>       qdev-properties.c
> 
> * extra change is addition of feat2prop() helper to deal with properties
>   naming using '-' instead of '_'. Used in this patch for 'model_id' name
>   conversion and converting along the way 'hv-spinlocks', but will be
>   reused in following patches for "hv_*" and +-foo conversions as well.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> v2:
>   - removed s/error_set/error_setg/;s/QERR*/with similar message/
>   - made PropertyInfo static
>   - Left setters/getters atwher they have been, only signature change
>     + usin visitors where needed
>   - use g_malloc0() instead of g_malloc() in x86_cpuid_get_model_id()
> ---
>  target-i386/cpu.c |  174 ++++++++++++++++++++++++++++++++---------------------
>  1 files changed, 105 insertions(+), 69 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index dfcf86e..5626931 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
[...]
> @@ -1297,6 +1345,17 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *name)
>      return -1;
>  }
>  
> +/* It converts all '_' in a feature string option name to '-', to make
> + * feature name to conform property naming rule which uses '-' instead of '_'
> + */
> +static inline void feat2prop(char *s)
> +{
> +    char *delimiter = strchr(s, '=');
> +    while ((s = strchr(s, '_')) && ((delimiter == NULL) || (s < delimiter))) {
> +        *s = '-';
> +    }
> +}
> +
>  /* Parse "+feature,-feature,feature=foo" CPU feature string
>   */
>  static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
> @@ -1318,6 +1377,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
>          } else if (featurestr[0] == '-') {
>              add_flagname_to_bitmaps(featurestr + 1, minus_features);
>          } else if ((val = strchr(featurestr, '='))) {
> +            feat2prop(featurestr);
>              *val = 0; val++;
>              if (!strcmp(featurestr, "family")) {
>                  object_property_parse(OBJECT(cpu), val, featurestr, errp);
> @@ -1345,9 +1405,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
>                  object_property_parse(OBJECT(cpu), num, featurestr, errp);
>              } else if (!strcmp(featurestr, "vendor")) {
>                  object_property_parse(OBJECT(cpu), val, featurestr, errp);
> -            } else if (!strcmp(featurestr, "model_id")) {
> -                object_property_parse(OBJECT(cpu), val, "model-id", errp);
> -            } else if (!strcmp(featurestr, "tsc_freq")) {
> +            } else if (!strcmp(featurestr, "model-id")) {
> +                object_property_parse(OBJECT(cpu), val, featurestr, errp);
> +            } else if (!strcmp(featurestr, "tsc-freq")) {
>                  int64_t tsc_freq;
>                  char *err;
>                  char num[32];
> @@ -1360,7 +1420,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error **errp)
>                  }
>                  snprintf(num, sizeof(num), "%" PRId64, tsc_freq);
>                  object_property_parse(OBJECT(cpu), num, "tsc-frequency", errp);
> -            } else if (!strcmp(featurestr, "hv_spinlocks")) {
> +            } else if (!strcmp(featurestr, "hv-spinlocks")) {
>                  char *err;
>                  numvalue = strtoul(val, &err, 0);
>                  if (!*val || *err) {
[snip]

Thanks, split this part off and applied to qom-cpu (modified as below):

https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

  */
 static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error
**errp)
@@ -1329,6 +1339,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,
char *fe
atures, Error **errp)
             add_flagname_to_bitmaps(featurestr + 1, minus_features);
         } else if ((val = strchr(featurestr, '='))) {
             *val = 0; val++;
+            feat2prop(featurestr);
             if (!strcmp(featurestr, "family")) {
                 object_property_parse(OBJECT(cpu), val, featurestr, errp);
             } else if (!strcmp(featurestr, "model")) {
@@ -1355,9 +1366,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,
char *fe
atures, Error **errp)
                 object_property_parse(OBJECT(cpu), num, featurestr, errp);
             } else if (!strcmp(featurestr, "vendor")) {
                 object_property_parse(OBJECT(cpu), val, featurestr, errp);
-            } else if (!strcmp(featurestr, "model_id")) {
-                object_property_parse(OBJECT(cpu), val, "model-id", errp);
-            } else if (!strcmp(featurestr, "tsc_freq")) {
+            } else if (!strcmp(featurestr, "model-id")) {
+                object_property_parse(OBJECT(cpu), val, featurestr, errp);
+            } else if (!strcmp(featurestr, "tsc-freq")) {
                 int64_t tsc_freq;
                 char *err;
                 char num[32];
@@ -1370,7 +1381,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,
char *features, Error **errp)
                 }
                 snprintf(num, sizeof(num), "%" PRId64, tsc_freq);
                 object_property_parse(OBJECT(cpu), num,
"tsc-frequency", errp);
-            } else if (!strcmp(featurestr, "hv_spinlocks")) {
+            } else if (!strcmp(featurestr, "hv-spinlocks")) {
                 char *err;
                 numvalue = strtoul(val, &err, 0);
                 if (!*val || *err) {

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index f34ba23..697848d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1307,6 +1307,16 @@  static int cpu_x86_find_by_name(x86_def_t
*x86_cpu_def, c
onst char *name)
     return -1;
 }

+/* Convert all '_' in a feature string option name to '-', to make feature
+ * name conform to QOM property naming rule, which uses '-' instead of '_'.
+ */
+static inline void feat2prop(char *s)
+{
+    while ((s = strchr(s, '_'))) {
+        *s = '-';
+    }
+}
+
 /* Parse "+feature,-feature,feature=foo" CPU feature string