All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR
@ 2016-06-10  0:58 Bharata B Rao
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type Bharata B Rao
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

Hi,

This is the next version of the CPU hotplug patchset for PowerPC
sPAPR target. The hotplug semantics looks like this:

(qemu) device_add POWER8E-spapr-cpu-core,id=core2,core-id=16[,threads=4]
(qemu) device_add host-spapr-cpu-core,id=core2,core-id=16[,threads=4]
(qemu) device_add POWER8E_v2.1-spapr-cpu-core,id=core2,core-id=16[,threads=4]

Changes in v4
-------------
- Rebased against David Gibson's ppc-cpu-hotplug and hence dropped those
  patches that are already part of that tree.
- We were assuming the CPU thread to be always of type PowerPCCPU which
  needn't be true. Hence use actual CPU type's instance_size when
  object_initialize'ing the threads as per David's suggestion. This requires
  us to know the instance_size for a given type for which a new QOM API
  object_type_get_size() has been introduced in this version.
- Consolidate CPU init related routines in spapr_cpu_core.c. As part of this
  move spapr_cpu_init() and its dependencies to spapr_cpu_core.c.
- Got rid of the temporary unplug list when removing CPU cores.
- Folded spapr_cpu_core_create_threads() into spapr_cpu_core_realize() and
  fixed the error path in in spapr_cpu_core_realize().
- Add support for -cpu host.

TODOs remaining
---------------
- Work on David's suggestion of intializing CPU's ObjectClass in
  class_init rather than instance_init.
- Use object_initialize_with_type instead of object_initialize when
  creating CPU threads of a core.
- Use vcpu_dt_id logic when populating core id in
  spapr_query_hotpluggable_cpus().
- Handle CPU compat properly (-cpu host,compat=POWER7)

v3: https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg01829.html

Bharata B Rao (7):
  qom: API to get instance_size of a type
  spapr: Abstract CPU core device and type specific core devices
  spapr: Move spapr_cpu_init() to spapr_cpu_core.c
  spapr: convert boot CPUs into CPU core devices
  spapr: CPU hotplug support
  spapr: CPU hot unplug support
  hmp: Add 'info hotpluggable-cpus' HMP command

Igor Mammedov (2):
  QMP: Add query-hotpluggable-cpus
  spapr: implement query-hotpluggable-cpus callback

 hmp-commands-info.hx            |  14 ++
 hmp.c                           |  41 ++++
 hmp.h                           |   1 +
 hw/ppc/Makefile.objs            |   1 +
 hw/ppc/spapr.c                  | 215 +++++++++++++++------
 hw/ppc/spapr_cpu_core.c         | 405 ++++++++++++++++++++++++++++++++++++++++
 hw/ppc/spapr_events.c           |   3 +
 hw/ppc/spapr_rtas.c             |  24 +++
 include/hw/boards.h             |   5 +
 include/hw/ppc/spapr.h          |   7 +
 include/hw/ppc/spapr_cpu_core.h |  36 ++++
 include/qom/object.h            |   8 +-
 monitor.c                       |  13 ++
 qapi-schema.json                |  55 ++++++
 qmp-commands.hx                 |  23 +++
 qom/object.c                    |   8 +
 target-ppc/kvm.c                |  28 +++
 17 files changed, 828 insertions(+), 59 deletions(-)
 create mode 100644 hw/ppc/spapr_cpu_core.c
 create mode 100644 include/hw/ppc/spapr_cpu_core.h

-- 
2.1.0

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  4:04   ` David Gibson
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 2/9] spapr: Abstract CPU core device and type specific core devices Bharata B Rao
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

Add an API object_type_get_size(const char *typename) that returns the
instance_size of the give typename.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 include/qom/object.h | 8 +++++++-
 qom/object.c         | 8 ++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 21bb5ff..460ddfc 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1608,5 +1608,11 @@ int object_child_foreach_recursive(Object *obj,
  */
 Object *container_get(Object *root, const char *path);
 
-
+/**
+ * object_type_get_size:
+ * @typename: Name of the Type whose instance_size is required
+ *
+ * Returns the instance_size of the given @typename.
+ */
+size_t object_type_get_size(const char *typename);
 #endif
diff --git a/qom/object.c b/qom/object.c
index 3bc8a00..0e75877 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -202,6 +202,14 @@ static size_t type_object_get_size(TypeImpl *ti)
     return 0;
 }
 
+size_t object_type_get_size(const char *typename)
+{
+    TypeImpl *type = type_get_by_name(typename);
+
+    g_assert(type != NULL);
+    return type_object_get_size(type);
+}
+
 static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
 {
     assert(target_type);
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 2/9] spapr: Abstract CPU core device and type specific core devices
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  4:24   ` David Gibson
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 3/9] spapr: Move spapr_cpu_init() to spapr_cpu_core.c Bharata B Rao
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

Add sPAPR specific abastract CPU core device that is based on generic
CPU core device. Use this as base type to create sPAPR CPU specific core
devices.

TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctly

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 hw/ppc/Makefile.objs            |   1 +
 hw/ppc/spapr.c                  |   3 +-
 hw/ppc/spapr_cpu_core.c         | 160 ++++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h          |   1 +
 include/hw/ppc/spapr_cpu_core.h |  29 ++++++++
 target-ppc/kvm.c                |  28 +++++++
 6 files changed, 220 insertions(+), 2 deletions(-)
 create mode 100644 hw/ppc/spapr_cpu_core.c
 create mode 100644 include/hw/ppc/spapr_cpu_core.h

diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
index c1ffc77..5cc6608 100644
--- a/hw/ppc/Makefile.objs
+++ b/hw/ppc/Makefile.objs
@@ -4,6 +4,7 @@ obj-y += ppc.o ppc_booke.o
 obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o
 obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
 obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o
+obj-$(CONFIG_PSERIES) += spapr_cpu_core.o
 ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
 obj-y += spapr_pci_vfio.o
 endif
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 0636642..87f4e53 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1606,8 +1606,7 @@ static void spapr_boot_set(void *opaque, const char *boot_device,
     machine->boot_order = g_strdup(boot_device);
 }
 
-static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
-                           Error **errp)
+void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
 {
     CPUPPCState *env = &cpu->env;
 
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
new file mode 100644
index 0000000..b8b97c9
--- /dev/null
+++ b/hw/ppc/spapr_cpu_core.c
@@ -0,0 +1,160 @@
+/*
+ * sPAPR CPU core device, acts as container of CPU thread devices.
+ *
+ * Copyright (C) 2016 Bharata B Rao <bharata@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "hw/cpu/core.h"
+#include "hw/ppc/spapr_cpu_core.h"
+#include "target-ppc/cpu.h"
+#include "hw/ppc/spapr.h"
+#include "hw/boards.h"
+#include "qapi/error.h"
+#include <sysemu/cpus.h>
+#include "target-ppc/kvm_ppc.h"
+
+static int spapr_cpu_core_realize_child(Object *child, void *opaque)
+{
+    Error **errp = opaque;
+    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+    CPUState *cs = CPU(child);
+    PowerPCCPU *cpu = 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;
+}
+
+static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
+{
+    sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
+    CPUCore *cc = CPU_CORE(OBJECT(dev));
+    const char *typename = object_class_get_name(sc->cpu_class);
+    size_t size = object_type_get_size(typename);
+    Error *local_err = NULL;
+    Object *obj;
+    int i;
+
+    sc->threads = g_malloc0(size * cc->nr_threads);
+    for (i = 0; i < cc->nr_threads; i++) {
+        char id[32];
+        void *obj = sc->threads + i * size;
+
+        object_initialize(obj, size, typename);
+        snprintf(id, sizeof(id), "thread[%d]", i);
+        object_property_add_child(OBJECT(sc), id, obj, &local_err);
+        if (local_err) {
+            goto err;
+        }
+    }
+    object_child_foreach(OBJECT(dev), spapr_cpu_core_realize_child, &local_err);
+    if (local_err) {
+        goto err;
+    } else {
+        return;
+    }
+
+err:
+    while (i >= 0) {
+        obj = sc->threads + i * size;
+        object_unparent(obj);
+        i--;
+    }
+    g_free(sc->threads);
+    error_propagate(errp, local_err);
+}
+
+static void spapr_cpu_core_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    dc->realize = spapr_cpu_core_realize;
+}
+
+/*
+ * instance_init routines from different flavours of sPAPR CPU cores.
+ * TODO: Add support for 'host' core type.
+ */
+#define SPAPR_CPU_CORE_INITFN(_type, _fname) \
+static void glue(glue(spapr_cpu_core_, _fname), _initfn(Object *obj)) \
+{ \
+    sPAPRCPUCore *core = SPAPR_CPU_CORE(obj); \
+    char *name = g_strdup_printf("%s-" TYPE_POWERPC_CPU, stringify(_type)); \
+    ObjectClass *oc = object_class_by_name(name); \
+    g_assert(oc); \
+    g_free((void *)name); \
+    core->cpu_class = oc; \
+}
+
+SPAPR_CPU_CORE_INITFN(POWER7_v2.3, POWER7);
+SPAPR_CPU_CORE_INITFN(POWER7+_v2.1, POWER7plus);
+SPAPR_CPU_CORE_INITFN(POWER8_v2.0, POWER8);
+SPAPR_CPU_CORE_INITFN(POWER8E_v2.1, POWER8E);
+
+typedef struct SPAPRCoreInfo {
+    const char *name;
+    void (*initfn)(Object *obj);
+} SPAPRCoreInfo;
+
+static const SPAPRCoreInfo spapr_cores[] = {
+    /* POWER7 and aliases */
+    { .name = "POWER7_v2.3", .initfn = spapr_cpu_core_POWER7_initfn },
+    { .name = "POWER7", .initfn = spapr_cpu_core_POWER7_initfn },
+
+    /* POWER7+ and aliases */
+    { .name = "POWER7+_v2.1", .initfn = spapr_cpu_core_POWER7plus_initfn },
+    { .name = "POWER7+", .initfn = spapr_cpu_core_POWER7plus_initfn },
+
+    /* POWER8 and aliases */
+    { .name = "POWER8_v2.0", .initfn = spapr_cpu_core_POWER8_initfn },
+    { .name = "POWER8", .initfn = spapr_cpu_core_POWER8_initfn },
+    { .name = "power8", .initfn = spapr_cpu_core_POWER8_initfn },
+
+    /* POWER8E and aliases */
+    { .name = "POWER8E_v2.1", .initfn = spapr_cpu_core_POWER8E_initfn },
+    { .name = "POWER8E", .initfn = spapr_cpu_core_POWER8E_initfn },
+
+    { .name = NULL }
+};
+
+static void spapr_cpu_core_register(const SPAPRCoreInfo *info)
+{
+    TypeInfo type_info = {
+        .parent = TYPE_SPAPR_CPU_CORE,
+        .instance_size = sizeof(sPAPRCPUCore),
+        .instance_init = info->initfn,
+    };
+
+    type_info.name = g_strdup_printf("%s-" TYPE_SPAPR_CPU_CORE, info->name);
+    type_register(&type_info);
+    g_free((void *)type_info.name);
+}
+
+static const TypeInfo spapr_cpu_core_type_info = {
+    .name = TYPE_SPAPR_CPU_CORE,
+    .parent = TYPE_CPU_CORE,
+    .abstract = true,
+    .instance_size = sizeof(sPAPRCPUCore),
+    .class_init = spapr_cpu_core_class_init,
+};
+
+static void spapr_cpu_core_register_types(void)
+{
+    const SPAPRCoreInfo *info = spapr_cores;
+
+    type_register_static(&spapr_cpu_core_type_info);
+    while (info->name) {
+        spapr_cpu_core_register(info);
+        info++;
+    }
+}
+
+type_init(spapr_cpu_core_register_types)
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 971df3d..4ff14d6 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -582,6 +582,7 @@ void spapr_hotplug_req_add_by_count(sPAPRDRConnectorType 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);
 
 /* rtas-configure-connector state */
 struct sPAPRConfigureConnectorState {
diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h
new file mode 100644
index 0000000..424edec
--- /dev/null
+++ b/include/hw/ppc/spapr_cpu_core.h
@@ -0,0 +1,29 @@
+/*
+ * sPAPR CPU core device.
+ *
+ * Copyright (C) 2016 Bharata B Rao <bharata@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef HW_SPAPR_CPU_CORE_H
+#define HW_SPAPR_CPU_CORE_H
+
+#include "hw/qdev.h"
+#include "hw/cpu/core.h"
+#include "target-ppc/cpu-qom.h"
+
+#define TYPE_SPAPR_CPU_CORE "spapr-cpu-core"
+#define SPAPR_CPU_CORE(obj) \
+    OBJECT_CHECK(sPAPRCPUCore, (obj), TYPE_SPAPR_CPU_CORE)
+
+typedef struct sPAPRCPUCore {
+    /*< private >*/
+    CPUCore parent_obj;
+
+    /*< public >*/
+    void *threads;
+    ObjectClass *cpu_class;
+} sPAPRCPUCore;
+
+#endif
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 24d6032..20982d0 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -43,6 +43,9 @@
 #include "exec/memattrs.h"
 #include "sysemu/hostmem.h"
 #include "qemu/cutils.h"
+#if defined(TARGET_PPC64)
+#include "hw/ppc/spapr_cpu_core.h"
+#endif
 
 //#define DEBUG_KVM
 
@@ -2329,6 +2332,19 @@ static PowerPCCPUClass *ppc_cpu_get_family_class(PowerPCCPUClass *pcc)
     return POWERPC_CPU_CLASS(oc);
 }
 
+#if defined(TARGET_PPC64)
+static void spapr_cpu_core_host_initfn(Object *obj)
+{
+    sPAPRCPUCore *core = SPAPR_CPU_CORE(obj);
+    char *name = g_strdup_printf("%s-" TYPE_POWERPC_CPU, "host");
+    ObjectClass *oc = object_class_by_name(name);
+
+    g_assert(oc);
+    g_free((void *)name);
+    core->cpu_class = oc;
+}
+#endif
+
 static int kvm_ppc_register_host_cpu_type(void)
 {
     TypeInfo type_info = {
@@ -2350,6 +2366,18 @@ static int kvm_ppc_register_host_cpu_type(void)
     type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
     type_register(&type_info);
 
+#if defined(TARGET_PPC64)
+    type_info.name = g_strdup_printf("%s-"TYPE_SPAPR_CPU_CORE, "host");
+    type_info.parent = TYPE_SPAPR_CPU_CORE,
+    type_info.instance_size = sizeof(sPAPRCPUCore),
+    type_info.instance_init = spapr_cpu_core_host_initfn,
+    type_info.class_init = NULL;
+    type_register(&type_info);
+    g_free((void *)type_info.name);
+    type_info.instance_size = 0;
+    type_info.instance_init = NULL;
+#endif
+
     /* Register generic family CPU class for a family */
     pvr_pcc = ppc_cpu_get_family_class(pvr_pcc);
     dc = DEVICE_CLASS(pvr_pcc);
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 3/9] spapr: Move spapr_cpu_init() to spapr_cpu_core.c
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type Bharata B Rao
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 2/9] spapr: Abstract CPU core device and type specific core devices Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  4:27   ` David Gibson
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 4/9] spapr: convert boot CPUs into CPU core devices Bharata B Rao
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

Start consolidating CPU init related routines in spapr_cpu_core.c. As
part of this, move spapr_cpu_init() and its dependencies from spapr.c
to spapr_cpu_core.c

No functionality change in this patch.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 hw/ppc/spapr.c          | 47 -----------------------------------------------
 hw/ppc/spapr_cpu_core.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h  |  2 ++
 3 files changed, 50 insertions(+), 47 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 87f4e53..adaca42 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -89,8 +89,6 @@
 
 #define MIN_RMA_SLOF            128UL
 
-#define TIMEBASE_FREQ           512000000ULL
-
 #define PHANDLE_XICP            0x00001111
 
 #define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
@@ -1181,26 +1179,6 @@ static void ppc_spapr_reset(void)
 
 }
 
-static void spapr_cpu_reset(void *opaque)
-{
-    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
-    PowerPCCPU *cpu = opaque;
-    CPUState *cs = CPU(cpu);
-    CPUPPCState *env = &cpu->env;
-
-    cpu_reset(cs);
-
-    /* All CPUs start halted.  CPU0 is unhalted from the machine level
-     * reset code and the rest are explicitly started up by the guest
-     * using an RTAS call */
-    cs->halted = 1;
-
-    env->spr[SPR_HIOR] = 0;
-
-    ppc_hash64_set_external_hpt(cpu, spapr->htab, spapr->htab_shift,
-                                &error_fatal);
-}
-
 static void spapr_create_nvram(sPAPRMachineState *spapr)
 {
     DeviceState *dev = qdev_create(&spapr->vio_bus->bus, "spapr-nvram");
@@ -1606,31 +1584,6 @@ static void spapr_boot_set(void *opaque, const char *boot_device,
     machine->boot_order = g_strdup(boot_device);
 }
 
-void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
-{
-    CPUPPCState *env = &cpu->env;
-
-    /* Set time-base frequency to 512 MHz */
-    cpu_ppc_tb_init(env, TIMEBASE_FREQ);
-
-    /* Enable PAPR mode in TCG or KVM */
-    cpu_ppc_set_papr(cpu);
-
-    if (cpu->max_compat) {
-        Error *local_err = NULL;
-
-        ppc_set_compat(cpu, cpu->max_compat, &local_err);
-        if (local_err) {
-            error_propagate(errp, local_err);
-            return;
-        }
-    }
-
-    xics_cpu_setup(spapr->icp, cpu);
-
-    qemu_register_reset(spapr_cpu_reset, cpu);
-}
-
 /*
  * Reset routine for LMB DR devices.
  *
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index b8b97c9..e9eb754 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -14,6 +14,54 @@
 #include "qapi/error.h"
 #include <sysemu/cpus.h>
 #include "target-ppc/kvm_ppc.h"
+#include "hw/ppc/ppc.h"
+#include "target-ppc/mmu-hash64.h"
+#include <sysemu/numa.h>
+
+static void spapr_cpu_reset(void *opaque)
+{
+    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+    PowerPCCPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
+    CPUPPCState *env = &cpu->env;
+
+    cpu_reset(cs);
+
+    /* All CPUs start halted.  CPU0 is unhalted from the machine level
+     * reset code and the rest are explicitly started up by the guest
+     * using an RTAS call */
+    cs->halted = 1;
+
+    env->spr[SPR_HIOR] = 0;
+
+    ppc_hash64_set_external_hpt(cpu, spapr->htab, spapr->htab_shift,
+                                &error_fatal);
+}
+
+void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
+{
+    CPUPPCState *env = &cpu->env;
+
+    /* Set time-base frequency to 512 MHz */
+    cpu_ppc_tb_init(env, TIMEBASE_FREQ);
+
+    /* Enable PAPR mode in TCG or KVM */
+    cpu_ppc_set_papr(cpu);
+
+    if (cpu->max_compat) {
+        Error *local_err = NULL;
+
+        ppc_set_compat(cpu, cpu->max_compat, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
+        }
+    }
+
+    xics_cpu_setup(spapr->icp, cpu);
+
+    qemu_register_reset(spapr_cpu_reset, cpu);
+}
 
 static int spapr_cpu_core_realize_child(Object *child, void *opaque)
 {
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 4ff14d6..e372dae 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -16,6 +16,8 @@ typedef struct sPAPREventLogEntry sPAPREventLogEntry;
 #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
 #define SPAPR_ENTRY_POINT       0x100
 
+#define TIMEBASE_FREQ           512000000ULL
+
 typedef struct sPAPRMachineClass sPAPRMachineClass;
 typedef struct sPAPRMachineState sPAPRMachineState;
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 4/9] spapr: convert boot CPUs into CPU core devices
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
                   ` (2 preceding siblings ...)
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 3/9] spapr: Move spapr_cpu_init() to spapr_cpu_core.c Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 5/9] spapr: CPU hotplug support Bharata B Rao
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

Introduce sPAPRMachineClass.dr_cpu_enabled to indicate support for
CPU core hotplug. Initialize boot time CPUs as core deivces and prevent
topologies that result in partially filled cores. Both of these are done
only if CPU core hotplug is supported.

Note: An unrelated change in the call to xics_system_init() is done
in this patch as it makes sense to use the local variable smt introduced
in this patch instead of kvmppc_smt_threads() call here.

TODO: We derive sPAPR core type by looking at -cpu <model>. However
we don't take care of "compat=" feature yet for boot time as well
as hotplug CPUs.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c                  | 73 +++++++++++++++++++++++++++++++++++------
 hw/ppc/spapr_cpu_core.c         | 58 ++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h          |  2 ++
 include/hw/ppc/spapr_cpu_core.h |  3 ++
 4 files changed, 126 insertions(+), 10 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index adaca42..1435e38 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -66,6 +66,7 @@
 
 #include "hw/compat.h"
 #include "qemu/cutils.h"
+#include "hw/ppc/spapr_cpu_core.h"
 
 #include <libfdt.h>
 
@@ -1665,7 +1666,6 @@ static void ppc_spapr_init(MachineState *machine)
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
     const char *initrd_filename = machine->initrd_filename;
-    PowerPCCPU *cpu;
     PCIHostState *phb;
     int i;
     MemoryRegion *sysmem = get_system_memory();
@@ -1679,6 +1679,22 @@ static void ppc_spapr_init(MachineState *machine)
     long load_limit, fw_size;
     bool kernel_le = false;
     char *filename;
+    int smt = kvmppc_smt_threads();
+    int spapr_cores = smp_cpus / smp_threads;
+    int spapr_max_cores = max_cpus / smp_threads;
+
+    if (smc->dr_cpu_enabled) {
+        if (smp_cpus % smp_threads) {
+            error_report("smp_cpus (%u) must be multiple of threads (%u)",
+                         smp_cpus, smp_threads);
+            exit(1);
+        }
+        if (max_cpus % smp_threads) {
+            error_report("max_cpus (%u) must be multiple of threads (%u)",
+                         max_cpus, smp_threads);
+            exit(1);
+        }
+    }
 
     msi_nonbroken = true;
 
@@ -1725,8 +1741,7 @@ static void ppc_spapr_init(MachineState *machine)
 
     /* Set up Interrupt Controller before we create the VCPUs */
     spapr->icp = xics_system_init(machine,
-                                  DIV_ROUND_UP(max_cpus * kvmppc_smt_threads(),
-                                               smp_threads),
+                                  DIV_ROUND_UP(max_cpus * smt, smp_threads),
                                   XICS_IRQS, &error_fatal);
 
     if (smc->dr_lmb_enabled) {
@@ -1737,13 +1752,37 @@ static void ppc_spapr_init(MachineState *machine)
     if (machine->cpu_model == NULL) {
         machine->cpu_model = kvm_enabled() ? "host" : "POWER7";
     }
-    for (i = 0; i < smp_cpus; i++) {
-        cpu = cpu_ppc_init(machine->cpu_model);
-        if (cpu == NULL) {
-            error_report("Unable to find PowerPC CPU definition");
-            exit(1);
+
+    if (smc->dr_cpu_enabled) {
+        char *type = spapr_get_cpu_core_type(machine->cpu_model);
+
+        spapr->cores = g_new0(Object *, spapr_max_cores);
+        for (i = 0; i < spapr_cores; i++) {
+            int core_dt_id = i * smt;
+            Object *core;
+
+            if (!object_class_by_name(type)) {
+                error_report("Unable to find sPAPR CPU Core definition");
+                exit(1);
+            }
+
+            core  = object_new(type);
+            object_property_set_int(core, smp_threads, "nr-threads",
+                                    &error_fatal);
+            object_property_set_int(core, core_dt_id, CPU_CORE_PROP_CORE_ID,
+                                    &error_fatal);
+            object_property_set_bool(core, true, "realized", &error_fatal);
         }
-        spapr_cpu_init(spapr, cpu, &error_fatal);
+        g_free(type);
+    } else {
+        for (i = 0; i < smp_cpus; i++) {
+            PowerPCCPU *cpu = cpu_ppc_init(machine->cpu_model);
+            if (cpu == NULL) {
+                error_report("Unable to find PowerPC CPU definition");
+                exit(1);
+            }
+            spapr_cpu_init(spapr, cpu, &error_fatal);
+       }
     }
 
     if (kvm_enabled()) {
@@ -2209,10 +2248,19 @@ static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev,
     }
 }
 
+static void spapr_machine_device_pre_plug(HotplugHandler *hotplug_dev,
+                                          DeviceState *dev, Error **errp)
+{
+    if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
+        spapr_core_pre_plug(hotplug_dev, dev, errp);
+    }
+}
+
 static HotplugHandler *spapr_get_hotpug_handler(MachineState *machine,
                                              DeviceState *dev)
 {
-    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
+        object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
         return HOTPLUG_HANDLER(machine);
     }
     return NULL;
@@ -2251,11 +2299,13 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
     mc->has_dynamic_sysbus = true;
     mc->pci_allow_0_address = true;
     mc->get_hotplug_handler = spapr_get_hotpug_handler;
+    hc->pre_plug = spapr_machine_device_pre_plug;
     hc->plug = spapr_machine_device_plug;
     hc->unplug = spapr_machine_device_unplug;
     mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id;
 
     smc->dr_lmb_enabled = true;
+    smc->dr_cpu_enabled = true;
     fwc->get_dev_path = spapr_get_fw_dev_path;
     nc->nmi_monitor_handler = spapr_nmi;
 }
