short x86 CPU init cleanup (v3)
cover short x86 CPU init cleanup (v3)
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(-)
Signature · 1 line
1.7.11.7
PATCH 1/6 target-i386/cpu.c: coding style fixes
- Use spaces instead of tabs on cpu_x86_cpuid().
- Use braces on 'if' statement cpu_x86_find_by_name().
--- target-i386/cpu.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
target-i386/cpu.c +15 -13
@@ -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;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 1/6] target-i386/cpu.c: coding style fixes
Quoted 58 lines · On Tue, 4 Dec 2012 17:34:38 -0200 Eduardo Habkost <[email protected]> wrote:
- Use spaces instead of tabs on
cpu_x86_cpuid().
- Use braces on 'if' statementcpu_x86_find_by_name().Signed-off-by Eduardo Habkost <[email protected]>--- target-i386/cpu.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)target-i386/cpu.c +15
-13@@ -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;Signature · 1 line
1.7.11.7
Signature · 2 lines
Regards, Igor
PATCH 2/6 target-i386: cpu: separate feature string parsing from CPU model lookup
In reply to Eduardo HabkostInstead 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).
---
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(-)
target-i386/cpu.c +46 -23
@@ -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 )
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup
Quoted 15 lines · On Tue, 4 Dec 2012 17:34:39 -0200 Eduardo Habkost <[email protected]> wrote:
Instead of using parsing the whole
cpu_modelstring insidecpu_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 <[email protected]>
Quoted 8 lines
---
Changes v1 -> v2:
- Coding style changes
- Replace "goto error" with "return -1"Changes v2 -> v3:
- Fix memory leak on handling of errors formobject_property_set_str()
---
Signature · 2 lines
Regards, Igor
Andreas Färber
AppliedRe: [Qemu-devel] [PATCH 2/6] target-i386: cpu: separate feature string parsing from CPU model lookup
In reply to Eduardo HabkostAm 04.12.2012 20:34, schrieb Eduardo Habkost:
Quoted 1 line
Instead of using parsing the whole
cpu_modelstring inside
Dropped "using".
Quoted 2 lines
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.
[...]
Quoted 17 lines
target-i386/cpu.c +1
-5@@ -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*/
[...]
Quoted 10 lines
target-i386/cpu.c +1
-1@@ -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)); }
target-i386/cpu.c static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) · line 1237
Quoted 10 lines
target-i386/cpu.c +10
-0+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
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH 3/6 target-i386: use define for cpuid vendor string size
In reply to Eduardo HabkostFrom: Igor Mammedov <[email protected]>
--- target-i386/cpu.c | 6 +++--- target-i386/cpu.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)
target-i386/cpu.c +3 -3
@@ -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 ;
target-i386/cpu.h +2 -0
@@ -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" */
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
Quoted 3 lines · Eduardo Habkost
From: Igor Mammedov <[email protected]>
Signed-off-by Igor Mammedov <[email protected]>
Quoted 51 lines
--- target-i386/cpu.c | 6 +++--- target-i386/cpu.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)target-i386/cpu.c +3
-3@@ -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 ;target-i386/cpu.h +2
-0@@ -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" */ Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
Am 04.12.2012 20:38, schrieb Eduardo Habkost:
Quoted 6 lines · Eduardo Habkost
Quoted 3 lines
From: Igor Mammedov <[email protected]>
Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>
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
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
Quoted 8 lines · Andreas Färber
Am 04.12.2012 20:38, schrieb Eduardo Habkost:
Quoted 6 lines · Eduardo Habkost
Quoted 3 lines
From: Igor Mammedov <[email protected]>
Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>
Quoted 7 lines
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
Quoted 7 lines
Regards,
AndreasSignature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 3/6] target-i386: use define for cpuid vendor string size
Quoted 14 lines · On Wed, 5 Dec 2012 09:51:25 -0200 Eduardo Habkost <[email protected]> wrote:
Quoted 13 lines · Andreas Färber
Am 04.12.2012 20:38, schrieb Eduardo Habkost:
Quoted 6 lines · Eduardo Habkost
Quoted 3 lines
From: Igor Mammedov <[email protected]>
Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>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.
Quoted 8 lines
Quoted 2 lines
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: <[email protected]>
Message-Id: <[email protected]>
Message-Id: <[email protected]>
Message-Id: <[email protected]>
Quoted 15 lines
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/dc70027e0bd190832527b68579704384fd8b950bQuoted 7 lines
Regards,
AndreasSignature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH 4/6 target-i386: postpone cpuid_level update to realize time
In reply to Eduardo HabkostFrom: Igor Mammedov <[email protected]>
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().
--- target-i386/cpu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
target-i386/cpu.c +5 -3
@@ -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);
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 4/6] target-i386: postpone cpuid_level update to realize time
Quoted 7 lines · Eduardo Habkost
From: Igor Mammedov <[email protected]>
delay capping
cpuid_levelto 7 to realize time so property setters forcpuid_7_0_ebx_featuresand "level" could be used in any order/time betweenx86_cpu_initfn()andx86_cpu_realize().Signed-off-by Igor Mammedov <[email protected]>
Quoted 34 lines
--- target-i386/cpu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)target-i386/cpu.c +5
-3@@ -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);Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
PATCH 5/6 add visitor for parsing hz[KMG] input string
In reply to Eduardo HabkostFrom: Igor Mammedov <[email protected]>
--- qapi/qapi-visit-core.c | 11 +++++++++++ qapi/qapi-visit-core.h | 2 ++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+)
qapi/qapi-visit-core.c +11 -0
@@ -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); + } + } +}
qapi/qapi-visit-core.h +2 -0
@@ -62,6 +62,7 @@ struct Visitorvoid (*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
qapi/string-input-visitor.c +22 -0
@@ -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;
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
Quoted 4 lines · Eduardo Habkost
From: Igor Mammedov <[email protected]>
Signed-off-by Igor Mammedov <[email protected]>Acked-by Andreas Färber <[email protected]>
Quoted 88 lines
--- qapi/qapi-visit-core.c | 11 +++++++++++ qapi/qapi-visit-core.h | 2 ++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+)qapi/qapi-visit-core.c +11
-0@@ -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); + } + } +}qapi/qapi-visit-core.h +2
-0@@ -62,6 +62,7 @@ struct Visitorvoid (*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 qapi/string-input-visitor.c +22
-0@@ -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;Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
In reply to Eduardo HabkostAm 04.12.2012 20:34, schrieb Eduardo Habkost:
Quoted 4 lines
From: Igor Mammedov <[email protected]>
Signed-off-by Igor Mammedov <[email protected]>Acked-by Andreas Färber <[email protected]>
Mike, do we need to do anything here wrt deallocation visitors? Or can you ack?
Thanks,
Andreas
Quoted 85 lines
--- qapi/qapi-visit-core.c | 11 +++++++++++ qapi/qapi-visit-core.h | 2 ++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+)qapi/qapi-visit-core.c +11
-0@@ -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); + } + } +}qapi/qapi-visit-core.h +2
-0@@ -62,6 +62,7 @@ struct Visitorvoid (*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 qapi/string-input-visitor.c +22
-0@@ -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;
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
In reply to Eduardo HabkostQuoted 54 lines · Eduardo Habkost
From: Igor Mammedov <[email protected]>
Signed-off-by Igor Mammedov <[email protected]>Acked-by Andreas Färber <[email protected]>--- qapi/qapi-visit-core.c | 11 +++++++++++ qapi/qapi-visit-core.h | 2 ++ qapi/string-input-visitor.c | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+)qapi/qapi-visit-core.c +11
-0@@ -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); + } + } +}qapi/qapi-visit-core.h +2
-0@@ -62,6 +62,7 @@ struct Visitorvoid (*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 qapi/string-input-visitor.c +0
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true;
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 120
Quoted 10 lines
qapi/string-input-visitor.c +8
-0} +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.
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 123
Quoted 3 lines
qapi/string-input-visitor.c +3
-0+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?
Quoted 14 lines
qapi/string-input-visitor.c +10
-0+ } +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;
qapi/string-input-visitor.c StringInputVisitor *string_input_visitor_new(const char *str) · line 156
Quoted 4 lines
qapi/string-input-visitor.c +1
-0@@ -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.
Quoted 7 lines
qapi/string-input-visitor.c +0
-0v->string = str;return v;Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
Quoted 1 line · mdroth
On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote:
[...]
Quoted 24 lines
Quoted 6 lines
qapi/string-input-visitor.c +0
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true;qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 120
Quoted 10 lines
qapi/string-input-visitor.c +8
-0} +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 calledstrtod()directly maybe?If that's not the case, I think it should be fixed in the called function[s] rather than for each caller.
Quoted 6 lines
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 123
Quoted 3 lines
qapi/string-input-visitor.c +3
-0+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.
Quoted 16 lines
Quoted 16 lines
qapi/string-input-visitor.c +10
-0+ } +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;
Quoted 8 lines
qapi/string-input-visitor.c StringInputVisitor *string_input_visitor_new(const char *str) · line 156
Quoted 3 lines
qapi/string-input-visitor.c +1
-0v->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)
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
Quoted 63 lines · Eduardo Habkost
Quoted 1 line · mdroth
On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote:
[...]
Quoted 24 lines
Quoted 6 lines
qapi/string-input-visitor.c +0
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true;qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 120
Quoted 10 lines
qapi/string-input-visitor.c +8
-0} +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 calledstrtod()directly maybe?If that's not the case, I think it should be fixed in the called function[s] rather than for each caller.
Quoted 6 lines
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 123
Quoted 3 lines
qapi/string-input-visitor.c +3
-0+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.
Quoted 16 lines
Quoted 16 lines
qapi/string-input-visitor.c +10
-0+ } +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;Quoted 8 lines
qapi/string-input-visitor.c StringInputVisitor *string_input_visitor_new(const char *str) · line 156
Quoted 3 lines
qapi/string-input-visitor.c +1
-0v->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 :)
Quoted 7 lines
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)
Quoted 5 lines
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.
Quoted 4 lines
Signature · 2 lines
-- Eduardo
Re: [Qemu-devel] [PATCH 5/6] add visitor for parsing hz[KMG] input string
Quoted 87 lines · On Wed, 5 Dec 2012 15:00:59 -0600 mdroth <[email protected]> wrote:
Quoted 63 lines · Eduardo Habkost
Quoted 1 line · mdroth
On Tue, Dec 04, 2012 at 05:34:42PM -0200, Eduardo Habkost wrote:
[...]
Quoted 24 lines
Quoted 6 lines
qapi/string-input-visitor.c +0
-0@@ -110,6 +110,27 @@ static void parse_start_optional(Visitor *v, bool *present, *present = true;qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 120
Quoted 10 lines
qapi/string-input-visitor.c +8
-0} +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 calledstrtod()directly maybe?If that's not the case, I think it should be fixed in the called function[s] rather than for each caller.
Quoted 6 lines
qapi/string-input-visitor.c static void parse_start_optional(Visitor *v, bool *present, · line 123
Quoted 3 lines
qapi/string-input-visitor.c +3
-0+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.
Quoted 16 lines
Quoted 16 lines
qapi/string-input-visitor.c +10
-0+ } +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;Quoted 8 lines
qapi/string-input-visitor.c StringInputVisitor *string_input_visitor_new(const char *str) · line 156
Quoted 3 lines
qapi/string-input-visitor.c +1
-0v->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 :)
Quoted 7 lines
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)
Quoted 5 lines
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)
Quoted 6 lines
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 toqapi-visit-core.cmore 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
Quoted 5 lines
Quoted 5 lines
Signature · 2 lines
-- Eduardo
Signature · 2 lines
Regards, Igor
PATCH 6/6 target-i386: use visit_type_hz to parse tsc_freq property value
In reply to Eduardo HabkostFrom: Igor Mammedov <[email protected]>
--- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-i386/cpu.c +1 -1
@@ -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 ; }
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [PATCH 6/6] target-i386: use visit_type_hz to parse tsc_freq property value
Quoted 4 lines · Eduardo Habkost
From: Igor Mammedov <[email protected]>
Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Andreas Färber <[email protected]>
Quoted 23 lines
--- target-i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-i386/cpu.c +1
-1@@ -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 ; }Signature · 1 line
1.7.11.7
Signature · 1 line
Eduardo
Am 04.12.2012 20:34, schrieb Eduardo Habkost:
Quoted 3 lines
Igor Mammedov (4):
target-i386: use define for cpuid vendor string size
target-i386: postponecpuid_levelupdate 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
Quoted 9 lines
add visitor for parsing hz[KMG] input string
target-i386: usevisit_type_hzto parsetsc_freqproperty valueqapi/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(-)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg