From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1amsvQ-0005oX-S1 for qemu-devel@nongnu.org; Sun, 03 Apr 2016 21:03:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1amsvP-0004jq-3z for qemu-devel@nongnu.org; Sun, 03 Apr 2016 21:03:28 -0400 Date: Mon, 4 Apr 2016 10:13:54 +1000 From: David Gibson Message-ID: <20160404001354.GB16485@voom.fritz.box> References: <1459413561-30745-1-git-send-email-bharata@linux.vnet.ibm.com> <1459413561-30745-9-git-send-email-bharata@linux.vnet.ibm.com> <20160401050844.GP416@voom.redhat.com> <20160401061223.GA26248@in.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="QKdGvSO+nmPlgiQ/" Content-Disposition: inline In-Reply-To: <20160401061223.GA26248@in.ibm.com> Subject: Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: mjrosato@linux.vnet.ibm.com, agraf@suse.de, thuth@redhat.com, pkrempa@redhat.com, ehabkost@redhat.com, aik@ozlabs.ru, qemu-devel@nongnu.org, armbru@redhat.com, borntraeger@de.ibm.com, qemu-ppc@nongnu.org, pbonzini@redhat.com, imammedo@redhat.com, afaerber@suse.de, mdroth@linux.vnet.ibm.com --QKdGvSO+nmPlgiQ/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 01, 2016 at 11:42:23AM +0530, Bharata B Rao wrote: > On Fri, Apr 01, 2016 at 04:08:44PM +1100, David Gibson wrote: > > On Thu, Mar 31, 2016 at 02:09:17PM +0530, Bharata B Rao wrote: > > > Introduce core devices for each CPU type supported by sPAPR. These > > > core devices are derived from the base spapr-cpu-core device type. > > >=20 > > > TODO: > > > - Add core types for other remaining CPU types > > > - Handle CPU model alias correctly > > >=20 > > > Signed-off-by: Bharata B Rao > > > --- > > > hw/ppc/spapr.c | 3 +- > > > hw/ppc/spapr_cpu_core.c | 118 ++++++++++++++++++++++++++++++= ++++++++++ > > > include/hw/ppc/spapr.h | 1 + > > > include/hw/ppc/spapr_cpu_core.h | 36 ++++++++++++ > > > 4 files changed, 156 insertions(+), 2 deletions(-) > > >=20 > > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > > > index 64c4acc..45ac5dc 100644 > > > --- a/hw/ppc/spapr.c > > > +++ b/hw/ppc/spapr.c > > > @@ -1614,8 +1614,7 @@ static void spapr_boot_set(void *opaque, const = char *boot_device, > > > machine->boot_order =3D g_strdup(boot_device); > > > } > > > =20 > > > -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, > > > - Error **errp) > > > +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error= **errp) > > > { > > > CPUPPCState *env =3D &cpu->env; > > > =20 > > > diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c > > > index 8cbe2a5..3751a54 100644 > > > --- a/hw/ppc/spapr_cpu_core.c > > > +++ b/hw/ppc/spapr_cpu_core.c > > > @@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = =3D { > > > .instance_size =3D sizeof(sPAPRCPUCore), > > > }; > > > =20 > > > +#define DEFINE_SPAPR_CPU_CORE(_name) = \ > > > +static void = \ > > > +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int th= reads, \ > > > + Error **errp) = \ > > > +{ = \ > > > + int i; = \ > > > + Error *local_err =3D NULL; = \ > > > + sPAPRCPUCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); = \ > > > + glue(_name, sPAPRCPUCore) * core =3D = \ > > > + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev)); = \ > > > + = \ > > > + for (i =3D 0; i < threads; i++) { = \ > > > + char id[32]; = \ > > > + = \ > > > + object_initialize(&sc->threads[i], sizeof(sc->threads[i]), = \ > > > + object_class_get_name(core->cpu)); = \ > > > + snprintf(id, sizeof(id), "thread[%d]", i); = \ > > > + object_property_add_child(OBJECT(core), id, OBJECT(&sc->thre= ads[i]), \ > > > + &local_err); = \ > > > + if (local_err) { = \ > > > + goto err; = \ > > > + } = \ > > > + } = \ > > > + return; = \ > > > + = \ > > > +err: = \ > > > + while (--i) { = \ > > > + object_unparent(OBJECT(&sc->threads[i])); = \ > > > + } = \ > > > + error_propagate(errp, local_err); = \ > > > +} = \ > > > + = \ > > > +static int = \ > > > +glue(_name, _spapr_cpu_core_realize_child)(Object *child, void *opaq= ue) \ > > > +{ = \ > > > + Error **errp =3D opaque; = \ > > > + sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); = \ > > > + CPUState *cs =3D CPU(child); = \ > > > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); = \ > > > + = \ > > > + object_property_set_bool(child, true, "realized", errp); = \ > > > + if (*errp) { = \ > > > + return 1; = \ > > > + } = \ > > > + = \ > > > + spapr_cpu_init(spapr, cpu, errp); = \ > > > + if (*errp) { = \ > > > + return 1; = \ > > > + } = \ > > > + return 0; = \ > > > +} = \ > >=20 > > If you put the ObjectClass * for the threads in the base abstract > > class's class structure, then you can move most of this logic to the > > abstract class as well and make the macro-ized stuff much smaller. > >=20 > > The realize_child stuff doesn't even need the ObjectClass* in the base > > class to factor out. > >=20 > > > +static void = \ > > > +glue(_name, _spapr_cpu_core_realize)(DeviceState *dev, Error **errp)= \ > > > +{ = \ > > > + sPAPRCPUCore *sc =3D SPAPR_CPU_CORE(OBJECT(dev)); = \ > > > + CPUCore *cc =3D CPU_CORE(OBJECT(dev)); = \ > > > + Error *local_err =3D NULL; = \ > > > + = \ > > > + /* = \ > > > + * TODO: This is CPU model specific CPU core's realize routine. = \ > > > + * However I am initializing "threads" field of the parent type = \ > > > + * sPAPRCPUCore here. Is this ok ? If not I will have make "thre= ads" \ > > > + * part of CPU model specific CPU core type and have different p= lug() \ > > > + * handlers for each type instead of having a common plug() hand= ler \ > > > + * for all core types. = \ > > > + */ = \ > > > + sc->threads =3D g_new0(PowerPCCPU, cc->threads); = \ > > > + glue(_name, _spapr_cpu_core_create_threads)(dev, cc->threads, &l= ocal_err); \ > > > + if (local_err) { = \ > > > + goto out; = \ > > > + } = \ > > > + = \ > > > + object_child_foreach(OBJECT(dev), = \ > > > + glue(_name, _spapr_cpu_core_realize_child),= \ > > > + &local_err); = \ > > > + = \ > > > +out: = \ > > > + if (local_err) { = \ > > > + g_free(sc->threads); = \ > > > + error_propagate(errp, local_err); = \ > > > + } = \ > > > +} = \ > > > + = \ > > > +static void = \ > > > +glue(_name, _spapr_cpu_core_instance_init)(Object *obj) = \ > > > +{ = \ > > > + glue(_name, sPAPRCPUCore) * core =3D glue(_name, _SPAPR_CPU_CORE= )(obj); \ > > > + const char *type =3D stringify(_name) "-" TYPE_POWERPC_CPU; = \ > > > + ObjectClass *oc =3D object_class_by_name(type); = \ > > > + = \ > > > + core->cpu =3D oc; = \ > > > +} = \ > > > + = \ > > > +static void = \ > > > +glue(_name, _spapr_cpu_core_class_init)(ObjectClass *oc, void *data)= \ > > > +{ = \ > > > + = \ > > > + DeviceClass *dc =3D DEVICE_CLASS(oc); = \ > > > + dc->realize =3D glue(_name, _spapr_cpu_core_realize); = \ > >=20 > > I think the only callback you should need to construct in the macro is > > class_init to initialize the ObjectClass* field. > >=20 > > > +} = \ > > > + = \ > > > +static const TypeInfo glue(_name, _spapr_cpu_core_type_info) =3D = \ > > > +{ = \ > > > + .name =3D stringify(_name) "-" TYPE_SPAPR_CPU_CORE, = \ > > > + .parent =3D TYPE_SPAPR_CPU_CORE, = \ > > > + .instance_size =3D sizeof(glue(_name, sPAPRCPUCore)), = \ > > > + .instance_init =3D glue(_name, _spapr_cpu_core_instance_init), = \ > > > + .class_init =3D glue(_name, _spapr_cpu_core_class_init), = \ > > > +}; > > > + > > > +DEFINE_SPAPR_CPU_CORE(host); > > > +DEFINE_SPAPR_CPU_CORE(POWER7); > > > +DEFINE_SPAPR_CPU_CORE(POWER8); > > > + > > > static void spapr_cpu_core_register_types(void) > > > { > > > type_register_static(&spapr_cpu_core_type_info); > > > + type_register_static(&host_spapr_cpu_core_type_info); > > > + type_register_static(&POWER7_spapr_cpu_core_type_info); > > > + type_register_static(&POWER8_spapr_cpu_core_type_info); > > > } > > > =20 > > > type_init(spapr_cpu_core_register_types) > > > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h > > > index 098d85d..0fdf448 100644 > > > --- a/include/hw/ppc/spapr.h > > > +++ b/include/hw/ppc/spapr.h > > > @@ -585,6 +585,7 @@ void spapr_hotplug_req_add_by_count(sPAPRDRConnec= torType drc_type, > > > uint32_t count); > > > void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type, > > > uint32_t count); > > > +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error= **errp); > > > =20 > > > /* rtas-configure-connector state */ > > > struct sPAPRConfigureConnectorState { > > > diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_c= pu_core.h > > > index e3340ea..71e69c0 100644 > > > --- a/include/hw/ppc/spapr_cpu_core.h > > > +++ b/include/hw/ppc/spapr_cpu_core.h > > > @@ -24,4 +24,40 @@ typedef struct sPAPRCPUCore { > > > PowerPCCPU *threads; > > > } sPAPRCPUCore; > > > =20 > > > +#define TYPE_host_SPAPR_CPU_CORE "host-spapr-cpu-core" > > > +#define host_SPAPR_CPU_CORE(obj) \ > > > + OBJECT_CHECK(hostsPAPRCPUCore, (obj), TYPE_host_SPAPR_CPU_CORE) > > > + > > > +typedef struct hostsPAPRCPUCore { > > > + /*< private >*/ > > > + sPAPRCPUCore parent_obj; > > > + > > > + /*< public >*/ > > > + ObjectClass *cpu; > > > +} hostsPAPRCPUCore; > > > +#define TYPE_POWER7_SPAPR_CPU_CORE "POWER7-spapr-cpu-core" > > > +#define POWER7_SPAPR_CPU_CORE(obj) \ > > > + OBJECT_CHECK(POWER7sPAPRCPUCore, (obj), TYPE_POWER7_SPAPR_CPU_CO= RE) > > > + > > > +typedef struct POWER7sPAPRCPUCore { > > > + /*< private >*/ > > > + sPAPRCPUCore parent_obj; > > > + > > > + /*< public >*/ > > > + ObjectClass *cpu; > > > +} POWER7sPAPRCPUCore; > > > + > > > +#define TYPE_POWER8_SPAPR_CPU_CORE "POWER8-spapr-cpu-core" > > > +#define POWER8_SPAPR_CPU_CORE(obj) \ > > > + OBJECT_CHECK(POWER8sPAPRCPUCore, (obj), TYPE_POWER8_SPAPR_CPU_CO= RE) > > > + > > > +typedef struct POWER8sPAPRCPUCore { > > > + /*< private >*/ > > > + sPAPRCPUCore parent_obj; > > > + > > > + /*< public >*/ > > > + ObjectClass *cpu; > > > +} POWER8sPAPRCPUCore; > >=20 > > These are all identical so should also be macro constructed as well. > > I don't think there's actually any need for the structures to be > > exposed in a header file either, so you should be able to do it in the > > same macro that constructs the implementation. > >=20 > > Uh.. except if you move the ObjectClass* to the base class you won't > > even need these. >=20 > The only reason (currently) POWER8sPAPRCPUCore exists separately from > the base class sPAPRCPUCore is that it represents POWER8 core which > is stored as ObjectClass*. >=20 > Now if we don't track cpu type (ObjectClass *) as part of > POWER8sPAPRCPUCore but push that up to sPAPRCPUCore, I am not > sure if that would be at the right abstraction level. Not as part of sPAPRCPUCore, but as part of sPAPRCPUCoreClass. We don't have a structure for the class at present, but we can add one. You can think of it as a method that sPAPRCPUCore and subclasses have which returns the correct ObjectClass *, except that we don't actually need a method (function pointer) - a simple data pointer in the class will suffice. --=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 --QKdGvSO+nmPlgiQ/ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXAbHCAAoJEGw4ysog2bOS1S0QAMZ1TnBdevgyqCPG9HH6yTyI DCwOCfP5FI0lmlDoIn72qf/ZY7IGk8/ARitdvEz90w8ToG9HaVItOxI8nh7clWS2 fXTu/Qa25ij/Ec9RMtGezZO2BHTqrNYlK8zBpjyt8VwZpuFPZbiVuM+kWlCw8aB6 yr+AIaN8XhAVMaglb6y42s5EShaVEeaImZNMTGCtst07lvGUy82t+fIOF+FvcDpM EsoN0QeAz1RbPWZD3cUpbMsnMbflRfjpY7WfL9C7H7zAP8aqPEsPHfs0NZnugBfv vIU6wiIzkN7Kcu1vUcUhTgTH5keT++6RcZKE9f/z0wWp7p7ysHOY9pzh64Pu/vnO ZRs2qR7tFmlfpXGnmIZxI8bKw5LyDol8mhnFh94z+enDPHpbzoU+MTtIcNdAWkCq cTVKGMwkTBleybppQKwy8Qx2+jBsL9oF9/wu1PaD+nX49hsfAdXkG77sk48muVom klDQcZARegqxOpvJ7pmTEYu67u8Yk5jPXFpBwCq9QTXcmuSJqeYHl+arwK6yO6Lw EJhlQl9DMe2XpSXOZbglFzo/BpmZ8Xn98FDhuSFb36EDGw4fW7eFmrfqvA+KPBQQ MRkzRuMT/0JUTBW/NVfXQUpRbMeSrC96meIKm+ZRbikrtRcSbr736xIA8stZok6v 2SEkRodf2VuvYpl94K4v =umr3 -----END PGP SIGNATURE----- --QKdGvSO+nmPlgiQ/--