@@ -2331,7 +2381,10 @@ static void spapr_machine_2_6_instance_options(MachineState *machine)
 
 static void spapr_machine_2_6_class_options(MachineClass *mc)
 {
+    sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
+
     spapr_machine_2_7_class_options(mc);
+    smc->dr_cpu_enabled = false;
     SET_MACHINE_COMPAT(mc, SPAPR_COMPAT_2_6);
 }
 
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index e9eb754..6eb2a25 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -63,6 +63,64 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
     qemu_register_reset(spapr_cpu_reset, cpu);
 }
 
+/*
+ * Return the sPAPR CPU core type for @model which essentially is the CPU
+ * model specified with -cpu cmdline option.
+ */
+char *spapr_get_cpu_core_type(const char *model)
+{
+    char *core_type;
+    gchar **model_pieces = g_strsplit(model, ",", 2);
+
+    core_type = g_strdup_printf("%s-%s", model_pieces[0], TYPE_SPAPR_CPU_CORE);
+    g_strfreev(model_pieces);
+    return core_type;
+}
+
+void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                         Error **errp)
+{
+    MachineState *machine = MACHINE(OBJECT(hotplug_dev));
+    sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev));
+    int spapr_max_cores = max_cpus / smp_threads;
+    int index;
+    int smt = kvmppc_smt_threads();
+    Error *local_err = NULL;
+    CPUCore *cc = CPU_CORE(dev);
+    char *base_core_type = spapr_get_cpu_core_type(machine->cpu_model);
+    const char *type = object_get_typename(OBJECT(dev));
+
+    if (strcmp(base_core_type, type)) {
+        error_setg(&local_err, "CPU core type should be %s", base_core_type);
+        goto out;
+    }
+
+    if (cc->nr_threads != smp_threads) {
+        error_setg(&local_err, "threads must be %d", smp_threads);
+        goto out;
+    }
+
+    if (cc->core_id % smt) {
+        error_setg(&local_err, "invalid core id %d\n", cc->core_id);
+        goto out;
+    }
+
+    index = cc->core_id / smt;
+    if (index < 0 || index >= spapr_max_cores) {
+        error_setg(&local_err, "core id %d out of range", cc->core_id);
+        goto out;
+    }
+
+    if (spapr->cores[index]) {
+        error_setg(&local_err, "core %d already populated", cc->core_id);
+        goto out;
+    }
+
+out:
+    g_free(base_core_type);
+    error_propagate(errp, local_err);
+}
+
 static int spapr_cpu_core_realize_child(Object *child, void *opaque)
 {
     Error **errp = opaque;
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index e372dae..ab393fd 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -38,6 +38,7 @@ struct sPAPRMachineClass {
 
     /*< public >*/
     bool dr_lmb_enabled;       /* enable dynamic-reconfig/hotplug of LMBs */
+    bool dr_cpu_enabled;       /* enable dynamic-reconfig/hotplug of CPUs */
     bool use_ohci_by_default;  /* use USB-OHCI instead of XHCI */
 };
 
@@ -81,6 +82,7 @@ struct sPAPRMachineState {
     /*< public >*/
     char *kvm_type;
     MemoryHotplugState hotplug_memory;
+    Object **cores;
 };
 
 #define H_SUCCESS         0
diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h
index 424edec..401381b 100644
--- a/include/hw/ppc/spapr_cpu_core.h
+++ b/include/hw/ppc/spapr_cpu_core.h
@@ -26,4 +26,7 @@ typedef struct sPAPRCPUCore {
     ObjectClass *cpu_class;
 } sPAPRCPUCore;
 
+void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                         Error **errp);
+char *spapr_get_cpu_core_type(const char *model);
 #endif
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 5/9] spapr: CPU hotplug support
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
                   ` (3 preceding siblings ...)
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 4/9] spapr: convert boot CPUs into CPU core devices Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 6/9] spapr: CPU hot unplug support Bharata B Rao
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

Set up device tree entries for the hotplugged CPU core and use the
exising RTAS event logging infrastructure to send CPU hotplug notification
to the guest.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/ppc/spapr.c                  | 78 +++++++++++++++++++++++++++++++++-------
 hw/ppc/spapr_cpu_core.c         | 80 +++++++++++++++++++++++++++++++++++++++++
 hw/ppc/spapr_events.c           |  3 ++
 hw/ppc/spapr_rtas.c             | 24 +++++++++++++
 include/hw/ppc/spapr.h          |  2 ++
 include/hw/ppc/spapr_cpu_core.h |  2 ++
 6 files changed, 176 insertions(+), 13 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 1435e38..32c2da7 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -604,6 +604,16 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset,
     size_t page_sizes_prop_size;
     uint32_t vcpus_per_socket = smp_threads * smp_cores;
     uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)};
+    sPAPRDRConnector *drc;
+    sPAPRDRConnectorClass *drck;
+    int drc_index;
+
+    drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, index);
+    if (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)));
+    }
 
     /* Note: we keep CI large pages off for now because a 64K capable guest
      * provisioned with large pages might otherwise try to map a qemu
@@ -987,6 +997,16 @@ static void spapr_finalize_fdt(sPAPRMachineState *spapr,
         _FDT(spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB));
     }
 
+    if (smc->dr_cpu_enabled) {
+        int offset = fdt_path_offset(fdt, "/cpus");
+        ret = spapr_drc_populate_dt(fdt, offset, NULL,
+                                    SPAPR_DR_CONNECTOR_TYPE_CPU);
+        if (ret < 0) {
+            error_report("Couldn't set up CPU DR device tree properties");
+            exit(1);
+        }
+    }
+
     _FDT((fdt_pack(fdt)));
 
     if (fdt_totalsize(fdt) > FDT_MAX_SIZE) {
@@ -1757,21 +1777,30 @@ static void ppc_spapr_init(MachineState *machine)
         char *type = spapr_get_cpu_core_type(machine->cpu_model);
 
         spapr->cores = g_new0(Object *, spapr_max_cores);
-        for (i = 0; i < spapr_cores; i++) {
+        for (i = 0; i < spapr_max_cores; i++) {
             int core_dt_id = i * smt;
-            Object *core;
-
-            if (!object_class_by_name(type)) {
-                error_report("Unable to find sPAPR CPU Core definition");
-                exit(1);
+            sPAPRDRConnector *drc =
+                spapr_dr_connector_new(OBJECT(spapr),
+                                       SPAPR_DR_CONNECTOR_TYPE_CPU, core_dt_id);
+
+            qemu_register_reset(spapr_drc_reset, drc);
+
+            if (i < spapr_cores) {
+                char *type = spapr_get_cpu_core_type(machine->cpu_model);
+                Object *core;
+
+                if (!object_class_by_name(type)) {
+                    error_report("Unable to find sPAPR CPU Core definition");
+                    exit(1);
+                }
+
+                core  = object_new(type);
+                object_property_set_int(core, smp_threads, "nr-threads",
+                                        &error_fatal);
+                object_property_set_int(core, core_dt_id, CPU_CORE_PROP_CORE_ID,
+                                        &error_fatal);
+                object_property_set_bool(core, true, "realized", &error_fatal);
             }
-
-            core  = object_new(type);
-            object_property_set_int(core, smp_threads, "nr-threads",
-                                    &error_fatal);
-            object_property_set_int(core, core_dt_id, CPU_CORE_PROP_CORE_ID,
-                                    &error_fatal);
-            object_property_set_bool(core, true, "realized", &error_fatal);
         }
         g_free(type);
     } else {
@@ -2193,6 +2222,27 @@ out:
     error_propagate(errp, local_err);
 }
 
+void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset,
+                                    sPAPRMachineState *spapr)
+{
+    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, spapr);
+    g_free(nodename);
+
+    *fdt_offset = offset;
+    return fdt;
+}
+
 static void spapr_machine_device_plug(HotplugHandler *hotplug_dev,
                                       DeviceState *dev, Error **errp)
 {
@@ -2237,6 +2287,8 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev,
         }
 
         spapr_memory_plug(hotplug_dev, dev, node, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
+        spapr_core_plug(hotplug_dev, dev, errp);
     }
 }
 
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 6eb2a25..0418b45 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -41,6 +41,8 @@ static void spapr_cpu_reset(void *opaque)
 void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
 {
     CPUPPCState *env = &cpu->env;
+    CPUState *cs = CPU(cpu);
+    int i;
 
     /* Set time-base frequency to 512 MHz */
     cpu_ppc_tb_init(env, TIMEBASE_FREQ);
@@ -58,9 +60,18 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
         }
     }
 
+    /* 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;
+        }
+    }
+
     xics_cpu_setup(spapr->icp, cpu);
 
     qemu_register_reset(spapr_cpu_reset, cpu);
+    spapr_cpu_reset(cpu);
 }
 
 /*
@@ -77,10 +88,74 @@ char *spapr_get_cpu_core_type(const char *model)
     return core_type;
 }
 
+void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                     Error **errp)
+{
+    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(OBJECT(hotplug_dev));
+    sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev));
+    sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
+    CPUCore *cc = CPU_CORE(dev);
+    CPUState *cs = CPU(core->threads);
+    sPAPRDRConnector *drc;
+    sPAPRDRConnectorClass *drck;
+    Error *local_err = NULL;
+    void *fdt = NULL;
+    int fdt_offset = 0;
+    int index;
+    int smt = kvmppc_smt_threads();
+
+    drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, cc->core_id);
+    index = cc->core_id / smt;
+    spapr->cores[index] = OBJECT(dev);
+
+    if (!smc->dr_cpu_enabled) {
+        /*
+         * This is a cold plugged CPU core but the machine doesn't support
+         * DR. So skip the hotplug path ensuring that the core 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(cs, &fdt_offset, spapr);
+    }
+
+    drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
+    drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_err);
+    if (local_err) {
+        g_free(fdt);
+        spapr->cores[index] = NULL;
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    if (dev->hotplugged) {
+        /*
+         * Send hotplug notification interrupt to the guest only in case
+         * of hotplugged CPUs.
+         */
+        spapr_hotplug_req_add_by_index(drc);
+    } else {
+        /*
+         * Set the right DRC states for cold plugged CPU.
+         */
+        drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USABLE);
+        drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_UNISOLATED);
+    }
+}
+
 void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
                          Error **errp)
 {
     MachineState *machine = MACHINE(OBJECT(hotplug_dev));
+    sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(OBJECT(hotplug_dev));
     sPAPRMachineState *spapr = SPAPR_MACHINE(OBJECT(hotplug_dev));
     int spapr_max_cores = max_cpus / smp_threads;
     int index;
@@ -95,6 +170,11 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
         goto out;
     }
 
+    if (!smc->dr_cpu_enabled && dev->hotplugged) {
+        error_setg(&local_err, "CPU hotplug not supported for this machine");
+        goto out;
+    }
+
     if (cc->nr_threads != smp_threads) {
         error_setg(&local_err, "threads must be %d", smp_threads);
         goto out;
diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
index 049fb1b..af80992 100644
--- a/hw/ppc/spapr_events.c
+++ b/hw/ppc/spapr_events.c
@@ -449,6 +449,9 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,
     case SPAPR_DR_CONNECTOR_TYPE_LMB:
         hp->hotplug_type = RTAS_LOG_V6_HP_TYPE_MEMORY;
         break;
+    case SPAPR_DR_CONNECTOR_TYPE_CPU:
+        hp->hotplug_type = 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 43e2c68..dc058e5 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -36,6 +36,7 @@
 
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
+#include "hw/ppc/ppc.h"
 #include "qapi-event.h"
 #include "hw/boards.h"
 
@@ -164,6 +165,27 @@ static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_,
     rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
 }
 
+/*
+ * Set the timebase offset of the CPU to that of first CPU.
+ * This helps hotplugged CPU to have the correct timebase offset.
+ */
+static void spapr_cpu_update_tb_offset(PowerPCCPU *cpu)
+{
+    PowerPCCPU *fcpu = POWERPC_CPU(first_cpu);
+
+    cpu->env.tb_env->tb_offset = fcpu->env.tb_env->tb_offset;
+}
+
+static void spapr_cpu_set_endianness(PowerPCCPU *cpu)
+{
+    PowerPCCPU *fcpu = POWERPC_CPU(first_cpu);
+    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(fcpu);
+
+    if (!pcc->interrupts_big_endian(fcpu)) {
+        cpu->env.spr[SPR_LPCR] |= LPCR_ILE;
+    }
+}
+
 static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,
                            uint32_t token, uint32_t nargs,
                            target_ulong args,
@@ -200,6 +222,8 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,
         env->nip = start;
         env->gpr[3] = r3;
         cs->halted = 0;
+        spapr_cpu_set_endianness(cpu);
+        spapr_cpu_update_tb_offset(cpu);
 
         qemu_cpu_kick(cs);
 
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index ab393fd..f647999 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -587,6 +587,8 @@ void spapr_hotplug_req_add_by_count(sPAPRDRConnectorType drc_type,
 void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type,
                                           uint32_t count);
 void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp);
+void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset,
+                                    sPAPRMachineState *spapr);
 
 /* rtas-configure-connector state */
 struct sPAPRConfigureConnectorState {
diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h
index 401381b..7cb0515 100644
--- a/include/hw/ppc/spapr_cpu_core.h
+++ b/include/hw/ppc/spapr_cpu_core.h
@@ -29,4 +29,6 @@ typedef struct sPAPRCPUCore {
 void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
                          Error **errp);
 char *spapr_get_cpu_core_type(const char *model);
+void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                     Error **errp);
 #endif
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 6/9] spapr: CPU hot unplug support
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
                   ` (4 preceding siblings ...)
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 5/9] spapr: CPU hotplug support Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 7/9] QMP: Add query-hotpluggable-cpus Bharata B Rao
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

