From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a3Zxx-00074B-AL for qemu-devel@nongnu.org; Mon, 30 Nov 2015 20:42:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a3Zxw-0001As-6k for qemu-devel@nongnu.org; Mon, 30 Nov 2015 20:42:49 -0500 Date: Tue, 1 Dec 2015 12:34:06 +1100 From: David Gibson Message-ID: <20151201013406.GH31343@voom.redhat.com> References: <1448024079-20808-1-git-send-email-bharata@linux.vnet.ibm.com> <1448024079-20808-10-git-send-email-bharata@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Hlh2aiwFLCZwGcpw" Content-Disposition: inline In-Reply-To: <1448024079-20808-10-git-send-email-bharata@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v5 09/10] 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 --Hlh2aiwFLCZwGcpw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 20, 2015 at 06:24:38PM +0530, Bharata B Rao wrote: > 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 | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 71 insertions(+) >=20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index 4434d45..6dca553 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -2401,11 +2401,82 @@ static void spapr_machine_device_plug(HotplugHand= ler *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_release(DeviceState *dev, void *opaque) I'd prefer to see this called "core_release" since "cpu" doesn't make it clear that it's acting on a whole core. > +{ > + CPUState *cs; > + int i; > + int id =3D ppc_get_vcpu_dt_id(POWERPC_CPU(CPU(dev))); > + > + for (i =3D id; i < id + smp_threads; i++) { > + CPU_FOREACH(cs) { > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > + > + if (i =3D=3D ppc_get_vcpu_dt_id(cpu)) { > + spapr_cpu_destroy(cpu); > + cpu_remove(cs); > + } > + } > + } > +} > + > +static int spapr_cpu_unplug(HotplugHandler *hotplug_dev, DeviceState *de= v, > + Error **errp) > +{ > + 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 (core) will > + * continue and signal hot unplug event to the guest. > + */ > + if ((id % smt) !=3D 0) { > + return 0; > + } > + g_assert(drc); > + > + drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); > + drck->detach(drc, dev, spapr_cpu_release, NULL, &local_err); > + if (local_err) { > + error_propagate(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_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_CPU)) { > + if (!smc->dr_cpu_enabled) { > + error_setg(errp, "CPU hot unplug not supported on this machi= ne"); > + return; > + } > + spapr_cpu_unplug(hotplug_dev, dev, errp); > } > } > =20 --=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 --Hlh2aiwFLCZwGcpw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWXPkNAAoJEGw4ysog2bOSi+IP/jNc0XDW6Ca8FsueDThTTvhd q5nguB/XQ3uOYozAvMms1UJS73dQVK7PRdkarxw7i9iWsKDatbUPyrjq4ojsBKtW /Eh+Ix0905XozNVSUxhZjylOnT8DZFdNRxRi81MezJzTzt0Uh7X40HWrCMCouUDl XeHu91wQWh0VuVqbet0jnZ/KQk8QWVTO9MxPtPw8zsoZntiDopNfd5dHVAM7c38T x1ZjqZa3NbRfhWxzRx2JouWhtCLBQX/L/PXDcaU8UhE/YnmSBaydw+hQ8s3Q/RJE pGOIUJh9sSEYhhcUvqh8bgVs9UeTvKriNPm1uZD4HKRJj3Foc4Xj10qVbiFTtMIE SrSF8pWnB9ihRwDtvDdM9R7vmbLUtC20Ag/3BmqQKmK9BltzN2TV/wec43NAH58q iUsQwIWja2AY5O8vFFO+ttP+Hz3NI9Doaot79wwuOdL0+dECYudiI2sV5CftVpn4 8UlDC7pLRGh5GjqIvumNqeyhecqXNjjfrrUtcypnJylONRNoGLoePWvzkglvJ2yw fywfjc4Kh9azoK63R9tsnHJu8C94Qo+m0TJpS1uW2SDC+2RH0OZd5/ouq7IEQDpW B1NFgMpGomz1aEtaLhxBd9NMOPoVjCPo5K2lmDjejKuy2YWSp6LE0PskV2QqdgLn TnkLDdLxd8kkO/WUNBRK =mNuH -----END PGP SIGNATURE----- --Hlh2aiwFLCZwGcpw--