Skip to contentSkip to conversation

spapr: fix cpu core hotunplug call flow

PATCH Applied Igor Mammedov 3 participants 8 messages Feb 2, 2017 – Feb 6, 2017

lore
Share & tools
lore
#0 lore raw

cover spapr: fix cpu core hotunplug call flow

Make cpu core hotunplug use the same (expected) unplug_request/unplug call flow like spapr memory unplug and mem/cpu unplug on x86.

While doing it separate internal cpu core handling and machine wiring code and move machine related callbacks close to related machine code in spapr.c.

Series applies on top of tags/ppc-for-2.9-20170202 pull req.

repo for testing:
[email protected]:imammedo/qemu.git spapr_cpu_unplug_cleanup

CC David Gibson <[email protected]> (supporter:sPAPR)
CC Alexander Graf <[email protected]> (supporter:sPAPR)
CC Bharata B Rao <[email protected]>

Igor Mammedov (3):
spapr: cpu core: separate child threads destruction from machine state
operations
spapr: move spapr_core_[foo]plug() callbacks close to machine code in
spapr.c
spapr: make cpu core unplug follow expected hotunplug call flow

 include/hw/ppc/spapr_cpu_core.h |   6 --
 hw/ppc/spapr.c                  | 150 +++++++++++++++++++++++++++++++++++++++-
 hw/ppc/spapr_cpu_core.c         | 137 +-----------------------------------
 3 files changed, 151 insertions(+), 142 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 spapr: cpu core: separate child threads destruction from machine state operations

---
 hw/ppc/spapr_cpu_core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
hw/ppc/spapr_cpu_core.c +10 -5
index 9dddaeb..b9e5f80 100644
@@ -111,11 +111,19 @@ char *spapr_get_cpu_core_type(const char *model)
 
 static void spapr_core_release(DeviceState *dev, void *opaque)
 {
+    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+    CPUCore *cc = CPU_CORE(dev);
+
+    spapr->cores[cc->core_id / smp_threads] = NULL;
+    object_unparent(OBJECT(dev));
+}
+
+static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)
+{
     sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
     sPAPRCPUCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(OBJECT(dev));
     const char *typename = object_class_get_name(scc->cpu_class);
     size_t size = object_type_get_instance_size(typename);
-    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
     CPUCore *cc = CPU_CORE(dev);
     int i;
 
@@ -129,11 +137,7 @@ static void spapr_core_release(DeviceState *dev, void *opaque)
         cpu_remove_sync(cs);
         object_unparent(obj);
     }
-
-    spapr->cores[cc->core_id / smp_threads] = NULL;
-
     g_free(sc->threads);
-    object_unparent(OBJECT(dev));
 }
 
 void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
@@ -368,6 +372,7 @@ void spapr_cpu_core_class_init(ObjectClass *oc, void *data)
     sPAPRCPUCoreClass *scc = SPAPR_CPU_CORE_CLASS(oc);
 
     dc->realize = spapr_cpu_core_realize;
+    dc->unrealize = spapr_cpu_core_unrealizefn;
     scc->cpu_class = cpu_class_by_name(TYPE_POWERPC_CPU, data);
     g_assert(scc->cpu_class);
 }
Signature · 1 line
2.7.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] spapr: cpu core: separate child threads destruction from machine state operations

Quoted 5 lines · Igor Mammedov
---
 hw/ppc/spapr_cpu_core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

I would mention explicitly that we are adding core unrealizefn and doing threads' destruction from it now.

Otherwise, Reviewed-by: Bharata B Rao <[email protected]>

Regards,
Bharata.

#3 lore raw

PATCH v2 1/3 spapr: cpu core: separate child threads destruction from machine state operations

Split off destroying VCPU threads from drc callback spapr_core_release() into new spapr_cpu_core_unrealizefn() which takes care of internal cpu core state cleanup (i.e. VCPU threads) and is called when object_unparent(core) is called.