Remove the CPU core device by removing the underlying CPU thread devices.
Hot removal of CPU for sPAPR guests is achieved by sending the hot unplug
notification to the guest. Release the vCPU object after CPU hot unplug so
that vCPU fd can be parked and reused.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 hw/ppc/spapr.c                  |  8 ++++++
 hw/ppc/spapr_cpu_core.c         | 59 +++++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr_cpu_core.h |  2 ++
 3 files changed, 69 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 32c2da7..b622d55 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2295,8 +2295,16 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev,
 static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev,
                                       DeviceState *dev, Error **errp)
 {
+    sPAPRMachineClass *smc = 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_SPAPR_CPU_CORE)) {
+        if (!smc->dr_cpu_enabled) {
+            error_setg(errp, "CPU hot unplug not supported on this machine");
+            return;
+        }
+        spapr_core_unplug(hotplug_dev, dev, errp);
     }
 }
 
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 0418b45..c2edc43 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -38,6 +38,14 @@ static void spapr_cpu_reset(void *opaque)
                                 &error_fatal);
 }
 
+static void spapr_cpu_destroy(PowerPCCPU *cpu)
+{
+    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+
+    xics_cpu_destroy(spapr->icp, cpu);
+    qemu_unregister_reset(spapr_cpu_reset, cpu);
+}
+
 void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
 {
     CPUPPCState *env = &cpu->env;
@@ -88,6 +96,57 @@ char *spapr_get_cpu_core_type(const char *model)
     return core_type;
 }
 
+static void spapr_core_release(DeviceState *dev, void *opaque)
+{
+    sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
+    const char *typename = object_class_get_name(sc->cpu_class);
+    size_t size = object_type_get_size(typename);
+    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+    sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
+    CPUCore *cc = CPU_CORE(dev);
+    int smt = kvmppc_smt_threads();
+    int i;
+
+    for (i = 0; i < cc->nr_threads; i++) {
+        void *obj = sc->threads + i * size;
+        DeviceState *dev = DEVICE(obj);
+        CPUState *cs = CPU(dev);
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+
+        spapr_cpu_destroy(cpu);
+        cpu_remove_sync(cs);
+        object_unparent(obj);
+    }
+
+    spapr->cores[cc->core_id / smt] = NULL;
+
+    g_free(core->threads);
+    object_unparent(OBJECT(dev));
+}
+
+void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                       Error **errp)
+{
+    sPAPRCPUCore *core = SPAPR_CPU_CORE(OBJECT(dev));
+    PowerPCCPU *cpu = POWERPC_CPU(core->threads);
+    int id = ppc_get_vcpu_dt_id(cpu);
+    sPAPRDRConnector *drc =
+        spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id);
+    sPAPRDRConnectorClass *drck;
+    Error *local_err = NULL;
+
+    g_assert(drc);
+
+    drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
+    drck->detach(drc, dev, spapr_core_release, NULL, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    spapr_hotplug_req_remove_by_index(drc);
+}
+
 void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
                      Error **errp)
 {
diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h
index 7cb0515..1c9b319 100644
--- a/include/hw/ppc/spapr_cpu_core.h
+++ b/include/hw/ppc/spapr_cpu_core.h
@@ -31,4 +31,6 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
 char *spapr_get_cpu_core_type(const char *model);
 void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
                      Error **errp);
+void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                       Error **errp);
 #endif
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 7/9] QMP: Add query-hotpluggable-cpus
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
                   ` (5 preceding siblings ...)
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 6/9] spapr: CPU hot unplug support Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 8/9] hmp: Add 'info hotpluggable-cpus' HMP command Bharata B Rao
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

From: Igor Mammedov <imammedo@redhat.com>

It will allow mgmt to query present and hotpluggable CPU objects,
it is required from a target platform that wishes to support command
to implement and set MachineClass.query_hotpluggable_cpus callback,
which will return a list of possible CPU objects with options that
would be needed for hotplugging possible CPU objects.

There are:
'type': 'str' - QOM CPU object type for usage with device_add
'vcpus-count': 'int' - number of logical VCPU threads per
                        CPU object (mgmt needs to know)

and a set of optional fields that are to used for hotplugging a CPU
objects and would allows mgmt tools to know what/where it could be
hotplugged;
[node],[socket],[core],[thread]

For present CPUs there is a 'qom-path' field which would allow mgmt to
inspect whatever object/abstraction the target platform considers
as CPU object.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
 include/hw/boards.h |  5 +++++
 monitor.c           | 13 +++++++++++++
 qapi-schema.json    | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 qmp-commands.hx     | 23 ++++++++++++++++++++++
 4 files changed, 96 insertions(+)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index d268bd0..3ed6155 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -81,6 +81,10 @@ typedef struct {
  *    Returns an array of @CPUArchId architecture-dependent CPU IDs
  *    which includes CPU IDs for present and possible to hotplug CPUs.
  *    Caller is responsible for freeing returned list.
+ * @query_hotpluggable_cpus:
+ *    Returns a @HotpluggableCPUList, which describes CPUs objects which
+ *    could be added with -device/device_add.
+ *    Caller is responsible for freeing returned list.
  */
 struct MachineClass {
     /*< private >*/
@@ -124,6 +128,7 @@ struct MachineClass {
                                            DeviceState *dev);
     unsigned (*cpu_index_to_socket_id)(unsigned cpu_index);
     CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
+    HotpluggableCPUList *(*query_hotpluggable_cpus)(MachineState *machine);
 };
 
 /**
diff --git a/monitor.c b/monitor.c
index 404d594..f89dca9 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4273,3 +4273,16 @@ GICCapabilityList *qmp_query_gic_capabilities(Error **errp)
     return NULL;
 }
 #endif
+
+HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+
+    if (!mc->query_hotpluggable_cpus) {
+        error_setg(errp, QERR_FEATURE_DISABLED, "query-hotpluggable-cpus");
+        return NULL;
+    }
+
+    return mc->query_hotpluggable_cpus(ms);
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index 8483bdf..2167e98 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4235,3 +4235,58 @@
 # Since: 2.6
 ##
 { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }
+
+##
+# CpuInstanceProperties
+#
+# List of properties to be used for hotplugging a CPU instance,
+# it should be passed by management with device_add command when
+# a CPU is being hotplugged.
+#
+# Note: currently there are 4 properties that could be present
+# but management should be prepared to pass through other
+# properties with device_add command to allow for future
+# interface extension.
+#
+# @node: #optional NUMA node ID the CPU belongs to
+# @socket: #optional socket number within node/board the CPU belongs to
+# @core: #optional core number within socket the CPU belongs to
+# @thread: #optional thread number within core the CPU belongs to
+#
+# Since: 2.7
+##
+{ 'struct': 'CpuInstanceProperties',
+  'data': { '*node': 'int',
+            '*socket': 'int',
+            '*core': 'int',
+            '*thread': 'int'
+  }
+}
+
+##
+# @HotpluggableCPU
+#
+# @type: CPU object type for usage with device_add command
+# @props: list of properties to be used for hotplugging CPU
+# @vcpus-count: number of logical VCPU threads @HotpluggableCPU provides
+# @qom-path: #optional link to existing CPU object if CPU is present or
+#            omitted if CPU is not present.
+#
+# Since: 2.7
+##
+{ 'struct': 'HotpluggableCPU',
+  'data': { 'type': 'str',
+            'vcpus-count': 'int',
+            'props': 'CpuInstanceProperties',
+            '*qom-path': 'str'
+          }
+}
+
+##
+# @query-hotpluggable-cpus
+#
+# Returns: a list of HotpluggableCPU objects.
+#
+# Since: 2.7
+##
+{ 'command': 'query-hotpluggable-cpus', 'returns': ['HotpluggableCPU'] }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 28801a2..d9aef78 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -4933,3 +4933,26 @@ Example:
                 { "version": 3, "emulated": false, "kernel": true } ] }
 
 EQMP
+
+    {
+        .name       = "query-hotpluggable-cpus",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_query_hotpluggable_cpus,
+    },
+
+SQMP
+Show existing/possible CPUs
+---------------------------
+
+Arguments: None.
+
+Example for pseries machine type started with
+-smp 2,cores=2,maxcpus=4 -cpu POWER8:
+
+-> { "execute": "query-hotpluggable-cpus" }
+<- {"return": [
+     { "props": { "core": 8 }, "type": "POWER8-spapr-cpu-core",
+       "vcpus-count": 1 },
+     { "props": { "core": 0 }, "type": "POWER8-spapr-cpu-core",
+       "vcpus-count": 1, "qom-path": "/machine/unattached/device[0]"}
+   ]}'
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 8/9] hmp: Add 'info hotpluggable-cpus' HMP command
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
                   ` (6 preceding siblings ...)
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 7/9] QMP: Add query-hotpluggable-cpus Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  8:34   ` David Gibson
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 9/9] spapr: implement query-hotpluggable-cpus callback Bharata B Rao
  2016-06-10  5:14 ` [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR David Gibson
  9 siblings, 1 reply; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

This is the HMP equivalent for QMP query-hotpluggable-cpus.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
 hmp-commands-info.hx | 14 ++++++++++++++
 hmp.c                | 41 +++++++++++++++++++++++++++++++++++++++++
 hmp.h                |  1 +
 3 files changed, 56 insertions(+)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 52539c3..7da9e6c 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -800,6 +800,20 @@ STEXI
 Display the latest dump status.
 ETEXI
 
+    {
+        .name       = "hotpluggable-cpus",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Show information about hotpluggable CPUs",
+        .mhandler.cmd = hmp_hotpluggable_cpus,
+    },
+
+STEXI
+@item info hotpluggable-cpus
+@findex hotpluggable-cpus
+Show information about hotpluggable CPUs
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/hmp.c b/hmp.c
index a4b1d3d..14d4712 100644
--- a/hmp.c
+++ b/hmp.c
@@ -2424,3 +2424,44 @@ void hmp_info_dump(Monitor *mon, const QDict *qdict)
 
     qapi_free_DumpQueryResult(result);
 }
+
+void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
+    HotpluggableCPUList *saved = l;
+    CpuInstanceProperties *c;
+
+    if (err != NULL) {
+        hmp_handle_error(mon, &err);
+        return;
+    }
+
+    monitor_printf(mon, "Hotpluggable CPUs:\n");
+    while (l) {
+        monitor_printf(mon, "  type: \"%s\"\n", l->value->type);
+        monitor_printf(mon, "  vcpus_count: \"%ld\"\n", l->value->vcpus_count);
+        if (l->value->has_qom_path) {
+            monitor_printf(mon, "  qom_path: \"%s\"\n", l->value->qom_path);
+        }
+
+        c = l->value->props;
+        monitor_printf(mon, "  CPUInstance Properties:\n");
+        if (c->has_node) {
+            monitor_printf(mon, "    node: \"%ld\"\n", c->node);
+        }
+        if (c->has_socket) {
+            monitor_printf(mon, "    socket: \"%ld\"\n", c->socket);
+        }
+        if (c->has_core) {
+            monitor_printf(mon, "    core: \"%ld\"\n", c->core);
+        }
+        if (c->has_thread) {
+            monitor_printf(mon, "    thread: \"%ld\"\n", c->thread);
+        }
+
+        l = l->next;
+    }
+
+    qapi_free_HotpluggableCPUList(saved);
+}
diff --git a/hmp.h b/hmp.h
index 093d65f..f5d9749 100644
--- a/hmp.h
+++ b/hmp.h
@@ -132,5 +132,6 @@ void hmp_rocker_ports(Monitor *mon, const QDict *qdict);
 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict);
 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict);
 void hmp_info_dump(Monitor *mon, const QDict *qdict);
