From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLDN1-0005Iu-Ki for qemu-devel@nongnu.org; Wed, 05 Mar 2014 10:04:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLDMw-0002pz-Ku for qemu-devel@nongnu.org; Wed, 05 Mar 2014 10:04:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:30525) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLDMw-0002pm-Bs for qemu-devel@nongnu.org; Wed, 05 Mar 2014 10:04:26 -0500 Date: Wed, 5 Mar 2014 16:04:21 +0100 From: Igor Mammedov Message-ID: <20140305160421.4ce44afe@nial.usersys.redhat.com> In-Reply-To: <1393901749-5944-2-git-send-email-afaerber@suse.de> References: <1393901749-5944-1-git-send-email-afaerber@suse.de> <1393901749-5944-2-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH qom-cpu 1/6] cpu: Introduce CPUClass::parse_features() hook List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?ISO-8859-1?B?RuRyYmVy?= Cc: Alexey Kardashevskiy , qemu-devel@nongnu.org, Eduardo Habkost On Tue, 4 Mar 2014 03:55:44 +0100 Andreas F=E4rber wrote: > Adapt the X86CPU implementation to suit the generic hook. > This involves a cleanup of error handling to cope with NULL errp. >=20 > Signed-off-by: Andreas F=E4rber > --- > include/qom/cpu.h | 3 +++ > target-i386/cpu.c | 36 +++++++++++++++++++++--------------- > 2 files changed, 24 insertions(+), 15 deletions(-) >=20 > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index 64ebfa5..43d253a 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -67,6 +67,8 @@ struct TranslationBlock; > * CPUClass: > * @class_by_name: Callback to map -cpu command line model name to an > * instantiatable CPU type. > + * @parse_features: Callback to parse command line arguments. > + * The argument may be modified by the callback. Could you specify which argument is expected to be modified? > * @reset: Callback to reset the #CPUState to its initial state. > * @reset_dump_flags: #CPUDumpFlags to use for reset logging. > * @has_work: Callback for checking if there is work to do. > @@ -96,6 +98,7 @@ typedef struct CPUClass { > /*< public >*/ > =20 > ObjectClass *(*class_by_name)(const char *cpu_model); > + void (*parse_features)(CPUState *cpu, char *str, Error **errp); > =20 > void (*reset)(CPUState *cpu); > int reset_dump_flags; > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index cbc8cd6..653840a 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -1626,8 +1626,10 @@ static inline void feat2prop(char *s) > =20 > /* Parse "+feature,-feature,feature=3Dfoo" CPU feature string > */ > -static void cpu_x86_parse_featurestr(X86CPU *cpu, char *features, Error = **errp) > +static void x86_cpu_parse_featurestr(CPUState *cs, char *features, > + Error **errp) > { > + X86CPU *cpu =3D X86_CPU(cs); > char *featurestr; /* Single 'key=3Dvalue" string being parsed */ > /* Features to be added */ > FeatureWordArray plus_features =3D { 0 }; > @@ -1635,6 +1637,7 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, c= har *features, Error **errp) > FeatureWordArray minus_features =3D { 0 }; > uint32_t numvalue; > CPUX86State *env =3D &cpu->env; > + Error *local_err =3D NULL; > =20 > featurestr =3D features ? strtok(features, ",") : NULL; > =20 > @@ -1653,16 +1656,16 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,= char *features, Error **errp) > =20 > numvalue =3D strtoul(val, &err, 0); > if (!*val || *err) { > - error_setg(errp, "bad numerical value %s", val); > + error_setg(&local_err, "bad numerical value %s", val= ); > goto out; > } > if (numvalue < 0x80000000) { > - fprintf(stderr, "xlevel value shall always be >=3D 0= x80000000" > - ", fixup will be removed in future versions\= n"); > + error_report("xlevel value shall always be >=3D 0x80= 000000" > + ", fixup will be removed in future vers= ions"); > numvalue +=3D 0x80000000; > } > snprintf(num, sizeof(num), "%" PRIu32, numvalue); > - object_property_parse(OBJECT(cpu), num, featurestr, errp= ); > + object_property_parse(OBJECT(cpu), num, featurestr, &loc= al_err); > } else if (!strcmp(featurestr, "tsc-freq")) { > int64_t tsc_freq; > char *err; > @@ -1671,36 +1674,38 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu,= char *features, Error **errp) > tsc_freq =3D strtosz_suffix_unit(val, &err, > STRTOSZ_DEFSUFFIX_B, 1000= ); > if (tsc_freq < 0 || *err) { > - error_setg(errp, "bad numerical value %s", val); > + error_setg(&local_err, "bad numerical value %s", val= ); > goto out; > } > snprintf(num, sizeof(num), "%" PRId64, tsc_freq); > - object_property_parse(OBJECT(cpu), num, "tsc-frequency",= errp); > + object_property_parse(OBJECT(cpu), num, "tsc-frequency", > + &local_err); > } else if (!strcmp(featurestr, "hv-spinlocks")) { > char *err; > const int min =3D 0xFFF; > char num[32]; > numvalue =3D strtoul(val, &err, 0); > if (!*val || *err) { > - error_setg(errp, "bad numerical value %s", val); > + error_setg(&local_err, "bad numerical value %s", val= ); > goto out; > } > if (numvalue < min) { > - fprintf(stderr, "hv-spinlocks value shall always be = >=3D 0x%x" > - ", fixup will be removed in future versions\= n", > + error_report("hv-spinlocks value shall always be >= =3D 0x%x" > + ", fixup will be removed in future versions", > min); > numvalue =3D min; > } > snprintf(num, sizeof(num), "%" PRId32, numvalue); > - object_property_parse(OBJECT(cpu), num, featurestr, errp= ); > + object_property_parse(OBJECT(cpu), num, featurestr, &loc= al_err); > } else { > - object_property_parse(OBJECT(cpu), val, featurestr, errp= ); > + object_property_parse(OBJECT(cpu), val, featurestr, &loc= al_err); > } > } else { > feat2prop(featurestr); > - object_property_parse(OBJECT(cpu), "on", featurestr, errp); > + object_property_parse(OBJECT(cpu), "on", featurestr, &local_= err); > } > - if (error_is_set(errp)) { > + if (local_err) { > + error_propagate(errp, local_err); > goto out; > } > featurestr =3D strtok(NULL, ","); > @@ -1926,7 +1931,7 @@ X86CPU *cpu_x86_create(const char *cpu_model, Devic= eState *icc_bridge, > goto out; > } > =20 > - cpu_x86_parse_featurestr(cpu, features, &error); > + x86_cpu_parse_featurestr(CPU(cpu), features, &error); > if (error) { > goto out; > } > @@ -2748,6 +2753,7 @@ static void x86_cpu_common_class_init(ObjectClass *= oc, void *data) > cc->reset =3D x86_cpu_reset; > cc->reset_dump_flags =3D CPU_DUMP_FPU | CPU_DUMP_CCOP; > =20 > + cc->parse_features =3D x86_cpu_parse_featurestr; > cc->has_work =3D x86_cpu_has_work; > cc->do_interrupt =3D x86_cpu_do_interrupt; > cc->dump_state =3D x86_cpu_dump_state;