From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIs5U-0007fj-7X for qemu-devel@nongnu.org; Tue, 12 Jan 2016 01:05:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIs5S-0005UE-EX for qemu-devel@nongnu.org; Tue, 12 Jan 2016 01:05:48 -0500 Date: Tue, 12 Jan 2016 17:06:34 +1100 From: David Gibson Message-ID: <20160112060634.GW22925@voom.redhat.com> References: <1452236119-24452-1-git-send-email-bharata@linux.vnet.ibm.com> <1452236119-24452-12-git-send-email-bharata@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="fqQSV+MVmQEkpBtA" Content-Disposition: inline In-Reply-To: <1452236119-24452-12-git-send-email-bharata@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v6 11/11] spapr: CPU hot unplug support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: mdroth@linux.vnet.ibm.com, aik@ozlabs.ru, agraf@suse.de, qemu-devel@nongnu.org, pbonzini@redhat.com, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de, ehabkost@redhat.com --fqQSV+MVmQEkpBtA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 08, 2016 at 12:25:19PM +0530, Bharata B Rao wrote: > Remove the CPU core device by removing the underlying CPU thread devices. > Support hot removal of CPU for sPAPR guests by sending the hot unplug > notification to the guest via EPOW interrupt. Release the vCPU object > after CPU hot unplug so that vCPU fd can be parked and reused. >=20 > Signed-off-by: Bharata B Rao > --- > hw/ppc/spapr.c | 113 +++++++++++++++++++++++++++++++++++++++++++= ++++++ > include/hw/ppc/spapr.h | 6 +++ > 2 files changed, 119 insertions(+) >=20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index c2af9ca..43cb726 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -93,6 +93,9 @@ > =20 > #define HTAB_SIZE(spapr) (1ULL << ((spapr)->htab_shift)) > =20 > +static QLIST_HEAD(cpu_unplug_list, sPAPRCPUUnplug) cpu_unplug_list > + =3D QLIST_HEAD_INITIALIZER(cpu_unplug_list); > + > static XICSState *try_create_xics(const char *type, int nr_servers, > int nr_irqs, Error **errp) > { > @@ -2432,11 +2435,121 @@ static void spapr_machine_device_plug(HotplugHan= dler *hotplug_dev, > } > } > =20 > +static void spapr_cpu_destroy(PowerPCCPU *cpu) > +{ > + sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_machine()); > + > + xics_cpu_destroy(spapr->icp, cpu); > + qemu_unregister_reset(spapr_cpu_reset, cpu); > +} > + > +static void spapr_cpu_core_cleanup(void) > +{ > + sPAPRCPUUnplug *unplug, *next; > + Object *cpu; > + > + QLIST_FOREACH_SAFE(unplug, &cpu_unplug_list, node, next) { > + cpu =3D unplug->cpu; > + object_unparent(cpu); > + QLIST_REMOVE(unplug, node); > + g_free(unplug); > + } > +} > + > +static void spapr_add_cpu_to_unplug_list(Object *cpu) > +{ > + sPAPRCPUUnplug *unplug =3D g_malloc(sizeof(*unplug)); > + > + unplug->cpu =3D cpu; > + QLIST_INSERT_HEAD(&cpu_unplug_list, unplug, node); > +} > + > +static int spapr_cpu_release(Object *obj, void *opaque) > +{ > + DeviceState *dev =3D DEVICE(obj); > + CPUState *cs =3D CPU(dev); > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > + > + spapr_cpu_destroy(cpu); > + cpu_remove_sync(cs); > + > + /* > + * We are still walking the core object's children list, and > + * hence can't cleanup this CPU thread object just yet. Put > + * it on a list for later removal. > + */ > + spapr_add_cpu_to_unplug_list(obj); > + return 0; > +} > + > +static void spapr_core_release(DeviceState *dev, void *opaque) > +{ > + object_child_foreach(OBJECT(dev), spapr_cpu_release, opaque); > + spapr_cpu_core_cleanup(); > + object_unparent(OBJECT(dev)); I'd prefer to see the unplug_list as a local to this function (passed to spapr_cpu_release via opaque) rather than using a new global. > +} > + > +static int spapr_core_detach(Object *obj, void *opaque) > +{ > + sPAPRCoreState *core =3D opaque; > + DeviceState *dev =3D DEVICE(obj); > + CPUState *cs =3D CPU(dev); > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > + int id =3D ppc_get_vcpu_dt_id(cpu); > + int smt =3D kvmppc_smt_threads(); > + sPAPRDRConnector *drc =3D > + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id); > + sPAPRDRConnectorClass *drck; > + Error *local_err =3D NULL; > + > + /* > + * SMT threads return from here, only main thread (thread 0) will > + * continue and signal hot unplug event to the guest. > + */ This seems silly. spapr_core_unplug() iterates through all the children only to have all of them except thread 0 ignore the call.. Can't you just grab the first thread and do this logic directly from spapr_core_unplug()? Same question for the plug side, though I didn't think of it when I was looking at that. > + if ((id % smt) !=3D 0) { > + return 0; > + } > + g_assert(drc); > + > + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); > + drck->detach(drc, core->dev, spapr_core_release, NULL, &local_err); > + if (local_err) { > + error_propagate(core->errp, local_err); > + return 1; > + } > + > + /* > + * In addition to hotplugged CPUs, send the hot-unplug notification > + * interrupt to the guest for coldplugged CPUs started via -device > + * option too. > + */ > + spapr_hotplug_req_remove_by_index(drc); > + return 0; > +} > + > +static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *= dev, > + Error **errp) > +{ > + sPAPRCoreState core; > + > + core.dev =3D dev; > + core.errp =3D errp; > + object_child_foreach(OBJECT(dev), spapr_core_detach, &core); > +} > + > static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > + sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(qdev_get_machine(= )); > + > if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { > error_setg(errp, "Memory hot unplug not supported by sPAPR"); > + } else if (object_dynamic_cast(OBJECT(dev), TYPE_POWERPC_CPU_CORE)) { > + if (!smc->dr_cpu_enabled) { > + error_setg(errp, "CPU hot unplug not supported on this machi= ne"); > + return; > + } > + spapr_core_unplug(hotplug_dev, dev, errp); > } > } > =20 > diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h > index 68d51d6..4d89016 100644 > --- a/include/hw/ppc/spapr.h > +++ b/include/hw/ppc/spapr.h > @@ -88,6 +88,12 @@ typedef struct sPAPRCoreState { > Error **errp; > } sPAPRCoreState; > =20 > +/* List to store unplugged CPU objects for cleanup during unplug */ > +typedef struct sPAPRCPUUnplug { > + Object *cpu; > + QLIST_ENTRY(sPAPRCPUUnplug) node; > +} sPAPRCPUUnplug; > + > #define H_SUCCESS 0 > #define H_BUSY 1 /* Hardware busy -- retry later */ > #define H_CLOSED 2 /* Resource closed */ --=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 --fqQSV+MVmQEkpBtA Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWlJfqAAoJEGw4ysog2bOSYREP/3ggaiuNrPPBoK7N6DCrRz6R yPWvnVnm9vaTXP2UexurAx2srgNz4iGgyAK0t5F9rEHLhS7s8oqfogz9EYkR00xX cEJ2mKmxWuRYfFwdprg0Jux2MHmuhCFg719ae9HhUGN36VeEr/4s5egH4yq4e+wt G2Oa0sCOcx3OE5fMaNXiUM7F76ymVT+Cgz9VUCR7MfCOpkek4bm6mV5PzRWjE6lP XE9wNxZD0Noa72XTOCT0ah1tter/WLMdGSsGCJdXmblcBL/txAarCJbb0/JPY8Ok bMJKnNXnn5PwGiZ2Z0xXZ/w1yAtsAkiXd4LVuzvuAGSnDjsEp6zlW4p0pVFvUqKh w0ieU4ytT4Ryu6AvWiCDtAo6BqGkD4C/ITk72cDsAcM+iZjBjOC/1OlG9tOIGL+e m69PjqMeDP37Y1tcXZUtRxVo3rVXzvANlcqKdSPgYx5Ecr84Zj4wv1GyIseUXRof sP0WPjYT05PZZDr0YWKvT5Vd6e0OeGfTVcOd/DwS5NDT3UozMKM8fC/+4kizpoii a+zgx1OQ3g0p/AvldQaqN5IJJ9LPPZDG9J4bh8R+nZ36f7wnpqZZsY+WzNDGXmVh U/lM2EDANzass1lH6Ipca/ZUlyAP2QQjjej8swyBmPWbJrTzOzMXug7b9mKKd1bQ KBcwkRLrpobKQ4giruO8 =c5aV -----END PGP SIGNATURE----- --fqQSV+MVmQEkpBtA--