+void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
 
 #endif
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [Qemu-devel] [PATCH v4 9/9] spapr: implement query-hotpluggable-cpus callback
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
                   ` (7 preceding siblings ...)
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 8/9] hmp: Add 'info hotpluggable-cpus' HMP command Bharata B Rao
@ 2016-06-10  0:59 ` Bharata B Rao
  2016-06-10  5:14 ` [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR David Gibson
  9 siblings, 0 replies; 22+ messages in thread
From: Bharata B Rao @ 2016-06-10  0:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-ppc, david, imammedo, thuth, aik, agraf, pbonzini, ehabkost,
	pkrempa, mdroth, eblake, mjrosato, borntraeger, Bharata B Rao

From: Igor Mammedov <imammedo@redhat.com>

It returns a list of present/possible to hotplug CPU
objects with a list of properties to use with
device_add.

in spapr case returned list would looks like:
-> { "execute": "query-hotpluggable-cpus" }
<- {"return": [
     { "props": { "core": 8 }, "type": "POWER8-spapr-cpu-core",
       "vcpus-count": 2 },
     { "props": { "core": 0 }, "type": "POWER8-spapr-cpu-core",
       "vcpus-count": 2,
       "qom-path": "/machine/unattached/device[0]"}
   ]}'

TODO:
  add 'node' property for core <-> numa node mapping

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
---
 hw/ppc/spapr.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index b622d55..23dbf54 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -67,6 +67,7 @@
 #include "hw/compat.h"
 #include "qemu/cutils.h"
 #include "hw/ppc/spapr_cpu_core.h"
+#include "qmp-commands.h"
 
 #include <libfdt.h>
 
@@ -2333,6 +2334,38 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)
     return cpu_index / smp_threads / smp_cores;
 }
 
+static HotpluggableCPUList *spapr_query_hotpluggable_cpus(MachineState *machine)
+{
+    int i;
+    HotpluggableCPUList *head = NULL;
+    sPAPRMachineState *spapr = SPAPR_MACHINE(machine);
+    int spapr_max_cores = max_cpus / smp_threads;
+    int smt = kvmppc_smt_threads();
+
+    for (i = 0; i < spapr_max_cores; i++) {
+        HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1);
+        HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
+        CpuInstanceProperties *cpu_props = g_new0(typeof(*cpu_props), 1);
+
+        cpu_item->type = spapr_get_cpu_core_type(machine->cpu_model);
+        cpu_item->vcpus_count = smp_threads;
+        cpu_props->has_core = true;
+        cpu_props->core = i * smt;
+        /* TODO: add 'has_node/node' here to describe
+           to which node core belongs */
+
+        cpu_item->props = cpu_props;
+        if (spapr->cores[i]) {
+            cpu_item->has_qom_path = true;
+            cpu_item->qom_path = object_get_canonical_path(spapr->cores[i]);
+        }
+        list_item->value = cpu_item;
+        list_item->next = head;
+        head = list_item;
+    }
+    return head;
+}
+
 static void spapr_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -2363,6 +2396,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
     hc->plug = spapr_machine_device_plug;
     hc->unplug = spapr_machine_device_unplug;
     mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id;
+    mc->query_hotpluggable_cpus = spapr_query_hotpluggable_cpus;
 
     smc->dr_lmb_enabled = true;
     smc->dr_cpu_enabled = true;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type Bharata B Rao
@ 2016-06-10  4:04   ` David Gibson
  2016-06-10  7:38     ` Igor Mammedov
  0 siblings, 1 reply; 22+ messages in thread
From: David Gibson @ 2016-06-10  4:04 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: qemu-devel, qemu-ppc, imammedo, thuth, aik, agraf, pbonzini,
	ehabkost, pkrempa, mdroth, eblake, mjrosato, borntraeger

[-- Attachment #1: Type: text/plain, Size: 1823 bytes --]

On Fri, Jun 10, 2016 at 06:29:00AM +0530, Bharata B Rao wrote:
> Add an API object_type_get_size(const char *typename) that returns the
> instance_size of the give typename.
> 
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

This looks sensible to me, it would be nice to have an ack or two from
the qemu community at large.

> ---
>  include/qom/object.h | 8 +++++++-
>  qom/object.c         | 8 ++++++++
>  2 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 21bb5ff..460ddfc 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -1608,5 +1608,11 @@ int object_child_foreach_recursive(Object *obj,
>   */
>  Object *container_get(Object *root, const char *path);
>  
> -
> +/**
> + * object_type_get_size:
> + * @typename: Name of the Type whose instance_size is required
> + *
> + * Returns the instance_size of the given @typename.
> + */
> +size_t object_type_get_size(const char *typename);
>  #endif
> diff --git a/qom/object.c b/qom/object.c
> index 3bc8a00..0e75877 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -202,6 +202,14 @@ static size_t type_object_get_size(TypeImpl *ti)
>      return 0;
>  }
>  
> +size_t object_type_get_size(const char *typename)
> +{
> +    TypeImpl *type = type_get_by_name(typename);
> +
> +    g_assert(type != NULL);
> +    return type_object_get_size(type);
> +}
> +
>  static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
>  {
>      assert(target_type);

-- 
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH v4 2/9] spapr: Abstract CPU core device and type specific core devices
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 2/9] spapr: Abstract CPU core device and type specific core devices Bharata B Rao
@ 2016-06-10  4:24   ` David Gibson
  0 siblings, 0 replies; 22+ messages in thread
From: David Gibson @ 2016-06-10  4:24 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: qemu-devel, qemu-ppc, imammedo, thuth, aik, agraf, pbonzini,
	ehabkost, pkrempa, mdroth, eblake, mjrosato, borntraeger