That leaves spapr_core_release() only with board mgmt code, which will be moved to board related file in follow up patch along with the rest on hotplug callbacks.

---
 hw/ppc/spapr_cpu_core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
hw/ppc/spapr_cpu_core.c +10 -5
index 9dddaeb..b9e5f80 100644
@@ -111,11 +111,19 @@ char *spapr_get_cpu_core_type(const char *model)
 
 static void spapr_core_release(DeviceState *dev, void *opaque)
 {
+    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+    CPUCore *cc = CPU_CORE(dev);
+
+    spapr->cores[cc->core_id / smp_threads] = NULL;
+    object_unparent(OBJECT(dev));
+}
+
+static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)
+{
     sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
     sPAPRCPUCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(OBJECT(dev));
     const char *typename = object_class_get_name(scc->cpu_class);
     size_t size = object_type_get_instance_size(typename);
-    sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
     CPUCore *cc = CPU_CORE(dev);
     int i;
 
@@ -129,11 +137,7 @@ static void spapr_core_release(DeviceState *dev, void *opaque)
         cpu_remove_sync(cs);
         object_unparent(obj);
     }
-
-    spapr->cores[cc->core_id / smp_threads] = NULL;
-
     g_free(sc->threads);
-    object_unparent(OBJECT(dev));
 }
 
 void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
@@ -368,6 +372,7 @@ void spapr_cpu_core_class_init(ObjectClass *oc, void *data)
     sPAPRCPUCoreClass *scc = SPAPR_CPU_CORE_CLASS(oc);
 
     dc->realize = spapr_cpu_core_realize;
+    dc->unrealize = spapr_cpu_core_unrealizefn;
     scc->cpu_class = cpu_class_by_name(TYPE_POWERPC_CPU, data);
     g_assert(scc->cpu_class);
 }
Signature · 1 line
2.7.4
#4 lore raw

PATCH 2/3 spapr: move spapr_core_[foo]plug() callbacks close to machine code in spapr.c

In reply to Igor Mammedov

spapr_core_pre_plug/spapr_core_plug/spapr_core_unplug() are managing wiring CPU core into spapr machine state and not internal CPU core state. So move them from spapr_cpu_core.c to spapr.c where other similar (spapr_memory_[foo]plug()) callbacks are located, which also matches x86 target practice.

---
 include/hw/ppc/spapr_cpu_core.h |   6 --
 hw/ppc/spapr.c                  | 138 ++++++++++++++++++++++++++++++++++++++++
 hw/ppc/spapr_cpu_core.c         | 138 ----------------------------------------
 3 files changed, 138 insertions(+), 144 deletions(-)
include/hw/ppc/spapr_cpu_core.h +0 -6
index 50292f4..3c35665 100644
@@ -34,12 +34,6 @@ typedef struct sPAPRCPUCoreClass {
     ObjectClass *cpu_class;
 } sPAPRCPUCoreClass;
 
-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);
-void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
-                       Error **errp);
 void spapr_cpu_core_class_init(ObjectClass *oc, void *data);
 #endif
hw/ppc/spapr.c +138 -0

144 lines not on this page · raw message

hw/ppc/spapr_cpu_core.c +0 -138

150 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/3 spapr: make cpu core unplug follow expected hotunplug call flow

In reply to Igor Mammedov

spapr_core_unplug() were essentially spapr_core_unplug_request() handler that requested CPU removal and registered callback which did actual cpu core removali but it was called from spapr_machine_device_unplug() which is intended for actual object removal. Commit (cf632463 spapr: Memory hot-unplug support) sort of fixed it introducing spapr_machine_device_unplug_request() and calling spapr_core_unplug() but it hasn't renamed callback and by mistake calls it from spapr_machine_device_unplug().

However spapr_machine_device_unplug() isn't ever called for cpu core since spapr_core_release() doesn't follow expected hotunplug call flow which is:
1: device_del() ->

        hotplug_handler_unplug_request() ->
            set destroy_cb()

