Core based CPU hotplug for PowerPC sPAPR
cover Core based CPU hotplug for PowerPC sPAPR
Hi,
This is v2.1 of "Core based CPU hotplug for PowerPC sPAPR". v2 was posted
here: https://lists.gnu.org/archive/html/qemu-ppc/2016-03/msg00201.html
I am making this v2.1 instead of v3 as this introduces a change in device_add semantics and if we don't want to continue this, I will go back to the previous v2 semantics from v3 onwards. v2 had spapr-cpu-core device that served as CPU core device for all types of PowerPCCPU threads. In this version however, spapr-cpu-core becomes an abstract device and we will have different core devices for each of the PowerPCCPU type. So in this version, the hotplug semantics looks like this:
(qemu) device_add POWER8-spapr-cpu-core,id=core2,core=16[,threads=4]
cpu_model specification is gone as it becomes redundant with different core types for each CPU type. CPU core types are defined only for host, POWER7 and POWER8 models only (and not for their variants/aliases) yet.
I have mostly taken care of all the review comments that I got for v2.
Major changes in this version (v2.1)
------------------------------------
- Semantics change: spapr-cpu-core to POWER8-spapr-cpu-core and likewise
- Included Igor's pre_plug patch.
Bharata B Rao (10):
exec: Remove cpu from cpus list during cpu_exec_exit()
exec: Do vmstate unregistration from cpu_exec_exit()
cpu: Add a sync version of cpu_remove()
cpu: Abstract CPU core type
spapr: Abstract CPU core device
spapr: Add CPU type specific core devices
spapr: convert boot CPUs into CPU core devices
spapr: CPU hotplug support
xics,xics_kvm: Handle CPU unplug correctly
spapr: CPU hot unplug support
Gu Zheng (1):
cpu: Reclaim vCPU objects
Igor Mammedov (1):
qdev: hotplug: Introduce HotplugHandler.pre_plug() callback
cpus.c | 51 +++++- exec.c | 41 ++++- hw/core/hotplug.c | 11 ++ hw/core/qdev.c | 9 +- hw/cpu/Makefile.objs | 1 + hw/cpu/core.c | 87 ++++++++++ hw/intc/xics.c | 14 ++ hw/intc/xics_kvm.c | 8 +- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr.c | 150 +++++++++++++++-- hw/ppc/spapr_cpu_core.c | 349 ++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 3 + hw/ppc/spapr_rtas.c | 24 +++ include/hw/cpu/core.h | 31 ++++ include/hw/hotplug.h | 14 +- include/hw/ppc/spapr.h | 6 + include/hw/ppc/spapr_cpu_core.h | 79 +++++++++ include/hw/ppc/xics.h | 1 + include/qom/cpu.h | 18 +++ include/sysemu/kvm.h | 1 + kvm-all.c | 57 ++++++- kvm-stub.c | 5 + 22 files changed, 932 insertions(+), 29 deletions(-) create mode 100644 hw/cpu/core.c create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/cpu/core.h create mode 100644 include/hw/ppc/spapr_cpu_core.h
Signature · 1 line
2.1.0
RFC PATCH 1/12 exec: Remove cpu from cpus list during cpu_exec_exit()
CPUState *cpu gets added to the cpus list during cpu_exec_init(). It should be removed from cpu_exec_exit().
cpu_exec_exit() is called from generic CPU::instance_finalize and some archs like PowerPC call it from CPU unrealizefn. So ensure that we dequeue the cpu only once.
Now -1 value for cpu->cpu_index indicates that we have already dequeued the cpu for CONFIG_USER_ONLY case also.
--- exec.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-)
exec.c +24 -8
@@ -609,15 +609,9 @@ static int cpu_get_free_index(Error **errp) return cpu; } -void cpu_exec_exit (CPUState *cpu) +static void cpu_release_index (CPUState *cpu) { -if (cpu->cpu_index ==-1 ) { -/* cpu_index was never allocated by this @cpu or was already freed. */ -return ; - } -bitmap_clear (cpu_index_map, cpu->cpu_index,1 ); - cpu->cpu_index =-1 ; }#else
@@ -632,11 +626,33 @@ static int cpu_get_free_index(Error **errp) return cpu_index; } -void cpu_exec_exit (CPUState *cpu) +static void cpu_release_index (CPUState *cpu) { +return ; }#endif +void cpu_exec_exit (CPUState *cpu) +{ +#if defined(CONFIG_USER_ONLY ) +cpu_list_lock (); +#endif +if (cpu->cpu_index ==-1 ) { +/* cpu_index was never allocated by this @cpu or was already freed. */ +#if defined(CONFIG_USER_ONLY ) +cpu_list_unlock (); +#endif +return ; + } + +QTAILQ_REMOVE (&cpus, cpu, node); +cpu_release_index (cpu); + cpu->cpu_index =-1 ; +#if defined(CONFIG_USER_ONLY ) +cpu_list_unlock (); +#endif +} +void cpu_exec_init (CPUState *cpu,Error **errp) {CPUClass *cc =CPU_GET_CLASS (cpu);
Signature · 1 line
2.1.0
RFC PATCH 2/12 exec: Do vmstate unregistration from cpu_exec_exit()
In reply to Bharata B Raocpu_exec_init() does vmstate_register for the CPU device. This needs to be undone from cpu_exec_exit(). This change is needed to support CPU hot removal.
--- exec.c | 9 +++++++++ 1 file changed, 9 insertions(+)
exec.c +9 -0
@@ -634,6 +634,8 @@ static void cpu_release_index(CPUState *cpu)void cpu_exec_exit (CPUState *cpu) { +CPUClass *cc =CPU_GET_CLASS (cpu); +#if defined(CONFIG_USER_ONLY )cpu_list_lock ();#endif
@@ -651,6 +653,13 @@ void cpu_exec_exit(CPUState *cpu)#if defined(CONFIG_USER_ONLY )cpu_list_unlock ();#endif + +if (cc->vmsd !=NULL ) { +vmstate_unregister (NULL , cc->vmsd, cpu); + } +if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) { +vmstate_unregister (NULL , &vmstate_cpu_common, cpu); + } }void cpu_exec_init (CPUState *cpu,Error **errp)
Signature · 1 line
2.1.0
RFC PATCH 3/12 cpu: Reclaim vCPU objects
In reply to Bharata B RaoFrom: Gu Zheng <[email protected]>
In order to deal well with the kvm vcpus (which can not be removed without any protection), we do not close KVM vcpu fd, just record and mark it as stopped into a list, so that we can reuse it for the appending cpu hot-add request if possible. It is also the approach that kvm guys suggested:
https://www.mail-archive.com/[email protected]/msg102839.html
[- Explicit CPU_REMOVE() from qemu_kvm/tcg_destroy_vcpu()
isn't needed as it is done from cpu_exec_exit()
- Use iothread mutex instead of global mutex during destroy
- Don't cleanup vCPU object from vCPU thread context but leave it to the callers (device_add/device_del)]
--- cpus.c | 39 +++++++++++++++++++++++++++++++++-- include/qom/cpu.h | 10 +++++++++ include/sysemu/kvm.h | 1 + kvm-all.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++- kvm-stub.c | 5 +++++ 5 files changed, 109 insertions(+), 3 deletions(-)
cpus.c +37 -2
@@ -953,6 +953,18 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data)qemu_cpu_kick (cpu); } +static void qemu_kvm_destroy_vcpu (CPUState *cpu) +{ +if (kvm_destroy_vcpu (cpu) <0 ) { +error_report ("kvm_destroy_vcpu failed" ); +exit (EXIT_FAILURE ); + } +} + +static void qemu_tcg_destroy_vcpu (CPUState *cpu) +{ +} +static void flush_queued_work (CPUState *cpu) {struct qemu_work_item *wi;
@@ -1045,7 +1057,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) cpu->created = true;qemu_cond_signal (&qemu_cpu_cond); -while (1 ) { + do { if (cpu_can_run(cpu)) { r = kvm_cpu_exec(cpu); if (r == EXCP_DEBUG) {
@@ -1053,8 +1065,10 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) } }qemu_kvm_wait_io_event (cpu); - } + }while (!cpu->unplug ||cpu_can_run (cpu)); +qemu_kvm_destroy_vcpu (cpu); +qemu_mutex_unlock_iothread ();return NULL ; }
@@ -1108,6 +1122,7 @@ static void tcg_exec_all(void);static void *qemu_tcg_cpu_thread_fn (void *arg) {CPUState *cpu = arg; +CPUState *remove_cpu =NULL ;rcu_register_thread ();
@@ -1145,6 +1160,16 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } }qemu_tcg_wait_io_event (QTAILQ_FIRST (&cpus)); +CPU_FOREACH (cpu) { +if (cpu->unplug && !cpu_can_run (cpu)) { + remove_cpu = cpu; +break ; + } + } +if (remove_cpu) { +qemu_tcg_destroy_vcpu (remove_cpu); + remove_cpu =NULL ; + } }return NULL ;
@@ -1301,6 +1326,13 @@ void resume_all_vcpus(void) } } +void cpu_remove (CPUState *cpu) +{ + cpu->stop = true; + cpu->unplug = true; +qemu_cpu_kick (cpu); +} +/* For temporary buffers for forming a name */ #define VCPU_THREAD_NAME_SIZE 16
@@ -1517,6 +1549,9 @@ static void tcg_exec_all(void)break ; } }else if (cpu->stop || cpu->stopped) { +if (cpu->unplug) { + next_cpu =CPU_NEXT (cpu); + }break ; } }
include/qom/cpu.h +10 -0
@@ -237,6 +237,7 @@ struct kvm_run;* @halted: Nonzero if the CPU is in suspended state. * @stop: Indicates a pending stop request. * @stopped: Indicates the CPU has been artificially stopped. +* @unplug: Indicates a pending CPU unplug request. * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this * CPU and return to its top level loop.
@@ -289,6 +290,7 @@ struct CPUState {bool created;bool stop;bool stopped; +bool unplug;bool crash_occurred;bool exit_request;uint32_t interrupt_request;
@@ -756,6 +758,14 @@ void cpu_exit(CPUState *cpu);void cpu_resume (CPUState *cpu);/** +* cpu_remove: +* @cpu: The CPU to remove. +* +* Requests the CPU to be removed. +*/ +void cpu_remove (CPUState *cpu); + +/** * qemu_init_vcpu: * @cpu: The vCPU to initialize. *
include/sysemu/kvm.h +1 -0
@@ -216,6 +216,7 @@ int kvm_has_intx_set_mask(void);int kvm_init_vcpu (CPUState *cpu);int kvm_cpu_exec (CPUState *cpu); +int kvm_destroy_vcpu (CPUState *cpu);#ifdef NEED_CPU_H
kvm-all.c +56 -1
87 lines not on this page · raw message
kvm-stub.c +5 -0
@@ -33,6 +33,11 @@ bool kvm_allowed;bool kvm_readonly_mem_allowed;bool kvm_ioeventfd_any_length_allowed; +int kvm_destroy_vcpu (CPUState *cpu) +{ +return -ENOSYS ; +} +int kvm_init_vcpu (CPUState *cpu) {return -ENOSYS ;
Signature · 1 line
2.1.0
RFC PATCH 4/12 cpu: Add a sync version of cpu_remove()
In reply to Bharata B RaoThis sync API will be used by the CPU hotplug code to wait for the CPU to completely get removed before flagging the failure to the device_add command.
Sync version of this call is needed to correctly recover from CPU realization failures when ->plug() handler fails.
--- cpus.c | 12 ++++++++++++ include/qom/cpu.h | 8 ++++++++ 2 files changed, 20 insertions(+)
cpus.c +12 -0
@@ -1068,6 +1068,8 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) }while (!cpu->unplug ||cpu_can_run (cpu));qemu_kvm_destroy_vcpu (cpu); + cpu->created = false; +qemu_cond_signal (&qemu_cpu_cond);qemu_mutex_unlock_iothread ();return NULL ; }
@@ -1168,6 +1170,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) }if (remove_cpu) {qemu_tcg_destroy_vcpu (remove_cpu); + cpu->created = false; +qemu_cond_signal (&qemu_cpu_cond); remove_cpu =NULL ; } }
@@ -1333,6 +1337,14 @@ void cpu_remove(CPUState *cpu)qemu_cpu_kick (cpu); } +void cpu_remove_sync (CPUState *cpu) +{ +cpu_remove (cpu); +while (cpu->created) { +qemu_cond_wait (&qemu_cpu_cond, &qemu_global_mutex); + } +} +/* For temporary buffers for forming a name */ #define VCPU_THREAD_NAME_SIZE 16
include/qom/cpu.h +8 -0
@@ -765,6 +765,14 @@ void cpu_resume(CPUState *cpu);*/ void cpu_remove (CPUState *cpu); +/** +* cpu_remove_sync: +* @cpu: The CPU to remove. +* +* Requests the CPU to be removed and waits till it is removed. +*/ +void cpu_remove_sync (CPUState *cpu); +/** * qemu_init_vcpu: * @cpu: The vCPU to initialize.
Signature · 1 line
2.1.0
RFC PATCH 5/12 qdev: hotplug: Introduce HotplugHandler.pre_plug() callback
In reply to Bharata B RaoFrom: Igor Mammedov <[email protected]>
pre_plug callback is to be called before device.realize() is executed. This would allow to check/set device's properties from HotplugHandler.
--- hw/core/hotplug.c | 11 +++++++++++ hw/core/qdev.c | 9 ++++++++- include/hw/hotplug.h | 14 +++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-)
hw/core/hotplug.c +11 -0
@@ -13,6 +13,17 @@#include "hw/hotplug.h" #include "qemu/module.h" +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp) +{ +HotplugHandlerClass *hdc =HOTPLUG_HANDLER_GET_CLASS (plug_handler); + +if (hdc->pre_plug) { + hdc->pre_plug (plug_handler, plugged_dev, errp); + } +} +void hotplug_handler_plug (HotplugHandler *plug_handler,DeviceState *plugged_dev,Error **errp)
hw/core/qdev.c +8 -1
@@ -1062,6 +1062,14 @@ static void device_set_realized(Object *obj, bool value, Error **errp)g_free (name); } + hotplug_ctrl =qdev_get_hotplug_handler (dev); +if (hotplug_ctrl) { +hotplug_handler_pre_plug (hotplug_ctrl, dev, &local_err); +if (local_err !=NULL ) { + goto fail; + } + } +if (dc->realize) { dc->realize (dev, &local_err); }
@@ -1072,7 +1080,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)DEVICE_LISTENER_CALL (realize, Forward, dev); - hotplug_ctrl =qdev_get_hotplug_handler (dev);if (hotplug_ctrl) {hotplug_handler_plug (hotplug_ctrl, dev, &local_err); }
include/hw/hotplug.h +13 -1
@@ -46,7 +46,8 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,* hardware (un)plug functions. * * @parent: Opaque parent interface. -* @plug: plug callback. +* @pre_plug: pre plug callback called at start of device.realize(true) +* @plug: plug callback called at end of device.realize(true). * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling.
@@ -59,6 +60,7 @@ typedef struct HotplugHandlerClass {InterfaceClass parent;/* <public> */ +hotplug_fn pre_plug;hotplug_fn plug;hotplug_fn unplug_request;hotplug_fn unplug;
@@ -74,6 +76,16 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, Error **errp);/** +* hotplug_handler_pre_plug: +* +* Call #HotplugHandlerClass.pre_plug callback of @plug_handler. +*/ +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp); + + +/** * hotplug_handler_unplug_request: * * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.
Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v2.1 05/12] qdev: hotplug: Introduce HotplugHandler.pre_plug() callback
Quoted 7 lines · Bharata B Rao
From: Igor Mammedov <[email protected]>
pre_plugcallback is to be called beforedevice.realize()is executed. This would allow to check/set device's properties from HotplugHandler.Signed-off-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>
It would be really nice to get some opinion on this from Andreas or Paolo.
Quoted 94 lines
--- hw/core/hotplug.c | 11 +++++++++++ hw/core/qdev.c | 9 ++++++++- include/hw/hotplug.h | 14 +++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-)hw/core/hotplug.c +11
-0@@ -13,6 +13,17 @@#include "hw/hotplug.h" #include "qemu/module.h" +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp) +{ +HotplugHandlerClass *hdc =HOTPLUG_HANDLER_GET_CLASS (plug_handler); + +if (hdc->pre_plug) { + hdc->pre_plug (plug_handler, plugged_dev, errp); + } +} +void hotplug_handler_plug (HotplugHandler *plug_handler,DeviceState *plugged_dev,Error **errp)hw/core/qdev.c +8
-1@@ -1062,6 +1062,14 @@ static void device_set_realized(Object *obj, bool value, Error **errp)g_free (name); } + hotplug_ctrl =qdev_get_hotplug_handler (dev); +if (hotplug_ctrl) { +hotplug_handler_pre_plug (hotplug_ctrl, dev, &local_err); +if (local_err !=NULL ) { + goto fail; + } + } +if (dc->realize) { dc->realize (dev, &local_err); }@@ -1072,7 +1080,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)DEVICE_LISTENER_CALL (realize, Forward, dev); - hotplug_ctrl =qdev_get_hotplug_handler (dev);if (hotplug_ctrl) {hotplug_handler_plug (hotplug_ctrl, dev, &local_err); }include/hw/hotplug.h +13
-1@@ -46,7 +46,8 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,* hardware (un)plug functions. * * @parent: Opaque parent interface. -* @plug: plug callback. +* @pre_plug: pre plug callback called at start of device.realize(true) +* @plug: plug callback called at end of device.realize(true). * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling. @@ -59,6 +60,7 @@ typedef struct HotplugHandlerClass {InterfaceClass parent;/* <public> */ +hotplug_fn pre_plug;hotplug_fn plug;hotplug_fn unplug_request;hotplug_fn unplug;@@ -74,6 +76,16 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, Error **errp);/** +* hotplug_handler_pre_plug: +* +* Call #HotplugHandlerClass.pre_plug callback of @plug_handler. +*/ +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp); + + +/** * hotplug_handler_unplug_request: * * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.
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
Re: [Qemu-devel] [RFC PATCH v2.1 05/12] qdev: hotplug: Introduce HotplugHandler.pre_plug() callback
Quoted 6 lines · David Gibson
Quoted 5 lines · Bharata B Rao
From: Igor Mammedov <[email protected]>
pre_plugcallback is to be called beforedevice.realize()is executed. This would allow to check/set device's properties from HotplugHandler.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>It would be really nice to get some opinion on this from Andreas or Paolo.
Certainly okay for me, Igor did all of the HotplugHandler design and work.
Paolo
Quoted 95 lines
Quoted 94 lines
--- hw/core/hotplug.c | 11 +++++++++++ hw/core/qdev.c | 9 ++++++++- include/hw/hotplug.h | 14 +++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-)hw/core/hotplug.c +11
-0@@ -13,6 +13,17 @@#include "hw/hotplug.h" #include "qemu/module.h" +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp) +{ +HotplugHandlerClass *hdc =HOTPLUG_HANDLER_GET_CLASS (plug_handler); + +if (hdc->pre_plug) { + hdc->pre_plug (plug_handler, plugged_dev, errp); + } +} +void hotplug_handler_plug (HotplugHandler *plug_handler,DeviceState *plugged_dev,Error **errp)hw/core/qdev.c +8
-1@@ -1062,6 +1062,14 @@ static void device_set_realized(Object *obj, bool value, Error **errp)g_free (name); } + hotplug_ctrl =qdev_get_hotplug_handler (dev); +if (hotplug_ctrl) { +hotplug_handler_pre_plug (hotplug_ctrl, dev, &local_err); +if (local_err !=NULL ) { + goto fail; + } + } +if (dc->realize) { dc->realize (dev, &local_err); }@@ -1072,7 +1080,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)DEVICE_LISTENER_CALL (realize, Forward, dev); - hotplug_ctrl =qdev_get_hotplug_handler (dev);if (hotplug_ctrl) {hotplug_handler_plug (hotplug_ctrl, dev, &local_err); }include/hw/hotplug.h +13
-1@@ -46,7 +46,8 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,* hardware (un)plug functions. * * @parent: Opaque parent interface. -* @plug: plug callback. +* @pre_plug: pre plug callback called at start of device.realize(true) +* @plug: plug callback called at end of device.realize(true). * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling. @@ -59,6 +60,7 @@ typedef struct HotplugHandlerClass {InterfaceClass parent;/* <public> */ +hotplug_fn pre_plug;hotplug_fn plug;hotplug_fn unplug_request;hotplug_fn unplug;@@ -74,6 +76,16 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, Error **errp);/** +* hotplug_handler_pre_plug: +* +* Call #HotplugHandlerClass.pre_plug callback of @plug_handler. +*/ +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp); + + +/** * hotplug_handler_unplug_request: * * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.
Re: [Qemu-devel] [RFC PATCH v2.1 05/12] qdev: hotplug: Introduce HotplugHandler.pre_plug() callback
Quoted 12 lines · Paolo Bonzini
Quoted 9 lines · David Gibson
Quoted 7 lines · Bharata B Rao
From: Igor Mammedov <[email protected]>
pre_plugcallback is to be called beforedevice.realize()is executed. This would allow to check/set device's properties from HotplugHandler.Signed-off-by Igor Mammedov <[email protected]>Signed-off-by Bharata B Rao <[email protected]>
Quoted 7 lines
Quoted 4 lines
Reviewed-by David Gibson <[email protected]>It would be really nice to get some opinion on this from Andreas or Paolo.
Certainly okay for me, Igor did all of the HotplugHandler design and work.
Ok, good to hear. Thanks.
Quoted 99 lines
Paolo
Quoted 95 lines
Quoted 94 lines
--- hw/core/hotplug.c | 11 +++++++++++ hw/core/qdev.c | 9 ++++++++- include/hw/hotplug.h | 14 +++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-)hw/core/hotplug.c +11
-0@@ -13,6 +13,17 @@#include "hw/hotplug.h" #include "qemu/module.h" +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp) +{ +HotplugHandlerClass *hdc =HOTPLUG_HANDLER_GET_CLASS (plug_handler); + +if (hdc->pre_plug) { + hdc->pre_plug (plug_handler, plugged_dev, errp); + } +} +void hotplug_handler_plug (HotplugHandler *plug_handler,DeviceState *plugged_dev,Error **errp)hw/core/qdev.c +8
-1@@ -1062,6 +1062,14 @@ static void device_set_realized(Object *obj, bool value, Error **errp)g_free (name); } + hotplug_ctrl =qdev_get_hotplug_handler (dev); +if (hotplug_ctrl) { +hotplug_handler_pre_plug (hotplug_ctrl, dev, &local_err); +if (local_err !=NULL ) { + goto fail; + } + } +if (dc->realize) { dc->realize (dev, &local_err); }@@ -1072,7 +1080,6 @@ static void device_set_realized(Object *obj, bool value, Error **errp)DEVICE_LISTENER_CALL (realize, Forward, dev); - hotplug_ctrl =qdev_get_hotplug_handler (dev);if (hotplug_ctrl) {hotplug_handler_plug (hotplug_ctrl, dev, &local_err); }include/hw/hotplug.h +13
-1@@ -46,7 +46,8 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,* hardware (un)plug functions. * * @parent: Opaque parent interface. -* @plug: plug callback. +* @pre_plug: pre plug callback called at start of device.realize(true) +* @plug: plug callback called at end of device.realize(true). * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices that * require asynchronous unplug handling. @@ -59,6 +60,7 @@ typedef struct HotplugHandlerClass {InterfaceClass parent;/* <public> */ +hotplug_fn pre_plug;hotplug_fn plug;hotplug_fn unplug_request;hotplug_fn unplug;@@ -74,6 +76,16 @@ void hotplug_handler_plug(HotplugHandler *plug_handler, Error **errp);/** +* hotplug_handler_pre_plug: +* +* Call #HotplugHandlerClass.pre_plug callback of @plug_handler. +*/ +void hotplug_handler_pre_plug (HotplugHandler *plug_handler, +DeviceState *plugged_dev, +Error **errp); + + +/** * hotplug_handler_unplug_request: * * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.
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
RFC PATCH 6/12 cpu: Abstract CPU core type
In reply to Bharata B RaoAdd an abstract CPU core type that could be used by machines that want to define and hotplug CPUs in core granularity.
--- hw/cpu/Makefile.objs | 1 + hw/cpu/core.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/cpu/core.h | 31 ++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 hw/cpu/core.c create mode 100644 include/hw/cpu/core.h
hw/cpu/Makefile.objs +1 -0
@@ -2,4 +2,5 @@ obj-$(CONFIG_ARM11MPCORE) += arm11mpcore.o obj-$(CONFIG_REALVIEW) += realview_mpcore.o obj-$(CONFIG_A9MPCORE) += a9mpcore.o obj-$(CONFIG_A15MPCORE) += a15mpcore.o +obj-y += core.o
hw/cpu/core.c new file +87 -0
87 lines not on this page · raw message
include/hw/cpu/core.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* CPU core abstract device +* +* Copyright (C) 2016 Bharata B Rao <[email protected]> +* +* 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_CPU_CORE_H +#define HW_CPU_CORE_H + +#include "qemu/osdep.h" +#include "hw/qdev.h" + +#define TYPE_CPU_CORE "cpu-core" + +#define CPU_CORE (obj) \ + OBJECT_CHECK(CPUCore, (obj), TYPE_CPU_CORE) + +typedef struct CPUCore { +/*< private >*/ +DeviceState parent_obj; + +/*< public >*/ +int core; +int threads; +}CPUCore ; + +#define CPU_CORE_PROP_CORE "core" + +#endif
Signature · 1 line
2.1.0
RFC PATCH 7/12 spapr: Abstract CPU core device
In reply to Bharata B RaoAdd sPAPR specific abastract CPU core device that is based on generic CPU core device. This will serve as base type for all PowerPC CPU specific core devices.
--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 30 ++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 27 +++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.h
hw/ppc/Makefile.objs +1 -0
@@ -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
hw/ppc/spapr_cpu_core.c new file +30 -0
@@ -0,0 +1,30 @@ +/* +* sPAPR CPU core device, acts as container of CPU thread devices. +* +* Copyright (C) 2016 Bharata B Rao <[email protected]> +* +* 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 "hw/ppc/spapr.h" +#include "hw/boards.h" +#include "qemu/error-report.h" +#include "qapi/visitor.h" +#include <sysemu/cpus.h> +#include "target-ppc/kvm_ppc.h" + +static const TypeInfo spapr_cpu_core_type_info = { + .name =TYPE_SPAPR_CPU_CORE , + .parent =TYPE_CPU_CORE , + .abstract = true, + .instance_size =sizeof (sPAPRCPUCore), +}; + +static void spapr_cpu_core_register_types (void ) +{ +type_register_static (&spapr_cpu_core_type_info); +} + +type_init (spapr_cpu_core_register_types)
include/hw/ppc/spapr_cpu_core.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* sPAPR CPU core device. +* +* Copyright (C) 2016 Bharata B Rao <[email protected]> +* +* 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" + +#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 >*/ +PowerPCCPU *threads; +}sPAPRCPUCore ; + +#endif
Signature · 1 line
2.1.0
RFC PATCH 8/12 spapr: Add CPU type specific core devices
In reply to Bharata B RaoIntroduce core devices for each CPU type supported by sPAPR. These core devices are derived from the base spapr-cpu-core device type.
TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctly
--- hw/ppc/spapr.c | 3 +- hw/ppc/spapr_cpu_core.c | 118 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 36 ++++++++++++ 4 files changed, 156 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +1 -2
@@ -1614,8 +1614,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;
hw/ppc/spapr_cpu_core.c +118 -0
127 lines not on this page · raw message
include/hw/ppc/spapr.h +1 -0
@@ -585,6 +585,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 {
include/hw/ppc/spapr_cpu_core.h +36 -0
@@ -24,4 +24,40 @@ typedef struct sPAPRCPUCore { PowerPCCPU *threads; } sPAPRCPUCore; +#define TYPE_host_SPAPR_CPU_CORE "host-spapr-cpu-core" +#define host_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(hostsPAPRCPUCore, (obj), TYPE_host_SPAPR_CPU_CORE) + +typedef struct hostsPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}hostsPAPRCPUCore ; + +#define TYPE_POWER7_SPAPR_CPU_CORE "POWER7-spapr-cpu-core" +#define POWER7_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER7sPAPRCPUCore, (obj), TYPE_POWER7_SPAPR_CPU_CORE) + +typedef struct POWER7sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER7sPAPRCPUCore ; + +#define TYPE_POWER8_SPAPR_CPU_CORE "POWER8-spapr-cpu-core" +#define POWER8_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER8sPAPRCPUCore, (obj), TYPE_POWER8_SPAPR_CPU_CORE) + +typedef struct POWER8sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER8sPAPRCPUCore ; +#endif
Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices
Quoted 78 lines · Bharata B Rao
Introduce core devices for each CPU type supported by sPAPR. These core devices are derived from the base spapr-cpu-core device type.
TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctlySigned-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 3 +- hw/ppc/spapr_cpu_core.c | 118 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 36 ++++++++++++ 4 files changed, 156 insertions(+), 2 deletions(-)hw/ppc/spapr.c +1
-2@@ -1614,8 +1614,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;hw/ppc/spapr_cpu_core.c +41
-0@@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = { .instance_size = sizeof(sPAPRCPUCore), }; +#define DEFINE_SPAPR_CPU_CORE (_name) \ +static void \ +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads, \ + Error **errp) \ +{ \ + int i; \ + Error *local_err = NULL; \ + sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); \ + glue(_name, sPAPRCPUCore) * core = \ + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev)); \ + \ + for (i = 0; i < threads; i++) { \ + char id[32]; \ + \ + object_initialize(&sc->threads[i], sizeof(sc->threads[i]), \ + object_class_get_name(core->cpu)); \ + snprintf(id, sizeof(id), "thread[%d]", i); \ + object_property_add_child(OBJECT(core), id, OBJECT(&sc->threads[i]), \ + &local_err); \ + if (local_err) { \ + goto err; \ + } \ + } \ + return; \ + \ +err: \ + while (--i) { \ + object_unparent(OBJECT(&sc->threads[i])); \ + } \ + error_propagate(errp, local_err); \ +} \ + \ +static int \ +glue(_name, _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); \
hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 75
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+if (*errp) { \ +return 1 ; \ + } \ + \ +spapr_cpu_init (spapr, cpu, errp); \ +if (*errp) { \ +return 1 ; \ + } \ +return 0 ; \ +} \
If you put the ObjectClass * for the threads in the base abstract class's class structure, then you can move most of this logic to the abstract class as well and make the macro-ized stuff much smaller.
The realize_child stuff doesn't even need the ObjectClass* in the base class to factor out.
Quoted 38 lines
hw/ppc/spapr_cpu_core.c +38
-0+static void \ +glue (_name ,_spapr_cpu_core_realize )(DeviceState *dev,Error **errp) \ +{ \ +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); \ +CPUCore *cc =CPU_CORE (OBJECT (dev)); \ +Error *local_err =NULL ; \ + \ +/* \ +* TODO: This is CPU model specific CPU core's realize routine. \ +* However I am initializing "threads" field of the parent type \ +* sPAPRCPUCore here. Is this ok ? If not I will have make "threads" \ +* part of CPU model specific CPU core type and have different plug() \ +* handlers for each type instead of having a common plug() handler \ +* for all core types. \ +*/ \ + sc->threads =g_new0 (PowerPCCPU, cc->threads); \ +glue (_name, _spapr_cpu_core_create_threads)(dev, cc->threads, &local_err); \ +if (local_err) { \ + goto out; \ + } \ + \ +object_child_foreach (OBJECT (dev), \ +glue (_name, _spapr_cpu_core_realize_child), \ + &local_err); \ + \ +out: \ +if (local_err) { \ +g_free (sc->threads); \ +error_propagate (errp, local_err); \ + } \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_instance_init )(Object *obj) \ +{ \ +glue (_name, sPAPRCPUCore) * core =glue (_name, _SPAPR_CPU_CORE)(obj); \ + const char *type = stringify(_name) "-" TYPE_POWERPC_CPU; \ +ObjectClass *oc =object_class_by_name (type); \
hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 124
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+ \ + core->cpu = oc; \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_class_init )(ObjectClass *oc,void *data) \ +{ \ + \ +DeviceClass *dc =DEVICE_CLASS (oc); \ + dc->realize =glue (_name, _spapr_cpu_core_realize); \
I think the only callback you should need to construct in the macro is class_init to initialize the ObjectClass* field.
Quoted 68 lines
hw/ppc/spapr_cpu_core.c +18
-0+} \ + \ +static const TypeInfo glue (_name ,_spapr_cpu_core_type_info ) = \ +{ \ + .name = stringify(_name) "-" TYPE_SPAPR_CPU_CORE, \ + .parent =TYPE_SPAPR_CPU_CORE , \ + .instance_size =sizeof (glue (_name ,sPAPRCPUCore )), \ + .instance_init =glue (_name, _spapr_cpu_core_instance_init), \ + .class_init =glue (_name, _spapr_cpu_core_class_init), \ +}; + +DEFINE_SPAPR_CPU_CORE (host); +DEFINE_SPAPR_CPU_CORE (POWER7 ); +DEFINE_SPAPR_CPU_CORE (POWER8 ); +static void spapr_cpu_core_register_types (void ) {type_register_static (&spapr_cpu_core_type_info); +type_register_static (&host_spapr_cpu_core_type_info); +type_register_static (&POWER7_spapr_cpu_core_type_info); +type_register_static (&POWER8_spapr_cpu_core_type_info); }type_init (spapr_cpu_core_register_types)include/hw/ppc/spapr.h +1
-0@@ -585,6 +585,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 {include/hw/ppc/spapr_cpu_core.h +24
-0@@ -24,4 +24,40 @@ typedef struct sPAPRCPUCore {PowerPCCPU *threads; } sPAPRCPUCore; +#define TYPE_host_SPAPR_CPU_CORE "host-spapr-cpu-core" +#define host_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(hostsPAPRCPUCore, (obj), TYPE_host_SPAPR_CPU_CORE) + +typedef struct hostsPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}hostsPAPRCPUCore ; +#define TYPE_POWER7_SPAPR_CPU_CORE "POWER7-spapr-cpu-core" +#define POWER7_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER7sPAPRCPUCore, (obj), TYPE_POWER7_SPAPR_CPU_CORE) + +typedef struct POWER7sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER7sPAPRCPUCore ; + +#define TYPE_POWER8_SPAPR_CPU_CORE "POWER8-spapr-cpu-core"
include/hw/ppc/spapr_cpu_core.h typedef struct sPAPRCPUCore { · line 60
Quoted 10 lines
include/hw/ppc/spapr_cpu_core.h +10
-0+#define POWER8_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER8sPAPRCPUCore, (obj), TYPE_POWER8_SPAPR_CPU_CORE) + +typedef struct POWER8sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER8sPAPRCPUCore ;
These are all identical so should also be macro constructed as well. I don't think there's actually any need for the structures to be exposed in a header file either, so you should be able to do it in the same macro that constructs the implementation.
Uh.. except if you move the ObjectClass* to the base class you won't even need these.
Quoted 1 line
include/hw/ppc/spapr_cpu_core.h +0
-0#endif
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
Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices
Quoted 233 lines · David Gibson
Quoted 78 lines · Bharata B Rao
Introduce core devices for each CPU type supported by sPAPR. These core devices are derived from the base spapr-cpu-core device type.
TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctlySigned-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 3 +- hw/ppc/spapr_cpu_core.c | 118 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 36 ++++++++++++ 4 files changed, 156 insertions(+), 2 deletions(-)hw/ppc/spapr.c +1
-2@@ -1614,8 +1614,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;hw/ppc/spapr_cpu_core.c +41
-0@@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = { .instance_size = sizeof(sPAPRCPUCore), }; +#define DEFINE_SPAPR_CPU_CORE (_name) \ +static void \ +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads, \ + Error **errp) \ +{ \ + int i; \ + Error *local_err = NULL; \ + sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); \ + glue(_name, sPAPRCPUCore) * core = \ + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev)); \ + \ + for (i = 0; i < threads; i++) { \ + char id[32]; \ + \ + object_initialize(&sc->threads[i], sizeof(sc->threads[i]), \ + object_class_get_name(core->cpu)); \ + snprintf(id, sizeof(id), "thread[%d]", i); \ + object_property_add_child(OBJECT(core), id, OBJECT(&sc->threads[i]), \ + &local_err); \ + if (local_err) { \ + goto err; \ + } \ + } \ + return; \ + \ +err: \ + while (--i) { \ + object_unparent(OBJECT(&sc->threads[i])); \ + } \ + error_propagate(errp, local_err); \ +} \ + \ +static int \ +glue(_name, _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); \hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 75
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+if (*errp) { \ +return 1 ; \ + } \ + \ +spapr_cpu_init (spapr, cpu, errp); \ +if (*errp) { \ +return 1 ; \ + } \ +return 0 ; \ +} \If you put the ObjectClass * for the threads in the base abstract class's class structure, then you can move most of this logic to the abstract class as well and make the macro-ized stuff much smaller.
The
realize_childstuff doesn't even need the ObjectClass* in the base class to factor out.Quoted 38 lines
hw/ppc/spapr_cpu_core.c +38
-0+static void \ +glue (_name ,_spapr_cpu_core_realize )(DeviceState *dev,Error **errp) \ +{ \ +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); \ +CPUCore *cc =CPU_CORE (OBJECT (dev)); \ +Error *local_err =NULL ; \ + \ +/* \ +* TODO: This is CPU model specific CPU core's realize routine. \ +* However I am initializing "threads" field of the parent type \ +* sPAPRCPUCore here. Is this ok ? If not I will have make "threads" \ +* part of CPU model specific CPU core type and have different plug() \ +* handlers for each type instead of having a common plug() handler \ +* for all core types. \ +*/ \ + sc->threads =g_new0 (PowerPCCPU, cc->threads); \ +glue (_name, _spapr_cpu_core_create_threads)(dev, cc->threads, &local_err); \ +if (local_err) { \ + goto out; \ + } \ + \ +object_child_foreach (OBJECT (dev), \ +glue (_name, _spapr_cpu_core_realize_child), \ + &local_err); \ + \ +out: \ +if (local_err) { \ +g_free (sc->threads); \ +error_propagate (errp, local_err); \ + } \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_instance_init )(Object *obj) \ +{ \ +glue (_name, sPAPRCPUCore) * core =glue (_name, _SPAPR_CPU_CORE)(obj); \ + const char *type = stringify(_name) "-" TYPE_POWERPC_CPU; \ +ObjectClass *oc =object_class_by_name (type); \hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 124
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+ \ + core->cpu = oc; \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_class_init )(ObjectClass *oc,void *data) \ +{ \ + \ +DeviceClass *dc =DEVICE_CLASS (oc); \ + dc->realize =glue (_name, _spapr_cpu_core_realize); \I think the only callback you should need to construct in the macro is
class_initto initialize the ObjectClass* field.Quoted 68 lines
hw/ppc/spapr_cpu_core.c +18
-0+} \ + \ +static const TypeInfo glue (_name ,_spapr_cpu_core_type_info ) = \ +{ \ + .name = stringify(_name) "-" TYPE_SPAPR_CPU_CORE, \ + .parent =TYPE_SPAPR_CPU_CORE , \ + .instance_size =sizeof (glue (_name ,sPAPRCPUCore )), \ + .instance_init =glue (_name, _spapr_cpu_core_instance_init), \ + .class_init =glue (_name, _spapr_cpu_core_class_init), \ +}; + +DEFINE_SPAPR_CPU_CORE (host); +DEFINE_SPAPR_CPU_CORE (POWER7 ); +DEFINE_SPAPR_CPU_CORE (POWER8 ); +static void spapr_cpu_core_register_types (void ) {type_register_static (&spapr_cpu_core_type_info); +type_register_static (&host_spapr_cpu_core_type_info); +type_register_static (&POWER7_spapr_cpu_core_type_info); +type_register_static (&POWER8_spapr_cpu_core_type_info); }type_init (spapr_cpu_core_register_types)include/hw/ppc/spapr.h +1
-0@@ -585,6 +585,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 {include/hw/ppc/spapr_cpu_core.h +24
-0@@ -24,4 +24,40 @@ typedef struct sPAPRCPUCore {PowerPCCPU *threads; } sPAPRCPUCore; +#define TYPE_host_SPAPR_CPU_CORE "host-spapr-cpu-core" +#define host_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(hostsPAPRCPUCore, (obj), TYPE_host_SPAPR_CPU_CORE) + +typedef struct hostsPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}hostsPAPRCPUCore ; +#define TYPE_POWER7_SPAPR_CPU_CORE "POWER7-spapr-cpu-core" +#define POWER7_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER7sPAPRCPUCore, (obj), TYPE_POWER7_SPAPR_CPU_CORE) + +typedef struct POWER7sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER7sPAPRCPUCore ; + +#define TYPE_POWER8_SPAPR_CPU_CORE "POWER8-spapr-cpu-core"include/hw/ppc/spapr_cpu_core.h typedef struct sPAPRCPUCore { · line 60
Quoted 10 lines
include/hw/ppc/spapr_cpu_core.h +10
-0+#define POWER8_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER8sPAPRCPUCore, (obj), TYPE_POWER8_SPAPR_CPU_CORE) + +typedef struct POWER8sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER8sPAPRCPUCore ;These are all identical so should also be macro constructed as well. I don't think there's actually any need for the structures to be exposed in a header file either, so you should be able to do it in the same macro that constructs the implementation.
Quoted 2 lines
Uh.. except if you move the ObjectClass* to the base class you won't even need these.
The only reason (currently) POWER8sPAPRCPUCore exists separately from the base class sPAPRCPUCore is that it represents POWER8 core which is stored as ObjectClass*.
Now if we don't track cpu type (ObjectClass *) as part of POWER8sPAPRCPUCore but push that up to sPAPRCPUCore, I am not sure if that would be at the right abstraction level.
Apart from the above, can you also look at the TODO I have put on the top of _spapr_cpu_core_create_threads() routine in this patch ? I am not sure if what I have done there is the right thing to do.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices
Quoted 237 lines · Bharata B Rao
Quoted 233 lines · David Gibson
Quoted 78 lines · Bharata B Rao
Introduce core devices for each CPU type supported by sPAPR. These core devices are derived from the base spapr-cpu-core device type.
TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctlySigned-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 3 +- hw/ppc/spapr_cpu_core.c | 118 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 36 ++++++++++++ 4 files changed, 156 insertions(+), 2 deletions(-)hw/ppc/spapr.c +1
-2@@ -1614,8 +1614,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;hw/ppc/spapr_cpu_core.c +41
-0@@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = { .instance_size = sizeof(sPAPRCPUCore), }; +#define DEFINE_SPAPR_CPU_CORE (_name) \ +static void \ +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads, \ + Error **errp) \ +{ \ + int i; \ + Error *local_err = NULL; \ + sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); \ + glue(_name, sPAPRCPUCore) * core = \ + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev)); \ + \ + for (i = 0; i < threads; i++) { \ + char id[32]; \ + \ + object_initialize(&sc->threads[i], sizeof(sc->threads[i]), \ + object_class_get_name(core->cpu)); \ + snprintf(id, sizeof(id), "thread[%d]", i); \ + object_property_add_child(OBJECT(core), id, OBJECT(&sc->threads[i]), \ + &local_err); \ + if (local_err) { \ + goto err; \ + } \ + } \ + return; \ + \ +err: \ + while (--i) { \ + object_unparent(OBJECT(&sc->threads[i])); \ + } \ + error_propagate(errp, local_err); \ +} \ + \ +static int \ +glue(_name, _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); \hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 75
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+if (*errp) { \ +return 1 ; \ + } \ + \ +spapr_cpu_init (spapr, cpu, errp); \ +if (*errp) { \ +return 1 ; \ + } \ +return 0 ; \ +} \If you put the ObjectClass * for the threads in the base abstract class's class structure, then you can move most of this logic to the abstract class as well and make the macro-ized stuff much smaller.
The
realize_childstuff doesn't even need the ObjectClass* in the base class to factor out.Quoted 38 lines
hw/ppc/spapr_cpu_core.c +38
-0+static void \ +glue (_name ,_spapr_cpu_core_realize )(DeviceState *dev,Error **errp) \ +{ \ +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); \ +CPUCore *cc =CPU_CORE (OBJECT (dev)); \ +Error *local_err =NULL ; \ + \ +/* \ +* TODO: This is CPU model specific CPU core's realize routine. \ +* However I am initializing "threads" field of the parent type \ +* sPAPRCPUCore here. Is this ok ? If not I will have make "threads" \ +* part of CPU model specific CPU core type and have different plug() \ +* handlers for each type instead of having a common plug() handler \ +* for all core types. \ +*/ \ + sc->threads =g_new0 (PowerPCCPU, cc->threads); \ +glue (_name, _spapr_cpu_core_create_threads)(dev, cc->threads, &local_err); \ +if (local_err) { \ + goto out; \ + } \ + \ +object_child_foreach (OBJECT (dev), \ +glue (_name, _spapr_cpu_core_realize_child), \ + &local_err); \ + \ +out: \ +if (local_err) { \ +g_free (sc->threads); \ +error_propagate (errp, local_err); \ + } \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_instance_init )(Object *obj) \ +{ \ +glue (_name, sPAPRCPUCore) * core =glue (_name, _SPAPR_CPU_CORE)(obj); \ + const char *type = stringify(_name) "-" TYPE_POWERPC_CPU; \ +ObjectClass *oc =object_class_by_name (type); \hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 124
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+ \ + core->cpu = oc; \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_class_init )(ObjectClass *oc,void *data) \ +{ \ + \ +DeviceClass *dc =DEVICE_CLASS (oc); \ + dc->realize =glue (_name, _spapr_cpu_core_realize); \I think the only callback you should need to construct in the macro is
class_initto initialize the ObjectClass* field.Quoted 68 lines
hw/ppc/spapr_cpu_core.c +18
-0+} \ + \ +static const TypeInfo glue (_name ,_spapr_cpu_core_type_info ) = \ +{ \ + .name = stringify(_name) "-" TYPE_SPAPR_CPU_CORE, \ + .parent =TYPE_SPAPR_CPU_CORE , \ + .instance_size =sizeof (glue (_name ,sPAPRCPUCore )), \ + .instance_init =glue (_name, _spapr_cpu_core_instance_init), \ + .class_init =glue (_name, _spapr_cpu_core_class_init), \ +}; + +DEFINE_SPAPR_CPU_CORE (host); +DEFINE_SPAPR_CPU_CORE (POWER7 ); +DEFINE_SPAPR_CPU_CORE (POWER8 ); +static void spapr_cpu_core_register_types (void ) {type_register_static (&spapr_cpu_core_type_info); +type_register_static (&host_spapr_cpu_core_type_info); +type_register_static (&POWER7_spapr_cpu_core_type_info); +type_register_static (&POWER8_spapr_cpu_core_type_info); }type_init (spapr_cpu_core_register_types)include/hw/ppc/spapr.h +1
-0@@ -585,6 +585,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 {include/hw/ppc/spapr_cpu_core.h +24
-0@@ -24,4 +24,40 @@ typedef struct sPAPRCPUCore {PowerPCCPU *threads; } sPAPRCPUCore; +#define TYPE_host_SPAPR_CPU_CORE "host-spapr-cpu-core" +#define host_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(hostsPAPRCPUCore, (obj), TYPE_host_SPAPR_CPU_CORE) + +typedef struct hostsPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}hostsPAPRCPUCore ; +#define TYPE_POWER7_SPAPR_CPU_CORE "POWER7-spapr-cpu-core" +#define POWER7_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER7sPAPRCPUCore, (obj), TYPE_POWER7_SPAPR_CPU_CORE) + +typedef struct POWER7sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER7sPAPRCPUCore ; + +#define TYPE_POWER8_SPAPR_CPU_CORE "POWER8-spapr-cpu-core"include/hw/ppc/spapr_cpu_core.h typedef struct sPAPRCPUCore { · line 60
Quoted 10 lines
include/hw/ppc/spapr_cpu_core.h +10
-0+#define POWER8_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER8sPAPRCPUCore, (obj), TYPE_POWER8_SPAPR_CPU_CORE) + +typedef struct POWER8sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER8sPAPRCPUCore ;These are all identical so should also be macro constructed as well. I don't think there's actually any need for the structures to be exposed in a header file either, so you should be able to do it in the same macro that constructs the implementation.
Quoted 2 lines
Uh.. except if you move the ObjectClass* to the base class you won't even need these.
Quoted 7 lines
The only reason (currently) POWER8sPAPRCPUCore exists separately from the base class sPAPRCPUCore is that it represents POWER8 core which is stored as ObjectClass*.
Now if we don't track cpu type (ObjectClass *) as part of POWER8sPAPRCPUCore but push that up to sPAPRCPUCore, I am not sure if that would be at the right abstraction level.
Not as part of sPAPRCPUCore, but as part of sPAPRCPUCoreClass. We don't have a structure for the class at present, but we can add one. You can think of it as a method that sPAPRCPUCore and subclasses have which returns the correct ObjectClass *, except that we don't actually need a method (function pointer) - a simple data pointer in the class will suffice.
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
Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices
Quoting David Gibson (2016-04-03 19:13:54)
Quoted 246 lines · Bharata B Rao
Quoted 237 lines · David Gibson
Quoted 233 lines · Bharata B Rao
Quoted 78 lines
Introduce core devices for each CPU type supported by sPAPR. These core devices are derived from the base spapr-cpu-core device type.
TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctlySigned-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 3 +- hw/ppc/spapr_cpu_core.c | 118 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 36 ++++++++++++ 4 files changed, 156 insertions(+), 2 deletions(-)hw/ppc/spapr.c +1
-2@@ -1614,8 +1614,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;hw/ppc/spapr_cpu_core.c +41
-0@@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = { .instance_size = sizeof(sPAPRCPUCore), }; +#define DEFINE_SPAPR_CPU_CORE (_name) \ +static void \ +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads, \ + Error **errp) \ +{ \ + int i; \ + Error *local_err = NULL; \ + sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); \ + glue(_name, sPAPRCPUCore) * core = \ + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev)); \ + \ + for (i = 0; i < threads; i++) { \ + char id[32]; \ + \ + object_initialize(&sc->threads[i], sizeof(sc->threads[i]), \ + object_class_get_name(core->cpu)); \ + snprintf(id, sizeof(id), "thread[%d]", i); \ + object_property_add_child(OBJECT(core), id, OBJECT(&sc->threads[i]), \ + &local_err); \ + if (local_err) { \ + goto err; \ + } \ + } \ + return; \ + \ +err: \ + while (--i) { \ + object_unparent(OBJECT(&sc->threads[i])); \ + } \ + error_propagate(errp, local_err); \ +} \ + \ +static int \ +glue(_name, _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); \hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 75
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+if (*errp) { \ +return 1 ; \ + } \ + \ +spapr_cpu_init (spapr, cpu, errp); \ +if (*errp) { \ +return 1 ; \ + } \ +return 0 ; \ +} \If you put the ObjectClass * for the threads in the base abstract class's class structure, then you can move most of this logic to the abstract class as well and make the macro-ized stuff much smaller.
The
realize_childstuff doesn't even need the ObjectClass* in the base class to factor out.Quoted 38 lines
hw/ppc/spapr_cpu_core.c +38
-0+static void \ +glue (_name ,_spapr_cpu_core_realize )(DeviceState *dev,Error **errp) \ +{ \ +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev)); \ +CPUCore *cc =CPU_CORE (OBJECT (dev)); \ +Error *local_err =NULL ; \ + \ +/* \ +* TODO: This is CPU model specific CPU core's realize routine. \ +* However I am initializing "threads" field of the parent type \ +* sPAPRCPUCore here. Is this ok ? If not I will have make "threads" \ +* part of CPU model specific CPU core type and have different plug() \ +* handlers for each type instead of having a common plug() handler \ +* for all core types. \ +*/ \ + sc->threads =g_new0 (PowerPCCPU, cc->threads); \ +glue (_name, _spapr_cpu_core_create_threads)(dev, cc->threads, &local_err); \ +if (local_err) { \ + goto out; \ + } \ + \ +object_child_foreach (OBJECT (dev), \ +glue (_name, _spapr_cpu_core_realize_child), \ + &local_err); \ + \ +out: \ +if (local_err) { \ +g_free (sc->threads); \ +error_propagate (errp, local_err); \ + } \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_instance_init )(Object *obj) \ +{ \ +glue (_name, sPAPRCPUCore) * core =glue (_name, _SPAPR_CPU_CORE)(obj); \ + const char *type = stringify(_name) "-" TYPE_POWERPC_CPU; \ +ObjectClass *oc =object_class_by_name (type); \hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 124
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+ \ + core->cpu = oc; \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_class_init )(ObjectClass *oc,void *data) \ +{ \ + \ +DeviceClass *dc =DEVICE_CLASS (oc); \ + dc->realize =glue (_name, _spapr_cpu_core_realize); \I think the only callback you should need to construct in the macro is
class_initto initialize the ObjectClass* field.Quoted 68 lines
hw/ppc/spapr_cpu_core.c +18
-0+} \ + \ +static const TypeInfo glue (_name ,_spapr_cpu_core_type_info ) = \ +{ \ + .name = stringify(_name) "-" TYPE_SPAPR_CPU_CORE, \ + .parent =TYPE_SPAPR_CPU_CORE , \ + .instance_size =sizeof (glue (_name ,sPAPRCPUCore )), \ + .instance_init =glue (_name, _spapr_cpu_core_instance_init), \ + .class_init =glue (_name, _spapr_cpu_core_class_init), \ +}; + +DEFINE_SPAPR_CPU_CORE (host); +DEFINE_SPAPR_CPU_CORE (POWER7 ); +DEFINE_SPAPR_CPU_CORE (POWER8 ); +static void spapr_cpu_core_register_types (void ) {type_register_static (&spapr_cpu_core_type_info); +type_register_static (&host_spapr_cpu_core_type_info); +type_register_static (&POWER7_spapr_cpu_core_type_info); +type_register_static (&POWER8_spapr_cpu_core_type_info); }type_init (spapr_cpu_core_register_types)include/hw/ppc/spapr.h +1
-0@@ -585,6 +585,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 {include/hw/ppc/spapr_cpu_core.h +24
-0@@ -24,4 +24,40 @@ typedef struct sPAPRCPUCore {PowerPCCPU *threads; } sPAPRCPUCore; +#define TYPE_host_SPAPR_CPU_CORE "host-spapr-cpu-core" +#define host_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(hostsPAPRCPUCore, (obj), TYPE_host_SPAPR_CPU_CORE) + +typedef struct hostsPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}hostsPAPRCPUCore ; +#define TYPE_POWER7_SPAPR_CPU_CORE "POWER7-spapr-cpu-core" +#define POWER7_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER7sPAPRCPUCore, (obj), TYPE_POWER7_SPAPR_CPU_CORE) + +typedef struct POWER7sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER7sPAPRCPUCore ; + +#define TYPE_POWER8_SPAPR_CPU_CORE "POWER8-spapr-cpu-core"include/hw/ppc/spapr_cpu_core.h typedef struct sPAPRCPUCore { · line 60
Quoted 10 lines
include/hw/ppc/spapr_cpu_core.h +10
-0+#define POWER8_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER8sPAPRCPUCore, (obj), TYPE_POWER8_SPAPR_CPU_CORE) + +typedef struct POWER8sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER8sPAPRCPUCore ;These are all identical so should also be macro constructed as well. I don't think there's actually any need for the structures to be exposed in a header file either, so you should be able to do it in the same macro that constructs the implementation.
Quoted 2 lines
Uh.. except if you move the ObjectClass* to the base class you won't even need these.
Quoted 7 lines
The only reason (currently) POWER8sPAPRCPUCore exists separately from the base class sPAPRCPUCore is that it represents POWER8 core which is stored as ObjectClass*.
Now if we don't track cpu type (ObjectClass *) as part of POWER8sPAPRCPUCore but push that up to sPAPRCPUCore, I am not sure if that would be at the right abstraction level.
Quoted 6 lines
Not as part of sPAPRCPUCore, but as part of sPAPRCPUCoreClass. We don't have a structure for the class at present, but we can add one. You can think of it as a method that sPAPRCPUCore and subclasses have which returns the correct ObjectClass *, except that we don't actually need a method (function pointer) - a simple data pointer in the class will suffice.
Sorry, I'd missed this thread when I posted my other reply.
I agree it should be pushed up a level so we can drop most of the macro stuff. arm_cpu_register_types() seems to provide a fairly straightforward example of defining derivative types by modifying parent Object's state via their instance_init functions.
But it does seem unecessary in this case to do it for every instance, since that state (ObjectClass *cpu) will be common/immutable for all instances.
So I think both approaches are workable and acceptable, but doing it your way vs. what I suggested in my other reply does seem like the nicer way to handle it.
Quoted 6 lines
Signature · 5 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
Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices
In reply to Bharata B RaoQuoted 95 lines · Bharata B Rao
Introduce core devices for each CPU type supported by sPAPR. These core devices are derived from the base spapr-cpu-core device type.
TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctlySigned-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 3 +- hw/ppc/spapr_cpu_core.c | 118 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 36 ++++++++++++ 4 files changed, 156 insertions(+), 2 deletions(-)hw/ppc/spapr.c +1
-2@@ -1614,8 +1614,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;hw/ppc/spapr_cpu_core.c +58
-0@@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = { .instance_size = sizeof(sPAPRCPUCore), }; +#define DEFINE_SPAPR_CPU_CORE (_name) \ +static void \ +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads, \ + Error **errp) \ +{ \ + int i; \ + Error *local_err = NULL; \ + sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); \ + glue(_name, sPAPRCPUCore) * core = \ + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev)); \ + \ + for (i = 0; i < threads; i++) { \ + char id[32]; \ + \ + object_initialize(&sc->threads[i], sizeof(sc->threads[i]), \ + object_class_get_name(core->cpu)); \ + snprintf(id, sizeof(id), "thread[%d]", i); \ + object_property_add_child(OBJECT(core), id, OBJECT(&sc->threads[i]), \ + &local_err); \ + if (local_err) { \ + goto err; \ + } \ + } \ + return; \ + \ +err: \ + while (--i) { \ + object_unparent(OBJECT(&sc->threads[i])); \ + } \ + error_propagate(errp, local_err); \ +} \ + \ +static int \ +glue(_name, _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 \ +glue(_name, _spapr_cpu_core_realize)(DeviceState *dev, Error **errp) \ +{ \ + sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); \ + CPUCore *cc = CPU_CORE(OBJECT(dev)); \ + Error *local_err = NULL; \
hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 92
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +9
-0+ \ +/* \ +* TODO: This is CPU model specific CPU core's realize routine. \ +* However I am initializing "threads" field of the parent type \ +* sPAPRCPUCore here. Is this ok ? If not I will have make "threads" \ +* part of CPU model specific CPU core type and have different plug() \ +* handlers for each type instead of having a common plug() handler \ +* for all core types. \ +*/ \
I think that should be fine - it's generally ok for methods to manipulate superclass data fields (technically this is what C++ calls a "protected" as opposed to "private" field).
Quoted 114 lines
hw/ppc/spapr_cpu_core.c +51
-0+ sc->threads =g_new0 (PowerPCCPU, cc->threads); \ +glue (_name, _spapr_cpu_core_create_threads)(dev, cc->threads, &local_err); \ +if (local_err) { \ + goto out; \ + } \ + \ +object_child_foreach (OBJECT (dev), \ +glue (_name, _spapr_cpu_core_realize_child), \ + &local_err); \ + \ +out: \ +if (local_err) { \ +g_free (sc->threads); \ +error_propagate (errp, local_err); \ + } \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_instance_init )(Object *obj) \ +{ \ +glue (_name, sPAPRCPUCore) * core =glue (_name, _SPAPR_CPU_CORE)(obj); \ + const char *type = stringify(_name) "-" TYPE_POWERPC_CPU; \ +ObjectClass *oc = object_class_by_name(type); \ +\ +core->cpu = oc; \ +} \ +\ +static void \ +glue(_name, _spapr_cpu_core_class_init)(ObjectClass *oc, void *data) \ +{ \ +\ +DeviceClass *dc = DEVICE_CLASS(oc); \ +dc->realize = glue(_name, _spapr_cpu_core_realize); \ +} \ +\ +static const TypeInfo glue(_name, _spapr_cpu_core_type_info) = \ +{ \ +.name = stringify(_name) " -" TYPE_SPAPR_CPU_CORE, \ +.parent = TYPE_SPAPR_CPU_CORE, \ +.instance_size = sizeof(glue(_name, sPAPRCPUCore)), \ +.instance_init = glue(_name, _spapr_cpu_core_instance_init), \ +.class_init = glue(_name, _spapr_cpu_core_class_init), \ +}; + +DEFINE_SPAPR_CPU_CORE (host); +DEFINE_SPAPR_CPU_CORE (POWER7 ); +DEFINE_SPAPR_CPU_CORE (POWER8 ); +static void spapr_cpu_core_register_types (void ) {type_register_static (&spapr_cpu_core_type_info); +type_register_static (&host_spapr_cpu_core_type_info); +type_register_static (&POWER7_spapr_cpu_core_type_info); +type_register_static (&POWER8_spapr_cpu_core_type_info); }
type_init(spapr_cpu_core_register_types)include/hw/ppc/spapr.h +1
-0@@ -585,6 +585,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 {include/hw/ppc/spapr_cpu_core.h +36
-0@@ -24,4 +24,40 @@ typedef struct sPAPRCPUCore { PowerPCCPU *threads; } sPAPRCPUCore; +#define TYPE_host_SPAPR_CPU_CORE "host-spapr-cpu-core" +#define host_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(hostsPAPRCPUCore, (obj), TYPE_host_SPAPR_CPU_CORE) + +typedef struct hostsPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}hostsPAPRCPUCore ; + +#define TYPE_POWER7_SPAPR_CPU_CORE "POWER7-spapr-cpu-core" +#define POWER7_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER7sPAPRCPUCore, (obj), TYPE_POWER7_SPAPR_CPU_CORE) + +typedef struct POWER7sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER7sPAPRCPUCore ; + +#define TYPE_POWER8_SPAPR_CPU_CORE "POWER8-spapr-cpu-core" +#define POWER8_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER8sPAPRCPUCore, (obj), TYPE_POWER8_SPAPR_CPU_CORE) + +typedef struct POWER8sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER8sPAPRCPUCore ; +#endif
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
Re: [Qemu-devel] [RFC PATCH v2.1 08/12] spapr: Add CPU type specific core devices
In reply to Bharata B RaoQuoting Bharata B Rao (2016-03-31 03:39:17)
Quoted 94 lines
Introduce core devices for each CPU type supported by sPAPR. These core devices are derived from the base spapr-cpu-core device type.
TODO:
- Add core types for other remaining CPU types
- Handle CPU model alias correctlySigned-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 3 +- hw/ppc/spapr_cpu_core.c | 118 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 36 ++++++++++++ 4 files changed, 156 insertions(+), 2 deletions(-)hw/ppc/spapr.c +1
-2@@ -1614,8 +1614,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;hw/ppc/spapr_cpu_core.c +57
-0@@ -22,9 +22,127 @@ static const TypeInfo spapr_cpu_core_type_info = { .instance_size = sizeof(sPAPRCPUCore), }; +#define DEFINE_SPAPR_CPU_CORE (_name) \ +static void \ +glue(_name, _spapr_cpu_core_create_threads)(DeviceState *dev, int threads, \ + Error **errp) \ +{ \ + int i; \ + Error *local_err = NULL; \ + sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); \ + glue(_name, sPAPRCPUCore) * core = \ + glue(_name, _SPAPR_CPU_CORE)(OBJECT(dev)); \ + \ + for (i = 0; i < threads; i++) { \ + char id[32]; \ + \ + object_initialize(&sc->threads[i], sizeof(sc->threads[i]), \ + object_class_get_name(core->cpu)); \ + snprintf(id, sizeof(id), "thread[%d]", i); \ + object_property_add_child(OBJECT(core), id, OBJECT(&sc->threads[i]), \ + &local_err); \ + if (local_err) { \ + goto err; \ + } \ + } \ + return; \ + \ +err: \ + while (--i) { \ + object_unparent(OBJECT(&sc->threads[i])); \ + } \ + error_propagate(errp, local_err); \ +} \ + \ +static int \ +glue(_name, _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 \ +glue(_name, _spapr_cpu_core_realize)(DeviceState *dev, Error **errp) \ +{ \ + sPAPRCPUCore *sc = SPAPR_CPU_CORE(OBJECT(dev)); \ + CPUCore *cc = CPU_CORE(OBJECT(dev)); \
hw/ppc/spapr_cpu_core.c static const TypeInfo spapr_cpu_core_type_info = { · line 91
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+Error *local_err =NULL ; \ + \ +/* \ +* TODO: This is CPU model specific CPU core's realize routine. \ +* However I am initializing "threads" field of the parent type \ +* sPAPRCPUCore here. Is this ok ? If not I will have make "threads" \ +* part of CPU model specific CPU core type and have different plug() \ +* handlers for each type instead of having a common plug() handler \ +* for all core types. \ +*/ \
Not sure, but there seems to be precedence for descendants of CPUClass at least. e.g. arm_cpu_realizefn() modifies it's parent CPUState.
But do we even need a model-specific realize? It seems like once core->cpu is set via the model's instance_init, the same realize / create_threads functions can be shared by everyone thanks to object_class_get_name(). So maybe we could move ObjectClass *cpu up into sPAPRCPUCore, and use a common realize set via spapr_cpu_core_class_init?
If that's doable, we could drop all the macros, or at least limit them to basically just a model-specific instance_init that sets sPAPRCPUCore->cpu. You might not even need typedefs for the different models at that point, since instance_size == sizeof(sPAPRCPUCore) for everyone at that point. Currently, at least.
In fact, arm_cpu_register_types() seems to do something very similar for registering TypeInfos for tuples of (model name, init fn).
Quoted 117 lines
hw/ppc/spapr_cpu_core.c +51
-0+ sc->threads =g_new0 (PowerPCCPU, cc->threads); \ +glue (_name, _spapr_cpu_core_create_threads)(dev, cc->threads, &local_err); \ +if (local_err) { \ + goto out; \ + } \ + \ +object_child_foreach (OBJECT (dev), \ +glue (_name, _spapr_cpu_core_realize_child), \ + &local_err); \ + \ +out: \ +if (local_err) { \ +g_free (sc->threads); \ +error_propagate (errp, local_err); \ + } \ +} \ + \ +static void \ +glue (_name ,_spapr_cpu_core_instance_init )(Object *obj) \ +{ \ +glue (_name, sPAPRCPUCore) * core =glue (_name, _SPAPR_CPU_CORE)(obj); \ + const char *type = stringify(_name) "-" TYPE_POWERPC_CPU; \ +ObjectClass *oc = object_class_by_name(type); \ +\ +core->cpu = oc; \ +} \ +\ +static void \ +glue(_name, _spapr_cpu_core_class_init)(ObjectClass *oc, void *data) \ +{ \ +\ +DeviceClass *dc = DEVICE_CLASS(oc); \ +dc->realize = glue(_name, _spapr_cpu_core_realize); \ +} \ +\ +static const TypeInfo glue(_name, _spapr_cpu_core_type_info) = \ +{ \ +.name = stringify(_name) " -" TYPE_SPAPR_CPU_CORE, \ +.parent = TYPE_SPAPR_CPU_CORE, \ +.instance_size = sizeof(glue(_name, sPAPRCPUCore)), \ +.instance_init = glue(_name, _spapr_cpu_core_instance_init), \ +.class_init = glue(_name, _spapr_cpu_core_class_init), \ +}; + +DEFINE_SPAPR_CPU_CORE (host); +DEFINE_SPAPR_CPU_CORE (POWER7 ); +DEFINE_SPAPR_CPU_CORE (POWER8 ); +static void spapr_cpu_core_register_types (void ) {type_register_static (&spapr_cpu_core_type_info); +type_register_static (&host_spapr_cpu_core_type_info); +type_register_static (&POWER7_spapr_cpu_core_type_info); +type_register_static (&POWER8_spapr_cpu_core_type_info); }type_init (spapr_cpu_core_register_types)include/hw/ppc/spapr.h +1
-0@@ -585,6 +585,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 {include/hw/ppc/spapr_cpu_core.h +36
-0@@ -24,4 +24,40 @@ typedef struct sPAPRCPUCore { PowerPCCPU *threads; } sPAPRCPUCore; +#define TYPE_host_SPAPR_CPU_CORE "host-spapr-cpu-core" +#define host_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(hostsPAPRCPUCore, (obj), TYPE_host_SPAPR_CPU_CORE) + +typedef struct hostsPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}hostsPAPRCPUCore ; + +#define TYPE_POWER7_SPAPR_CPU_CORE "POWER7-spapr-cpu-core" +#define POWER7_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER7sPAPRCPUCore, (obj), TYPE_POWER7_SPAPR_CPU_CORE) + +typedef struct POWER7sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER7sPAPRCPUCore ; + +#define TYPE_POWER8_SPAPR_CPU_CORE "POWER8-spapr-cpu-core" +#define POWER8_SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(POWER8sPAPRCPUCore, (obj), TYPE_POWER8_SPAPR_CPU_CORE) + +typedef struct POWER8sPAPRCPUCore { +/*< private >*/ +sPAPRCPUCore parent_obj; + +/*< public >*/ +ObjectClass *cpu; +}POWER8sPAPRCPUCore ; +#endif Signature · 1 line
2.1.0
RFC PATCH 9/12 spapr: convert boot CPUs into CPU core devices
In reply to Bharata B RaoIntroduce 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.
--- hw/ppc/spapr.c | 73 +++++++++++++++++++++++++++++++++++------ hw/ppc/spapr_cpu_core.c | 45 +++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ include/hw/ppc/spapr_cpu_core.h | 3 ++ 4 files changed, 113 insertions(+), 10 deletions(-)
hw/ppc/spapr.c +63 -10
@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h>
@@ -1614,6 +1615,10 @@ static void spapr_boot_set(void *opaque, const char *boot_device, machine->boot_order =g_strdup (boot_device); } +/* +* TODO: Check if some of these can be moved to rtas_start_cpu() where +* a few other things required for hotplugged CPUs are being done. +*/ void spapr_cpu_init (sPAPRMachineState *spapr,PowerPCCPU *cpu,Error **errp) {CPUPPCState *env = &cpu->env;
@@ -1644,6 +1649,7 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)xics_cpu_setup (spapr->icp, cpu);qemu_register_reset (spapr_cpu_reset, cpu); +spapr_cpu_reset (cpu); }/*
@@ -1727,7 +1733,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 ();
@@ -1741,6 +1746,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_supported = true;
@@ -1787,8 +1808,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) {
@@ -1799,13 +1819,34 @@ 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) { + spapr->cores = g_new0(Object *, spapr_max_cores); + +for (i =0 ; i < spapr_max_cores; i++) { +int core_dt_id = i * smt; + +if (i < spapr_cores) { +char *type =spapr_get_cpu_core_type (machine->cpu_model); +Object *core =object_new (type); + +g_free (type); +object_property_set_int (core, smp_threads,"threads" , + &error_fatal); +object_property_set_int (core, core_dt_id,CPU_CORE_PROP_CORE , + &error_fatal); +object_property_set_bool (core, true,"realized" , &error_fatal); + } } -spapr_cpu_init (spapr, cpu, &error_fatal); + }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 ()) {
@@ -2257,10 +2298,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 ;
@@ -2299,11 +2349,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; }
@@ -2383,6 +2435,7 @@ static void spapr_machine_2_5_class_options(MachineClass *mc)spapr_machine_2_6_class_options (mc); smc->use_ohci_by_default = true; + smc->dr_cpu_enabled = false;SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_5 ); }
hw/ppc/spapr_cpu_core.c +45 -0
54 lines not on this page · raw message
include/hw/ppc/spapr.h +2 -0
@@ -36,6 +36,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 */ };
@@ -79,6 +80,7 @@ struct sPAPRMachineState {/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory; +Object **cores; };#define H_SUCCESS 0
include/hw/ppc/spapr_cpu_core.h +3 -0
@@ -60,4 +60,7 @@ typedef struct POWER8sPAPRCPUCore { ObjectClass *cpu; } POWER8sPAPRCPUCore; +void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp); +char *spapr_get_cpu_core_type (const char *model);#endif
Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v2.1 09/12] spapr: convert boot CPUs into CPU core devices
Quoted 10 lines · 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 ofkvmppc_smt_threads()call here.Signed-off-by Bharata B Rao <[email protected]>
Quoted 255 lines
--- hw/ppc/spapr.c | 73 +++++++++++++++++++++++++++++++++++------ hw/ppc/spapr_cpu_core.c | 45 +++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ include/hw/ppc/spapr_cpu_core.h | 3 ++ 4 files changed, 113 insertions(+), 10 deletions(-)hw/ppc/spapr.c +63
-10@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h> @@ -1614,6 +1615,10 @@ static void spapr_boot_set(void *opaque, const char *boot_device, machine->boot_order =g_strdup (boot_device); } +/* +* TODO: Check if some of these can be moved to rtas_start_cpu() where +* a few other things required for hotplugged CPUs are being done. +*/ void spapr_cpu_init (sPAPRMachineState *spapr,PowerPCCPU *cpu,Error **errp) {CPUPPCState *env = &cpu->env;@@ -1644,6 +1649,7 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)xics_cpu_setup (spapr->icp, cpu);qemu_register_reset (spapr_cpu_reset, cpu); +spapr_cpu_reset (cpu); }/* @@ -1727,7 +1733,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 ();@@ -1741,6 +1746,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_supported = true;@@ -1787,8 +1808,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) {@@ -1799,13 +1819,34 @@ 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) { + spapr->cores = g_new0(Object *, spapr_max_cores); + +for (i =0 ; i < spapr_max_cores; i++) { +int core_dt_id = i * smt; + +if (i < spapr_cores) { +char *type =spapr_get_cpu_core_type (machine->cpu_model); +Object *core =object_new (type); + +g_free (type); +object_property_set_int (core, smp_threads,"threads" , + &error_fatal); +object_property_set_int (core, core_dt_id,CPU_CORE_PROP_CORE , + &error_fatal); +object_property_set_bool (core, true,"realized" , &error_fatal); + } } -spapr_cpu_init (spapr, cpu, &error_fatal); + }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 ()) {@@ -2257,10 +2298,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 ;@@ -2299,11 +2349,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; }@@ -2383,6 +2435,7 @@ static void spapr_machine_2_5_class_options(MachineClass *mc)spapr_machine_2_6_class_options (mc); smc->use_ohci_by_default = true; + smc->dr_cpu_enabled = false;SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_5 ); }hw/ppc/spapr_cpu_core.c +45
-0@@ -15,6 +15,40 @@#include <sysemu/cpus.h> #include "target-ppc/kvm_ppc.h" +void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int spapr_max_cores = max_cpus / smp_threads; +int index; +int smt =kvmppc_smt_threads (); +Error *local_err =NULL ; +CPUCore *cc =CPU_CORE (dev); + +if (cc->threads != smp_threads) { +error_setg (&local_err,"threads must be %d" , smp_threads); + goto out; + } + +if (cc->core % smt) { +error_setg (&local_err,"invalid core id %d\n" , cc->core); + goto out; + } + + index = cc->core / smt; +if (index <0 || index >= spapr_max_cores) { +error_setg (&local_err,"core id %d out of range" , cc->core); + goto out; + } + +if (spapr->cores[index]) { +error_setg (&local_err,"core %d already populated" , cc->core); + } + +out: +error_propagate (errp, local_err); +} +static const TypeInfo spapr_cpu_core_type_info = { .name =TYPE_SPAPR_CPU_CORE , .parent =TYPE_CPU_CORE ,@@ -146,3 +180,14 @@ static void spapr_cpu_core_register_types(void) }type_init (spapr_cpu_core_register_types) + +/* +* TODO: Looks fragile :( +*/ +char *spapr_get_cpu_core_type(const char *model) +{ +char core_type[32 ]; + +snprintf (core_type,32 ,"%s-%s" , model,TYPE_SPAPR_CPU_CORE ); +return g_strdup (core_type); +}include/hw/ppc/spapr.h +2
-0@@ -36,6 +36,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 */ };@@ -79,6 +80,7 @@ struct sPAPRMachineState {/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory; +Object **cores; };#define H_SUCCESS 0include/hw/ppc/spapr_cpu_core.h +3
-0@@ -60,4 +60,7 @@ typedef struct POWER8sPAPRCPUCore { ObjectClass *cpu; } POWER8sPAPRCPUCore; +void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp); +char *spapr_get_cpu_core_type (const char *model);#endif
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
Re: [Qemu-devel] [RFC PATCH v2.1 09/12] spapr: convert boot CPUs into CPU core devices
In reply to Bharata B RaoQuoting Bharata B Rao (2016-03-31 03:39:18)
Quoted 96 lines
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 ofkvmppc_smt_threads()call here.Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 73 +++++++++++++++++++++++++++++++++++------ hw/ppc/spapr_cpu_core.c | 45 +++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ include/hw/ppc/spapr_cpu_core.h | 3 ++ 4 files changed, 113 insertions(+), 10 deletions(-)hw/ppc/spapr.c +23
-6@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h> @@ -1614,6 +1615,10 @@ static void spapr_boot_set(void *opaque, const char *boot_device, machine->boot_order =g_strdup (boot_device); } +/* +* TODO: Check if some of these can be moved to rtas_start_cpu() where +* a few other things required for hotplugged CPUs are being done. +*/ void spapr_cpu_init (sPAPRMachineState *spapr,PowerPCCPU *cpu,Error **errp) {CPUPPCState *env = &cpu->env;@@ -1644,6 +1649,7 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)xics_cpu_setup (spapr->icp, cpu);qemu_register_reset (spapr_cpu_reset, cpu); +spapr_cpu_reset (cpu); }/* @@ -1727,7 +1733,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 ();@@ -1741,6 +1746,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_supported = true;@@ -1787,8 +1808,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) {@@ -1799,13 +1819,34 @@ 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 ) {
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1829
Quoted 10 lines
hw/ppc/spapr.c +8
-2-error_report ("Unable to find PowerPC CPU definition" ); -exit (1 ); + +if (smc->dr_cpu_enabled) { + spapr->cores = g_new0(Object *, spapr_max_cores); + +for (i =0 ; i < spapr_max_cores; i++) { +int core_dt_id = i * smt; + +if (i < spapr_cores) {
Is there any reason to not just have the for() loop stop at spapr_cores? Maybe I missed something in the subsequent patches, but it seems like we never end up doing anything beyond i < spapr_cores.
Quoted 10 lines
hw/ppc/spapr.c +10
-0+char *type =spapr_get_cpu_core_type (machine->cpu_model); +Object *core =object_new (type); + +g_free (type); +object_property_set_int (core, smp_threads,"threads" , + &error_fatal); +object_property_set_int (core, core_dt_id,CPU_CORE_PROP_CORE , + &error_fatal); +object_property_set_bool (core, true,"realized" , &error_fatal); + }
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1848
Quoted 10 lines
hw/ppc/spapr.c +8
-1} -spapr_cpu_init (spapr, cpu, &error_fatal); + }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);
Is there anything that prevents us using core modeling in the non-DR case as well? Having management of invididual threads/spapr_cpu_init contained in within one place seems beneficial beyond hotplug. Is it because cores are currently limited to cpus == "threads" via pre_plug hook? Maybe it makes sense to loosen that restriction in the special case where DR isn't enabled?
Quoted 142 lines
hw/ppc/spapr.c +14
-1+ } }if (kvm_enabled ()) {@@ -2257,10 +2298,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 ;@@ -2299,11 +2349,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; }@@ -2383,6 +2435,7 @@ static void spapr_machine_2_5_class_options(MachineClass *mc)spapr_machine_2_6_class_options (mc); smc->use_ohci_by_default = true; + smc->dr_cpu_enabled = false;SET_MACHINE_COMPAT (mc,SPAPR_COMPAT_2_5 ); }hw/ppc/spapr_cpu_core.c +45
-0@@ -15,6 +15,40 @@#include <sysemu/cpus.h> #include "target-ppc/kvm_ppc.h" +void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +int spapr_max_cores = max_cpus / smp_threads; +int index; +int smt =kvmppc_smt_threads (); +Error *local_err =NULL ; +CPUCore *cc =CPU_CORE (dev); + +if (cc->threads != smp_threads) { +error_setg (&local_err,"threads must be %d" , smp_threads); + goto out; + } + +if (cc->core % smt) { +error_setg (&local_err,"invalid core id %d\n" , cc->core); + goto out; + } + + index = cc->core / smt; +if (index <0 || index >= spapr_max_cores) { +error_setg (&local_err,"core id %d out of range" , cc->core); + goto out; + } + +if (spapr->cores[index]) { +error_setg (&local_err,"core %d already populated" , cc->core); + } + +out: +error_propagate (errp, local_err); +} +static const TypeInfo spapr_cpu_core_type_info = { .name =TYPE_SPAPR_CPU_CORE , .parent =TYPE_CPU_CORE ,@@ -146,3 +180,14 @@ static void spapr_cpu_core_register_types(void) }type_init (spapr_cpu_core_register_types) + +/* +* TODO: Looks fragile :( +*/ +char *spapr_get_cpu_core_type(const char *model) +{ +char core_type[32 ]; + +snprintf (core_type,32 ,"%s-%s" , model,TYPE_SPAPR_CPU_CORE ); +return g_strdup (core_type); +}include/hw/ppc/spapr.h +2
-0@@ -36,6 +36,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 */ };@@ -79,6 +80,7 @@ struct sPAPRMachineState {/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory; +Object **cores; };#define H_SUCCESS 0include/hw/ppc/spapr_cpu_core.h +3
-0@@ -60,4 +60,7 @@ typedef struct POWER8sPAPRCPUCore { ObjectClass *cpu; } POWER8sPAPRCPUCore; +void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp); +char *spapr_get_cpu_core_type (const char *model);#endif Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v2.1 09/12] spapr: convert boot CPUs into CPU core devices
Quoted 103 lines · Michael Roth
Quoting Bharata B Rao (2016-03-31 03:39:18)
Quoted 102 lines
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 ofkvmppc_smt_threads()call here.Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 73 +++++++++++++++++++++++++++++++++++------ hw/ppc/spapr_cpu_core.c | 45 +++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ include/hw/ppc/spapr_cpu_core.h | 3 ++ 4 files changed, 113 insertions(+), 10 deletions(-)hw/ppc/spapr.c +27
-8@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h> @@ -1614,6 +1615,10 @@ static void spapr_boot_set(void *opaque, const char *boot_device, machine->boot_order =g_strdup (boot_device); } +/* +* TODO: Check if some of these can be moved to rtas_start_cpu() where +* a few other things required for hotplugged CPUs are being done. +*/ void spapr_cpu_init (sPAPRMachineState *spapr,PowerPCCPU *cpu,Error **errp) {CPUPPCState *env = &cpu->env;@@ -1644,6 +1649,7 @@ void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp)xics_cpu_setup (spapr->icp, cpu);qemu_register_reset (spapr_cpu_reset, cpu); +spapr_cpu_reset (cpu); }/* @@ -1727,7 +1733,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 ();@@ -1741,6 +1746,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_supported = true;@@ -1787,8 +1808,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) {@@ -1799,13 +1819,34 @@ 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) { + spapr->cores = g_new0(Object *, spapr_max_cores); +
Quoted 8 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1829
Quoted 4 lines
hw/ppc/spapr.c +4
-0+for (i =0 ; i < spapr_max_cores; i++) { +int core_dt_id = i * smt; + +if (i < spapr_cores) {Is there any reason to not just have the
for()loop stop atspapr_cores? Maybe I missed something in the subsequent patches, but it seems like we never end up doing anything beyond i <spapr_cores.
In the next patch, I create DR connectors for all spapr_max_cores but create only spapr_cores number of cores (boot time cores). Having said that I will have the for loop changed to spapr_cores in this patch and move to spapr_max_cores in the next patch.
Quoted 22 lines
Quoted 11 lines
hw/ppc/spapr.c +10
-0+char *type =spapr_get_cpu_core_type (machine->cpu_model); +Object *core =object_new (type); + +g_free (type); +object_property_set_int (core, smp_threads,"threads" , + &error_fatal); +object_property_set_int (core, core_dt_id,CPU_CORE_PROP_CORE , + &error_fatal); +object_property_set_bool (core, true,"realized" , &error_fatal); + }hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1848
Quoted 10 lines
hw/ppc/spapr.c +8
-1} -spapr_cpu_init (spapr, cpu, &error_fatal); + }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);
Quoted 6 lines
Is there anything that prevents us using core modeling in the non-DR case as well? Having management of invididual threads/spapr_cpu_init contained in within one place seems beneficial beyond hotplug. Is it because cores are currently limited to cpus == "threads" via
pre_plughook? Maybe it makes sense to loosen that restriction in the special case where DR isn't enabled?
CPU core devices are created only when CPU DR capability is present. To support migration of older guests that don't know about CPU core devices, I retain the CPU thread initialization code as above.
Regards,
Bharata.
RFC PATCH 10/12 spapr: CPU hotplug support
In reply to Bharata B RaoSet 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.
--- hw/ppc/spapr.c | 58 ++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 70 +++++++++++++++++++++++++++++++++++++++++ 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, 159 insertions(+)
hw/ppc/spapr.c +58 -0
@@ -603,6 +603,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 ) {
@@ -1622,6 +1642,8 @@ static void spapr_boot_set(void *opaque, const char *boot_device,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 );
@@ -1646,6 +1668,14 @@ 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);
@@ -1825,6 +1855,11 @@ static void ppc_spapr_init(MachineState *machine)for (i =0 ; i < spapr_max_cores; i++) {int core_dt_id = i * smt; +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);
@@ -2247,6 +2282,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) {
@@ -2287,6 +2343,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); } }
hw/ppc/spapr_cpu_core.c +70 -0
88 lines not on this page · raw message
hw/ppc/spapr_events.c +3 -0
@@ -437,6 +437,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
hw/ppc/spapr_rtas.c +24 -0
@@ -34,6 +34,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"
@@ -161,6 +162,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,
@@ -197,6 +219,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);
include/hw/ppc/spapr.h +2 -0
@@ -588,6 +588,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 {
include/hw/ppc/spapr_cpu_core.h +2 -0
@@ -63,4 +63,6 @@ typedef struct POWER8sPAPRCPUCore {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
Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v2.1 10/12] spapr: CPU hotplug support
Quoted 5 lines · 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 <[email protected]>
Quoted 17 lines
--- hw/ppc/spapr.c | 58 ++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 70 +++++++++++++++++++++++++++++++++++++++++ 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, 159 insertions(+)hw/ppc/spapr.c +0
-0@@ -603,6 +603,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)};
hw/ppc/spapr.c static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset, · line 615
Quoted 10 lines
hw/ppc/spapr.c +10
-0+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))); + }
It seems like now we have a concrete representation for cpu cores, we ought to be passing a cpu core instead of a thread state to the dt populate function. I guess that complicates backwards compat stuff for older machine types though.
Quoted 70 lines
hw/ppc/spapr.c +36
-0/* 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 ) {@@ -1622,6 +1642,8 @@ static void spapr_boot_set(void *opaque, const char *boot_device,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 );@@ -1646,6 +1668,14 @@ 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);@@ -1825,6 +1855,11 @@ static void ppc_spapr_init(MachineState *machine)for (i =0 ; i < spapr_max_cores; i++) {int core_dt_id = i * smt; +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);@@ -2247,6 +2282,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);
hw/ppc/spapr.c out: · line 2305
Quoted 10 lines
hw/ppc/spapr.c +10
-0+ 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; +} +
Ugh. I've really got to find time to clean up a bunch of the DT construction stuff in spapr. Not something in the scope of this patch, though.
Quoted 162 lines
hw/ppc/spapr.c +2
-0static void spapr_machine_device_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {@@ -2287,6 +2343,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); } }hw/ppc/spapr_cpu_core.c +70
-0@@ -18,6 +18,7 @@void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ());sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());int spapr_max_cores = max_cpus / smp_threads;int index;@@ -25,6 +26,11 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,Error *local_err =NULL ;CPUCore *cc =CPU_CORE (dev); +if (!smc->dr_cpu_enabled && dev->hotplugged) { +error_setg (&local_err,"CPU hotplug not supported for this machine" ); + goto out; + } +if (cc->threads != smp_threads) {error_setg (&local_err,"threads must be %d" , smp_threads); goto out;@@ -49,6 +55,70 @@ out:error_propagate (errp, local_err); } +void spapr_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +CPUCore *cc =CPU_CORE (dev); +CPUState *cs =CPU (&core->threads[0 ]); +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); + index = cc->core / 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); + dev->hotplugged = true; + } + + 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 ); + } +} +static const TypeInfo spapr_cpu_core_type_info = { .name =TYPE_SPAPR_CPU_CORE , .parent =TYPE_CPU_CORE ,hw/ppc/spapr_events.c +3
-0@@ -437,6 +437,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 hw/ppc/spapr_rtas.c +22
-0@@ -34,6 +34,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" @@ -161,6 +162,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,
hw/ppc/spapr_rtas.c static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, · line 223
Quoted 5 lines
hw/ppc/spapr_rtas.c +2
-0@@ -197,6 +219,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);
I'd kind of like to see these rtas_start_cpu() changes split out to a separate patch, but it's not worth respinning just for that.
Quoted 26 lines
hw/ppc/spapr_rtas.c +0
-0qemu_cpu_kick (cs);include/hw/ppc/spapr.h +2
-0@@ -588,6 +588,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 {include/hw/ppc/spapr_cpu_core.h +2
-0@@ -63,4 +63,6 @@ typedef struct POWER8sPAPRCPUCore {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
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
Re: [Qemu-devel] [RFC PATCH v2.1 10/12] spapr: CPU hotplug support
In reply to Bharata B RaoQuoting Bharata B Rao (2016-03-31 03:39:19)
Quoted 181 lines
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 <[email protected]>--- hw/ppc/spapr.c | 58 ++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 70 +++++++++++++++++++++++++++++++++++++++++ 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, 159 insertions(+)hw/ppc/spapr.c +58
-0@@ -603,6 +603,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 ) {@@ -1622,6 +1642,8 @@ static void spapr_boot_set(void *opaque, const char *boot_device,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 );@@ -1646,6 +1668,14 @@ 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);@@ -1825,6 +1855,11 @@ static void ppc_spapr_init(MachineState *machine)for (i =0 ; i < spapr_max_cores; i++) {int core_dt_id = i * smt; +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);@@ -2247,6 +2282,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) {@@ -2287,6 +2343,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); } }hw/ppc/spapr_cpu_core.c +34
-0@@ -18,6 +18,7 @@void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ());sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());int spapr_max_cores = max_cpus / smp_threads;int index;@@ -25,6 +26,11 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,Error *local_err =NULL ;CPUCore *cc =CPU_CORE (dev); +if (!smc->dr_cpu_enabled && dev->hotplugged) { +error_setg (&local_err,"CPU hotplug not supported for this machine" ); + goto out; + } +if (cc->threads != smp_threads) {error_setg (&local_err,"threads must be %d" , smp_threads); goto out;@@ -49,6 +55,70 @@ out:error_propagate (errp, local_err); } +void spapr_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +CPUCore *cc =CPU_CORE (dev); +CPUState *cs =CPU (&core->threads[0 ]); +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); + index = cc->core / 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 ; + }
hw/ppc/spapr_cpu_core.c out: · line 95
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +10
-0+ +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); + dev->hotplugged = true;
This doesn't seem necessary ^
Re: [Qemu-devel] [RFC PATCH v2.1 10/12] spapr: CPU hotplug support
Quoted 186 lines · Michael Roth
Quoting Bharata B Rao (2016-03-31 03:39:19)
Quoted 185 lines
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 <[email protected]>--- hw/ppc/spapr.c | 58 ++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 70 +++++++++++++++++++++++++++++++++++++++++ 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, 159 insertions(+)hw/ppc/spapr.c +58
-0@@ -603,6 +603,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 ) {@@ -1622,6 +1642,8 @@ static void spapr_boot_set(void *opaque, const char *boot_device,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 );@@ -1646,6 +1668,14 @@ 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);@@ -1825,6 +1855,11 @@ static void ppc_spapr_init(MachineState *machine)for (i =0 ; i < spapr_max_cores; i++) {int core_dt_id = i * smt; +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);@@ -2247,6 +2282,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) {@@ -2287,6 +2343,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); } }hw/ppc/spapr_cpu_core.c +38
-0@@ -18,6 +18,7 @@void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ());sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());int spapr_max_cores = max_cpus / smp_threads;int index;@@ -25,6 +26,11 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,Error *local_err =NULL ;CPUCore *cc =CPU_CORE (dev); +if (!smc->dr_cpu_enabled && dev->hotplugged) { +error_setg (&local_err,"CPU hotplug not supported for this machine" ); + goto out; + } +if (cc->threads != smp_threads) {error_setg (&local_err,"threads must be %d" , smp_threads); goto out;@@ -49,6 +55,70 @@ out:error_propagate (errp, local_err); } +void spapr_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +CPUCore *cc =CPU_CORE (dev); +CPUState *cs =CPU (&core->threads[0 ]); +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); + index = cc->core / 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); + +/*
Quoted 8 lines
hw/ppc/spapr_cpu_core.c out: · line 95
Quoted 6 lines
hw/ppc/spapr_cpu_core.c +6
-0+* 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); + dev->hotplugged = true;This doesn't seem necessary ^
Yes, this hunk refuses to die, I just ensured that it is removed finally.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v2.1 10/12] spapr: CPU hotplug support
In reply to Bharata B RaoQuoted 3 lines · On Thu, 31 Mar 2016 14:09:19 +0530 Bharata B Rao <[email protected]>…
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.
perhaps you could reuse:
[RFC,20/42] machine: add cpu-hotplug machine option
http://patchwork.ozlabs.org/patch/617516/
to enable cpu hotplug explicitly,
and by default machine would be hotplug less saving resources.
Quoted 127 lines
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 58 ++++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 70 +++++++++++++++++++++++++++++++++++++++++ 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, 159 insertions(+)hw/ppc/spapr.c +58
-0@@ -603,6 +603,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 ) {@@ -1622,6 +1642,8 @@ static void spapr_boot_set(void *opaque, const char *boot_device,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 );@@ -1646,6 +1668,14 @@ 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);@@ -1825,6 +1855,11 @@ static void ppc_spapr_init(MachineState *machine)for (i =0 ; i < spapr_max_cores; i++) {int core_dt_id = i * smt; +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);@@ -2247,6 +2282,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) {@@ -2287,6 +2343,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); } }hw/ppc/spapr_cpu_core.c +0
-0
hw/ppc/spapr_cpu_core.c line 22
Quoted 5 lines
hw/ppc/spapr_cpu_core.c +1
-0@@ -18,6 +18,7 @@void spapr_core_pre_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ());sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ());
looks like hotplug_dev is machine,
so why don't just cast it instead of qdev_get_machine().
the same applies to other plug handlers.
Quoted 172 lines
hw/ppc/spapr_cpu_core.c +69
-0int spapr_max_cores = max_cpus / smp_threads;int index;@@ -25,6 +26,11 @@ void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,Error *local_err =NULL ;CPUCore *cc =CPU_CORE (dev); +if (!smc->dr_cpu_enabled && dev->hotplugged) { +error_setg (&local_err,"CPU hotplug not supported for this machine" ); + goto out; + } +if (cc->threads != smp_threads) {error_setg (&local_err,"threads must be %d" , smp_threads); goto out;@@ -49,6 +55,70 @@ out:error_propagate (errp, local_err); } +void spapr_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +CPUCore *cc =CPU_CORE (dev); +CPUState *cs =CPU (&core->threads[0 ]); +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); + index = cc->core / 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); + dev->hotplugged = true; + } + + 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 ); + } +} +static const TypeInfo spapr_cpu_core_type_info = { .name =TYPE_SPAPR_CPU_CORE , .parent =TYPE_CPU_CORE ,hw/ppc/spapr_events.c +3
-0@@ -437,6 +437,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 hw/ppc/spapr_rtas.c +24
-0@@ -34,6 +34,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" @@ -161,6 +162,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,@@ -197,6 +219,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);include/hw/ppc/spapr.h +2
-0@@ -588,6 +588,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 {include/hw/ppc/spapr_cpu_core.h +2
-0@@ -63,4 +63,6 @@ typedef struct POWER8sPAPRCPUCore {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
Re: [Qemu-devel] [RFC PATCH v2.1 10/12] spapr: CPU hotplug support
Quoted 7 lines · Igor Mammedov
Quoted 3 lines · On Thu, 31 Mar 2016 14:09:19 +0530 Bharata B Rao <[email protected]>…
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.
Quoted 7 lines
perhaps you could reuse:
[RFC,20/42] machine: add cpu-hotplug machine option
http://patchwork.ozlabs.org/patch/617516/to enable cpu hotplug explicitly,
and by default machine would be hotplug less saving resources.
We explicitly enable hotplug for specific machine type versions by setting sPAPRMachineClass.dr_cpu_enabled. So we check it to ensure that there are no DR connector objects (the resources needed for hotplug) created for a machine that doesn't support CPU hotplug. Similar is the case for memory hotplug.
So you are suggesting that we switch from sAPPR specific check (sPAPRMachineClass.dr_cpu_enabled) to the above MachineState.cpu_hotplug ?
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v2.1 10/12] spapr: CPU hotplug support
Quoted 16 lines · On Fri, 6 May 2016 15:44:10 +0530 Bharata B Rao <[email protected]>…
Quoted 7 lines · Igor Mammedov
Quoted 3 lines · On Thu, 31 Mar 2016 14:09:19 +0530 Bharata B Rao <[email protected]>…
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.
Quoted 7 lines
perhaps you could reuse:
[RFC,20/42] machine: add cpu-hotplug machine option
http://patchwork.ozlabs.org/patch/617516/to enable cpu hotplug explicitly,
and by default machine would be hotplug less saving resources.
Quoted 8 lines
We explicitly enable hotplug for specific machine type versions by setting sPAPRMachineClass.dr_cpu_enabled. So we check it to ensure that there are no DR connector objects (the resources needed for hotplug) created for a machine that doesn't support CPU hotplug. Similar is the case for memory hotplug.
So you are suggesting that we switch from sAPPR specific check (sPAPRMachineClass.dr_cpu_enabled) to the above MachineState.cpu_hotplug ?
yep, i.e. make user explicitly say that he want cpu hotplug enabled. instead of allocating resources for it when user doesn't care about it.
It saves some memory/io ports for x86, not sure what it would save for sPAPR, but at least one doesn't have to guess if hotplug is needed by looking at smp_cpus & max_cpus.
Quoted 5 lines
Regards,
Bharata.
RFC PATCH 11/12 xics, xics_kvm: Handle CPU unplug correctly
In reply to Bharata B RaoXICS is setup for each CPU during initialization. Provide a routine to undo the same when CPU is unplugged. While here, move ss->cs management into xics from xics_kvm since there is nothing KVM specific in it. Also ensure xics reset doesn't set irq for CPUs that are already unplugged.
This allows reboot of a VM that has undergone CPU hotplug and unplug to work correctly.
--- hw/intc/xics.c | 14 ++++++++++++++ hw/intc/xics_kvm.c | 8 ++++---- include/hw/ppc/xics.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-)
hw/intc/xics.c +14 -0
@@ -45,6 +45,18 @@ static int get_cpu_index_by_dt_id(int cpu_dt_id)return -1 ; } +void xics_cpu_destroy (XICSState *icp,PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); +ICPState *ss = &icp->ss[cs->cpu_index]; + +assert (cs->cpu_index < icp->nr_servers); +assert (cs == ss->cs); + + ss->output =NULL ; + ss->cs =NULL ; +} +void xics_cpu_setup (XICSState *icp,PowerPCCPU *cpu) {CPUState *cs =CPU (cpu);
@@ -54,6 +66,8 @@ void xics_cpu_setup(XICSState *icp, PowerPCCPU *cpu)assert (cs->cpu_index < icp->nr_servers); + ss->cs = cs; +if (info->cpu_setup) { info->cpu_setup (icp, cpu); }
hw/intc/xics_kvm.c +4 -4
@@ -110,8 +110,10 @@ static void icp_kvm_reset(DeviceState *dev) icp->pending_priority =0xff ; icp->mfrr =0xff ; -/* Make all outputs are deasserted */ -qemu_set_irq (icp->output,0 ); +/* Make all outputs as deasserted only if the CPU thread is in use */ +if (icp->output) { +qemu_set_irq (icp->output,0 ); + }icp_set_kvm_state (icp,1 ); }
@@ -344,8 +346,6 @@ static void xics_kvm_cpu_setup(XICSState *icp, PowerPCCPU *cpu)if (icpkvm->kernel_xics_fd !=-1 ) {int ret; - ss->cs = cs; - ret =kvm_vcpu_enable_cap (cs,KVM_CAP_IRQ_XICS ,0 , icpkvm->kernel_xics_fd,kvm_arch_vcpu_id (cs));if (ret <0 ) {
include/hw/ppc/xics.h +1 -0
@@ -167,5 +167,6 @@ int xics_alloc_block(XICSState *icp, int src, int num, bool lsi, bool align,void xics_free (XICSState *icp,int irq,int num);void xics_cpu_setup (XICSState *icp,PowerPCCPU *cpu); +void xics_cpu_destroy (XICSState *icp,PowerPCCPU *cpu);#endif /* __XICS_H__ */
Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v2.1 11/12] xics, xics_kvm: Handle CPU unplug correctly
Quoting Bharata B Rao (2016-03-31 03:39:20)
Quoted 21 lines
XICS is setup for each CPU during initialization. Provide a routine to undo the same when CPU is unplugged. While here, move
ss->csmanagement into xics fromxics_kvmsince there is nothing KVM specific in it. Also ensure xics reset doesn't set irq for CPUs that are already unplugged.This allows reboot of a VM that has undergone CPU hotplug and unplug to work correctly.
Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>--- hw/intc/xics.c | 14 ++++++++++++++ hw/intc/xics_kvm.c | 8 ++++---- include/hw/ppc/xics.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-)hw/intc/xics.c +0
-0
hw/intc/xics.c static int get_cpu_index_by_dt_id(int cpu_dt_id) · line 52
Quoted 8 lines
hw/intc/xics.c +5
-0@@ -45,6 +45,18 @@ static int get_cpu_index_by_dt_id(int cpu_dt_id)return -1 ; } +void xics_cpu_destroy (XICSState *icp,PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); +ICPState *ss = &icp->ss[cs->cpu_index]; +
If the following assertion is false, I think you'd get an OOB before you reached it due to the assignment above.
Quoted 7 lines
hw/intc/xics.c +7
-0+assert (cs->cpu_index < icp->nr_servers); +assert (cs == ss->cs); + + ss->output =NULL ; + ss->cs =NULL ; +} +
Re: [Qemu-devel] [RFC PATCH v2.1 11/12] xics, xics_kvm: Handle CPU unplug correctly
Quoted 25 lines · Michael Roth
Quoting Bharata B Rao (2016-03-31 03:39:20)
Quoted 24 lines
XICS is setup for each CPU during initialization. Provide a routine to undo the same when CPU is unplugged. While here, move
ss->csmanagement into xics fromxics_kvmsince there is nothing KVM specific in it. Also ensure xics reset doesn't set irq for CPUs that are already unplugged.This allows reboot of a VM that has undergone CPU hotplug and unplug to work correctly.
Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>--- hw/intc/xics.c | 14 ++++++++++++++ hw/intc/xics_kvm.c | 8 ++++---- include/hw/ppc/xics.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-)hw/intc/xics.c +0
-0@@ -45,6 +45,18 @@ static int get_cpu_index_by_dt_id(int cpu_dt_id)return -1 ; }
Quoted 8 lines
hw/intc/xics.c static int get_cpu_index_by_dt_id(int cpu_dt_id) · line 52
Quoted 5 lines
hw/intc/xics.c +5
-0+void xics_cpu_destroy (XICSState *icp,PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); +ICPState *ss = &icp->ss[cs->cpu_index]; +If the following assertion is false, I think you'd get an OOB before you reached it due to the assignment above.
It should be ok. The assignment above will compute an out of bounds address, but it doesn't dereference it.
Quoted 8 lines
Quoted 7 lines
hw/intc/xics.c +7
-0+assert (cs->cpu_index < icp->nr_servers); +assert (cs == ss->cs); + + ss->output =NULL ; + ss->cs =NULL ; +} +
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
Re: [Qemu-devel] [RFC PATCH v2.1 11/12] xics, xics_kvm: Handle CPU unplug correctly
Quoting David Gibson (2016-04-05 19:43:46)
Quoted 35 lines · Michael Roth
Quoted 25 lines
Quoting Bharata B Rao (2016-03-31 03:39:20)
Quoted 24 lines
XICS is setup for each CPU during initialization. Provide a routine to undo the same when CPU is unplugged. While here, move
ss->csmanagement into xics fromxics_kvmsince there is nothing KVM specific in it. Also ensure xics reset doesn't set irq for CPUs that are already unplugged.This allows reboot of a VM that has undergone CPU hotplug and unplug to work correctly.
Signed-off-by Bharata B Rao <[email protected]>Reviewed-by David Gibson <[email protected]>--- hw/intc/xics.c | 14 ++++++++++++++ hw/intc/xics_kvm.c | 8 ++++---- include/hw/ppc/xics.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-)hw/intc/xics.c +0
-0@@ -45,6 +45,18 @@ static int get_cpu_index_by_dt_id(int cpu_dt_id)return -1 ; }Quoted 8 lines
hw/intc/xics.c static int get_cpu_index_by_dt_id(int cpu_dt_id) · line 52
Quoted 5 lines
hw/intc/xics.c +5
-0+void xics_cpu_destroy (XICSState *icp,PowerPCCPU *cpu) +{ +CPUState *cs =CPU (cpu); +ICPState *ss = &icp->ss[cs->cpu_index]; +If the following assertion is false, I think you'd get an OOB before you reached it due to the assignment above.
Quoted 2 lines
It should be ok. The assignment above will compute an out of bounds address, but it doesn't dereference it.
Ahh, right. I was thinking there was an actual access for some reason.
I might still prefer moving the assignment after the assert from a stylistic standpoint, in case other variables get introduced in the future that rely on *ss. Just a nit though.
Quoted 15 lines
Quoted 9 lines
Quoted 8 lines
hw/intc/xics.c +7
-0+assert (cs->cpu_index < icp->nr_servers); +assert (cs == ss->cs); + + ss->output =NULL ; + ss->cs =NULL ; +} +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
RFC PATCH 12/12 spapr: CPU hot unplug support
In reply to Bharata B RaoRemove 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.
--- hw/ppc/spapr.c | 16 ++++++++ hw/ppc/spapr_cpu_core.c | 86 +++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 11 ++++++ 4 files changed, 114 insertions(+)
hw/ppc/spapr.c +16 -0
@@ -2348,11 +2348,27 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, } } +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); +} +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); } }
hw/ppc/spapr_cpu_core.c +86 -0
92 lines not on this page · raw message
include/hw/ppc/spapr.h +1 -0
@@ -590,6 +590,7 @@ void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type,void spapr_cpu_init (sPAPRMachineState *spapr,PowerPCCPU *cpu,Error **errp);void *spapr_populate_hotplug_cpu_dt (CPUState *cs,int *fdt_offset,sPAPRMachineState *spapr); +void spapr_cpu_destroy (PowerPCCPU *cpu);/* rtas-configure-connector state */ struct sPAPRConfigureConnectorState {
include/hw/ppc/spapr_cpu_core.h +11 -0
@@ -65,4 +65,15 @@ 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); + +/* List to store unplugged CPU objects for cleanup during unplug */ +typedef struct sPAPRCPUUnplug { +Object *cpu; +QLIST_ENTRY (sPAPRCPUUnplug) node; +}sPAPRCPUUnplug ; + +QLIST_HEAD (sPAPRCPUUnplugList, sPAPRCPUUnplug); +#endif
Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v2.1 12/12] spapr: CPU hot unplug support
Quoted 51 lines · 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 <[email protected]>--- hw/ppc/spapr.c | 16 ++++++++ hw/ppc/spapr_cpu_core.c | 86 +++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 11 ++++++ 4 files changed, 114 insertions(+)hw/ppc/spapr.c +16
-0@@ -2348,11 +2348,27 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, } } +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); +} +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); } }hw/ppc/spapr_cpu_core.c +0
-0@@ -119,6 +119,92 @@ void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, }
hw/ppc/spapr_cpu_core.c void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 129
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +8
-0} +static void spapr_cpu_core_cleanup (struct sPAPRCPUUnplugList *unplug_list) +{ +sPAPRCPUUnplug *unplug, *next; +Object *cpu; + + QLIST_FOREACH_SAFE(unplug, unplug_list, node, next) { + cpu = unplug->cpu; +object_unparent (cpu);
Is there any danger in the fact that the cpu object is still in the QOM tree until unparented here? My usual expectation would be that you'd remove the object from the tree immediately, but defer the actual free. But I'm a bit unclear on how QOM removals are supposed to work.
Quoted 113 lines
hw/ppc/spapr_cpu_core.c +78
-0+QLIST_REMOVE (unplug, node); +g_free (unplug); + } +} + +static void spapr_add_cpu_to_unplug_list (Object *cpu, +struct sPAPRCPUUnplugList *unplug_list) +{ +sPAPRCPUUnplug *unplug =g_malloc (sizeof (*unplug)); + + unplug->cpu = cpu; +QLIST_INSERT_HEAD (unplug_list, unplug, node); +} + +static int spapr_cpu_release (Object *obj,void *opaque) +{ +DeviceState *dev =DEVICE (obj); +CPUState *cs =CPU (dev); +PowerPCCPU *cpu =POWERPC_CPU (cs); +struct sPAPRCPUUnplugList *unplug_list = opaque; + +spapr_cpu_destroy (cpu); +cpu_remove_sync (cs); + +/* +* We are still walking the core object's children list, and +* hence can't cleanup this CPU thread object just yet. Put +* it on a list for later removal. +*/ +spapr_add_cpu_to_unplug_list (obj, unplug_list); +return 0 ; +} + +static void spapr_core_release (DeviceState *dev) +{ +struct sPAPRCPUUnplugList unplug_list; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +CPUCore *cc =CPU_CORE (dev); +int smt =kvmppc_smt_threads (); + +QLIST_INIT (&unplug_list); +object_child_foreach (OBJECT (dev), spapr_cpu_release, &unplug_list); +spapr_cpu_core_cleanup (&unplug_list); + spapr->cores[cc->core / smt] =NULL ; + +g_free (core->threads); +} + +static void spapr_core_release_unparent (DeviceState *dev,void *opaque) +{ +spapr_core_release (dev); +object_unparent (OBJECT (dev)); +} + +void spapr_core_unplug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +PowerPCCPU *cpu = &core->threads[0 ]; +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_unparent,NULL , &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +spapr_hotplug_req_remove_by_index (drc); +} +static const TypeInfo spapr_cpu_core_type_info = { .name =TYPE_SPAPR_CPU_CORE , .parent =TYPE_CPU_CORE ,include/hw/ppc/spapr.h +1
-0@@ -590,6 +590,7 @@ void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type,void spapr_cpu_init (sPAPRMachineState *spapr,PowerPCCPU *cpu,Error **errp);void *spapr_populate_hotplug_cpu_dt (CPUState *cs,int *fdt_offset,sPAPRMachineState *spapr); +void spapr_cpu_destroy (PowerPCCPU *cpu);/* rtas-configure-connector state */ struct sPAPRConfigureConnectorState {include/hw/ppc/spapr_cpu_core.h +11
-0@@ -65,4 +65,15 @@ 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); + +/* List to store unplugged CPU objects for cleanup during unplug */ +typedef struct sPAPRCPUUnplug { +Object *cpu; +QLIST_ENTRY (sPAPRCPUUnplug) node; +}sPAPRCPUUnplug ; + +QLIST_HEAD (sPAPRCPUUnplugList, sPAPRCPUUnplug); +#endif
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
Re: [Qemu-devel] [RFC PATCH v2.1 12/12] spapr: CPU hot unplug support
Quoted 54 lines · David Gibson
Quoted 53 lines · 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 <[email protected]>--- hw/ppc/spapr.c | 16 ++++++++ hw/ppc/spapr_cpu_core.c | 86 +++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_cpu_core.h | 11 ++++++ 4 files changed, 114 insertions(+)hw/ppc/spapr.c +16
-0@@ -2348,11 +2348,27 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, } } +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); +} +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); } }hw/ppc/spapr_cpu_core.c +0
-0@@ -119,6 +119,92 @@ void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, } }
Quoted 14 lines
hw/ppc/spapr_cpu_core.c void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 129
Quoted 8 lines
hw/ppc/spapr_cpu_core.c +8
-0+static void spapr_cpu_core_cleanup (struct sPAPRCPUUnplugList *unplug_list) +{ +sPAPRCPUUnplug *unplug, *next; +Object *cpu; + + QLIST_FOREACH_SAFE(unplug, unplug_list, node, next) { + cpu = unplug->cpu; +object_unparent (cpu);Is there any danger in the fact that the cpu object is still in the QOM tree until unparented here? My usual expectation would be that you'd remove the object from the tree immediately, but defer the actual free. But I'm a bit unclear on how QOM removals are supposed to work.
As per my understanding, object_unparent() removes the object from its parent and finalizes the child too.
The reason I defer unparenting of each CPU thread object like this is because from the parent core object's detach_cb routine (spapr_core_release), we are still walking the parent core's child list and can't immediately unparent the child thread objects.
Regards,
Bharata.
Quoted 15 lines · On Thu, 31 Mar 2016 14:09:09 +0530 Bharata B Rao <[email protected]>…
Hi,
This is v2.1 of "Core based CPU hotplug for PowerPC sPAPR". v2 was posted here:
https://lists.gnu.org/archive/html/qemu-ppc/2016-03/msg00201.htmlI am making this v2.1 instead of v3 as this introduces a change in
device_addsemantics and if we don't want to continue this, I will go back to the previous v2 semantics from v3 onwards. v2 had spapr-cpu-core device that served as CPU core device for all types of PowerPCCPU threads. In this version however, spapr-cpu-core becomes an abstract device and we will have different core devices for each of the PowerPCCPU type. So in this version, the hotplug semantics looks like this:
Quoted 8 lines
(qemu)
device_addPOWER8-spapr-cpu-core,id=core2,core=16[,threads=4]
cpu_modelspecification is gone as it becomes redundant with different core types for each CPU type. CPU core types are defined only for host, POWER7 and POWER8 models only (and not for their variants/aliases) yet.I have mostly taken care of all the review comments that I got for v2.
Could you rebase on top of current master, pls?
and fix compile error:hw/cpu/core.c: In function ‘core_prop_set_core’:hw/cpu/core.c:31:9: error: implicit declaration of function ‘error_propagate’ [-Werror=implicit-function-declaration]
error_propagate(errp, local_err);
Quoted 53 lines
Major changes in this version (v2.1)
------------------------------------
- Semantics change: spapr-cpu-core to POWER8-spapr-cpu-core and likewise
- Included Igor'spre_plugpatch.Bharata B Rao (10):
exec: Remove cpu from cpus list duringcpu_exec_exit()
exec: Do vmstate unregistration fromcpu_exec_exit()
cpu: Add a sync version ofcpu_remove()
cpu: Abstract CPU core type
spapr: Abstract CPU core device
spapr: Add CPU type specific core devices
spapr: convert boot CPUs into CPU core devices
spapr: CPU hotplug support
xics,xics_kvm: Handle CPU unplug correctly
spapr: CPU hot unplug supportGu Zheng (1):
cpu: Reclaim vCPU objectsIgor Mammedov (1):
qdev: hotplug: IntroduceHotplugHandler.pre_plug()callbackcpus.c | 51 +++++- exec.c | 41 ++++- hw/core/hotplug.c | 11 ++ hw/core/qdev.c | 9 +- hw/cpu/Makefile.objs | 1 + hw/cpu/core.c | 87 ++++++++++ hw/intc/xics.c | 14 ++ hw/intc/xics_kvm.c | 8 +- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr.c | 150 +++++++++++++++-- hw/ppc/spapr_cpu_core.c | 349 ++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 3 + hw/ppc/spapr_rtas.c | 24 +++ include/hw/cpu/core.h | 31 ++++ include/hw/hotplug.h | 14 +- include/hw/ppc/spapr.h | 6 + include/hw/ppc/spapr_cpu_core.h | 79 +++++++++ include/hw/ppc/xics.h | 1 + include/qom/cpu.h | 18 +++ include/sysemu/kvm.h | 1 + kvm-all.c | 57 ++++++- kvm-stub.c | 5 + 22 files changed, 932 insertions(+), 29 deletions(-) create mode 100644 hw/cpu/core.c create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/cpu/core.h create mode 100644 include/hw/ppc/spapr_cpu_core.h
Quoted 20 lines · Igor Mammedov
Quoted 17 lines · On Thu, 31 Mar 2016 14:09:09 +0530 Bharata B Rao <[email protected]>…
Hi,
This is v2.1 of "Core based CPU hotplug for PowerPC sPAPR". v2 was posted here:
https://lists.gnu.org/archive/html/qemu-ppc/2016-03/msg00201.htmlI am making this v2.1 instead of v3 as this introduces a change in
device_addsemantics and if we don't want to continue this, I will go back to the previous v2 semantics from v3 onwards. v2 had spapr-cpu-core device that served as CPU core device for all types of PowerPCCPU threads. In this version however, spapr-cpu-core becomes an abstract device and we will have different core devices for each of the PowerPCCPU type. So in this version, the hotplug semantics looks like this:(qemu)
device_addPOWER8-spapr-cpu-core,id=core2,core=16[,threads=4]
Quoted 7 lines
Quoted 6 lines
cpu_modelspecification is gone as it becomes redundant with different core types for each CPU type. CPU core types are defined only for host, POWER7 and POWER8 models only (and not for their variants/aliases) yet.I have mostly taken care of all the review comments that I got for v2.
Could you rebase on top of current master, pls?
Sure, I usually update, but missed it this time.
Quoted 5 lines
and fix compile error:
hw/cpu/core.c: In function ‘core_prop_set_core’:hw/cpu/core.c:31:9: error: implicit declaration of function ‘error_propagate’ [-Werror=implicit-function-declaration]error_propagate(errp, local_err);
I don't see this when compiling all the targets either on x86 or PPC systems. May be this is seen with latest master, in any case will check this out when spinning next version.
However do you have any specific comment to be addressed from this version before I post the next one ?
Regards,
Bharata.
Quoted 40 lines · On Tue, 5 Apr 2016 20:25:57 +0530 Bharata B Rao <[email protected]>…
Quoted 21 lines · Igor Mammedov
Quoted 18 lines · On Thu, 31 Mar 2016 14:09:09 +0530 Bharata B Rao <[email protected]>…
Hi,
This is v2.1 of "Core based CPU hotplug for PowerPC sPAPR". v2 was posted here:
https://lists.gnu.org/archive/html/qemu-ppc/2016-03/msg00201.htmlI am making this v2.1 instead of v3 as this introduces a change in
device_addsemantics and if we don't want to continue this, I will go back to the previous v2 semantics from v3 onwards. v2 had spapr-cpu-core device that served as CPU core device for all types of PowerPCCPU threads. In this version however, spapr-cpu-core becomes an abstract device and we will have different core devices for each of the PowerPCCPU type. So in this version, the hotplug semantics looks like this:(qemu)
device_addPOWER8-spapr-cpu-core,id=core2,core=16[,threads=4]Quoted 8 lines
Quoted 7 lines
cpu_modelspecification is gone as it becomes redundant with different core types for each CPU type. CPU core types are defined only for host, POWER7 and POWER8 models only (and not for their variants/aliases) yet.I have mostly taken care of all the review comments that I got for v2.
Could you rebase on top of current master, pls?
Sure, I usually update, but missed it this time.
Quoted 6 lines
and fix compile error:
hw/cpu/core.c: In function ‘core_prop_set_core’:hw/cpu/core.c:31:9: error: implicit declaration of function ‘error_propagate’ [-Werror=implicit-function-declaration]error_propagate(errp, local_err);
Quoted 6 lines
I don't see this when compiling all the targets either on x86 or PPC systems. May be this is seen with latest master, in any case will check this out when spinning next version.
However do you have any specific comment to be addressed from this version before I post the next one ?
Sorry, I haven't had a spare time to review it yet.
But device_add example looks good and similar what x86 will do, which is good from libvirt point of view as it would be able to implement hotplug in a uniform way for both targets.
Quoted 4 lines
Regards,
Bharata.
Quoted 40 lines · On Tue, 5 Apr 2016 20:25:57 +0530 Bharata B Rao <[email protected]>…
Quoted 21 lines · Igor Mammedov
Quoted 18 lines · On Thu, 31 Mar 2016 14:09:09 +0530 Bharata B Rao <[email protected]>…
Hi,
This is v2.1 of "Core based CPU hotplug for PowerPC sPAPR". v2 was posted here:
https://lists.gnu.org/archive/html/qemu-ppc/2016-03/msg00201.htmlI am making this v2.1 instead of v3 as this introduces a change in
device_addsemantics and if we don't want to continue this, I will go back to the previous v2 semantics from v3 onwards. v2 had spapr-cpu-core device that served as CPU core device for all types of PowerPCCPU threads. In this version however, spapr-cpu-core becomes an abstract device and we will have different core devices for each of the PowerPCCPU type. So in this version, the hotplug semantics looks like this:(qemu)
device_addPOWER8-spapr-cpu-core,id=core2,core=16[,threads=4]Quoted 8 lines
Quoted 7 lines
cpu_modelspecification is gone as it becomes redundant with different core types for each CPU type. CPU core types are defined only for host, POWER7 and POWER8 models only (and not for their variants/aliases) yet.I have mostly taken care of all the review comments that I got for v2.
Could you rebase on top of current master, pls?
Sure, I usually update, but missed it this time.
Quoted 6 lines
and fix compile error:
hw/cpu/core.c: In function ‘core_prop_set_core’:hw/cpu/core.c:31:9: error: implicit declaration of function ‘error_propagate’ [-Werror=implicit-function-declaration]error_propagate(errp, local_err);
Quoted 3 lines
I don't see this when compiling all the targets either on x86 or PPC systems. May be this is seen with latest master, in any case will check this out when spinning next version.
Series also breaks 'make check'
gdb ./ppc64-softmmu/qemu-system-ppc64
Program received signal SIGSEGV, Segmentation fault. object_class_get_name (klass=0x0) at qom/object.c:748
748 return klass->type->name;
(gdb) bt
#0 object_class_get_name (klass=0x0) at qom/object.c:748
#1 0x0000555555795aff in POWER7_spapr_cpu_core_create_threads (errp=0x7fffffffdc00, threads=0x1, dev=0x5555565bf930) at /home/imammedo/builds/qemu/hw/ppc/spapr_cpu_core.c:328
#2 POWER7_spapr_cpu_core_realize (dev=0x5555565bf930, errp=0x7fffffffdc80) at /home/imammedo/builds/qemu/hw/ppc/spapr_cpu_core.c:328
#3 0x00005555558af84c in device_set_realized (obj=0x5555565bf930, value=<optimized out>, errp=0x55555649fbd0 <error_fatal>) at hw/core/qdev.c:1074
#4 0x00005555559b542e in property_set_bool (obj=0x5555565bf930, v=<optimized out>, name=<optimized out>, opaque=0x5555565bfb20, errp=0x55555649fbd0 <error_fatal>)
at qom/object.c:1853
#5 0x00005555559b92b7 in object_property_set_qobject (obj=obj@entry=0x5555565bf930, value=value@entry=0x5555565bedd0, name=name@entry=0x555555ad403e "realized",
errp=errp@entry=0x55555649fbd0 <error_fatal>) at qom/qom-qobject.c:26
#6 0x00005555559b7130 in object_property_set_bool (obj=0x5555565bf930, value=<optimized out>, name=0x555555ad403e "realized", errp=0x55555649fbd0 <error_fatal>)
at qom/object.c:1150#7 0x0000555555786fc1 in ppc_spapr_init (machine=0x55555659fe50) at /home/imammedo/builds/qemu/hw/ppc/spapr.c:1859 #8 0x00005555556e54af in main (argc=<optimized out>, argv=<optimized
out>, envp=<optimized out>) at vl.c:4513