[-- Attachment #1: Type: text/plain, Size: 11320 bytes --]

On Fri, Jun 10, 2016 at 06:29:01AM +0530, Bharata B Rao wrote:
> Add sPAPR specific abastract CPU core device that is based on generic
> CPU core device. Use this as base type to create sPAPR CPU specific core
> devices.
> 
> TODO:
> - Add core types for other remaining CPU types
> - Handle CPU model alias correctly
> 
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> ---
>  hw/ppc/Makefile.objs            |   1 +
>  hw/ppc/spapr.c                  |   3 +-
>  hw/ppc/spapr_cpu_core.c         | 160 ++++++++++++++++++++++++++++++++++++++++
>  include/hw/ppc/spapr.h          |   1 +
>  include/hw/ppc/spapr_cpu_core.h |  29 ++++++++
>  target-ppc/kvm.c                |  28 +++++++
>  6 files changed, 220 insertions(+), 2 deletions(-)
>  create mode 100644 hw/ppc/spapr_cpu_core.c
>  create mode 100644 include/hw/ppc/spapr_cpu_core.h
> 
> diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
> index c1ffc77..5cc6608 100644
> --- a/hw/ppc/Makefile.objs
> +++ b/hw/ppc/Makefile.objs
> @@ -4,6 +4,7 @@ obj-y += ppc.o ppc_booke.o
>  obj-$(CONFIG_PSERIES) += spapr.o spapr_vio.o spapr_events.o
>  obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
>  obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o
> +obj-$(CONFIG_PSERIES) += spapr_cpu_core.o
>  ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
>  obj-y += spapr_pci_vfio.o
>  endif
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 0636642..87f4e53 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1606,8 +1606,7 @@ static void spapr_boot_set(void *opaque, const char *boot_device,
>      machine->boot_order = g_strdup(boot_device);
>  }
>  
> -static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,
> -                           Error **errp)
> +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
>  {
>      CPUPPCState *env = &cpu->env;
>  
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> new file mode 100644
> index 0000000..b8b97c9
> --- /dev/null
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -0,0 +1,160 @@
> +/*
> + * sPAPR CPU core device, acts as container of CPU thread devices.
> + *
> + * Copyright (C) 2016 Bharata B Rao <bharata@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +#include "hw/cpu/core.h"
> +#include "hw/ppc/spapr_cpu_core.h"
> +#include "target-ppc/cpu.h"
> +#include "hw/ppc/spapr.h"
> +#include "hw/boards.h"
> +#include "qapi/error.h"
> +#include <sysemu/cpus.h>
> +#include "target-ppc/kvm_ppc.h"
> +
> +static int spapr_cpu_core_realize_child(Object *child, void *opaque)
> +{
> +    Error **errp = opaque;
> +    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> +    CPUState *cs = CPU(child);
> +    PowerPCCPU *cpu = 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;
> +}
> +
> +static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
> +{
> +    sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
> +    CPUCore *cc = CPU_CORE(OBJECT(dev));
> +    const char *typename = object_class_get_name(sc->cpu_class);
> +    size_t size = object_type_get_size(typename);
> +    Error *local_err = NULL;
> +    Object *obj;
> +    int i;
> +
> +    sc->threads = g_malloc0(size * cc->nr_threads);
> +    for (i = 0; i < cc->nr_threads; i++) {
> +        char id[32];
> +        void *obj = sc->threads + i * size;
> +
> +        object_initialize(obj, size, typename);
> +        snprintf(id, sizeof(id), "thread[%d]", i);
> +        object_property_add_child(OBJECT(sc), id, obj, &local_err);
> +        if (local_err) {
> +            goto err;
> +        }
> +    }
> +    object_child_foreach(OBJECT(dev), spapr_cpu_core_realize_child, &local_err);
> +    if (local_err) {
> +        goto err;
> +    } else {
> +        return;
> +    }
> +
> +err:
> +    while (i >= 0) {
> +        obj = sc->threads + i * size;
> +        object_unparent(obj);
> +        i--;
> +    }
> +    g_free(sc->threads);
> +    error_propagate(errp, local_err);
> +}
> +
> +static void spapr_cpu_core_class_init(ObjectClass *oc, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(oc);
> +    dc->realize = spapr_cpu_core_realize;
> +}
> +
> +/*
> + * instance_init routines from different flavours of sPAPR CPU cores.
> + * TODO: Add support for 'host' core type.
> + */
> +#define SPAPR_CPU_CORE_INITFN(_type, _fname) \
> +static void glue(glue(spapr_cpu_core_, _fname), _initfn(Object *obj)) \
> +{ \
> +    sPAPRCPUCore *core = SPAPR_CPU_CORE(obj); \
> +    char *name = g_strdup_printf("%s-" TYPE_POWERPC_CPU, stringify(_type)); \
> +    ObjectClass *oc = object_class_by_name(name); \
> +    g_assert(oc); \
> +    g_free((void *)name); \
> +    core->cpu_class = oc; \
> +}

I still think this can be a class_init rather than instance_init
function, but that's a nit we can fix later.

> +
> +SPAPR_CPU_CORE_INITFN(POWER7_v2.3, POWER7);
> +SPAPR_CPU_CORE_INITFN(POWER7+_v2.1, POWER7plus);
> +SPAPR_CPU_CORE_INITFN(POWER8_v2.0, POWER8);
> +SPAPR_CPU_CORE_INITFN(POWER8E_v2.1, POWER8E);
> +
> +typedef struct SPAPRCoreInfo {
> +    const char *name;
> +    void (*initfn)(Object *obj);
> +} SPAPRCoreInfo;
> +
> +static const SPAPRCoreInfo spapr_cores[] = {
> +    /* POWER7 and aliases */
> +    { .name = "POWER7_v2.3", .initfn = spapr_cpu_core_POWER7_initfn },
> +    { .name = "POWER7", .initfn = spapr_cpu_core_POWER7_initfn },
> +
> +    /* POWER7+ and aliases */
> +    { .name = "POWER7+_v2.1", .initfn = spapr_cpu_core_POWER7plus_initfn },
> +    { .name = "POWER7+", .initfn = spapr_cpu_core_POWER7plus_initfn },
> +
> +    /* POWER8 and aliases */
> +    { .name = "POWER8_v2.0", .initfn = spapr_cpu_core_POWER8_initfn },
> +    { .name = "POWER8", .initfn = spapr_cpu_core_POWER8_initfn },
> +    { .name = "power8", .initfn = spapr_cpu_core_POWER8_initfn },
> +
> +    /* POWER8E and aliases */
> +    { .name = "POWER8E_v2.1", .initfn = spapr_cpu_core_POWER8E_initfn },
> +    { .name = "POWER8E", .initfn = spapr_cpu_core_POWER8E_initfn },
> +
> +    { .name = NULL }
> +};
> +
> +static void spapr_cpu_core_register(const SPAPRCoreInfo *info)
> +{
> +    TypeInfo type_info = {
> +        .parent = TYPE_SPAPR_CPU_CORE,
> +        .instance_size = sizeof(sPAPRCPUCore),
> +        .instance_init = info->initfn,
> +    };
> +
> +    type_info.name = g_strdup_printf("%s-" TYPE_SPAPR_CPU_CORE, info->name);
> +    type_register(&type_info);
> +    g_free((void *)type_info.name);
> +}
> +
> +static const TypeInfo spapr_cpu_core_type_info = {
> +    .name = TYPE_SPAPR_CPU_CORE,
> +    .parent = TYPE_CPU_CORE,
> +    .abstract = true,
> +    .instance_size = sizeof(sPAPRCPUCore),
> +    .class_init = spapr_cpu_core_class_init,
> +};
> +
> +static void spapr_cpu_core_register_types(void)
> +{
> +    const SPAPRCoreInfo *info = spapr_cores;
> +
> +    type_register_static(&spapr_cpu_core_type_info);
> +    while (info->name) {
> +        spapr_cpu_core_register(info);
> +        info++;
> +    }
> +}
> +
> +type_init(spapr_cpu_core_register_types)
> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> index 971df3d..4ff14d6 100644
> --- a/include/hw/ppc/spapr.h
> +++ b/include/hw/ppc/spapr.h
> @@ -582,6 +582,7 @@ void spapr_hotplug_req_add_by_count(sPAPRDRConnectorType 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);
>  
>  /* rtas-configure-connector state */
>  struct sPAPRConfigureConnectorState {
> diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h
> new file mode 100644
> index 0000000..424edec
> --- /dev/null
> +++ b/include/hw/ppc/spapr_cpu_core.h
> @@ -0,0 +1,29 @@
> +/*
> + * sPAPR CPU core device.
> + *
> + * Copyright (C) 2016 Bharata B Rao <bharata@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +#ifndef HW_SPAPR_CPU_CORE_H
> +#define HW_SPAPR_CPU_CORE_H
> +
> +#include "hw/qdev.h"
> +#include "hw/cpu/core.h"
> +#include "target-ppc/cpu-qom.h"
> +
> +#define TYPE_SPAPR_CPU_CORE "spapr-cpu-core"
> +#define SPAPR_CPU_CORE(obj) \
> +    OBJECT_CHECK(sPAPRCPUCore, (obj), TYPE_SPAPR_CPU_CORE)
> +
> +typedef struct sPAPRCPUCore {
> +    /*< private >*/
> +    CPUCore parent_obj;
> +
> +    /*< public >*/
> +    void *threads;
> +    ObjectClass *cpu_class;
> +} sPAPRCPUCore;
> +
> +#endif
> diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
> index 24d6032..20982d0 100644
> --- a/target-ppc/kvm.c
> +++ b/target-ppc/kvm.c
> @@ -43,6 +43,9 @@
>  #include "exec/memattrs.h"
>  #include "sysemu/hostmem.h"
>  #include "qemu/cutils.h"
> +#if defined(TARGET_PPC64)
> +#include "hw/ppc/spapr_cpu_core.h"
> +#endif
>  
>  //#define DEBUG_KVM
>  
> @@ -2329,6 +2332,19 @@ static PowerPCCPUClass *ppc_cpu_get_family_class(PowerPCCPUClass *pcc)
>      return POWERPC_CPU_CLASS(oc);
>  }
>  
> +#if defined(TARGET_PPC64)
> +static void spapr_cpu_core_host_initfn(Object *obj)
> +{
> +    sPAPRCPUCore *core = SPAPR_CPU_CORE(obj);
> +    char *name = g_strdup_printf("%s-" TYPE_POWERPC_CPU, "host");
> +    ObjectClass *oc = object_class_by_name(name);
> +
> +    g_assert(oc);
> +    g_free((void *)name);
> +    core->cpu_class = oc;
> +}
> +#endif
> +
>  static int kvm_ppc_register_host_cpu_type(void)
>  {
>      TypeInfo type_info = {
> @@ -2350,6 +2366,18 @@ static int kvm_ppc_register_host_cpu_type(void)
>      type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
>      type_register(&type_info);
>  
> +#if defined(TARGET_PPC64)
> +    type_info.name = g_strdup_printf("%s-"TYPE_SPAPR_CPU_CORE, "host");
> +    type_info.parent = TYPE_SPAPR_CPU_CORE,
> +    type_info.instance_size = sizeof(sPAPRCPUCore),
> +    type_info.instance_init = spapr_cpu_core_host_initfn,
> +    type_info.class_init = NULL;
> +    type_register(&type_info);
> +    g_free((void *)type_info.name);
> +    type_info.instance_size = 0;
> +    type_info.instance_init = NULL;
> +#endif

I think this will fail compile if you have a 64bit build which doesn't
have CONFIG_PSERIES.  Since none of the default configs do that, we
can probably get away with it for now.

> +
>      /* Register generic family CPU class for a family */
>      pvr_pcc = ppc_cpu_get_family_class(pvr_pcc);
>      dc = DEVICE_CLASS(pvr_pcc);

-- 
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH v4 3/9] spapr: Move spapr_cpu_init() to spapr_cpu_core.c
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 3/9] spapr: Move spapr_cpu_init() to spapr_cpu_core.c Bharata B Rao
@ 2016-06-10  4:27   ` David Gibson
  0 siblings, 0 replies; 22+ messages in thread
From: David Gibson @ 2016-06-10  4:27 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: qemu-devel, qemu-ppc, imammedo, thuth, aik, agraf, pbonzini,
	ehabkost, pkrempa, mdroth, eblake, mjrosato, borntraeger

[-- Attachment #1: Type: text/plain, Size: 5407 bytes --]

On Fri, Jun 10, 2016 at 06:29:02AM +0530, Bharata B Rao wrote:
> Start consolidating CPU init related routines in spapr_cpu_core.c. As
> part of this, move spapr_cpu_init() and its dependencies from spapr.c
> to spapr_cpu_core.c
> 
> No functionality change in this patch.
> 
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>

One nit..

> ---
>  hw/ppc/spapr.c          | 47 -----------------------------------------------
>  hw/ppc/spapr_cpu_core.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  include/hw/ppc/spapr.h  |  2 ++
>  3 files changed, 50 insertions(+), 47 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 87f4e53..adaca42 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -89,8 +89,6 @@
>  
>  #define MIN_RMA_SLOF            128UL
>  
> -#define TIMEBASE_FREQ           512000000ULL
> -
>  #define PHANDLE_XICP            0x00001111
>  
>  #define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
> @@ -1181,26 +1179,6 @@ static void ppc_spapr_reset(void)
>  
>  }
>  
> -static void spapr_cpu_reset(void *opaque)
> -{
> -    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> -    PowerPCCPU *cpu = opaque;
> -    CPUState *cs = CPU(cpu);
> -    CPUPPCState *env = &cpu->env;
> -
> -    cpu_reset(cs);
> -
> -    /* All CPUs start halted.  CPU0 is unhalted from the machine level
> -     * reset code and the rest are explicitly started up by the guest
> -     * using an RTAS call */
> -    cs->halted = 1;
> -
> -    env->spr[SPR_HIOR] = 0;
> -
> -    ppc_hash64_set_external_hpt(cpu, spapr->htab, spapr->htab_shift,
> -                                &error_fatal);
> -}
> -
>  static void spapr_create_nvram(sPAPRMachineState *spapr)
>  {
>      DeviceState *dev = qdev_create(&spapr->vio_bus->bus, "spapr-nvram");
> @@ -1606,31 +1584,6 @@ static void spapr_boot_set(void *opaque, const char *boot_device,
>      machine->boot_order = g_strdup(boot_device);
>  }
>  
> -void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
> -{
> -    CPUPPCState *env = &cpu->env;
> -
> -    /* Set time-base frequency to 512 MHz */
> -    cpu_ppc_tb_init(env, TIMEBASE_FREQ);
> -
> -    /* Enable PAPR mode in TCG or KVM */
> -    cpu_ppc_set_papr(cpu);
> -
> -    if (cpu->max_compat) {
> -        Error *local_err = NULL;
> -
> -        ppc_set_compat(cpu, cpu->max_compat, &local_err);
> -        if (local_err) {
> -            error_propagate(errp, local_err);
> -            return;
> -        }
> -    }
> -
> -    xics_cpu_setup(spapr->icp, cpu);
> -
> -    qemu_register_reset(spapr_cpu_reset, cpu);
> -}
> -
>  /*
>   * Reset routine for LMB DR devices.
>   *
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index b8b97c9..e9eb754 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -14,6 +14,54 @@
>  #include "qapi/error.h"
>  #include <sysemu/cpus.h>
>  #include "target-ppc/kvm_ppc.h"
> +#include "hw/ppc/ppc.h"
> +#include "target-ppc/mmu-hash64.h"
> +#include <sysemu/numa.h>
> +
> +static void spapr_cpu_reset(void *opaque)
> +{
> +    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
> +    PowerPCCPU *cpu = opaque;
> +    CPUState *cs = CPU(cpu);
> +    CPUPPCState *env = &cpu->env;
> +
> +    cpu_reset(cs);
> +
> +    /* All CPUs start halted.  CPU0 is unhalted from the machine level
> +     * reset code and the rest are explicitly started up by the guest
> +     * using an RTAS call */
> +    cs->halted = 1;
> +
> +    env->spr[SPR_HIOR] = 0;
> +
> +    ppc_hash64_set_external_hpt(cpu, spapr->htab, spapr->htab_shift,
> +                                &error_fatal);
> +}
> +
> +void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)
> +{
> +    CPUPPCState *env = &cpu->env;
> +
> +    /* Set time-base frequency to 512 MHz */
> +    cpu_ppc_tb_init(env, TIMEBASE_FREQ);
> +
> +    /* Enable PAPR mode in TCG or KVM */
> +    cpu_ppc_set_papr(cpu);
> +
> +    if (cpu->max_compat) {
> +        Error *local_err = NULL;
> +
> +        ppc_set_compat(cpu, cpu->max_compat, &local_err);
> +        if (local_err) {
> +            error_propagate(errp, local_err);
> +            return;
> +        }
> +    }
> +
> +    xics_cpu_setup(spapr->icp, cpu);
> +
> +    qemu_register_reset(spapr_cpu_reset, cpu);
> +}
>  
>  static int spapr_cpu_core_realize_child(Object *child, void *opaque)
>  {
> diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
> index 4ff14d6..e372dae 100644
> --- a/include/hw/ppc/spapr.h
> +++ b/include/hw/ppc/spapr.h
> @@ -16,6 +16,8 @@ typedef struct sPAPREventLogEntry sPAPREventLogEntry;
>  #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
>  #define SPAPR_ENTRY_POINT       0x100
>  
> +#define TIMEBASE_FREQ           512000000ULL
> +

Since this is now in a header which could be included anywhere, this
really needs an SPAPR_PREFIX.  I'll make that tweak myself when I
merge it.

>  typedef struct sPAPRMachineClass sPAPRMachineClass;
>  typedef struct sPAPRMachineState sPAPRMachineState;
>  

-- 
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR
  2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
                   ` (8 preceding siblings ...)
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 9/9] spapr: implement query-hotpluggable-cpus callback Bharata B Rao
@ 2016-06-10  5:14 ` David Gibson
  2016-06-15  6:04   ` [Qemu-devel] [Qemu-ppc] " David Gibson
  9 siblings, 1 reply; 22+ messages in thread
From: David Gibson @ 2016-06-10  5:14 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: qemu-devel, qemu-ppc, imammedo, thuth, aik, agraf, pbonzini,
	ehabkost, pkrempa, mdroth, eblake, mjrosato, borntraeger

