Received: from eggs.gnu.org ([2001:4830:134:3::10]:47611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yabax-0007FG-NP for qemu-devel@nongnu.org; Tue, 24 Mar 2015 23:03:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yabaw-0003Gq-3g for qemu-devel@nongnu.org; Tue, 24 Mar 2015 23:03:03 -0400 Date: Wed, 25 Mar 2015 14:03:45 +1100 From: David Gibson Message-ID: <20150325030345.GW25043@voom.fritz.box> References: <1427117764-23008-1-git-send-email-bharata@linux.vnet.ibm.com> <1427117764-23008-13-git-send-email-bharata@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="rK7ir9GIO0YQrgt+" Content-Disposition: inline In-Reply-To: <1427117764-23008-13-git-send-email-bharata@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [RFC PATCH v2 12/23] spapr: CPU hotplug support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bharata B Rao Cc: mdroth@linux.vnet.ibm.com, agraf@suse.de, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, tyreld@linux.vnet.ibm.com, nfont@linux.vnet.ibm.com, imammedo@redhat.com, afaerber@suse.de --rK7ir9GIO0YQrgt+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Mar 23, 2015 at 07:05:53PM +0530, Bharata B Rao wrote: > Support CPU hotplug via device-add command. Set up device tree > entries for the hotplugged CPU core and use the exising EPOW event > infrastructure to send CPU hotplug notification to the guest. >=20 > Signed-off-by: Bharata B Rao > --- > hw/ppc/spapr.c | 75 +++++++++++++++++++++++++++++++++++++++++++++= ++++++ > hw/ppc/spapr_events.c | 8 +++--- > hw/ppc/spapr_rtas.c | 11 ++++++++ > 3 files changed, 91 insertions(+), 3 deletions(-) >=20 > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index f52d38f..b48994b 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -33,6 +33,7 @@ > #include "sysemu/block-backend.h" > #include "sysemu/cpus.h" > #include "sysemu/kvm.h" > +#include "sysemu/device_tree.h" > #include "kvm_ppc.h" > #include "mmu-hash64.h" > #include "qom/cpu.h" > @@ -660,6 +661,10 @@ static void spapr_populate_cpu_dt(CPUState *cs, void= *fdt, int offset) > QemuOpts *opts =3D qemu_opts_find(qemu_find_opts("smp-opts"), NULL); > unsigned sockets =3D opts ? qemu_opt_get_number(opts, "sockets", 0) = : 0; > uint32_t cpus_per_socket =3D sockets ? (smp_cpus / sockets) : 1; > + sPAPRDRConnector *drc =3D > + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, index); > + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); > + int drc_index =3D drck->get_index(drc); > =20 > _FDT((fdt_setprop_cell(fdt, offset, "reg", index))); > _FDT((fdt_setprop_string(fdt, offset, "device_type", "cpu"))); > @@ -728,6 +733,8 @@ static void spapr_populate_cpu_dt(CPUState *cs, void = *fdt, int offset) > =20 > _FDT((fdt_setprop_cell(fdt, offset, "ibm,chip-id", > cs->cpu_index / cpus_per_socket))); > + _FDT((fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index))); > + What effect will this have when running with DR disabled? > _FDT(spapr_fixup_cpu_numa_smt_dt(fdt, offset, cs, spapr)); > } > @@ -1840,6 +1847,70 @@ static void spapr_nmi(NMIState *n, int cpu_index, = Error **errp) > } > } > =20 > +static void spapr_cpu_hotplug_add(DeviceState *dev, CPUState *cs, Error = **errp) > +{ > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > + DeviceClass *dc =3D DEVICE_GET_CLASS(cs); > + int id =3D ppc_get_vcpu_dt_id(cpu); > + sPAPRDRConnector *drc =3D > + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id); > + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); > + void *fdt; > + int offset, i, fdt_size; > + char *nodename; > + > + fdt =3D create_device_tree(&fdt_size); > + nodename =3D g_strdup_printf("%s@%x", dc->fw_name, id); > + offset =3D fdt_add_subnode(fdt, 0, nodename); > + > + /* Set NUMA node for the added CPU core */ > + for (i =3D 0; i < nb_numa_nodes; i++) { > + if (test_bit(cs->cpu_index, numa_info[i].node_cpu)) { > + cs->numa_node =3D i; > + break; > + } > + } > + > + spapr_populate_cpu_dt(cs, fdt, offset); > + g_free(nodename); > + > + drck->attach(drc, dev, fdt, offset, !dev->hotplugged, errp); > + if (*errp) { > + g_free(fdt); > + } > +} > + > +static void spapr_cpu_plug(HotplugHandler *hotplug_dev, DeviceState *dev, > + Error **errp) > +{ > + CPUState *cs =3D CPU(dev); > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > + int id =3D ppc_get_vcpu_dt_id(cpu); > + sPAPRDRConnector *drc =3D > + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id); > + int smt =3D kvmppc_smt_threads(); > + Error *local_err =3D NULL; > + > + /* > + * SMT threads return from here, only main thread (core) will > + * continue and signal hotplug event to the guest. > + */ > + if ((id % smt) !=3D 0) { > + return; > + } > + > + g_assert(drc); > + > + spapr_cpu_hotplug_add(dev, cs, &local_err); > + if (local_err) { > + error_propagate(errp, local_err); > + return; > + } > + spapr_hotplug_req_add_event(drc); > + > + return; > +} > + > static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, > DeviceState *dev, Error **errp) > { > @@ -1848,6 +1919,10 @@ static void spapr_machine_device_plug(HotplugHandl= er *hotplug_dev, > PowerPCCPU *cpu =3D POWERPC_CPU(cs); > =20 > spapr_cpu_init(cpu); > + spapr_cpu_reset(cpu); > + if (dev->hotplugged && spapr->dr_cpu_enabled) { > + spapr_cpu_plug(hotplug_dev, dev, errp); > + } > } > } > =20 > diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c > index be82815..4ae818a 100644 > --- a/hw/ppc/spapr_events.c > +++ b/hw/ppc/spapr_events.c > @@ -421,14 +421,16 @@ static void spapr_hotplug_req_event(sPAPRDRConnecto= r *drc, uint8_t hp_action) > hp->hdr.section_length =3D cpu_to_be16(sizeof(*hp)); > hp->hdr.section_version =3D 1; /* includes extended modifier */ > hp->hotplug_action =3D hp_action; > - > + hp->drc.index =3D cpu_to_be32(drck->get_index(drc)); > + hp->hotplug_identifier =3D RTAS_LOG_V6_HP_ID_DRC_INDEX; > =20 > switch (drc_type) { > case SPAPR_DR_CONNECTOR_TYPE_PCI: > - hp->drc.index =3D cpu_to_be32(drck->get_index(drc)); > - hp->hotplug_identifier =3D RTAS_LOG_V6_HP_ID_DRC_INDEX; > hp->hotplug_type =3D RTAS_LOG_V6_HP_TYPE_PCI; > break; > + case SPAPR_DR_CONNECTOR_TYPE_CPU: > + hp->hotplug_type =3D RTAS_LOG_V6_HP_TYPE_CPU; > + break; > default: > /* we shouldn't be signaling hotplug events for resources > * that don't support them > diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c > index 57ec97a..48aeb86 100644 > --- a/hw/ppc/spapr_rtas.c > +++ b/hw/ppc/spapr_rtas.c > @@ -121,6 +121,16 @@ static void rtas_query_cpu_stopped_state(PowerPCCPU = *cpu_, > rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); > } > =20 > +static void spapr_cpu_set_endianness(PowerPCCPU *cpu) > +{ > + PowerPCCPU *fcpu =3D POWERPC_CPU(first_cpu); > + PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(fcpu); In some ways it might be nicer to store the global endian mode in sPAPRMachineState, updating it on H_SET_MODE, rather than copying the first cpu, although I guess that works. > + if (!(*pcc->interrupts_big_endian)(fcpu)) { > + cpu->env.spr[SPR_LPCR] |=3D LPCR_ILE; > + } > +} > + > static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnvironment *spapr, > uint32_t token, uint32_t nargs, > target_ulong args, > @@ -157,6 +167,7 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPREnv= ironment *spapr, > env->nip =3D start; > env->gpr[3] =3D r3; > cs->halted =3D 0; > + spapr_cpu_set_endianness(cpu); > =20 > qemu_cpu_kick(cs); > =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 --rK7ir9GIO0YQrgt+ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVEiWRAAoJEGw4ysog2bOSPKgP/3B+TZRdOIq7MwOg9J8tDdEG H0fIjJfrABF5XKWuvNYK0Ih9JpllYDwFsJiEkYmThOcjEB79DCw3adXIHz5pBSQ7 Fs62He4uGD22QOOfVvY7IDBYpRfWk3kM3QPN6qMcJpPfshkSudWHGPR/i9FLZgAs xdt6W71Cd8vjgAy5qfKqLJgahIuVRoq0yM7h0MKpDwHl6vV8w6wkSNECQ1JT+CK2 /MnV6xghiR5Z5cpRJkwvWSbibAeSdliRIK8ul/xJrWRQuksxU7Pevqz290UPXyDN g8d7neQbDv/ItxL8cGyFzPTjONOwKu426ptmWmvb0bLTlGBaEiV240KITpsvpH/w p70/VL5IODWTGVdAWC2OKbhOP1l3D8z4KDsB/bSrO1+Ll/jCCY4RXFP8tIw2z3L3 IsDauCamqgeYwgC9p0XYqBSRG4bbI1K7p61m+z8XhZ5Y8s6sojjVleK1QoeYLtl0 Ksv7yVYYlTFuESNN0yj7d2iTCzj/5fXWylughe63lGfpYJWdFmUPD3Yh0oYgAZui qMRm6gM+6PKvMpNbzY0cVttTmBBtFEV2wd3VgoJDilRg0D8XCRwBHYqUrJmEPuOi 6NsHA0mEqHQI1IzpWJj/toOORDldQGdEiORO0iwOTvLNci2HeyqzfzpHD+pGaUMW hFxlTbXNag0V8hsxZx1R =2faJ -----END PGP SIGNATURE----- --rK7ir9GIO0YQrgt+--