From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFxjo-0000t1-Hz for qemu-devel@nongnu.org; Thu, 23 Jun 2016 02:03:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFxjm-0006X6-Qt for qemu-devel@nongnu.org; Thu, 23 Jun 2016 02:03:40 -0400 Date: Thu, 23 Jun 2016 16:05:14 +1000 From: David Gibson Message-ID: <20160623060514.GD17152@voom.fritz.box> References: <1466580229-4600-1-git-send-email-bharata@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="FN+gV9K+162wdwwF" Content-Disposition: inline In-Reply-To: <1466580229-4600-1-git-send-email-bharata@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [RFC PATCH v1 1/1] spapr: Support setting of compat CPU type for CPU cores List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, imammedo@redhat.com, thuth@redhat.com --FN+gV9K+162wdwwF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 22, 2016 at 12:53:49PM +0530, Bharata B Rao wrote: > Compat CPU type is typically specified on -cpu cmdline option like: > -cpu host,compat=3Dpower7 or -cpu POWER8E,compat=3Dpower7 etc. > With the introduction of sPAPR CPU core devices, we need to support > the same for core devices too. >=20 > Support the specification of CPU compat type on device_add command for > sPAPRCPUCore devices like: > (qemu) device_add POWER8E-spapr-cpu-core,id=3Dcore3,compat=3Dpower7,core-= id=3D24 >=20 > Signed-off-by: Bharata B Rao > --- > Changes in v1: > - In the routine that extracts "compat=3D" from -cpu cmdline, made the pa= rsing > generic as suggested by Thomas Huth so that it works in the presence of > any other additional features. > - Addressed review comments by David with major one being setting of > compat property directly instead of going via ->parse_features(). >=20 > TODO: > - Reconcile with Igor's work that make cpu features as global properties. > - Find a way to export the compat infomation via query-hotpluggable-cpus. >=20 > v0: https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg05279.html > =20 > hw/ppc/spapr.c | 8 +++++ > hw/ppc/spapr_cpu_core.c | 78 +++++++++++++++++++++++++++++++++++= ++++++ > include/hw/ppc/spapr_cpu_core.h | 2 ++ > 3 files changed, 88 insertions(+) >=20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index 778fa25..2049d7d 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -1807,6 +1807,7 @@ static void ppc_spapr_init(MachineState *machine) > if (i < spapr_cores) { > char *type =3D spapr_get_cpu_core_type(machine->cpu_mode= l); > Object *core; > + char *compat; > =20 > if (!object_class_by_name(type)) { > error_report("Unable to find sPAPR CPU Core definiti= on"); > @@ -1818,6 +1819,13 @@ static void ppc_spapr_init(MachineState *machine) > &error_fatal); > object_property_set_int(core, core_dt_id, CPU_CORE_PROP_= CORE_ID, > &error_fatal); > + compat =3D spapr_get_cpu_compat_type(machine->cpu_model); > + if (compat) { > + object_property_set_str(core, compat, "compat", > + &error_fatal); > + g_free(compat); > + } > + > object_property_set_bool(core, true, "realized", &error_= fatal); > } > } > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c > index 3a5da09..d500cd6 100644 > --- a/hw/ppc/spapr_cpu_core.c > +++ b/hw/ppc/spapr_cpu_core.c > @@ -96,6 +96,31 @@ char *spapr_get_cpu_core_type(const char *model) > return core_type; > } > =20 > +/* > + * Returns the CPU compat type specified in -cpu @model. > + */ > +char *spapr_get_cpu_compat_type(const char *model) > +{ > + char *model_str =3D g_strdup(model); > + char *featurestr, *compat =3D NULL; > + > + featurestr =3D model_str ? strtok(model_str, ",") : NULL; AFAICT strtok() is not thread-safe. > + while (featurestr) { > + char *val; > + if (!strncmp(featurestr, "compat=3D", 7)) { > + val =3D strchr(featurestr, '=3D'); You don't technically need the strchr(), since from the strncmp above, you know the answer will be featurestr + 6. > + val++; > + compat =3D g_strdup(val); > + goto out; > + } > + featurestr =3D strtok(NULL, ","); > + } > + > +out: > + g_free(model_str); > + return compat; > +} Couldn't we use one of the existing opts parsing functions in qemu for the above, anyway? > static void spapr_core_release(DeviceState *dev, void *opaque) > { > sPAPRCPUCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); > @@ -223,12 +248,31 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_de= v, DeviceState *dev, > CPUCore *cc =3D CPU_CORE(dev); > char *base_core_type =3D spapr_get_cpu_core_type(machine->cpu_model); > const char *type =3D object_get_typename(OBJECT(dev)); > + char *base_compat_type =3D NULL; > + char *compat =3D NULL; > + bool compat_set; > =20 > if (strcmp(base_core_type, type)) { > error_setg(&local_err, "CPU core type should be %s", base_core_t= ype); > goto out; > } > =20 > + base_compat_type =3D spapr_get_cpu_compat_type(machine->cpu_model); > + compat =3D object_property_get_str(OBJECT(dev), "compat", NULL); > + compat_set =3D compat && *compat; > + > + if (base_compat_type) { > + if ((compat_set && strcmp(base_compat_type, compat)) || > + !compat_set) { > + error_setg(&local_err, "CPU compat type should be %s", > + base_compat_type); > + goto out; > + } > + } else if (compat_set) { > + error_setg(&local_err, "CPU compat type shouldn't be set"); > + goto out; I don't think we want this else clause, because it will forbid the use of -global core_type,compat=3Dwhatever, which Igor says is the preferred approach for the future (IIUC, using -global is equivalent to setting the property explicitly on every instance). The if clause should be ok, since it implements a fallback to using -cpu, which we do want. > + } > + > if (!smc->dr_cpu_enabled && dev->hotplugged) { > error_setg(&local_err, "CPU hotplug not supported for this machi= ne"); > goto out; > @@ -256,6 +300,8 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev,= DeviceState *dev, > } > =20 > out: > + g_free(compat); > + g_free(base_compat_type); > g_free(base_core_type); > error_propagate(errp, local_err); > } > @@ -288,6 +334,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, = Error **errp) > Error *local_err =3D NULL; > Object *obj; > int i; > + char *compat =3D object_property_get_str(OBJECT(sc), "compat", NULL); > + bool compat_set =3D compat && *compat; > =20 > sc->threads =3D g_malloc0(size * cc->nr_threads); > for (i =3D 0; i < cc->nr_threads; i++) { > @@ -300,11 +348,18 @@ static void spapr_cpu_core_realize(DeviceState *dev= , Error **errp) > if (local_err) { > goto err; > } > + if (compat_set) { > + object_property_set_str(obj, compat, "compat", &local_err); > + if (local_err) { > + goto err; > + } > + } > } > object_child_foreach(OBJECT(dev), spapr_cpu_core_realize_child, &loc= al_err); > if (local_err) { > goto err; > } else { > + g_free(compat); > return; > } > =20 > @@ -315,9 +370,31 @@ err: > i--; > } > g_free(sc->threads); > + g_free(compat); > error_propagate(errp, local_err); > } > =20 > +static char *spapr_cpu_core_prop_get_compat(Object *obj, Error **errp) > +{ > + sPAPRCPUCore *core =3D SPAPR_CPU_CORE(obj); > + > + return g_strdup(core->cpu_compat); > +} > + > +static void spapr_cpu_core_prop_set_compat(Object *obj, const char *val, > + Error **errp) > +{ > + sPAPRCPUCore *core =3D SPAPR_CPU_CORE(obj); > + > + core->cpu_compat =3D g_strdup(val); > +} > + > +static void spapr_cpu_core_instance_init(Object *obj) > +{ > + object_property_add_str(obj, "compat", spapr_cpu_core_prop_get_compa= t, > + spapr_cpu_core_prop_set_compat, NULL); > +} > + > static void spapr_cpu_core_class_init(ObjectClass *oc, void *data) > { > DeviceClass *dc =3D DEVICE_CLASS(oc); > @@ -388,6 +465,7 @@ static const TypeInfo spapr_cpu_core_type_info =3D { > .parent =3D TYPE_CPU_CORE, > .abstract =3D true, > .instance_size =3D sizeof(sPAPRCPUCore), > + .instance_init =3D spapr_cpu_core_instance_init, > .class_init =3D spapr_cpu_core_class_init, > }; > =20 > diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_c= ore.h > index 1c9b319..e697dab 100644 > --- a/include/hw/ppc/spapr_cpu_core.h > +++ b/include/hw/ppc/spapr_cpu_core.h > @@ -24,11 +24,13 @@ typedef struct sPAPRCPUCore { > /*< public >*/ > void *threads; > ObjectClass *cpu_class; > + char *cpu_compat; > } sPAPRCPUCore; > =20 > void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, > Error **errp); > char *spapr_get_cpu_core_type(const char *model); > +char *spapr_get_cpu_compat_type(const char *model); > void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, > Error **errp); > void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev, --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --FN+gV9K+162wdwwF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXa3waAAoJEGw4ysog2bOSZZYQAJSD9k2BUu9PUS1WDN7W9NFr qXL2nKn8KVXLqJO6yzvLvAuJVxl9YPrm2QLyWX8PeFZztXky8kDUk42qHsja0Z2D wEYsh7i2x4ye4j908oQTiebDuqgH713Dm6yp4RDMXNHOTOR7UuyV+e+0rLD37Vu0 Z35OMMHdGQ3Rm1JYsuNVmabHPvnZ+pb/b+Borf3ZLFUw+p9Q8m0n5tF1adYFap+/ tT6CGtkSVrNQlGsskzZKKEXCmwG+lO972+9E/b3V0xF6v6b10MLKDCBIel0M7Cwt UFztcEBnx6Gun7CG9k9hIzCXwrvD5sx/etkeDlp+tq76sPJHBDoHrysyi4ULJ9ht JVBSRlTnHt5Z49b0PmQurzrNGz1eOmjPzKX2Yzl9BxjkvNORiih9J+7vf5bsDWRX tmrm9Oxyhh3ZIeV3IEFcBwVUMkmFH1LZo2LhCX5mJylejxiawG5QnB+YABKMcm3E 1vwNoZxD2EWQZGkEW3U+b68uxG4TMARu5xe9eCsgnbx0F7g0VbmzhGWD2s6ooMeo WeQxNmwdlU4aMlt+lipfBXVr41QfyQp7NvgL0+bFBvDAKLcMlONZzWGjHLYDSNrY HubWr7IbC3Ji77JZeneDp/hTlnulWKAxLeC0H+aDCuBLDoDEUjySNa++CmK1m1vH fL/Hp+eLF9kBqps+nbaq =7taO -----END PGP SIGNATURE----- --FN+gV9K+162wdwwF--