[-- Attachment #1: Type: text/plain, Size: 3640 bytes --]

On Fri, Jun 10, 2016 at 06:28:59AM +0530, Bharata B Rao wrote:
> Hi,
> 
> This is the next version of the CPU hotplug patchset for PowerPC
> sPAPR target. The hotplug semantics looks like this:
> 
> (qemu) device_add POWER8E-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> (qemu) device_add host-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> (qemu) device_add
> POWER8E_v2.1-spapr-cpu-core,id=core2,core-id=16[,threads=4]

I've merged these to my ppc-cpu-hotplug branch, and I'm doing some
testing.  It it checks out, I hope to send a pull request.

> 
> Changes in v4
> -------------
> - Rebased against David Gibson's ppc-cpu-hotplug and hence dropped those
>   patches that are already part of that tree.
> - We were assuming the CPU thread to be always of type PowerPCCPU which
>   needn't be true. Hence use actual CPU type's instance_size when
>   object_initialize'ing the threads as per David's suggestion. This requires
>   us to know the instance_size for a given type for which a new QOM API
>   object_type_get_size() has been introduced in this version.
> - Consolidate CPU init related routines in spapr_cpu_core.c. As part of this
>   move spapr_cpu_init() and its dependencies to spapr_cpu_core.c.
> - Got rid of the temporary unplug list when removing CPU cores.
> - Folded spapr_cpu_core_create_threads() into spapr_cpu_core_realize() and
>   fixed the error path in in spapr_cpu_core_realize().
> - Add support for -cpu host.
> 
> TODOs remaining
> ---------------
> - Work on David's suggestion of intializing CPU's ObjectClass in
>   class_init rather than instance_init.
> - Use object_initialize_with_type instead of object_initialize when
>   creating CPU threads of a core.
> - Use vcpu_dt_id logic when populating core id in
>   spapr_query_hotpluggable_cpus().
> - Handle CPU compat properly (-cpu host,compat=POWER7)
> 
> v3: https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg01829.html
> 
> Bharata B Rao (7):
>   qom: API to get instance_size of a type
>   spapr: Abstract CPU core device and type specific core devices
>   spapr: Move spapr_cpu_init() to spapr_cpu_core.c
>   spapr: convert boot CPUs into CPU core devices
>   spapr: CPU hotplug support
>   spapr: CPU hot unplug support
>   hmp: Add 'info hotpluggable-cpus' HMP command
> 
> Igor Mammedov (2):
>   QMP: Add query-hotpluggable-cpus
>   spapr: implement query-hotpluggable-cpus callback
> 
>  hmp-commands-info.hx            |  14 ++
>  hmp.c                           |  41 ++++
>  hmp.h                           |   1 +
>  hw/ppc/Makefile.objs            |   1 +
>  hw/ppc/spapr.c                  | 215 +++++++++++++++------
>  hw/ppc/spapr_cpu_core.c         | 405 ++++++++++++++++++++++++++++++++++++++++
>  hw/ppc/spapr_events.c           |   3 +
>  hw/ppc/spapr_rtas.c             |  24 +++
>  include/hw/boards.h             |   5 +
>  include/hw/ppc/spapr.h          |   7 +
>  include/hw/ppc/spapr_cpu_core.h |  36 ++++
>  include/qom/object.h            |   8 +-
>  monitor.c                       |  13 ++
>  qapi-schema.json                |  55 ++++++
>  qmp-commands.hx                 |  23 +++
>  qom/object.c                    |   8 +
>  target-ppc/kvm.c                |  28 +++
>  17 files changed, 828 insertions(+), 59 deletions(-)
>  create mode 100644 hw/ppc/spapr_cpu_core.c
>  create mode 100644 include/hw/ppc/spapr_cpu_core.h
> 

-- 
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type
  2016-06-10  4:04   ` David Gibson
@ 2016-06-10  7:38     ` Igor Mammedov
  2016-06-15  5:48       ` David Gibson
  0 siblings, 1 reply; 22+ messages in thread
From: Igor Mammedov @ 2016-06-10  7:38 UTC (permalink / raw)
  To: David Gibson
  Cc: Bharata B Rao, qemu-devel, qemu-ppc, thuth, aik, agraf, pbonzini,
	ehabkost, pkrempa, mdroth, eblake, mjrosato, borntraeger

On Fri, 10 Jun 2016 14:04:41 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Fri, Jun 10, 2016 at 06:29:00AM +0530, Bharata B Rao wrote:
> > Add an API object_type_get_size(const char *typename) that returns the
> > instance_size of the give typename.
I'd rename it to
  object_type_get_instance_size()
so it'd apparent what size is returned from name.

> > 
> > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>  
> 
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> 
> This looks sensible to me, it would be nice to have an ack or two from
> the qemu community at large.
> 
> > ---
> >  include/qom/object.h | 8 +++++++-
> >  qom/object.c         | 8 ++++++++
> >  2 files changed, 15 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/qom/object.h b/include/qom/object.h
> > index 21bb5ff..460ddfc 100644
> > --- a/include/qom/object.h
> > +++ b/include/qom/object.h
> > @@ -1608,5 +1608,11 @@ int object_child_foreach_recursive(Object *obj,
> >   */
> >  Object *container_get(Object *root, const char *path);
> >  
> > -
> > +/**
> > + * object_type_get_size:
> > + * @typename: Name of the Type whose instance_size is required
> > + *
> > + * Returns the instance_size of the given @typename.
> > + */
> > +size_t object_type_get_size(const char *typename);
> >  #endif
> > diff --git a/qom/object.c b/qom/object.c
> > index 3bc8a00..0e75877 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -202,6 +202,14 @@ static size_t type_object_get_size(TypeImpl *ti)
> >      return 0;
> >  }
> >  
> > +size_t object_type_get_size(const char *typename)
> > +{
> > +    TypeImpl *type = type_get_by_name(typename);
> > +
> > +    g_assert(type != NULL);
> > +    return type_object_get_size(type);
> > +}
> > +
> >  static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
> >  {
> >      assert(target_type);  
> 

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH v4 8/9] hmp: Add 'info hotpluggable-cpus' HMP command
  2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 8/9] hmp: Add 'info hotpluggable-cpus' HMP command Bharata B Rao
@ 2016-06-10  8:34   ` David Gibson
  0 siblings, 0 replies; 22+ messages in thread
From: David Gibson @ 2016-06-10  8:34 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: qemu-devel, qemu-ppc, imammedo, thuth, aik, agraf, pbonzini,
	ehabkost, pkrempa, mdroth, eblake, mjrosato, borntraeger

[-- Attachment #1: Type: text/plain, Size: 3482 bytes --]

On Fri, Jun 10, 2016 at 06:29:07AM +0530, Bharata B Rao wrote:
> This is the HMP equivalent for QMP query-hotpluggable-cpus.
> 
> Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

This has a compile error on 32-bit host, because qapi 'int' values are
actually uint64s.  I've fixed it in my tree.

> ---
>  hmp-commands-info.hx | 14 ++++++++++++++
>  hmp.c                | 41 +++++++++++++++++++++++++++++++++++++++++
>  hmp.h                |  1 +
>  3 files changed, 56 insertions(+)
> 
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index 52539c3..7da9e6c 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -800,6 +800,20 @@ STEXI
>  Display the latest dump status.
>  ETEXI
>  
> +    {
> +        .name       = "hotpluggable-cpus",
> +        .args_type  = "",
> +        .params     = "",
> +        .help       = "Show information about hotpluggable CPUs",
> +        .mhandler.cmd = hmp_hotpluggable_cpus,
> +    },
> +
> +STEXI
> +@item info hotpluggable-cpus
> +@findex hotpluggable-cpus
> +Show information about hotpluggable CPUs
> +ETEXI
> +
>  STEXI
>  @end table
>  ETEXI
> diff --git a/hmp.c b/hmp.c
> index a4b1d3d..14d4712 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -2424,3 +2424,44 @@ void hmp_info_dump(Monitor *mon, const QDict *qdict)
>  
>      qapi_free_DumpQueryResult(result);
>  }
> +
> +void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
> +{
> +    Error *err = NULL;
> +    HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
> +    HotpluggableCPUList *saved = l;
> +    CpuInstanceProperties *c;
> +
> +    if (err != NULL) {
> +        hmp_handle_error(mon, &err);
> +        return;
> +    }
> +
> +    monitor_printf(mon, "Hotpluggable CPUs:\n");
> +    while (l) {
> +        monitor_printf(mon, "  type: \"%s\"\n", l->value->type);
> +        monitor_printf(mon, "  vcpus_count: \"%ld\"\n", l->value->vcpus_count);
> +        if (l->value->has_qom_path) {
> +            monitor_printf(mon, "  qom_path: \"%s\"\n", l->value->qom_path);
> +        }
> +
> +        c = l->value->props;
> +        monitor_printf(mon, "  CPUInstance Properties:\n");
> +        if (c->has_node) {
> +            monitor_printf(mon, "    node: \"%ld\"\n", c->node);
> +        }
> +        if (c->has_socket) {
> +            monitor_printf(mon, "    socket: \"%ld\"\n", c->socket);
> +        }
> +        if (c->has_core) {
> +            monitor_printf(mon, "    core: \"%ld\"\n", c->core);
> +        }
> +        if (c->has_thread) {
> +            monitor_printf(mon, "    thread: \"%ld\"\n", c->thread);
> +        }
> +
> +        l = l->next;
> +    }
> +
> +    qapi_free_HotpluggableCPUList(saved);
> +}
> diff --git a/hmp.h b/hmp.h
> index 093d65f..f5d9749 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -132,5 +132,6 @@ void hmp_rocker_ports(Monitor *mon, const QDict *qdict);
>  void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict);
>  void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict);
>  void hmp_info_dump(Monitor *mon, const QDict *qdict);
> +void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
>  
>  #endif

-- 
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type
  2016-06-10  7:38     ` Igor Mammedov
@ 2016-06-15  5:48       ` David Gibson
  0 siblings, 0 replies; 22+ messages in thread
From: David Gibson @ 2016-06-15  5:48 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Bharata B Rao, qemu-devel, qemu-ppc, thuth, aik, agraf, pbonzini,
	ehabkost, pkrempa, mdroth, eblake, mjrosato, borntraeger