2: destroy_cb() ->
hotplug_handler_unplug() ->
object_unparent // actual device removal

Fix it by renaming spapr_core_unplug() to spapr_core_unplug_request() which is called from spapr_machine_device_unplug_request() and making spapr_core_release() call hotplug_handler_unplug() which will call spapr_machine_device_unplug() -> spapr_core_unplug() to remove cpu core.

---
 hw/ppc/spapr.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
hw/ppc/spapr.c +14 -4
index 8c2efd8..37cb338 100644
@@ -2488,7 +2488,8 @@ void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset,
     return fdt;
 }
 
-static void spapr_core_release(DeviceState *dev, void *opaque)
+static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
+                              Error **errp)
 {
     sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
     CPUCore *cc = CPU_CORE(dev);
@@ -2497,8 +2498,17 @@ static void spapr_core_release(DeviceState *dev, void *opaque)
     object_unparent(OBJECT(dev));
 }
 
-static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,
-                              Error **errp)
+static void spapr_core_release(DeviceState *dev, void *opaque)
+{
+    HotplugHandler *hotplug_ctrl;
+
+    hotplug_ctrl = qdev_get_hotplug_handler(dev);
+    hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort);
+}
+
+static
+void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
+                               Error **errp)
 {
     CPUCore *cc = CPU_CORE(dev);
     int smt = kvmppc_smt_threads();
@@ -2719,7 +2729,7 @@ static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_dev,
             error_setg(errp, "CPU hot unplug not supported on this machine");
             return;
         }
-        spapr_core_unplug(hotplug_dev, dev, errp);
+        spapr_core_unplug_request(hotplug_dev, dev, errp);
     }
 }
 
Signature · 1 line
2.7.4
#6 lore raw

Re: [Qemu-devel] [PATCH 3/3] spapr: make cpu core unplug follow expected hotunplug call flow

Quoted 25 lines · Igor Mammedov

spapr_core_unplug() were essentially spapr_core_unplug_request() handler that requested CPU removal and registered callback which did actual cpu core removali but it was called from spapr_machine_device_unplug() which is intended for actual object removal. Commit (cf632463 spapr: Memory hot-unplug support) sort of fixed it introducing spapr_machine_device_unplug_request() and calling spapr_core_unplug() but it hasn't renamed callback and by mistake calls it from spapr_machine_device_unplug().

However spapr_machine_device_unplug() isn't ever called for cpu core since spapr_core_release() doesn't follow expected hotunplug call flow which is:
1: device_del() ->

        hotplug_handler_unplug_request() ->
            set destroy_cb()

2: destroy_cb() ->
hotplug_handler_unplug() ->
object_unparent // actual device removal

Fix it by renaming spapr_core_unplug() to spapr_core_unplug_request() which is called from spapr_machine_device_unplug_request() and making spapr_core_release() call hotplug_handler_unplug() which will call spapr_machine_device_unplug() -> spapr_core_unplug() to remove cpu core.

Quoted 3 lines
---
 hw/ppc/spapr.c | 18 ++++++++++++++----

Regards,
Bharata.

Applied
#7 lore raw
In reply to Igor Mammedov
Quoted 10 lines · Igor Mammedov

Make cpu core hotunplug use the same (expected) unplug_request/unplug call flow like spapr memory unplug and mem/cpu unplug on x86.

While doing it separate internal cpu core handling and machine wiring code and move machine related callbacks close to related machine code in spapr.c.

Series applies on top of tags/ppc-for-2.9-20170202 pull req.

Quoted 7 lines

repo for testing:
[email protected]:imammedo/qemu.git spapr_cpu_unplug_cleanup

CC David Gibson <[email protected]> (supporter:sPAPR)
CC Alexander Graf <[email protected]> (supporter:sPAPR)
CC Bharata B Rao <[email protected]>

Merged to ppc-for-2.9.

Signature · 4 lines
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