spapr: fix cpu core hotunplug call flow
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
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
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
@@ -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
PATCH 2/3 spapr: move spapr_core_[foo]plug() callbacks close to machine code in spapr.c
In reply to Igor Mammedovspapr_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
@@ -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
PATCH 3/3 spapr: make cpu core unplug follow expected hotunplug call flow
In reply to Igor Mammedovspapr_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
@@ -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
Re: [Qemu-devel] [PATCH 1/3] spapr: cpu core: separate child threads destruction from machine state operations
In reply to Igor MammedovQuoted 5 lines · Igor Mammedov
Signed-off-by Igor Mammedov <[email protected]>--- 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.
Re: [Qemu-devel] [PATCH 3/3] spapr: make cpu core unplug follow expected hotunplug call flow
In reply to Igor MammedovQuoted 25 lines · Igor Mammedov
spapr_core_unplug()were essentiallyspapr_core_unplug_request()handler that requested CPU removal and registered callback which did actual cpu core removali but it was called fromspapr_machine_device_unplug()which is intended for actual object removal. Commit (cf632463spapr: Memory hot-unplug support) sort of fixed it introducingspapr_machine_device_unplug_request()and callingspapr_core_unplug()but it hasn't renamed callback and by mistake calls it fromspapr_machine_device_unplug().However
spapr_machine_device_unplug()isn't ever called for cpu core sincespapr_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 removalFix it by renaming
spapr_core_unplug()tospapr_core_unplug_request()which is called fromspapr_machine_device_unplug_request()and makingspapr_core_release()callhotplug_handler_unplug()which will callspapr_machine_device_unplug()->spapr_core_unplug()to remove cpu core.
Quoted 3 lines
Signed-off-by Igor Mammedov <[email protected]>--- hw/ppc/spapr.c | 18 ++++++++++++++----
Regards,
Bharata.
PATCH v2 1/3 spapr: cpu core: separate child threads destruction from machine state operations
In reply to Bharata B RaoSplit 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
@@ -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
David Gibson
AppliedQuoted 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.gitspapr_cpu_unplug_cleanupCC 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