[-- Attachment #1: Type: text/plain, Size: 2357 bytes --]

On Fri, Jun 10, 2016 at 09:38:24AM +0200, Igor Mammedov wrote:
> On Fri, 10 Jun 2016 14:04:41 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > On Fri, Jun 10, 2016 at 06:29:00AM +0530, Bharata B Rao wrote:
> > > Add an API object_type_get_size(const char *typename) that returns the
> > > instance_size of the give typename.
> I'd rename it to
>   object_type_get_instance_size()
> so it'd apparent what size is returned from name.

I'll make that change in my tree.

> 
> > > 
> > > Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>  
> > 
> > Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> > 
> > This looks sensible to me, it would be nice to have an ack or two from
> > the qemu community at large.
> > 
> > > ---
> > >  include/qom/object.h | 8 +++++++-
> > >  qom/object.c         | 8 ++++++++
> > >  2 files changed, 15 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/include/qom/object.h b/include/qom/object.h
> > > index 21bb5ff..460ddfc 100644
> > > --- a/include/qom/object.h
> > > +++ b/include/qom/object.h
> > > @@ -1608,5 +1608,11 @@ int object_child_foreach_recursive(Object *obj,
> > >   */
> > >  Object *container_get(Object *root, const char *path);
> > >  
> > > -
> > > +/**
> > > + * object_type_get_size:
> > > + * @typename: Name of the Type whose instance_size is required
> > > + *
> > > + * Returns the instance_size of the given @typename.
> > > + */
> > > +size_t object_type_get_size(const char *typename);
> > >  #endif
> > > diff --git a/qom/object.c b/qom/object.c
> > > index 3bc8a00..0e75877 100644
> > > --- a/qom/object.c
> > > +++ b/qom/object.c
> > > @@ -202,6 +202,14 @@ static size_t type_object_get_size(TypeImpl *ti)
> > >      return 0;
> > >  }
> > >  
> > > +size_t object_type_get_size(const char *typename)
> > > +{
> > > +    TypeImpl *type = type_get_by_name(typename);
> > > +
> > > +    g_assert(type != NULL);
> > > +    return type_object_get_size(type);
> > > +}
> > > +
> > >  static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
> > >  {
> > >      assert(target_type);  
> > 
> 

-- 
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR
  2016-06-10  5:14 ` [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR David Gibson
@ 2016-06-15  6:04   ` David Gibson
  2016-06-16  3:49     ` Bharata B Rao
  0 siblings, 1 reply; 22+ messages in thread
From: David Gibson @ 2016-06-15  6:04 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: mjrosato, thuth, pkrempa, ehabkost, qemu-devel, borntraeger,
	qemu-ppc, pbonzini, imammedo, eblake, mdroth

[-- Attachment #1: Type: text/plain, Size: 4047 bytes --]

On Fri, Jun 10, 2016 at 03:14:14PM +1000, David Gibson wrote:
> On Fri, Jun 10, 2016 at 06:28:59AM +0530, Bharata B Rao wrote:
> > Hi,
> > 
> > This is the next version of the CPU hotplug patchset for PowerPC
> > sPAPR target. The hotplug semantics looks like this:
> > 
> > (qemu) device_add POWER8E-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> > (qemu) device_add host-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> > (qemu) device_add
> > POWER8E_v2.1-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> 
> I've merged these to my ppc-cpu-hotplug branch, and I'm doing some
> testing.  It it checks out, I hope to send a pull request.

I've now merged this into my main ppc-for-2.7 branch.  I'll be doing
some testing, obviously, but I'd certain appreciate any other tests of
this branch with the hotplug code.

> 
> > 
> > Changes in v4
> > -------------
> > - Rebased against David Gibson's ppc-cpu-hotplug and hence dropped those
> >   patches that are already part of that tree.
> > - We were assuming the CPU thread to be always of type PowerPCCPU which
> >   needn't be true. Hence use actual CPU type's instance_size when
> >   object_initialize'ing the threads as per David's suggestion. This requires
> >   us to know the instance_size for a given type for which a new QOM API
> >   object_type_get_size() has been introduced in this version.
> > - Consolidate CPU init related routines in spapr_cpu_core.c. As part of this
> >   move spapr_cpu_init() and its dependencies to spapr_cpu_core.c.
> > - Got rid of the temporary unplug list when removing CPU cores.
> > - Folded spapr_cpu_core_create_threads() into spapr_cpu_core_realize() and
> >   fixed the error path in in spapr_cpu_core_realize().
> > - Add support for -cpu host.
> > 
> > TODOs remaining
> > ---------------
> > - Work on David's suggestion of intializing CPU's ObjectClass in
> >   class_init rather than instance_init.
> > - Use object_initialize_with_type instead of object_initialize when
> >   creating CPU threads of a core.
> > - Use vcpu_dt_id logic when populating core id in
> >   spapr_query_hotpluggable_cpus().
> > - Handle CPU compat properly (-cpu host,compat=POWER7)
> > 
> > v3: https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg01829.html
> > 
> > Bharata B Rao (7):
> >   qom: API to get instance_size of a type
> >   spapr: Abstract CPU core device and type specific core devices
> >   spapr: Move spapr_cpu_init() to spapr_cpu_core.c
> >   spapr: convert boot CPUs into CPU core devices
> >   spapr: CPU hotplug support
> >   spapr: CPU hot unplug support
> >   hmp: Add 'info hotpluggable-cpus' HMP command
> > 
> > Igor Mammedov (2):
> >   QMP: Add query-hotpluggable-cpus
> >   spapr: implement query-hotpluggable-cpus callback
> > 
> >  hmp-commands-info.hx            |  14 ++
> >  hmp.c                           |  41 ++++
> >  hmp.h                           |   1 +
> >  hw/ppc/Makefile.objs            |   1 +
> >  hw/ppc/spapr.c                  | 215 +++++++++++++++------
> >  hw/ppc/spapr_cpu_core.c         | 405 ++++++++++++++++++++++++++++++++++++++++
> >  hw/ppc/spapr_events.c           |   3 +
> >  hw/ppc/spapr_rtas.c             |  24 +++
> >  include/hw/boards.h             |   5 +
> >  include/hw/ppc/spapr.h          |   7 +
> >  include/hw/ppc/spapr_cpu_core.h |  36 ++++
> >  include/qom/object.h            |   8 +-
> >  monitor.c                       |  13 ++
> >  qapi-schema.json                |  55 ++++++
> >  qmp-commands.hx                 |  23 +++
> >  qom/object.c                    |   8 +
> >  target-ppc/kvm.c                |  28 +++
> >  17 files changed, 828 insertions(+), 59 deletions(-)
> >  create mode 100644 hw/ppc/spapr_cpu_core.c
> >  create mode 100644 include/hw/ppc/spapr_cpu_core.h
> > 
> 



-- 
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR
  2016-06-15  6:04   ` [Qemu-devel] [Qemu-ppc] " David Gibson
@ 2016-06-16  3:49     ` Bharata B Rao
  2016-06-16  6:41       ` David Gibson
  2016-06-16 11:49       ` Thomas Huth
  0 siblings, 2 replies; 22+ messages in thread
From: Bharata B Rao @ 2016-06-16  3:49 UTC (permalink / raw)
  To: David Gibson
  Cc: mjrosato, thuth, pkrempa, ehabkost, qemu-devel, borntraeger,
	qemu-ppc, pbonzini, imammedo, eblake, mdroth

On Wed, Jun 15, 2016 at 04:04:14PM +1000, David Gibson wrote:
> On Fri, Jun 10, 2016 at 03:14:14PM +1000, David Gibson wrote:
> > On Fri, Jun 10, 2016 at 06:28:59AM +0530, Bharata B Rao wrote:
> > > Hi,
> > > 
> > > This is the next version of the CPU hotplug patchset for PowerPC
> > > sPAPR target. The hotplug semantics looks like this:
> > > 
> > > (qemu) device_add POWER8E-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> > > (qemu) device_add host-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> > > (qemu) device_add
> > > POWER8E_v2.1-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> > 
> > I've merged these to my ppc-cpu-hotplug branch, and I'm doing some
> > testing.  It it checks out, I hope to send a pull request.
> 
> I've now merged this into my main ppc-for-2.7 branch.  I'll be doing
> some testing, obviously, but I'd certain appreciate any other tests of
> this branch with the hotplug code.

David, I don't see the unplug patch in your tree, intentional ?

Also I am working on supporting the CPU compat settings with the following
semantics:

-cpu host,power7 -device host-spapr-cpu-core,compat-cpu=power7

Whatever CPU compat level that is specifed with -cpu host is considered
as base and the compat-cpu property specified with -device will be
validated against the base compat level. And this property 'compat-cpu'
will be supported only for host-spapr-cpu-core type.

Is this semantics fine ?

Regards,
Bharata.

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR
  2016-06-16  3:49     ` Bharata B Rao
@ 2016-06-16  6:41       ` David Gibson
  2016-06-16 11:49       ` Thomas Huth
  1 sibling, 0 replies; 22+ messages in thread
From: David Gibson @ 2016-06-16  6:41 UTC (permalink / raw)
  To: Bharata B Rao
  Cc: mjrosato, thuth, pkrempa, ehabkost, qemu-devel, borntraeger,
	qemu-ppc, pbonzini, imammedo, eblake, mdroth

[-- Attachment #1: Type: text/plain, Size: 1893 bytes --]

On Thu, Jun 16, 2016 at 09:19:52AM +0530, Bharata B Rao wrote:
> On Wed, Jun 15, 2016 at 04:04:14PM +1000, David Gibson wrote:
> > On Fri, Jun 10, 2016 at 03:14:14PM +1000, David Gibson wrote:
> > > On Fri, Jun 10, 2016 at 06:28:59AM +0530, Bharata B Rao wrote:
> > > > Hi,
> > > > 
> > > > This is the next version of the CPU hotplug patchset for PowerPC
> > > > sPAPR target. The hotplug semantics looks like this:
> > > > 
> > > > (qemu) device_add POWER8E-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> > > > (qemu) device_add host-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> > > > (qemu) device_add
> > > > POWER8E_v2.1-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> > > 
> > > I've merged these to my ppc-cpu-hotplug branch, and I'm doing some
> > > testing.  It it checks out, I hope to send a pull request.
> > 
> > I've now merged this into my main ppc-for-2.7 branch.  I'll be doing
> > some testing, obviously, but I'd certain appreciate any other tests of
> > this branch with the hotplug code.
> 
> David, I don't see the unplug patch in your tree, intentional ?

Oops, no.  I've added it now.

> Also I am working on supporting the CPU compat settings with the following
> semantics:
> 
> -cpu host,power7 -device host-spapr-cpu-core,compat-cpu=power7
> 
> Whatever CPU compat level that is specifed with -cpu host is considered
> as base and the compat-cpu property specified with -device will be
> validated against the base compat level. And this property 'compat-cpu'
> will be supported only for host-spapr-cpu-core type.
> 
> Is this semantics fine ?

Uh.. I think so.  The semantics of cpu compat modes have always
confused me.

-- 
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR
  2016-06-16  3:49     ` Bharata B Rao
  2016-06-16  6:41       ` David Gibson
@ 2016-06-16 11:49       ` Thomas Huth
  2016-06-16 16:57         ` Igor Mammedov
  1 sibling, 1 reply; 22+ messages in thread
From: Thomas Huth @ 2016-06-16 11:49 UTC (permalink / raw)
  To: bharata, David Gibson
  Cc: mjrosato, pkrempa, ehabkost, qemu-devel, borntraeger, qemu-ppc,
	pbonzini, imammedo, eblake, mdroth

On 16.06.2016 05:49, Bharata B Rao wrote:
> On Wed, Jun 15, 2016 at 04:04:14PM +1000, David Gibson wrote:
>> On Fri, Jun 10, 2016 at 03:14:14PM +1000, David Gibson wrote:
>>> On Fri, Jun 10, 2016 at 06:28:59AM +0530, Bharata B Rao wrote:
>>>> Hi,
>>>>
>>>> This is the next version of the CPU hotplug patchset for PowerPC
>>>> sPAPR target. The hotplug semantics looks like this:
>>>>
>>>> (qemu) device_add POWER8E-spapr-cpu-core,id=core2,core-id=16[,threads=4]
>>>> (qemu) device_add host-spapr-cpu-core,id=core2,core-id=16[,threads=4]
>>>> (qemu) device_add
>>>> POWER8E_v2.1-spapr-cpu-core,id=core2,core-id=16[,threads=4]
>>>
>>> I've merged these to my ppc-cpu-hotplug branch, and I'm doing some
>>> testing.  It it checks out, I hope to send a pull request.
>>
>> I've now merged this into my main ppc-for-2.7 branch.  I'll be doing
>> some testing, obviously, but I'd certain appreciate any other tests of
>> this branch with the hotplug code.
> 
> David, I don't see the unplug patch in your tree, intentional ?
> 
> Also I am working on supporting the CPU compat settings with the following
> semantics:
> 
> -cpu host,power7 -device host-spapr-cpu-core,compat-cpu=power7

I think the old syntax was something like:

 -cpu POWER8,compat=power7

So maybe keep that "compat=" prefix for both options?

 Thomas

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR
  2016-06-16 11:49       ` Thomas Huth
@ 2016-06-16 16:57         ` Igor Mammedov
  0 siblings, 0 replies; 22+ messages in thread
From: Igor Mammedov @ 2016-06-16 16:57 UTC (permalink / raw)
  To: Thomas Huth
  Cc: bharata, David Gibson, mjrosato, pkrempa, ehabkost, qemu-devel,
	mdroth, borntraeger, qemu-ppc, pbonzini

On Thu, 16 Jun 2016 13:49:38 +0200
Thomas Huth <thuth@redhat.com> wrote:

> On 16.06.2016 05:49, Bharata B Rao wrote:
> > On Wed, Jun 15, 2016 at 04:04:14PM +1000, David Gibson wrote:  
> >> On Fri, Jun 10, 2016 at 03:14:14PM +1000, David Gibson wrote:  
> >>> On Fri, Jun 10, 2016 at 06:28:59AM +0530, Bharata B Rao wrote:  
> >>>> Hi,
> >>>>
> >>>> This is the next version of the CPU hotplug patchset for PowerPC
> >>>> sPAPR target. The hotplug semantics looks like this:
> >>>>
> >>>> (qemu) device_add POWER8E-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> >>>> (qemu) device_add host-spapr-cpu-core,id=core2,core-id=16[,threads=4]
> >>>> (qemu) device_add
> >>>> POWER8E_v2.1-spapr-cpu-core,id=core2,core-id=16[,threads=4]  
> >>>
> >>> I've merged these to my ppc-cpu-hotplug branch, and I'm doing some
> >>> testing.  It it checks out, I hope to send a pull request.  
> >>
> >> I've now merged this into my main ppc-for-2.7 branch.  I'll be doing
> >> some testing, obviously, but I'd certain appreciate any other tests of
> >> this branch with the hotplug code.  
> > 
> > David, I don't see the unplug patch in your tree, intentional ?
> > 
> > Also I am working on supporting the CPU compat settings with the following
> > semantics:
> > 
> > -cpu host,power7 -device host-spapr-cpu-core,compat-cpu=power7  
> 
> I think the old syntax was something like:
> 
>  -cpu POWER8,compat=power7
> 
> So maybe keep that "compat=" prefix for both options?
seconded,
it should be canonical property syntax "name=value"

> 
>  Thomas
> 
> 

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-06-16 16:57 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-10  0:58 [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR Bharata B Rao
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 1/9] qom: API to get instance_size of a type Bharata B Rao
2016-06-10  4:04   ` David Gibson
2016-06-10  7:38     ` Igor Mammedov
2016-06-15  5:48       ` David Gibson
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 2/9] spapr: Abstract CPU core device and type specific core devices Bharata B Rao
2016-06-10  4:24   ` David Gibson
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 3/9] spapr: Move spapr_cpu_init() to spapr_cpu_core.c Bharata B Rao
2016-06-10  4:27   ` David Gibson
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 4/9] spapr: convert boot CPUs into CPU core devices Bharata B Rao
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 5/9] spapr: CPU hotplug support Bharata B Rao
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 6/9] spapr: CPU hot unplug support Bharata B Rao
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 7/9] QMP: Add query-hotpluggable-cpus Bharata B Rao
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 8/9] hmp: Add 'info hotpluggable-cpus' HMP command Bharata B Rao
2016-06-10  8:34   ` David Gibson
2016-06-10  0:59 ` [Qemu-devel] [PATCH v4 9/9] spapr: implement query-hotpluggable-cpus callback Bharata B Rao
2016-06-10  5:14 ` [Qemu-devel] [PATCH v4 0/9] Core based CPU hotplug for PowerPC sPAPR David Gibson
2016-06-15  6:04   ` [Qemu-devel] [Qemu-ppc] " David Gibson
2016-06-16  3:49     ` Bharata B Rao
2016-06-16  6:41       ` David Gibson
2016-06-16 11:49       ` Thomas Huth
2016-06-16 16:57         ` Igor Mammedov

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.