From: David Gibson <david@gibson.dropbear.id.au>
To: Bharata B Rao <bharata@linux.vnet.ibm.com>
Cc: mdroth@linux.vnet.ibm.com, aik@ozlabs.ru, 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
Subject: Re: [Qemu-devel] [RFC PATCH v3 12/24] spapr: CPU hotplug support
Date: Thu, 7 May 2015 11:03:47 +1000 [thread overview]
Message-ID: <20150507010347.GE1407@voom.redhat.com> (raw)
In-Reply-To: <20150506061420.GO18380@in.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 8525 bytes --]
On Wed, May 06, 2015 at 11:44:20AM +0530, Bharata B Rao wrote:
> On Tue, May 05, 2015 at 04:59:51PM +1000, David Gibson wrote:
> > On Fri, Apr 24, 2015 at 12:17:34PM +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.
> > >
> > > Also support cold plugged CPUs that are specified by -device option
> > > on cmdline.
> > >
> > > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> > > ---
> > > hw/ppc/spapr.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > > hw/ppc/spapr_events.c | 8 ++--
> > > hw/ppc/spapr_rtas.c | 11 +++++
> > > 3 files changed, 145 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> > > index b526b7d..9b0701c 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"
> > > @@ -662,6 +663,17 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset)
> > > unsigned sockets = opts ? qemu_opt_get_number(opts, "sockets", 0) : 0;
> > > uint32_t cpus_per_socket = sockets ? (smp_cpus / sockets) : 1;
> > > uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)};
> > > + sPAPRDRConnector *drc;
> > > + sPAPRDRConnectorClass *drck;
> > > + int drc_index;
> > > +
> > > + if (spapr->dr_cpu_enabled) {
> > > + drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, index);
> > > + g_assert(drc);
> > > + drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
> > > + drc_index = drck->get_index(drc);
> > > + _FDT((fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index)));
> > > + }
> > >
> > > _FDT((fdt_setprop_cell(fdt, offset, "reg", index)));
> > > _FDT((fdt_setprop_string(fdt, offset, "device_type", "cpu")));
> > > @@ -1850,6 +1862,114 @@ static void spapr_nmi(NMIState *n, int cpu_index, Error **errp)
> > > }
> > > }
> > >
> > > +static void *spapr_populate_hotplug_cpu_dt(DeviceState *dev, CPUState *cs,
> > > + int *fdt_offset)
> > > +{
> > > + PowerPCCPU *cpu = POWERPC_CPU(cs);
> > > + DeviceClass *dc = DEVICE_GET_CLASS(cs);
> > > + int id = ppc_get_vcpu_dt_id(cpu);
> > > + void *fdt;
> > > + int offset, fdt_size;
> > > + char *nodename;
> > > +
> > > + fdt = create_device_tree(&fdt_size);
> > > + nodename = g_strdup_printf("%s@%x", dc->fw_name, id);
> > > + offset = fdt_add_subnode(fdt, 0, nodename);
> > > +
> > > + spapr_populate_cpu_dt(cs, fdt, offset);
> > > + g_free(nodename);
> > > +
> > > + *fdt_offset = offset;
> > > + return fdt;
> > > +}
> > > +
> > > +static void spapr_cpu_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
> > > + Error **errp)
> > > +{
> > > + CPUState *cs = CPU(dev);
> > > + PowerPCCPU *cpu = POWERPC_CPU(cs);
> > > + int id = ppc_get_vcpu_dt_id(cpu);
> > > + sPAPRDRConnector *drc =
> > > + spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id);
> > > + sPAPRDRConnectorClass *drck;
> > > + int smt = kvmppc_smt_threads();
> > > + Error *local_err = NULL;
> > > + void *fdt = NULL;
> > > + int i, fdt_offset = 0;
> > > +
> > > + /* Set NUMA node for the added CPUs */
> > > + for (i = 0; i < nb_numa_nodes; i++) {
> > > + if (test_bit(cs->cpu_index, numa_info[i].node_cpu)) {
> > > + cs->numa_node = i;
> > > + break;
> > > + }
> > > + }
> > > +
> > > + /*
> > > + * SMT threads return from here, only main thread (core) will
> > > + * continue and signal hotplug event to the guest.
> > > + */
> > > + if ((id % smt) != 0) {
> > > + return;
> > > + }
> >
> > Couldn't you avoid this by attaching this call to the core device,
> > rather than the individual vcpu thread objects?
>
> Adding a socket device will result in realize call for that device.
> Socket realizefn will call core realizefn and core realizefn will call
> thread (or CPU) realizefn. device_set_realized() will call ->plug handler
> for all these devices (socket, cores and threads) and that's how we
> end up here even for threads.
>
> This will be same when I get rid of socket abstraction and hot plug
> cores for the same reason as above.
>
> And calling ->plug handler in the context of threads is required
> to initialize board specific CPU bits for the CPU thread that is being
> realized.
Right, but can't you do the thread specific initialization from the
thread hotplug path, and the core specific initialization (basically
everything below this if) from the core hotplug path?
>
> >
> >
> > > + if (!spapr->dr_cpu_enabled) {
> > > + /*
> > > + * This is a cold plugged CPU but the machine doesn't support
> > > + * DR. So skip the hotplug path ensuring that the CPU is brought
> > > + * up online with out an associated DR connector.
> > > + */
> > > + return;
> > > + }
> > > +
> > > + g_assert(drc);
> > > +
> > > + /*
> > > + * Setup CPU DT entries only for hotplugged CPUs. For boot time or
> > > + * coldplugged CPUs DT entries are setup in spapr_finalize_fdt().
> > > + */
> > > + if (dev->hotplugged) {
> > > + fdt = spapr_populate_hotplug_cpu_dt(dev, cs, &fdt_offset);
> > > + }
> > > +
> > > + drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
> > > + drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_err);
> > > + if (local_err) {
> > > + g_free(fdt);
> > > + error_propagate(errp, local_err);
> > > + return;
> > > + }
> > > +
> > > + /*
> > > + * We send hotplug notification interrupt to the guest only in case
> > > + * of hotplugged CPUs.
> > > + */
> > > + if (dev->hotplugged) {
> > > + spapr_hotplug_req_add_event(drc);
> > > + } else {
> > > + /*
> > > + * HACK to support removal of hotplugged CPU after VM migration:
> > > + *
> > > + * Since we want to be able to hot-remove those coldplugged CPUs
> > > + * started at boot time using -device option at the target VM, we set
> > > + * the right allocation_state and isolation_state for them, which for
> > > + * the hotplugged CPUs would be set via RTAS calls done from the
> > > + * guest during hotplug.
> > > + *
> > > + * This allows the coldplugged CPUs started using -device option to
> > > + * have the right isolation and allocation states as expected by the
> > > + * CPU hot removal code.
> > > + *
> > > + * This hack will be removed once we have DRC states migrated as part
> > > + * of VM migration.
> > > + */
> > > + drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USABLE);
> > > + drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOLATED);
> > > + }
> > > +
> > > + return;
> > > +}
> > > +
> > > static void spapr_machine_device_plug(HotplugHandler *hotplug_dev,
> > > DeviceState *dev, Error **errp)
> > > {
> > > @@ -1858,6 +1978,15 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev,
> > > PowerPCCPU *cpu = POWERPC_CPU(cs);
> > >
> > > spapr_cpu_init(cpu);
> > > + spapr_cpu_reset(cpu);
> >
> > I'm a little surprised these get called here, rather than in the
> > creation / realize path of the core qdev.
>
> These two routines (spapr_cpu_init and spapr_cpu_reset) are sPAPR or
> board specific and I can't even have them as part of ppc_cpu_realizefn.
Oh, yes of course. Sorry.
> We had discussed this earlier at
> http://lists.gnu.org/archive/html/qemu-devel/2015-02/msg04399.html
>
> Regards,
> Bharata.
>
--
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
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2015-05-07 1:32 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-24 6:47 [Qemu-devel] [RFC PATCH v3 00/24] CPU and Memory hotplug for PowerPC sPAPR guests Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 01/24] spapr: enable PHB/CPU/LMB hotplug for pseries-2.3 Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 02/24] spapr: Add DRC dt entries for CPUs Bharata B Rao
2015-05-04 11:46 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 03/24] spapr: Consider max_cpus during xics initialization Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 04/24] spapr: Support ibm, lrdr-capacity device tree property Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 05/24] spapr: Reorganize CPU dt generation code Bharata B Rao
2015-04-26 11:47 ` Bharata B Rao
2015-04-27 5:36 ` Bharata B Rao
2015-05-04 12:01 ` David Gibson
2015-05-04 11:59 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 06/24] spapr: Consolidate cpu init code into a routine Bharata B Rao
2015-05-04 16:10 ` Thomas Huth
2015-05-06 4:28 ` Bharata B Rao
2015-05-06 6:32 ` Thomas Huth
2015-05-06 8:45 ` Bharata B Rao
2015-05-06 9:37 ` Thomas Huth
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 07/24] cpu: Prepare Socket container type Bharata B Rao
2015-05-05 1:47 ` David Gibson
2015-05-06 4:36 ` Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 08/24] ppc: Prepare CPU socket/core abstraction Bharata B Rao
2015-05-04 15:15 ` Thomas Huth
2015-05-06 4:40 ` Bharata B Rao
2015-05-06 6:52 ` Thomas Huth
2015-05-05 6:46 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 09/24] spapr: Add CPU hotplug handler Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 10/24] ppc: Update cpu_model in MachineState Bharata B Rao
2015-05-05 6:49 ` David Gibson
2015-05-06 4:49 ` Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 11/24] ppc: Create sockets and cores for CPUs Bharata B Rao
2015-05-05 6:52 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 12/24] spapr: CPU hotplug support Bharata B Rao
2015-05-04 15:53 ` Thomas Huth
2015-05-06 5:37 ` Bharata B Rao
2015-05-05 6:59 ` David Gibson
2015-05-06 6:14 ` Bharata B Rao
2015-05-07 1:03 ` David Gibson [this message]
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 13/24] cpus: Add Error argument to cpu_exec_init() Bharata B Rao
2015-05-05 7:01 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 14/24] cpus: Convert cpu_index into a bitmap Bharata B Rao
2015-05-05 7:10 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 15/24] ppc: Move cpu_exec_init() call to realize function Bharata B Rao
2015-05-05 7:12 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 16/24] qom: Introduce object_has_no_children() API Bharata B Rao
2015-05-05 7:13 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 17/24] cpus: Reclaim vCPU objects Bharata B Rao
2015-05-05 7:20 ` David Gibson
2015-05-06 6:37 ` Bharata B Rao
2015-05-07 1:06 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 18/24] xics_kvm: Don't enable KVM_CAP_IRQ_XICS if already enabled Bharata B Rao
2015-05-05 7:22 ` David Gibson
2015-05-06 5:42 ` Bharata B Rao
2015-05-07 1:07 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 19/24] xics_kvm: Add cpu_destroy method to XICS Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 20/24] spapr: CPU hot unplug support Bharata B Rao
2015-05-05 7:28 ` David Gibson
2015-05-06 7:55 ` Bharata B Rao
2015-05-07 1:09 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 21/24] spapr: Initialize hotplug memory address space Bharata B Rao
2015-05-05 7:33 ` David Gibson
2015-05-06 7:58 ` Bharata B Rao
2015-05-05 8:48 ` Igor Mammedov
2015-05-06 8:23 ` Bharata B Rao
2015-05-07 1:12 ` David Gibson
2015-05-07 5:01 ` Bharata B Rao
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 22/24] numa: API to lookup NUMA node by address Bharata B Rao
2015-05-05 7:35 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 23/24] spapr: Support ibm, dynamic-reconfiguration-memory Bharata B Rao
2015-05-05 7:40 ` David Gibson
2015-05-06 8:27 ` Bharata B Rao
2015-05-07 1:13 ` David Gibson
2015-04-24 6:47 ` [Qemu-devel] [RFC PATCH v3 24/24] spapr: Memory hotplug support Bharata B Rao
2015-05-05 7:45 ` David Gibson
2015-05-06 8:30 ` Bharata B Rao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150507010347.GE1407@voom.redhat.com \
--to=david@gibson.dropbear.id.au \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=bharata@linux.vnet.ibm.com \
--cc=imammedo@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=nfont@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=tyreld@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.