Core based CPU hotplug for PowerPC sPAPR
cover Core based CPU hotplug for PowerPC sPAPR
Hi,
This is an attempt to implement CPU hotplug for PowerPC sPAPR based on the approach suggested by Andreas. While I say that, I should also explicitly add that I have tried to follow Andreas' suggestions to the best of my understanding and hence there could be bits which are still not as per expectations.
I have tried to model this similarly to what Andreas did for x86 an year back at
https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg04858.html
- Base type to represent CPU core
static const TypeInfo cpu_core_type_info = {
.name = TYPE_CPU_CORE,
.parent = TYPE_DEVICE,
.abstract = true,
};
This is similar to the abstract socket device type that Andreas created
- sPAPR specific CPU core device
static const TypeInfo spapr_cpu_core_type_info = {
.name = TYPE_SPAPR_CPU_CORE,
.parent = TYPE_CPU_CORE, .instance_init = spapr_cpu_core_instance_init, .instance_size = sizeof(sPAPRCPUCore), .class_init = spapr_cpu_core_class_init,
};
This is similar to TYPE_X86_CPU_SOCKET that Andreas created to represent the x86 specifc CPU socket.
- QOM links from machine object to CPU objects
Target machine determines the hotplug granularity. Granularity is "core" for PowerPC.
MacineClass:init() would create as many "core" links as necessary to span the max_cpus. The links are set for all the boot CPU cores from machine init. For rest of the cores, the links are left dangling and will be set during hotplug.
The link essentially indicates or represents the CPU slots present on the board. The link name is used to identify the slot. In case of PowerPC, standard link names like core[0], core[1] etc will be used. Archs that work at socket granularity could use link names like socket[0] etc.
sPAPR core device will have a property called "slot" which will be used to determine to which slot the core will get plugged into. Users are expected to use existing link names like core[0] etc as the values for slot property of the core device. Command to hotplug will look like this:
(qemu) device_add spapr_cpu_core,id=core2,slot=core[2]
- Creation of thread objects from core.
It is ideal to create the thread objects from core object's instance_init. However thread object creation needs two inputs: number of threads and cpu_model. If we want to stick to the global values for these (smp_threads and MachineState.cpu_model), then we already know how many threads of what type to create in core's instance_init.
However, if we want to be flexible and support heterogenous configuration in future, nr_threads and cpu_model can be made properties of core device and the CPU threads can be created from core object's property setters. While this implementation defines these two properties to obtain nr_threads and cpu_model, heterogenous configurations aren't allowed.
sPAPR core device looks like this:
typedef struct sPAPRCPUCore {
/*< private >*/
DeviceState parent_obj;
/*< public >*/
int nr_threads;
char *cpu_model;
char *slot;
PowerPCCPU *threads;
} sPAPRCPUCore;@nr_threads, @cpu_model and @slot get set as properties during device_add of spapr_cpu_core device.
(qemu) device_add spapr_cpu_core,id=core2,nr_threads=8,cpu_model=host,slot=core[2]
This will result in a core with 8 threads of cpu_model "host" getting created and the resulting core will populate the pre-existing slot "core[2].
@threads will be g_malloc'ed to contain @nr_threads from property setter.
@cpu_model along with the base CPU type of powerpc64-cpu will be used to create the actual PowerPCCPU threads. So we will have CPU types like host-powerpc64-cpu or POWER8-powerpc64-cpu etc.
- QMP interface
The layout that I have in this implementation is more or less what Igor has implemented/suggested.
MachineClass:cpu_slots() will be main interface to collect CPU slot information. Target machine can implement them to provide information about slots. What sits in the slot (core, socket or thread) is determined by the machine.
{ 'struct': 'CPUInfo',
'data': { 'arch-id': 'int',
'type': 'str',
'*thread': 'int',
'*core': 'int',
'*socket' : 'int',
'*node' : 'int',
'*qom-path': 'str'
}
}{ 'struct': 'CPUSlotInfo',
'data': { '*id': 'str',
'type': 'str',
'hotplug-granularity' : 'str',
'slot-id' : 'str',
'*qom-path': 'str',
'realized': 'bool',
'*nr-cpus': 'int',
'*cpus' : ['CPUInfo']
}
}The slot links that we created from machine object will serve as the starting point to get the information about available CPU slots and their occupancy status. We can walk the link properties of the machine object, and extract information about "core" links for PowerPC.
Each CPU slot will provide the following information:
Slot name/ID: core[0] etc for PowerPChotplug_granularity: "core" for PowerPC (Probably not required)
type: "spapr-cpu-core" for sPAPR
realized: true/false indicating if the slot is populated or not
I feel, the above information should be enough for the management to come up with an appropriate device_add command to create and fill a core into an empty slot.
If the slot is populated, the following additional information is provided:
qom_path: QOM path of the core (PowerPC) devicenr_cpus: Number of CPUs that are part of this slot
Each CPU will then have: Type, Arch ID, Thread ID, Core ID, Socket ID,
NUMA node.
This patchset is present at:
https://github.com/bharata/qemu/commits/spapr-cpu-core
Bharata B Rao (6):
cpu: Abstract CPU core type
spapr: CPU core device
spapr: Represent boot CPUs as spapr-cpu-core devices
spapr: CPU hotplug support
qmp,spapr: Show hot-plugged/pluggable CPU slots in the Machine
hmp: Implement 'info cpu-slots'
hmp-commands-info.hx | 14 ++ hmp.c | 56 ++++++++ hmp.h | 1 + hw/core/machine.c | 19 +++ hw/cpu/Makefile.objs | 1 + hw/cpu/core.c | 22 +++ hw/ppc/Makefile.objs | 1 + hw/ppc/spapr.c | 311 ++++++++++++++++++++++++++++++++++++++-- hw/ppc/spapr_cpu_core.c | 210 +++++++++++++++++++++++++++ hw/ppc/spapr_events.c | 3 + hw/ppc/spapr_rtas.c | 24 ++++ include/hw/boards.h | 4 + include/hw/cpu/core.h | 17 +++ include/hw/ppc/spapr.h | 4 + include/hw/ppc/spapr_cpu_core.h | 32 +++++ qapi-schema.json | 85 +++++++++++ qmp-commands.hx | 47 ++++++ 17 files changed, 843 insertions(+), 8 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/6 cpu: Abstract CPU core type
Add 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 | 22 ++++++++++++++++++++++ include/hw/cpu/core.h | 17 +++++++++++++++++ 3 files changed, 40 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 +22 -0
@@ -0,0 +1,22 @@ +/* +* 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. +*/ +#include "hw/cpu/core.h" + +static const TypeInfo cpu_core_type_info = { + .name =TYPE_CPU_CORE , + .parent =TYPE_DEVICE , + .abstract = true, +}; + +static void cpu_core_register_types (void ) +{ +type_register_static (&cpu_core_type_info); +} + +type_init (cpu_core_register_types)
include/hw/cpu/core.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* 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" + +#endif
Signature · 1 line
2.1.0
RFC PATCH 2/6 spapr: CPU core device
In reply to Bharata B RaoAdd sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 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 +210 -0
210 lines not on this page · raw message
include/hw/ppc/spapr_cpu_core.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* 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 >*/ +DeviceState parent_obj; + +/*< public >*/ +int nr_threads; +char *cpu_model; +char *slot; +PowerPCCPU *threads; +}sPAPRCPUCore ; + +#define SPAPR_CPU_CORE_SLOT_PROP "slot" + +#endif
Signature · 1 line
2.1.0
RFC PATCH 3/6 spapr: Represent boot CPUs as spapr-cpu-core devices
In reply to Bharata B RaoInitialize boot CPUs as spapr-cpu-core devices and create links from machine object to these core devices. These links can be considered as CPU slots in which core devices will get hot-plugged. spapr-cpu-core device's slot property indicates the slot where it is plugged. Information about all the CPU slots can be obtained by walking these links.
--- hw/ppc/spapr.c | 65 +++++++++++++++++++++++++++++++++++++++++++------- include/hw/ppc/spapr.h | 3 +++ 2 files changed, 60 insertions(+), 8 deletions(-)
hw/ppc/spapr.c +57 -8
@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h>
@@ -1720,6 +1721,21 @@ static void spapr_validate_node_memory(MachineState *machine, Error **errp) } } +/* +* Check to see if core is being hot-plugged into an already populated slot. +*/ +static void spapr_cpu_core_allow_set_link (Object *obj,const char *name, +Object *val,Error **errp) +{ +Object *core =object_property_get_link (qdev_get_machine (), name,NULL ); + +if (core) { +char *path =object_get_canonical_path (core); +error_setg (errp,"Slot %s already populated with %s" , name, path); +g_free (path); + } +} +/* pSeries LPAR / sPAPR hardware init */ static void ppc_spapr_init (MachineState *machine) {
@@ -1728,7 +1744,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 ();
@@ -1742,6 +1757,8 @@ static void ppc_spapr_init(MachineState *machine)long load_limit, fw_size;bool kernel_le = false;char *filename; +int spapr_cores = smp_cpus / smp_threads; +int spapr_max_cores = max_cpus / smp_threads; msi_supported = true;
@@ -1800,13 +1817,38 @@ 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 ); + + spapr->cores =g_malloc0 (spapr_max_cores *sizeof (Object)); + +for (i =0 ; i < spapr_max_cores; i++) { +Object *spapr_cpu_core =object_new (TYPE_SPAPR_CPU_CORE ); +char name[32 ]; + +object_property_set_str (spapr_cpu_core, machine->cpu_model,"cpu_model" , + &error_fatal); +object_property_set_int (spapr_cpu_core, smp_threads,"nr_threads" , + &error_fatal); +/* +* Create links from machine objects to all possible cores. +*/ +snprintf (name,sizeof (name),"%s[%d]" ,SPAPR_MACHINE_CPU_CORE_PROP , i); +object_property_add_link (OBJECT (spapr), name,TYPE_SPAPR_CPU_CORE , + (Object **)&spapr->cores[i], + spapr_cpu_core_allow_set_link,0 , + &error_fatal); + +/* +* Set the link from machine object to core object for all +* boot time CPUs specified with -smp and realize them. +* For rest of the hotpluggable cores this is happens from +* the core hotplug/realization path. +*/ +if (i < spapr_cores) { +object_property_set_str (spapr_cpu_core, name, +SPAPR_CPU_CORE_SLOT_PROP , &error_fatal); +object_property_set_bool (spapr_cpu_core, true,"realized" , + &error_fatal); } -spapr_cpu_init (spapr, cpu, &error_fatal); }if (kvm_enabled ()) {
@@ -2209,6 +2251,7 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (hotplug_dev);if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {int node;
@@ -2245,6 +2288,11 @@ 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_CPU )) { +CPUState *cs =CPU (dev); +PowerPCCPU *cpu =POWERPC_CPU (cs); + +spapr_cpu_init (ms, cpu, errp); } }
@@ -2259,7 +2307,8 @@ static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev,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_CPU )) {return HOTPLUG_HANDLER (machine); }return NULL ;
include/hw/ppc/spapr.h +3 -0
@@ -79,8 +79,11 @@ struct sPAPRMachineState {/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory; +Object *cores; }; +#define SPAPR_MACHINE_CPU_CORE_PROP "core" +#define H_SUCCESS 0#define H_BUSY 1/* Hardware busy -- retry later */ #define H_CLOSED 2/* Resource closed */
Signature · 1 line
2.1.0
RFC PATCH 4/6 spapr: CPU hotplug support
In reply to Bharata B RaoSet up device tree entries for the hotplugged CPU core and use the exising EPOW event infrastructure to send CPU hotplug notification to the guest.
--- hw/ppc/spapr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_events.c | 3 ++ hw/ppc/spapr_rtas.c | 24 +++++++++ include/hw/ppc/spapr.h | 1 + 4 files changed, 163 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +135 -1
@@ -603,6 +603,18 @@ 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)}; +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRDRConnector *drc; +sPAPRDRConnectorClass *drck; +int drc_index; + +if (smc->dr_cpu_enabled) { + drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_CPU , index); +g_assert (drc); + drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + drc_index = drck->get_index (drc); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,my-drc-index" , drc_index))); + }/* 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 +999,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 ) { +fprintf (stderr,"Couldn't set up CPU DR device tree properties\n" ); +exit (1 ); + } + } +_FDT ((fdt_pack (fdt)));if (fdt_totalsize (fdt) >FDT_MAX_SIZE ) {
@@ -1759,6 +1781,7 @@ static void ppc_spapr_init(MachineState *machine)char *filename;int spapr_cores = smp_cpus / smp_threads;int spapr_max_cores = max_cpus / smp_threads; +int smt =kvmppc_smt_threads (); msi_supported = true;
@@ -1813,6 +1836,15 @@ static void ppc_spapr_init(MachineState *machine)spapr_validate_node_memory (machine, &error_fatal); } +if (smc->dr_cpu_enabled) { +for (i =0 ; i < spapr_max_cores; i++) { +sPAPRDRConnector *drc = +spapr_dr_connector_new (OBJECT (spapr), +SPAPR_DR_CONNECTOR_TYPE_CPU , i * smt); +qemu_register_reset (spapr_drc_reset, drc); + } + } +/* init CPUs */ if (machine->cpu_model ==NULL ) { machine->cpu_model =kvm_enabled () ?"host" :"POWER7" ;
@@ -2247,6 +2279,88 @@ out:error_propagate (errp, local_err); } +static void *spapr_populate_hotplug_cpu_dt (DeviceState *dev,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_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +PowerPCCPU *cpu = &core->threads[0 ]; +CPUState *cs =CPU (cpu); +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 ; +void *fdt =NULL ; +int fdt_offset =0 ; + +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 (dev, cs, &fdt_offset, ms); + 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); +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 ); + } +return ; +} +static void spapr_machine_device_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {
@@ -2291,8 +2405,25 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {CPUState *cs =CPU (dev);PowerPCCPU *cpu =POWERPC_CPU (cs); +int i; + +if (!smc->dr_cpu_enabled && dev->hotplugged) { +error_setg (errp,"CPU hotplug not supported for this machine" ); +return ; + } + +/* 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 ; + } + }spapr_cpu_init (ms, cpu, errp); +spapr_cpu_reset (cpu); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) { +spapr_core_plug (hotplug_dev, dev, errp); } }
@@ -2308,7 +2439,8 @@ static HotplugHandler *spapr_get_hotpug_handler(MachineState *machine, DeviceState *dev) {if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) || -object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +object_dynamic_cast (OBJECT (dev),TYPE_CPU ) || +object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) {return HOTPLUG_HANDLER (machine); }return NULL ;
@@ -2352,6 +2484,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) 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; }
@@ -2431,6 +2564,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_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 +1 -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 */ };
Signature · 1 line
2.1.0
RFC PATCH 5/6 qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Bharata B RaoImplement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.
--- hw/core/machine.c | 19 +++++++++ hw/ppc/spapr.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 4 ++ qapi-schema.json | 85 +++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++ 5 files changed, 267 insertions(+)
hw/core/machine.c +19 -0
@@ -17,6 +17,25 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" +#include "qmp-commands.h" + +/* +* QMP: query-cpu-slots +* +* TODO: Ascertain if this is the right place to for this arch-neutral routine. +*/ +CPUSlotInfoList *qmp_query_cpu_slots (Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +if (!mc->cpu_slots) { +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; + } + +return mc->cpu_slots (ms); +}static char *machine_get_accel (Object *obj,Error **errp) {
hw/ppc/spapr.c +112 -0
124 lines not on this page · raw message
include/hw/boards.h +4 -0
@@ -57,6 +57,9 @@ bool machine_mem_merge(MachineState *machine);* Set only by old machines because they need to keep * compatibility on code that exposed QEMU_VERSION to guests in * the past (and now use qemu_hw_version()). +* @cpu_slots: +* Provides information about populated and yet-to-be populated +* CPU slots in the machine. Used by QMP query-cpu-slots. */ struct MachineClass {/*< private >*/
@@ -99,6 +102,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + CPUSlotInfoList *(*cpu_slots)(MachineState *machine); };/**
qapi-schema.json +85 -0
88 lines not on this page · raw message
qmp-commands.hx +47 -0
50 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC PATCH 6/6 hmp: Implement 'info cpu-slots'
In reply to Bharata B Rao--- hmp-commands-info.hx | 14 +++++++++++++ hmp.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + 3 files changed, 71 insertions(+)
hmp-commands-info.hx +14 -0
@@ -786,6 +786,20 @@ STEXI Display the value of a storage key (s390 only) ETEXI + { + .name = "cpu-slots", + .args_type = "", + .params = "", + .help = "show CPU slots", + .mhandler.cmd = hmp_info_cpu_slots, + }, + +STEXI +@item info cpu-slots +@findex cpu-slots +Show CPU slots +ETEXI + STEXI @end table ETEXI
hmp.c +56 -0
59 lines not on this page · raw message
hmp.h +1 -0
@@ -131,5 +131,6 @@ void hmp_rocker(Monitor *mon, const QDict *qdict);void hmp_rocker_ports (Monitor *mon,const QDict *qdict);void hmp_rocker_of_dpa_flows (Monitor *mon,const QDict *qdict);void hmp_rocker_of_dpa_groups (Monitor *mon,const QDict *qdict); +void hmp_info_cpu_slots (Monitor *mon,const QDict *qdict);#endif
Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Bharata B RaoQuoted 5 lines · Bharata B Rao
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>
Looks good overall, a few minor points below.
Quoted 101 lines
--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +75
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/
hw/ppc/spapr_cpu_core.c line 85
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU );
I think you want to use cpu_class_by_name() rather than explicitly constructing the class name here.
Quoted 33 lines
hw/ppc/spapr_cpu_core.c new file +33
-0+object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{
hw/ppc/spapr_cpu_core.c line 128
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + }
I'm not sure if this is the right place to test this. Possibly it should be tested in the machine hotplug handler instead.
Quoted 25 lines
hw/ppc/spapr_cpu_core.c new file +25
-0+ core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err);
hw/ppc/spapr_cpu_core.c line 164
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + }
Likewise, not sure if this is the right place for this check.
Quoted 66 lines
hw/ppc/spapr_cpu_core.c new file +45
-0+ core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); +object_property_add_str (obj,"slot" , + spapr_cpu_core_prop_get_slot, + spapr_cpu_core_prop_set_slot, +NULL ); +} + +static void spapr_cpu_core_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = spapr_cpu_core_realize; +} + +static const TypeInfo spapr_cpu_core_type_info = { + .name =TYPE_SPAPR_CPU_CORE , + .parent =TYPE_CPU_CORE , + .instance_init = spapr_cpu_core_instance_init, + .instance_size =sizeof (sPAPRCPUCore), + .class_init = spapr_cpu_core_class_init, +}; + +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 +15
-0@@ -0,0 +1,32 @@ +/* +* 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"
include/hw/ppc/spapr_cpu_core.h line 25
Quoted 10 lines
include/hw/ppc/spapr_cpu_core.h new file +10
-0+#define SPAPR_CPU_CORE (obj) \ + OBJECT_CHECK(sPAPRCPUCore, (obj), TYPE_SPAPR_CPU_CORE) + +typedef struct sPAPRCPUCore { + /*< private >*/ + DeviceState parent_obj; + + /*< public >*/ + int nr_threads; + char *cpu_model;
I think this might be better as an ObjectClass *, rather than a string. It avoids strdup()ing above, and works a bit more nicely with cpu_class_by_name().
Quoted 7 lines
include/hw/ppc/spapr_cpu_core.h new file +7
-0+char *slot; + PowerPCCPU *threads; +} sPAPRCPUCore; + +#define SPAPR_CPU_CORE_SLOT_PROP "slot" + +#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 v0 3/6] spapr: Represent boot CPUs as spapr-cpu-core devices
In reply to Bharata B RaoQuoted 67 lines · Bharata B Rao
Initialize boot CPUs as spapr-cpu-core devices and create links from machine object to these core devices. These links can be considered as CPU slots in which core devices will get hot-plugged. spapr-cpu-core device's slot property indicates the slot where it is plugged. Information about all the CPU slots can be obtained by walking these links.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 65 +++++++++++++++++++++++++++++++++++++++++++------- include/hw/ppc/spapr.h | 3 +++ 2 files changed, 60 insertions(+), 8 deletions(-)hw/ppc/spapr.c +18
-1@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h> @@ -1720,6 +1721,21 @@ static void spapr_validate_node_memory(MachineState *machine, Error **errp) } } +/* +* Check to see if core is being hot-plugged into an already populated slot. +*/ +static void spapr_cpu_core_allow_set_link (Object *obj,const char *name, +Object *val,Error **errp) +{ +Object *core =object_property_get_link (qdev_get_machine (), name,NULL ); + +if (core) { +char *path =object_get_canonical_path (core); +error_setg (errp,"Slot %s already populated with %s" , name, path); +g_free (path); + } +} +/* pSeries LPAR / sPAPR hardware init */ static void ppc_spapr_init (MachineState *machine) {@@ -1728,7 +1744,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 ();@@ -1742,6 +1757,8 @@ static void ppc_spapr_init(MachineState *machine)long load_limit, fw_size;bool kernel_le = false;char *filename; +int spapr_cores = smp_cpus / smp_threads; +int spapr_max_cores = max_cpus / smp_threads; msi_supported = true;@@ -1800,13 +1817,38 @@ static void ppc_spapr_init(MachineState *machine)if (machine->cpu_model ==NULL ) { machine->cpu_model =kvm_enabled () ?"host" :"POWER7" ; }
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1824
Quoted 10 lines
hw/ppc/spapr.c +5
-5-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 ); + + spapr->cores =g_malloc0 (spapr_max_cores *sizeof (Object)); + +for (i =0 ; i < spapr_max_cores; i++) { +Object *spapr_cpu_core =object_new (TYPE_SPAPR_CPU_CORE );
So.. if I understand correctly this will always construct maxcpus threads at startup. I's just that the ones beyond initial cpus won't be realized. Was that your intention? I thought the plan was to only construct the hotplugged cpus when they were hotplugged (in contrast to my earlier proposal).
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1834
Quoted 10 lines
hw/ppc/spapr.c +10
-0+char name[32 ]; + +object_property_set_str (spapr_cpu_core, machine->cpu_model,"cpu_model" , + &error_fatal); +object_property_set_int (spapr_cpu_core, smp_threads,"nr_threads" , + &error_fatal); +/* +* Create links from machine objects to all possible cores. +*/ +snprintf (name,sizeof (name),"%s[%d]" ,SPAPR_MACHINE_CPU_CORE_PROP , i);
Why do SPAPR_MACHINE_CPU_CORE_PROP and SPAPR_CPU_CORE_SLOT_PROP get #defines, but the other properties get bare strings? I find the bare strings are usually easier to follow.
Quoted 30 lines
hw/ppc/spapr.c +17
-1+object_property_add_link (OBJECT (spapr), name,TYPE_SPAPR_CPU_CORE , + (Object **)&spapr->cores[i], + spapr_cpu_core_allow_set_link,0 , + &error_fatal); + +/* +* Set the link from machine object to core object for all +* boot time CPUs specified with -smp and realize them. +* For rest of the hotpluggable cores this is happens from +* the core hotplug/realization path. +*/ +if (i < spapr_cores) { +object_property_set_str (spapr_cpu_core, name, +SPAPR_CPU_CORE_SLOT_PROP , &error_fatal); +object_property_set_bool (spapr_cpu_core, true,"realized" , + &error_fatal); } -spapr_cpu_init (spapr, cpu, &error_fatal); }if (kvm_enabled ()) {@@ -2209,6 +2251,7 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (hotplug_dev);if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {int node;
hw/ppc/spapr.c static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, · line 2295
Quoted 8 lines
hw/ppc/spapr.c +5
-0@@ -2245,6 +2288,11 @@ 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_CPU )) { +CPUState *cs =CPU (dev); +PowerPCCPU *cpu =POWERPC_CPU (cs); + +spapr_cpu_init (ms, cpu, errp);
I tend to thin the spapr_cpu_init() should be done from the core's create_threads() function, but I'm willing to be persuaded otherwise.
Quoted 29 lines
hw/ppc/spapr.c +2
-1} }@@ -2259,7 +2307,8 @@ static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev,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_CPU )) {return HOTPLUG_HANDLER (machine); }return NULL ;include/hw/ppc/spapr.h +3
-0@@ -79,8 +79,11 @@ struct sPAPRMachineState {/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory; +Object *cores; }; +#define SPAPR_MACHINE_CPU_CORE_PROP "core" +#define H_SUCCESS 0#define H_BUSY 1/* Hardware busy -- retry later */ #define H_CLOSED 2/* Resource closed */
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 v0 4/6] spapr: CPU hotplug support
In reply to Bharata B RaoQuoted 176 lines · Bharata B Rao
Set up device tree entries for the hotplugged CPU core and use the exising EPOW event infrastructure to send CPU hotplug notification to the guest.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_events.c | 3 ++ hw/ppc/spapr_rtas.c | 24 +++++++++ include/hw/ppc/spapr.h | 1 + 4 files changed, 163 insertions(+), 1 deletion(-)hw/ppc/spapr.c +121
-0@@ -603,6 +603,18 @@ 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)}; +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRDRConnector *drc; +sPAPRDRConnectorClass *drck; +int drc_index; + +if (smc->dr_cpu_enabled) { + drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_CPU , index); +g_assert (drc); + drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + drc_index = drck->get_index (drc); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,my-drc-index" , drc_index))); + }/* 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 +999,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 ) { +fprintf (stderr,"Couldn't set up CPU DR device tree properties\n" ); +exit (1 ); + } + } +_FDT ((fdt_pack (fdt)));if (fdt_totalsize (fdt) >FDT_MAX_SIZE ) {@@ -1759,6 +1781,7 @@ static void ppc_spapr_init(MachineState *machine)char *filename;int spapr_cores = smp_cpus / smp_threads;int spapr_max_cores = max_cpus / smp_threads; +int smt =kvmppc_smt_threads (); msi_supported = true;@@ -1813,6 +1836,15 @@ static void ppc_spapr_init(MachineState *machine)spapr_validate_node_memory (machine, &error_fatal); } +if (smc->dr_cpu_enabled) { +for (i =0 ; i < spapr_max_cores; i++) { +sPAPRDRConnector *drc = +spapr_dr_connector_new (OBJECT (spapr), +SPAPR_DR_CONNECTOR_TYPE_CPU , i * smt); +qemu_register_reset (spapr_drc_reset, drc); + } + } +/* init CPUs */ if (machine->cpu_model ==NULL ) { machine->cpu_model =kvm_enabled () ?"host" :"POWER7" ;@@ -2247,6 +2279,88 @@ out:error_propagate (errp, local_err); } +static void *spapr_populate_hotplug_cpu_dt (DeviceState *dev,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_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +PowerPCCPU *cpu = &core->threads[0 ]; +CPUState *cs =CPU (cpu); +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 ; +void *fdt =NULL ; +int fdt_offset =0 ; + +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 (dev, cs, &fdt_offset, ms); + 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); +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 ); + } +return ; +} +static void spapr_machine_device_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {@@ -2291,8 +2405,25 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {CPUState *cs =CPU (dev);PowerPCCPU *cpu =POWERPC_CPU (cs); +int i; + +if (!smc->dr_cpu_enabled && dev->hotplugged) { +error_setg (errp,"CPU hotplug not supported for this machine" ); +return ; + } +
hw/ppc/spapr.c static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, · line 2424
Quoted 10 lines
hw/ppc/spapr.c +8
-0+/* Set NUMA node for the added CPUs */ +for (i =0 ; i < nb_numa_nodes; i++) { +if (test_bit (cs->cpu_index, numa_info[i].node_cpu)) { + cs->numa_node = i; +break ; + } + }spapr_cpu_init (ms, cpu, errp); +spapr_cpu_reset (cpu);
It looks to me like all of this setup should be either in the last patch, or in this one, not split between them.
Quoted 72 lines
hw/ppc/spapr.c +6
-1+ }else if (object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) { +spapr_core_plug (hotplug_dev, dev, errp); } }@@ -2308,7 +2439,8 @@ static HotplugHandler *spapr_get_hotpug_handler(MachineState *machine, DeviceState *dev) {if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) || -object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +object_dynamic_cast (OBJECT (dev),TYPE_CPU ) || +object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) {return HOTPLUG_HANDLER (machine); }return NULL ;@@ -2352,6 +2484,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) 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; }@@ -2431,6 +2564,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_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 +12
-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; +} +
hw/ppc/spapr_rtas.c static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_, · line 185
Quoted 10 lines
hw/ppc/spapr_rtas.c +10
-0+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 ; + } +} +
Any particular reason for doing these things at rtas_start_cpu() time, but other initialization at plug time? Could you consolidate it to one place or the other?
Quoted 24 lines
hw/ppc/spapr_rtas.c +2
-0static 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 +1
-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 */ };
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 v0 3/6] spapr: Represent boot CPUs as spapr-cpu-core devices
In reply to David GibsonQuoted 76 lines · David Gibson
Quoted 75 lines · Bharata B Rao
Initialize boot CPUs as spapr-cpu-core devices and create links from machine object to these core devices. These links can be considered as CPU slots in which core devices will get hot-plugged. spapr-cpu-core device's slot property indicates the slot where it is plugged. Information about all the CPU slots can be obtained by walking these links.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 65 +++++++++++++++++++++++++++++++++++++++++++------- include/hw/ppc/spapr.h | 3 +++ 2 files changed, 60 insertions(+), 8 deletions(-)hw/ppc/spapr.c +21
-6@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h> @@ -1720,6 +1721,21 @@ static void spapr_validate_node_memory(MachineState *machine, Error **errp) } } +/* +* Check to see if core is being hot-plugged into an already populated slot. +*/ +static void spapr_cpu_core_allow_set_link (Object *obj,const char *name, +Object *val,Error **errp) +{ +Object *core =object_property_get_link (qdev_get_machine (), name,NULL ); + +if (core) { +char *path =object_get_canonical_path (core); +error_setg (errp,"Slot %s already populated with %s" , name, path); +g_free (path); + } +} +/* pSeries LPAR / sPAPR hardware init */ static void ppc_spapr_init (MachineState *machine) {@@ -1728,7 +1744,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 ();@@ -1742,6 +1757,8 @@ static void ppc_spapr_init(MachineState *machine)long load_limit, fw_size;bool kernel_le = false;char *filename; +int spapr_cores = smp_cpus / smp_threads; +int spapr_max_cores = max_cpus / smp_threads; msi_supported = true;@@ -1800,13 +1817,38 @@ 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 ); + + spapr->cores =g_malloc0 (spapr_max_cores *sizeof (Object)); +
Quoted 8 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1824
Quoted 2 lines
hw/ppc/spapr.c +2
-0+for (i =0 ; i < spapr_max_cores; i++) { +Object *spapr_cpu_core =object_new (TYPE_SPAPR_CPU_CORE );So.. if I understand correctly this will always construct maxcpus threads at startup. I's just that the ones beyond initial cpus won't be realized. Was that your intention? I thought the plan was to only construct the hotplugged cpus when they were hotplugged (in contrast to my earlier proposal).
Oops! The intention was to to create only cores for smp_cpus and let device_add create the rest. Will fix.
Quoted 12 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1834
Quoted 11 lines
hw/ppc/spapr.c +10
-0+char name[32 ]; + +object_property_set_str (spapr_cpu_core, machine->cpu_model,"cpu_model" , + &error_fatal); +object_property_set_int (spapr_cpu_core, smp_threads,"nr_threads" , + &error_fatal); +/* +* Create links from machine objects to all possible cores. +*/ +snprintf (name,sizeof (name),"%s[%d]" ,SPAPR_MACHINE_CPU_CORE_PROP , i);
Quoted 3 lines
Why do
SPAPR_MACHINE_CPU_CORE_PROPandSPAPR_CPU_CORE_SLOT_PROPget #defines, but the other properties get bare strings? I find the bare strings are usually easier to follow.
Let me check the convention regarding properties and stick to the common usage.
Quoted 33 lines
Quoted 33 lines
hw/ppc/spapr.c +17
-1+object_property_add_link (OBJECT (spapr), name,TYPE_SPAPR_CPU_CORE , + (Object **)&spapr->cores[i], + spapr_cpu_core_allow_set_link,0 , + &error_fatal); + +/* +* Set the link from machine object to core object for all +* boot time CPUs specified with -smp and realize them. +* For rest of the hotpluggable cores this is happens from +* the core hotplug/realization path. +*/ +if (i < spapr_cores) { +object_property_set_str (spapr_cpu_core, name, +SPAPR_CPU_CORE_SLOT_PROP , &error_fatal); +object_property_set_bool (spapr_cpu_core, true,"realized" , + &error_fatal); } -spapr_cpu_init (spapr, cpu, &error_fatal); }if (kvm_enabled ()) {@@ -2209,6 +2251,7 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (hotplug_dev);if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {int node;@@ -2245,6 +2288,11 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, }
Quoted 9 lines
hw/ppc/spapr.c static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, · line 2295
Quoted 6 lines
hw/ppc/spapr.c +5
-0spapr_memory_plug (hotplug_dev, dev, node, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +CPUState *cs =CPU (dev); +PowerPCCPU *cpu =POWERPC_CPU (cs); + +spapr_cpu_init (ms, cpu, errp);I tend to thin the
spapr_cpu_init()should be done from the core'screate_threads()function, but I'm willing to be persuaded otherwise.
In addition to core device, every cpu thread device will go through ->plug() invocation via its realization path. And spapr_cpu_init() is needed for every CPU thread. Let me check if it is possible to invoke this from core's routines.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Bharata B RaoQuoted 53 lines · Bharata B Rao
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.Signed-off-by Bharata B Rao <[email protected]>--- hw/core/machine.c | 19 +++++++++ hw/ppc/spapr.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 4 ++ qapi-schema.json | 85 +++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++ 5 files changed, 267 insertions(+)hw/core/machine.c +19
-0@@ -17,6 +17,25 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" +#include "qmp-commands.h" + +/* +* QMP: query-cpu-slots +* +* TODO: Ascertain if this is the right place to for this arch-neutral routine. +*/ +CPUSlotInfoList *qmp_query_cpu_slots (Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +if (!mc->cpu_slots) { +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; + } + +return mc->cpu_slots (ms); +}static char *machine_get_accel (Object *obj,Error **errp) {hw/ppc/spapr.c +0
-0@@ -2453,6 +2453,117 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)return cpu_index / smp_threads / smp_cores; }
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2465
Quoted 10 lines
hw/ppc/spapr.c +10
-0+static int spapr_cpuinfo_list (Object *obj,void *opaque) +{ +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); +CPUInfoList ***prev = opaque; + +if (object_dynamic_cast (obj,TYPE_CPU )) { +CPUInfoList *elem =g_new0 (CPUInfoList,1 ); +CPUInfo *s =g_new0 (CPUInfo,1 ); +CPUState *cpu =CPU (obj); +PowerPCCPU *pcpu =POWERPC_CPU (cpu);
Since you're assuming a POWERPC_CPU here, you should probably check that in the object_dynamic_cast() above.
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2470
Quoted 5 lines
hw/ppc/spapr.c +5
-0+ + s->arch_id =ppc_get_vcpu_dt_id (pcpu); + s->type =g_strdup (object_get_typename (obj)); + s->thread = cpu->cpu_index; + s->has_thread = true;
Unlike Igor's patch, you are attaching this thread information to, well, a thread, not a cpu slot. So I don't think the has_thread, has_core etc. booleans are useful any more.
Quoted 7 lines
hw/ppc/spapr.c +7
-0+ s->core = cpu->cpu_index / smp_threads; + s->has_core = true; +if (mc->cpu_index_to_socket_id) { + s->socket = mc->cpu_index_to_socket_id (cpu->cpu_index); + }else { + s->socket = cpu->cpu_index / smp_threads / smp_cores; + }
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2487
Quoted 10 lines
hw/ppc/spapr.c +10
-0+ s->has_socket = true; + s->node = cpu->numa_node; + s->has_node = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; + + elem->value = s; + elem->next =NULL ; + **prev = elem; + *prev = &elem->next;
Hmm.. the dt_id is the only power specific thing, here, wonder if there's a way we could make this generic.
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2489
Quoted 2 lines
hw/ppc/spapr.c +2
-0+ } +object_child_foreach (obj, spapr_cpuinfo_list, opaque);
Hmm.. IIUC this can be called either on a core, or on a thread, with somewhat different behaviour. That seems dangerously subtle.
Quoted 20 lines
hw/ppc/spapr.c +20
-0+return 0 ; +} + +static CPUSlotInfoList *spapr_cpu_slots (MachineState *machine) +{ +CPUSlotInfoList *head =NULL ; +CPUSlotInfoList **prev = &head; +Object *root_container; +ObjectProperty *prop; +ObjectPropertyIterator iter; + +/* +* TODO: There surely must be a better/easier way to walk all +* the link properties of an object ? +*/ + root_container =container_get (object_get_root (),"/machine" ); +object_property_iter_init (&iter, root_container); + +while ((prop =object_property_iter_next (&iter))) { +Object *obj;
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2519
Quoted 10 lines
hw/ppc/spapr.c +10
-0+DeviceState *dev; +CPUSlotInfoList *elem; +CPUSlotInfo *s; +CPUInfoList *cpu_head =NULL ; +CPUInfoList **cpu_prev = &cpu_head; +sPAPRCPUCore *core; + +if (!strstart (prop->type,"link<" ,NULL )) { +continue ; + }
Hmm.. we really out to have an is_link() helper, but that's not your problem.
Quoted 23 lines
hw/ppc/spapr.c +23
-0+if (!strstart (prop->name,SPAPR_MACHINE_CPU_CORE_PROP ,NULL )) { +continue ; + } + + elem =g_new0 (CPUSlotInfoList,1 ); + s =g_new0 (CPUSlotInfo,1 ); + + obj =object_property_get_link (root_container, prop->name,NULL ); +if (obj) { +/* Slot populated */ + dev =DEVICE (obj); + core =SPAPR_CPU_CORE (obj); + +if (dev->id) { + s->has_id = true; + s->id =g_strdup (dev->id); + } + s->realized =object_property_get_bool (obj,"realized" ,NULL ); + s->nr_cpus = core->nr_threads; + s->has_nr_cpus = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; +if (s->realized) {
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2553
Quoted 10 lines
hw/ppc/spapr.c +10
-0+spapr_cpuinfo_list (obj, &cpu_prev); + } + s->has_cpus = true; + }else { +/* Slot empty */ + s->has_id = false; + s->has_nr_cpus = false; + s->has_qom_path = false; + s->has_cpus = false; + s->realized = false;
Um.. doesn't this leave out the cpu model and nr_threads for a non-populated slot? Which is crucial information for mgmt to populate the slot.
I can't actually see that this interface gives you any information you can't already see from the qom tree.
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2562
Quoted 9 lines
hw/ppc/spapr.c +9
-0+ } + s->type =g_strdup (TYPE_SPAPR_CPU_CORE ); + s->hotplug_granularity =g_strdup (SPAPR_MACHINE_CPU_CORE_PROP ); + s->slot_id =g_strdup (prop->name); + s->cpus = cpu_head; + elem->value = s; + elem->next =NULL ; + *prev = elem; + prev = &elem->next;
I also wonder if there's a way to use the visit_* interfaces to avoid having to fully construct this list-of-lists.
I can't see any code that frees the info data structure either...
Quoted 185 lines
hw/ppc/spapr.c +5
-0+ } +return head; +} +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -2482,6 +2593,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) hc->plug = spapr_machine_device_plug; hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; + mc->cpu_slots = spapr_cpu_slots; smc->dr_lmb_enabled = true; smc->dr_cpu_enabled = true;include/hw/boards.h +4
-0@@ -57,6 +57,9 @@ bool machine_mem_merge(MachineState *machine);* Set only by old machines because they need to keep * compatibility on code that exposed QEMU_VERSION to guests in * the past (and now use qemu_hw_version()). +* @cpu_slots: +* Provides information about populated and yet-to-be populated +* CPU slots in the machine. Used by QMP query-cpu-slots. */ struct MachineClass {/*< private >*/ @@ -99,6 +102,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + CPUSlotInfoList *(*cpu_slots)(MachineState *machine); };/** qapi-schema.json +85
-0@@ -4083,3 +4083,88 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUInfo: +# +# Information about CPUs +# +# @arch-id: Arch-specific ID for the CPU. +# +# @type: QOM type of the CPU. +# +# @thread: Thread ID of the CPU. +# +# @core: Core ID of the CPU. +# +# @socket: Socket ID of the CPU. +# +# @node: NUMA node to which the CPU belongs. +# +# @qom-path: QOM path of the CPU object +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch-id': 'int', + 'type': 'str', + '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom-path': 'str' + } +} + +## +# @CPUSlotInfo: +# +# Information about CPU Slots +# +# @id: Device ID of the CPU composite object that occupies the slot. +# +# @type: QOM type of the CPU composite object that occupies the slot. +# +# @hotplug-granularity: Granularity of CPU composite hotplug for this slot, +# can be thread, core or socket. +# +# @slot-id: Slot's identifier. +# +# @qom-path: QOM path of the CPU composite object that occupies the slot. +# +# @realized: A boolean that indicates whether the slot is filled or empty. +# +# @nr-cpus: Number of CPUs that are part of CPU composite object that occupies +# this slot. +# +# @cpus: An array of @CPUInfo elements where each element describes one +# CPU that is part of this slot's CPU composite object. +# +# @type: QOM type +# +# Since: 2.6 +## + +{ 'struct': 'CPUSlotInfo', + 'data': { '*id': 'str', + 'type': 'str', + 'hotplug-granularity' : 'str', + 'slot-id' : 'str', + '*qom-path': 'str', + 'realized': 'bool', + '*nr-cpus': 'int', + '*cpus' : ['CPUInfo'] + } +} + +## +# @query-cpu-slots: +# +# Returns information for all CPU slots +# +# Returns: a list of @CPUSlotInfo +# +# Since: 2.6 +## +{ 'command': 'query-cpu-slots', 'returns': ['CPUSlotInfo'] }qmp-commands.hx +47
-0@@ -4825,3 +4825,50 @@ Example: {"type": 0, "out-pport": 0, "pport": 0, "vlan-id": 3840, "pop-vlan": 1, "id": 251658240} ]} + +EQMP + + { + .name = "query-cpu-slots", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_query_cpu_slots, + }, + +SQMP +@query-cpu-slots +-------------------- + +Show CPU slots information + +Example: +-> { "execute": "query-cpu-slots" } +<- {"return": [{ + "slot-id": "core[2]", + "hotplug-granularity": "core", + "realized": false, + "type": "spapr-cpu-core" + }, + { + "slot-id": "core[1]", + "qom-path": "/machine/unattached/device[2]", + "hotplug-granularity": "core", + "realized": true, + "type": "spapr-cpu-core" + "nr-cpus": 2, + "cpus": [ + {"thread": 8, + "socket": 0, + "core": 1, + "arch-id": 8, + "qom-path": "/machine/unattached/device[2]/thread[0]", + "node": 0, + "type": "host-powerpc64-cpu"}, + {"thread": 9, + "socket": 0, + "core": 1, + "arch-id": 9, + "qom-path": "/machine/unattached/device[2]/thread[2]", + "node": 0, + "type": "host-powerpc64-cpu"}] + } + ]}
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 v0 2/6] spapr: CPU core device
In reply to David GibsonQuoted 115 lines · David Gibson
Quoted 5 lines · Bharata B Rao
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>Looks good overall, a few minor points below.
Quoted 106 lines
--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +80
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) {
Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 85
Quoted 5 lines
hw/ppc/spapr_cpu_core.c new file +5
-0+char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU );I think you want to use
cpu_class_by_name()rather than explicitly constructing the class name here.
Good point, started using ObjectClass.
Quoted 39 lines
Quoted 39 lines
hw/ppc/spapr_cpu_core.c new file +38
-0+object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu
Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 128
Quoted 5 lines
hw/ppc/spapr_cpu_core.c new file +5
-0+*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + }I'm not sure if this is the right place to test this. Possibly it should be tested in the machine hotplug handler instead.
Not sure about the right place to validate this and nr_threads property. But it essentially boils down to backing out from property setter after object init vs backing out during realization.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to David GibsonDavid, I am responding to just one comment here and will respond to others in detail later.
Quoted 30 lines · David Gibson
Quoted 30 lines
hw/ppc/spapr.c +29
-0+if (!strstart (prop->name,SPAPR_MACHINE_CPU_CORE_PROP ,NULL )) { +continue ; + } + + elem =g_new0 (CPUSlotInfoList,1 ); + s =g_new0 (CPUSlotInfo,1 ); + + obj =object_property_get_link (root_container, prop->name,NULL ); +if (obj) { +/* Slot populated */ + dev =DEVICE (obj); + core =SPAPR_CPU_CORE (obj); + +if (dev->id) { + s->has_id = true; + s->id =g_strdup (dev->id); + } + s->realized =object_property_get_bool (obj,"realized" ,NULL ); + s->nr_cpus = core->nr_threads; + s->has_nr_cpus = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; +if (s->realized) { +spapr_cpuinfo_list (obj, &cpu_prev); + } + s->has_cpus = true; + }else { +/* Slot empty */ + s->has_id = false;
Quoted 8 lines
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2553
Quoted 4 lines
hw/ppc/spapr.c +4
-0+ s->has_nr_cpus = false; + s->has_qom_path = false; + s->has_cpus = false; + s->realized = false;Um.. doesn't this leave out the cpu model and
nr_threadsfor a non-populated slot? Which is crucial information for mgmt to populate the slot.
Actually if we don't allow heterogenous configurations, management currently knows how to get model and threads that have already been specified with -cpu and -smp global options respectively.
If we want to support heterogenous configurations, should we then have supported model types and thread values listed here ? At the moment I am not sure what those supported types and thread values could be.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Bharata B RaoQuoted 6 lines · Bharata B Rao
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>---
...
Quoted 86 lines
hw/ppc/spapr_cpu_core.c new file +80
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) {
hw/ppc/spapr_cpu_core.c line 90
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp);
Need to check errp here to see whether something went wrong?
Quoted 26 lines
hw/ppc/spapr_cpu_core.c new file +26
-0+ } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model(Object *obj, const char *val,
hw/ppc/spapr_cpu_core.c line 126
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+ Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model);
s/should/must/
Quoted 26 lines
hw/ppc/spapr_cpu_core.c new file +26
-0+return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value;
hw/ppc/spapr_cpu_core.c line 162
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+ +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads);
s/should/must/
hw/ppc/spapr_cpu_core.c line 167
Quoted 5 lines
hw/ppc/spapr_cpu_core.c new file +5
-0+return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU));
I think it's preferable to use g_new0 for such allocations instead.
Also, should this memory maybe be freed during instance_finalize again, so that there is no memory leak here in case the cores are deleted again one day?
Quoted 64 lines
hw/ppc/spapr_cpu_core.c new file +42
-0+if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); +object_property_add_str (obj,"slot" , + spapr_cpu_core_prop_get_slot, + spapr_cpu_core_prop_set_slot, +NULL ); +} + +static void spapr_cpu_core_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = spapr_cpu_core_realize; +} + +static const TypeInfo spapr_cpu_core_type_info = { + .name =TYPE_SPAPR_CPU_CORE , + .parent =TYPE_CPU_CORE , + .instance_init = spapr_cpu_core_instance_init, + .instance_size =sizeof (sPAPRCPUCore), + .class_init = spapr_cpu_core_class_init, +}; + +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 +16
-0@@ -0,0 +1,32 @@ +/* +* 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) \
include/hw/ppc/spapr_cpu_core.h line 26
Quoted 10 lines
include/hw/ppc/spapr_cpu_core.h new file +10
-0+ OBJECT_CHECK(sPAPRCPUCore, (obj), TYPE_SPAPR_CPU_CORE) + +typedef struct sPAPRCPUCore { + /*< private >*/ + DeviceState parent_obj; + + /*< public >*/ + int nr_threads; + char *cpu_model; + char *slot;
<bikeshedpainting>
I'd maybe call that "slot_name" instead ... if you only call it "slot", I'd rather think of an integer value than a string here. </bikeshedpainting>
include/hw/ppc/spapr_cpu_core.h line 32
Quoted 7 lines
include/hw/ppc/spapr_cpu_core.h new file +6
-0+ PowerPCCPU *threads; +} sPAPRCPUCore; + +#define SPAPR_CPU_CORE_SLOT_PROP "slot" + +#endif
Thomas
Re: [Qemu-devel] [RFC PATCH v0 4/6] spapr: CPU hotplug support
In reply to Bharata B RaoQuoted 36 lines · Bharata B Rao
Set up device tree entries for the hotplugged CPU core and use the exising EPOW event infrastructure to send CPU hotplug notification to the guest.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_events.c | 3 ++ hw/ppc/spapr_rtas.c | 24 +++++++++ include/hw/ppc/spapr.h | 1 + 4 files changed, 163 insertions(+), 1 deletion(-)hw/ppc/spapr.c +12
-0@@ -603,6 +603,18 @@ 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)}; +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRDRConnector *drc; +sPAPRDRConnectorClass *drck; +int drc_index; + +if (smc->dr_cpu_enabled) { + drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_CPU , index); +g_assert (drc); + drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + drc_index = drck->get_index (drc); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,my-drc-index" , drc_index))); + }/* 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
hw/ppc/spapr.c static void spapr_finalize_fdt(sPAPRMachineState *spapr, · line 1007
Quoted 9 lines
hw/ppc/spapr.c +6
-0@@ -987,6 +999,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 ) { +fprintf (stderr,"Couldn't set up CPU DR device tree properties\n" );
I think it's better to use error_report() nowadays instead.
Quoted 81 lines
hw/ppc/spapr.c +60
-0+exit (1 ); + } + } +_FDT ((fdt_pack (fdt)));if (fdt_totalsize (fdt) >FDT_MAX_SIZE ) {@@ -1759,6 +1781,7 @@ static void ppc_spapr_init(MachineState *machine)char *filename;int spapr_cores = smp_cpus / smp_threads;int spapr_max_cores = max_cpus / smp_threads; +int smt =kvmppc_smt_threads (); msi_supported = true;@@ -1813,6 +1836,15 @@ static void ppc_spapr_init(MachineState *machine)spapr_validate_node_memory (machine, &error_fatal); } +if (smc->dr_cpu_enabled) { +for (i =0 ; i < spapr_max_cores; i++) { +sPAPRDRConnector *drc = +spapr_dr_connector_new (OBJECT (spapr), +SPAPR_DR_CONNECTOR_TYPE_CPU , i * smt); +qemu_register_reset (spapr_drc_reset, drc); + } + } +/* init CPUs */ if (machine->cpu_model ==NULL ) { machine->cpu_model =kvm_enabled () ?"host" :"POWER7" ;@@ -2247,6 +2279,88 @@ out:error_propagate (errp, local_err); } +static void *spapr_populate_hotplug_cpu_dt (DeviceState *dev,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_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +PowerPCCPU *cpu = &core->threads[0 ]; +CPUState *cs =CPU (cpu); +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 ; +void *fdt =NULL ; +int fdt_offset =0 ; + +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.c out: · line 2337
Quoted 10 lines
hw/ppc/spapr.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 (dev, cs, &fdt_offset, ms); + dev->hotplugged = true;
That looks strange ... why "dev->hotplugged = true" after you've already checked that with the above if-statement?
Quoted 14 lines
hw/ppc/spapr.c +14
-0+ } + + drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + drck->attach (drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_err); +if (local_err) { +g_free (fdt); +error_propagate (errp, local_err); +return ; + } + +if (dev->hotplugged) { +/* +* Send hotplug notification interrupt to the guest only in case +* of hotplugged CPUs.
hw/ppc/spapr.c out: · line 2361
Quoted 10 lines
hw/ppc/spapr.c +10
-0+*/ +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 ); + } +return ;
Superfluous return statement.
Quoted 50 lines
hw/ppc/spapr.c +22
-1+} +static void spapr_machine_device_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {@@ -2291,8 +2405,25 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {CPUState *cs =CPU (dev);PowerPCCPU *cpu =POWERPC_CPU (cs); +int i; + +if (!smc->dr_cpu_enabled && dev->hotplugged) { +error_setg (errp,"CPU hotplug not supported for this machine" ); +return ; + } + +/* 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 ; + } + }spapr_cpu_init (ms, cpu, errp); +spapr_cpu_reset (cpu); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) { +spapr_core_plug (hotplug_dev, dev, errp); } }@@ -2308,7 +2439,8 @@ static HotplugHandler *spapr_get_hotpug_handler(MachineState *machine, DeviceState *dev) {if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) || -object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +object_dynamic_cast (OBJECT (dev),TYPE_CPU ) || +object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) {return HOTPLUG_HANDLER (machine); }return NULL ;@@ -2352,6 +2484,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) 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; }
hw/ppc/spapr.c static void spapr_machine_2_5_class_options(MachineClass *mc) · line 2570
Quoted 7 lines
hw/ppc/spapr.c +1
-0@@ -2431,6 +2564,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 ); }
Thomas
Re: [Qemu-devel] [RFC PATCH v0 4/6] spapr: CPU hotplug support
Quoted 40 lines · Thomas Huth
Quoted 39 lines · Bharata B Rao
Set up device tree entries for the hotplugged CPU core and use the exising EPOW event infrastructure to send CPU hotplug notification to the guest.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_events.c | 3 ++ hw/ppc/spapr_rtas.c | 24 +++++++++ include/hw/ppc/spapr.h | 1 + 4 files changed, 163 insertions(+), 1 deletion(-)hw/ppc/spapr.c +12
-0@@ -603,6 +603,18 @@ 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)}; +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRDRConnector *drc; +sPAPRDRConnectorClass *drck; +int drc_index; + +if (smc->dr_cpu_enabled) { + drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_CPU , index); +g_assert (drc); + drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + drc_index = drck->get_index (drc); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,my-drc-index" , drc_index))); + }/* 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 +999,16 @@ static void spapr_finalize_fdt(sPAPRMachineState *spapr,_FDT (spapr_drc_populate_dt (fdt,0 ,NULL ,SPAPR_DR_CONNECTOR_TYPE_LMB )); }
Quoted 8 lines
hw/ppc/spapr.c static void spapr_finalize_fdt(sPAPRMachineState *spapr, · line 1007
Quoted 6 lines
hw/ppc/spapr.c +6
-0+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 ) { +fprintf (stderr,"Couldn't set up CPU DR device tree properties\n" );I think it's better to use
error_report()nowadays instead.
Yeah, have been carrying this old hunk, will fix.
Quoted 87 lines
Quoted 87 lines
hw/ppc/spapr.c +65
-0+exit (1 ); + } + } +_FDT ((fdt_pack (fdt)));if (fdt_totalsize (fdt) >FDT_MAX_SIZE ) {@@ -1759,6 +1781,7 @@ static void ppc_spapr_init(MachineState *machine)char *filename;int spapr_cores = smp_cpus / smp_threads;int spapr_max_cores = max_cpus / smp_threads; +int smt =kvmppc_smt_threads (); msi_supported = true;@@ -1813,6 +1836,15 @@ static void ppc_spapr_init(MachineState *machine)spapr_validate_node_memory (machine, &error_fatal); } +if (smc->dr_cpu_enabled) { +for (i =0 ; i < spapr_max_cores; i++) { +sPAPRDRConnector *drc = +spapr_dr_connector_new (OBJECT (spapr), +SPAPR_DR_CONNECTOR_TYPE_CPU , i * smt); +qemu_register_reset (spapr_drc_reset, drc); + } + } +/* init CPUs */ if (machine->cpu_model ==NULL ) { machine->cpu_model =kvm_enabled () ?"host" :"POWER7" ;@@ -2247,6 +2279,88 @@ out:error_propagate (errp, local_err); } +static void *spapr_populate_hotplug_cpu_dt (DeviceState *dev,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_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +PowerPCCPU *cpu = &core->threads[0 ]; +CPUState *cs =CPU (cpu); +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 ; +void *fdt =NULL ; +int fdt_offset =0 ; + +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
Quoted 8 lines
hw/ppc/spapr.c out: · line 2337
Quoted 5 lines
hw/ppc/spapr.c +5
-0+* coldplugged CPUs DT entries are setup in spapr_finalize_fdt(). +*/ +if (dev->hotplugged) { + fdt =spapr_populate_hotplug_cpu_dt (dev, cs, &fdt_offset, ms); + dev->hotplugged = true;That looks strange ... why "
dev->hotplugged= true" after you've already checked that with the above if-statement?
Yeah this is a remnant of the implmentation that was based on David's proposal where all the devices were pre-created and I had to set dev->hotplugged manually here. Will remove as it is not needed here in this device_add based implementation.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 3/6] spapr: Represent boot CPUs as spapr-cpu-core devices
In reply to Bharata B RaoQuoted 64 lines · On Thu, 25 Feb 2016 21:52:39 +0530 Bharata B Rao <[email protected]>…
Initialize boot CPUs as spapr-cpu-core devices and create links from machine object to these core devices. These links can be considered as CPU slots in which core devices will get hot-plugged. spapr-cpu-core device's slot property indicates the slot where it is plugged. Information about all the CPU slots can be obtained by walking these links.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 65 +++++++++++++++++++++++++++++++++++++++++++------- include/hw/ppc/spapr.h | 3 +++ 2 files changed, 60 insertions(+), 8 deletions(-)hw/ppc/spapr.c +18
-1@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h> @@ -1720,6 +1721,21 @@ static void spapr_validate_node_memory(MachineState *machine, Error **errp) } } +/* +* Check to see if core is being hot-plugged into an already populated slot. +*/ +static void spapr_cpu_core_allow_set_link (Object *obj,const char *name, +Object *val,Error **errp) +{ +Object *core =object_property_get_link (qdev_get_machine (), name,NULL ); + +if (core) { +char *path =object_get_canonical_path (core); +error_setg (errp,"Slot %s already populated with %s" , name, path); +g_free (path); + } +} +/* pSeries LPAR / sPAPR hardware init */ static void ppc_spapr_init (MachineState *machine) {@@ -1728,7 +1744,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 ();@@ -1742,6 +1757,8 @@ static void ppc_spapr_init(MachineState *machine)long load_limit, fw_size;bool kernel_le = false;char *filename; +int spapr_cores = smp_cpus / smp_threads; +int spapr_max_cores = max_cpus / smp_threads; msi_supported = true;
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1821
Quoted 10 lines
hw/ppc/spapr.c +2
-5@@ -1800,13 +1817,38 @@ 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 ); + + spapr->cores =g_malloc0 (spapr_max_cores *sizeof (Object));
souldn't it be sizeof(Object *)
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1824
Quoted 3 lines
hw/ppc/spapr.c +3
-0+ +for (i =0 ; i < spapr_max_cores; i++) { +Object *spapr_cpu_core =object_new (TYPE_SPAPR_CPU_CORE );
you allocate spapr_max_cores cores but set links to only to spapr_cores only, it looks like all spapr_cpu_core objects are leaked for range spapr_cores..spapr_max_cores
Quoted 40 lines
hw/ppc/spapr.c +27
-1+char name[32 ]; + +object_property_set_str (spapr_cpu_core, machine->cpu_model,"cpu_model" , + &error_fatal); +object_property_set_int (spapr_cpu_core, smp_threads,"nr_threads" , + &error_fatal); +/* +* Create links from machine objects to all possible cores. +*/ +snprintf (name,sizeof (name),"%s[%d]" ,SPAPR_MACHINE_CPU_CORE_PROP , i); +object_property_add_link (OBJECT (spapr), name,TYPE_SPAPR_CPU_CORE , + (Object **)&spapr->cores[i], + spapr_cpu_core_allow_set_link,0 , + &error_fatal); + +/* +* Set the link from machine object to core object for all +* boot time CPUs specified with -smp and realize them. +* For rest of the hotpluggable cores this is happens from +* the core hotplug/realization path. +*/ +if (i < spapr_cores) { +object_property_set_str (spapr_cpu_core, name, +SPAPR_CPU_CORE_SLOT_PROP , &error_fatal); +object_property_set_bool (spapr_cpu_core, true,"realized" , + &error_fatal); } -spapr_cpu_init (spapr, cpu, &error_fatal); }if (kvm_enabled ()) {@@ -2209,6 +2251,7 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (hotplug_dev);if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {int node;
hw/ppc/spapr.c static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, · line 2291
Quoted 4 lines
hw/ppc/spapr.c +1
-0@@ -2245,6 +2288,11 @@ 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_CPU )) {
here probably should be CORE and not TYPE_CPU, then if board needs to set some state for child threads it could ennumerate child of core here and do the required job.
Quoted 33 lines
hw/ppc/spapr.c +6
-1+CPUState *cs =CPU (dev); +PowerPCCPU *cpu =POWERPC_CPU (cs); + +spapr_cpu_init (ms, cpu, errp); } }@@ -2259,7 +2307,8 @@ static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev,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_CPU )) {return HOTPLUG_HANDLER (machine); }return NULL ;include/hw/ppc/spapr.h +3
-0@@ -79,8 +79,11 @@ struct sPAPRMachineState {/*< public >*/ char *kvm_type;MemoryHotplugState hotplug_memory; +Object *cores; }; +#define SPAPR_MACHINE_CPU_CORE_PROP "core" +#define H_SUCCESS 0#define H_BUSY 1/* Hardware busy -- retry later */ #define H_CLOSED 2/* Resource closed */
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Bharata B RaoQuoted 5 lines · Bharata B Rao
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.
I guess this is still marked TODO because the series is still RFC?
Quoted 16 lines
Signed-off-by Bharata B Rao <[email protected]>---
+++
b/qapi-schema.jsonqapi-schema.json +7
-0@@ -4083,3 +4083,88 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUInfo: +# +# Information about CPUs +# +# @arch-id: Arch-specific ID for the CPU.
qapi-schema.json line 4102
Quoted 10 lines
qapi-schema.json +10
-0+# +# @type: QOM type of the CPU. +# +# @thread: Thread ID of the CPU. +# +# @core: Core ID of the CPU. +# +# @socket: Socket ID of the CPU. +# +# @node: NUMA node to which the CPU belongs.
Please add the '#optional' tag to the fields which are not always present.
qapi-schema.json line 4111
Quoted 9 lines
qapi-schema.json +9
-0+# +# @qom-path: QOM path of the CPU object +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch-id': 'int', + 'type': 'str',
The TODO in the commit message mentions that this should be converted to an enum.
qapi-schema.json line 4117
Quoted 6 lines
qapi-schema.json +6
-0+ '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom-path': 'str' + }
But looking better than the previous round.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Bharata B RaoQuoted 142 lines · Bharata B Rao
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.Signed-off-by Bharata B Rao <[email protected]>--- hw/core/machine.c | 19 +++++++++ hw/ppc/spapr.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 4 ++ qapi-schema.json | 85 +++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++ 5 files changed, 267 insertions(+)hw/core/machine.c +19
-0@@ -17,6 +17,25 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" +#include "qmp-commands.h" + +/* +* QMP: query-cpu-slots +* +* TODO: Ascertain if this is the right place to for this arch-neutral routine. +*/ +CPUSlotInfoList *qmp_query_cpu_slots (Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +if (!mc->cpu_slots) { +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; + } + +return mc->cpu_slots (ms); +}static char *machine_get_accel (Object *obj,Error **errp) {hw/ppc/spapr.c +89
-0@@ -2453,6 +2453,117 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)return cpu_index / smp_threads / smp_cores; } +static int spapr_cpuinfo_list (Object *obj,void *opaque) +{ +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); +CPUInfoList ***prev = opaque; + +if (object_dynamic_cast (obj,TYPE_CPU )) { +CPUInfoList *elem =g_new0 (CPUInfoList,1 ); +CPUInfo *s =g_new0 (CPUInfo,1 ); +CPUState *cpu =CPU (obj); +PowerPCCPU *pcpu =POWERPC_CPU (cpu); + + s->arch_id =ppc_get_vcpu_dt_id (pcpu); + s->type =g_strdup (object_get_typename (obj)); + s->thread = cpu->cpu_index; + s->has_thread = true; + s->core = cpu->cpu_index / smp_threads; + s->has_core = true; +if (mc->cpu_index_to_socket_id) { + s->socket = mc->cpu_index_to_socket_id (cpu->cpu_index); + }else { + s->socket = cpu->cpu_index / smp_threads / smp_cores; + } + s->has_socket = true; + s->node = cpu->numa_node; + s->has_node = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; + + elem->value = s; + elem->next =NULL ; + **prev = elem; + *prev = &elem->next; + } +object_child_foreach (obj, spapr_cpuinfo_list, opaque); +return 0 ; +} + +static CPUSlotInfoList *spapr_cpu_slots (MachineState *machine) +{ +CPUSlotInfoList *head =NULL ; +CPUSlotInfoList **prev = &head; +Object *root_container; +ObjectProperty *prop; +ObjectPropertyIterator iter; + +/* +* TODO: There surely must be a better/easier way to walk all +* the link properties of an object ? +*/ + root_container =container_get (object_get_root (),"/machine" ); +object_property_iter_init (&iter, root_container); + +while ((prop =object_property_iter_next (&iter))) { +Object *obj; +DeviceState *dev; +CPUSlotInfoList *elem; +CPUSlotInfo *s; +CPUInfoList *cpu_head =NULL ; +CPUInfoList **cpu_prev = &cpu_head; +sPAPRCPUCore *core; + +if (!strstart (prop->type,"link<" ,NULL )) { +continue ; + } + +if (!strstart (prop->name,SPAPR_MACHINE_CPU_CORE_PROP ,NULL )) { +continue ; + } + + elem =g_new0 (CPUSlotInfoList,1 ); + s =g_new0 (CPUSlotInfo,1 ); + + obj =object_property_get_link (root_container, prop->name,NULL ); +if (obj) { +/* Slot populated */ + dev =DEVICE (obj); + core =SPAPR_CPU_CORE (obj); + +if (dev->id) { + s->has_id = true; + s->id =g_strdup (dev->id); + } + s->realized =object_property_get_bool (obj,"realized" ,NULL ); + s->nr_cpus = core->nr_threads; + s->has_nr_cpus = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; +if (s->realized) { +spapr_cpuinfo_list (obj, &cpu_prev);
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2554
Quoted 10 lines
hw/ppc/spapr.c +10
-0+ } + s->has_cpus = true; + }else { +/* Slot empty */ + s->has_id = false; + s->has_nr_cpus = false; + s->has_qom_path = false; + s->has_cpus = false; + s->realized = false; + }
I think you could drop that whole else-path since you've already used g_new0 to make sure that the memory of the new CPUSlotInfo is cleared.
hw/ppc/spapr.c static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index) · line 2565
Quoted 11 lines
hw/ppc/spapr.c +11
-0+ s->type =g_strdup (TYPE_SPAPR_CPU_CORE ); + s->hotplug_granularity =g_strdup (SPAPR_MACHINE_CPU_CORE_PROP ); + s->slot_id =g_strdup (prop->name); + s->cpus = cpu_head; + elem->value = s; + elem->next =NULL ; + *prev = elem; + prev = &elem->next; + } +return head; +}
Thomas
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Bharata B RaoQuoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 208 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +177
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ + object_property_add(obj, "nr_threads", "int", + spapr_cpu_core_prop_get_nr_threads,
hw/ppc/spapr_cpu_core.c line 187
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+ spapr_cpu_core_prop_set_nr_threads, + NULL, NULL, NULL); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); +object_property_add_str (obj,"slot" , + spapr_cpu_core_prop_get_slot, + spapr_cpu_core_prop_set_slot, +NULL );
"slot" seems intended to be a machine-agnostic of mapping device types discovered from qmp_query_cpu_slots() to an appropriate "bus" location, but here's it a field specific to TYPE_SPAPR_CPU_CORE. It seems like maybe TYPE_CPU_CORE is a better place, but then on x86 I suppose it might be TYPE_CPU_SOCKET or something instead...
It almost seems like a TYPE_INTERFACE_SLOTABLE would be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists if qmp_query_cpu_slots() returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.
Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Quoted 64 lines
hw/ppc/spapr_cpu_core.c new file +23
-0+} + +static void spapr_cpu_core_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = spapr_cpu_core_realize; +} + +static const TypeInfo spapr_cpu_core_type_info = { + .name =TYPE_SPAPR_CPU_CORE , + .parent =TYPE_CPU_CORE , + .instance_init = spapr_cpu_core_instance_init, + .instance_size =sizeof (sPAPRCPUCore), + .class_init = spapr_cpu_core_class_init, +}; + +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 +32
-0@@ -0,0 +1,32 @@ +/* +* 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 >*/ +DeviceState parent_obj; + +/*< public >*/ +int nr_threads; +char *cpu_model; +char *slot; +PowerPCCPU *threads; +}sPAPRCPUCore ; + +#define SPAPR_CPU_CORE_SLOT_PROP "slot" + +#endif Signature · 1 line
2.1.0
Re: [Qemu-devel] [RFC PATCH v0 4/6] spapr: CPU hotplug support
In reply to David GibsonQuoted 185 lines · David Gibson
Quoted 184 lines · Bharata B Rao
Set up device tree entries for the hotplugged CPU core and use the exising EPOW event infrastructure to send CPU hotplug notification to the guest.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- hw/ppc/spapr_events.c | 3 ++ hw/ppc/spapr_rtas.c | 24 +++++++++ include/hw/ppc/spapr.h | 1 + 4 files changed, 163 insertions(+), 1 deletion(-)hw/ppc/spapr.c +128
-0@@ -603,6 +603,18 @@ 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)}; +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRDRConnector *drc; +sPAPRDRConnectorClass *drck; +int drc_index; + +if (smc->dr_cpu_enabled) { + drc =spapr_dr_connector_by_id (SPAPR_DR_CONNECTOR_TYPE_CPU , index); +g_assert (drc); + drck =SPAPR_DR_CONNECTOR_GET_CLASS (drc); + drc_index = drck->get_index (drc); +_FDT ((fdt_setprop_cell (fdt, offset,"ibm,my-drc-index" , drc_index))); + }/* 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 +999,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 ) { +fprintf (stderr,"Couldn't set up CPU DR device tree properties\n" ); +exit (1 ); + } + } +_FDT ((fdt_pack (fdt)));if (fdt_totalsize (fdt) >FDT_MAX_SIZE ) {@@ -1759,6 +1781,7 @@ static void ppc_spapr_init(MachineState *machine)char *filename;int spapr_cores = smp_cpus / smp_threads;int spapr_max_cores = max_cpus / smp_threads; +int smt =kvmppc_smt_threads (); msi_supported = true;@@ -1813,6 +1836,15 @@ static void ppc_spapr_init(MachineState *machine)spapr_validate_node_memory (machine, &error_fatal); } +if (smc->dr_cpu_enabled) { +for (i =0 ; i < spapr_max_cores; i++) { +sPAPRDRConnector *drc = +spapr_dr_connector_new (OBJECT (spapr), +SPAPR_DR_CONNECTOR_TYPE_CPU , i * smt); +qemu_register_reset (spapr_drc_reset, drc); + } + } +/* init CPUs */ if (machine->cpu_model ==NULL ) { machine->cpu_model =kvm_enabled () ?"host" :"POWER7" ;@@ -2247,6 +2279,88 @@ out:error_propagate (errp, local_err); } +static void *spapr_populate_hotplug_cpu_dt (DeviceState *dev,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_core_plug (HotplugHandler *hotplug_dev,DeviceState *dev, +Error **errp) +{ +sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (qdev_get_machine ()); +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +PowerPCCPU *cpu = &core->threads[0 ]; +CPUState *cs =CPU (cpu); +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 ; +void *fdt =NULL ; +int fdt_offset =0 ; + +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 (dev, cs, &fdt_offset, ms); + 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); +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 ); + } +return ; +} +static void spapr_machine_device_plug (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) {@@ -2291,8 +2405,25 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {CPUState *cs =CPU (dev);PowerPCCPU *cpu =POWERPC_CPU (cs); +int i; + +if (!smc->dr_cpu_enabled && dev->hotplugged) { +error_setg (errp,"CPU hotplug not supported for this machine" ); +return ; + } + +/* 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 ; + } + }
Quoted 5 lines
hw/ppc/spapr.c static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, · line 2424
Quoted 2 lines
hw/ppc/spapr.c +1
-0spapr_cpu_init (ms, cpu, errp); +spapr_cpu_reset (cpu);It looks to me like all of this setup should be either in the last patch, or in this one, not split between them.
The way I have done the functional split is like this:
- Introduce the spapr-cpu-core device as the 2nd patch in the series
- The previous patch converts the boot CPU initialization into spapr-cpu-core creation. So until this point, we can just boot a guest with this CPUs created as core devices.
- Then this patch adds the bits needed to actually perform a device_add operation of core device.
But I am open to re-arrange things if you feel it is necessary.
Quoted 79 lines
Quoted 79 lines
hw/ppc/spapr.c +6
-1+ }else if (object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) { +spapr_core_plug (hotplug_dev, dev, errp); } }@@ -2308,7 +2439,8 @@ static HotplugHandler *spapr_get_hotpug_handler(MachineState *machine, DeviceState *dev) {if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) || -object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +object_dynamic_cast (OBJECT (dev),TYPE_CPU ) || +object_dynamic_cast (OBJECT (dev),TYPE_SPAPR_CPU_CORE )) {return HOTPLUG_HANDLER (machine); }return NULL ;@@ -2352,6 +2484,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) 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; }@@ -2431,6 +2564,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_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 +18
-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)) {
Quoted 8 lines
hw/ppc/spapr_rtas.c static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_, · line 185
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+ cpu->env.spr[SPR_LPCR ] |=LPCR_ILE ; + } +} +Any particular reason for doing these things at
rtas_start_cpu()time, but other initialization at plug time? Could you consolidate it to one place or the other?
Those board specific things that are needed to be done have been consolidated into spapr_cpu_init() which will be called from the plug handler. We have discussed this earlier at:
https://lists.nongnu.org/archive/html/qemu-devel/2015-02/msg04399.html
It has been a while but there was a good reason why setting endianness here rather than in plug handler is necessary. W/o this LE hotplug on guests wouldn't work, I will dig up and come back on what exactly necessiated this change.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Michael RothQuoted 233 lines · Michael Roth
Quoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 208 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +177
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ + object_property_add(obj, "nr_threads", "int", + spapr_cpu_core_prop_get_nr_threads,hw/ppc/spapr_cpu_core.c line 187
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+ spapr_cpu_core_prop_set_nr_threads, + NULL, NULL, NULL); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); +object_property_add_str (obj,"slot" , + spapr_cpu_core_prop_get_slot, + spapr_cpu_core_prop_set_slot, +NULL );"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.
Quoted 3 lines
Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yeah, TBH the "slot" stuff has me a bit confused still. I'm intending to have a closer look at it once the more obvious cleanups are addressed.
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 v0 3/6] spapr: Represent boot CPUs as spapr-cpu-core devices
In reply to Igor MammedovQuoted 66 lines · Igor Mammedov
Quoted 63 lines · On Thu, 25 Feb 2016 21:52:39 +0530 Bharata B Rao <[email protected]>…
Initialize boot CPUs as spapr-cpu-core devices and create links from machine object to these core devices. These links can be considered as CPU slots in which core devices will get hot-plugged. spapr-cpu-core device's slot property indicates the slot where it is plugged. Information about all the CPU slots can be obtained by walking these links.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/spapr.c | 65 +++++++++++++++++++++++++++++++++++++++++++------- include/hw/ppc/spapr.h | 3 +++ 2 files changed, 60 insertions(+), 8 deletions(-)hw/ppc/spapr.c +18
-1@@ -64,6 +64,7 @@#include "hw/compat.h" #include "qemu-common.h" +#include "hw/ppc/spapr_cpu_core.h" #include <libfdt.h> @@ -1720,6 +1721,21 @@ static void spapr_validate_node_memory(MachineState *machine, Error **errp) } } +/* +* Check to see if core is being hot-plugged into an already populated slot. +*/ +static void spapr_cpu_core_allow_set_link (Object *obj,const char *name, +Object *val,Error **errp) +{ +Object *core =object_property_get_link (qdev_get_machine (), name,NULL ); + +if (core) { +char *path =object_get_canonical_path (core); +error_setg (errp,"Slot %s already populated with %s" , name, path); +g_free (path); + } +} +/* pSeries LPAR / sPAPR hardware init */ static void ppc_spapr_init (MachineState *machine) {@@ -1728,7 +1744,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 ();@@ -1742,6 +1757,8 @@ static void ppc_spapr_init(MachineState *machine)long load_limit, fw_size;bool kernel_le = false;char *filename; +int spapr_cores = smp_cpus / smp_threads; +int spapr_max_cores = max_cpus / smp_threads; msi_supported = true;
Quoted 12 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1821
Quoted 11 lines
hw/ppc/spapr.c +2
-5@@ -1800,13 +1817,38 @@ 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 ); + + spapr->cores =g_malloc0 (spapr_max_cores *sizeof (Object));souldn't it be
sizeof(Object *)
Yes, I meant to store the pointers to Object here, will change.
Quoted 7 lines
hw/ppc/spapr.c static void ppc_spapr_init(MachineState *machine) · line 1824
Quoted 4 lines
hw/ppc/spapr.c +3
-0+ +for (i =0 ; i < spapr_max_cores; i++) { +Object *spapr_cpu_core =object_new (TYPE_SPAPR_CPU_CORE );you allocate
spapr_max_corescores but set links to only tospapr_coresonly, it looks like allspapr_cpu_coreobjects are leaked for range spapr_cores..spapr_max_cores
Yes, as I replied in an ealier thread, the intention is to create links for all possible cores, but create only those many cores required for CPUs specified with -smp from machine init. The links will be set only for those cores. Hotplugged cores will get created and the links will be set for them during device_add. So the changed code now looks like this:
for (i = 0; i < spapr_max_cores; i++) {
char name[32];
/*
* Create links from machine objects to all possible cores.
*/
snprintf(name, sizeof(name), "%s[%d]", SPAPR_MACHINE_CPU_CORE_PROP, i);
object_property_add_link(OBJECT(spapr), name, TYPE_SPAPR_CPU_CORE,
(Object **)&spapr->cores[i],
spapr_cpu_core_allow_set_link, 0,
&error_fatal);
/*
* Create cores and set link from machine object to core object for
* boot time CPUs and realize them.
*/
if (i < spapr_cores) {
Object *core = object_new(TYPE_SPAPR_CPU_CORE);
object_property_set_str(core, machine->cpu_model, "cpu_model",
&error_fatal);
object_property_set_int(core, smp_threads, "nr_threads",
&error_fatal);
object_property_set_str(core, name, SPAPR_CPU_CORE_SLOT_PROP,
&error_fatal);
object_property_set_bool(core, true, "realized", &error_fatal);
}
}Quoted 43 lines
Quoted 43 lines
hw/ppc/spapr.c +27
-1+char name[32 ]; + +object_property_set_str (spapr_cpu_core, machine->cpu_model,"cpu_model" , + &error_fatal); +object_property_set_int (spapr_cpu_core, smp_threads,"nr_threads" , + &error_fatal); +/* +* Create links from machine objects to all possible cores. +*/ +snprintf (name,sizeof (name),"%s[%d]" ,SPAPR_MACHINE_CPU_CORE_PROP , i); +object_property_add_link (OBJECT (spapr), name,TYPE_SPAPR_CPU_CORE , + (Object **)&spapr->cores[i], + spapr_cpu_core_allow_set_link,0 , + &error_fatal); + +/* +* Set the link from machine object to core object for all +* boot time CPUs specified with -smp and realize them. +* For rest of the hotpluggable cores this is happens from +* the core hotplug/realization path. +*/ +if (i < spapr_cores) { +object_property_set_str (spapr_cpu_core, name, +SPAPR_CPU_CORE_SLOT_PROP , &error_fatal); +object_property_set_bool (spapr_cpu_core, true,"realized" , + &error_fatal); } -spapr_cpu_init (spapr, cpu, &error_fatal); }if (kvm_enabled ()) {@@ -2209,6 +2251,7 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (hotplug_dev);if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {int node;@@ -2245,6 +2288,11 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, }
Quoted 5 lines
hw/ppc/spapr.c static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, · line 2291
Quoted 2 lines
hw/ppc/spapr.c +1
-0spapr_memory_plug (hotplug_dev, dev, node, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {here probably should be CORE and not
TYPE_CPU, then if board needs to set some state for child threads it could ennumerate child of core here and do the required job.
Hmm, we have things to set for CPUs and cores as well from hotplug handler. So the above code is for CPUs and I have spapr_core_plug() which is called conditionally when device is of type TYPE_SPAPR_CPU_CORE.
Given that ->plug() is called during realization of both individual CPU threads as well as their parent core, I thought handling the setup for them separately like the above is simpler, no ?
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Thomas HuthQuoted 98 lines · Thomas Huth
Quoted 6 lines · Bharata B Rao
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>---
...
Quoted 90 lines
hw/ppc/spapr_cpu_core.c new file +84
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + + snprintf(type, sizeof(type), "%s-%s", core->cpu_model,
Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 90
Quoted 6 lines
hw/ppc/spapr_cpu_core.c new file +6
-0+ TYPE_POWERPC_CPU); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp);Need to check errp here to see whether something went wrong?
Yes, I will use local_err and them propagate.
Quoted 31 lines
Quoted 31 lines
hw/ppc/spapr_cpu_core.c new file +30
-0+ } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ());
Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 126
Quoted 6 lines
hw/ppc/spapr_cpu_core.c new file +6
-0+ +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model);s/should/must/
sure :)
Quoted 40 lines
Quoted 27 lines
hw/ppc/spapr_cpu_core.c new file +26
-0+return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value;hw/ppc/spapr_cpu_core.c line 162
Quoted 10 lines
hw/ppc/spapr_cpu_core.c new file +10
-0+ +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads);s/should/must/
Quoted 7 lines
hw/ppc/spapr_cpu_core.c line 167
Quoted 5 lines
hw/ppc/spapr_cpu_core.c new file +5
-0+return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU));I think it's preferable to use
g_new0for such allocations instead.
Ok.
Quoted 4 lines
Also, should this memory maybe be freed during
instance_finalizeagain, so that there is no memory leak here in case the cores are deleted again one day?
I will be forced to care of this when I add hot removal in the next version.
Quoted 72 lines
Quoted 72 lines
hw/ppc/spapr_cpu_core.c new file +42
-0+if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); +object_property_add_str (obj,"slot" , + spapr_cpu_core_prop_get_slot, + spapr_cpu_core_prop_set_slot, +NULL ); +} + +static void spapr_cpu_core_class_init (ObjectClass *oc,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (oc); + + dc->realize = spapr_cpu_core_realize; +} + +static const TypeInfo spapr_cpu_core_type_info = { + .name =TYPE_SPAPR_CPU_CORE , + .parent =TYPE_CPU_CORE , + .instance_init = spapr_cpu_core_instance_init, + .instance_size =sizeof (sPAPRCPUCore), + .class_init = spapr_cpu_core_class_init, +}; + +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 +23
-0@@ -0,0 +1,32 @@ +/* +* 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 >*/ + DeviceState parent_obj; + + /*< public >*/
Quoted 8 lines
include/hw/ppc/spapr_cpu_core.h line 26
Quoted 3 lines
include/hw/ppc/spapr_cpu_core.h new file +3
-0+int nr_threads; +char *cpu_model; +char *slot;<bikeshedpainting>
I'd maybe call that "slot_name" instead ... if you only call it "slot", I'd rather think of an integer value than a string here. </bikeshedpainting>
Point taken, pc-dimm has slot which is a number :)
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Eric BlakeQuoted 8 lines · Eric Blake
Quoted 5 lines · Bharata B Rao
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.I guess this is still marked TODO because the series is still RFC?
Yes.
Quoted 21 lines
Quoted 21 lines
Signed-off-by Bharata B Rao <[email protected]>---
+++
b/qapi-schema.jsonqapi-schema.json +11
-0@@ -4083,3 +4083,88 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUInfo: +# +# Information about CPUs +# +# @arch-id: Arch-specific ID for the CPU. +# +# @type: QOM type of the CPU. +# +# @thread: Thread ID of the CPU.
Quoted 9 lines
qapi-schema.json line 4102
Quoted 6 lines
qapi-schema.json +6
-0+# +# @core: Core ID of the CPU. +# +# @socket: Socket ID of the CPU. +# +# @node: NUMA node to which the CPU belongs.Please add the '#optional' tag to the fields which are not always present.
Sure.
Quoted 13 lines
qapi-schema.json line 4111
Quoted 9 lines
qapi-schema.json +9
-0+# +# @qom-path: QOM path of the CPU object +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch-id': 'int', + 'type': 'str',The TODO in the commit message mentions that this should be converted to an enum.
Quoted 8 lines
qapi-schema.json line 4117
Quoted 6 lines
qapi-schema.json +6
-0+ '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom-path': 'str' + }But looking better than the previous round.
Thanks for the review. Do you have any comments on the applicability/suitability of this interface from libvirt point of view for performing device_add based CPU hotplug ?
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Michael RothQuoted 217 lines · Michael Roth
Quoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 216 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +185
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); + object_property_add_str(obj, "slot", + spapr_cpu_core_prop_get_slot,
Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 187
Quoted 2 lines
hw/ppc/spapr_cpu_core.c new file +2
-0+ spapr_cpu_core_prop_set_slot, + NULL);"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...
Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 3/6] spapr: Represent boot CPUs as spapr-cpu-core devices
In reply to Bharata B RaoQuoted 3 lines · Bharata B Rao
Quoted 2 lines · Igor Mammedov
On Thu, 25 Feb 2016 21:52:39 +0530
Bharata B Rao <[email protected]> wrote:
[snip]
Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
hw/ppc/spapr.c +1
-0@@ -2209,6 +2251,7 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) {sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (qdev_get_machine ()); +sPAPRMachineState *ms =SPAPR_MACHINE (hotplug_dev);if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {int node;@@ -2245,6 +2288,11 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, }Quoted 5 lines
hw/ppc/spapr.c static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, · line 2291
Quoted 2 lines
hw/ppc/spapr.c +1
-0spapr_memory_plug (hotplug_dev, dev, node, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {here probably should be CORE and not
TYPE_CPU, then if board needs to set some state for child threads it could ennumerate child of core here and do the required job.
Quoted 7 lines
Hmm, we have things to set for CPUs and cores as well from hotplug handler. So the above code is for CPUs and I have
spapr_core_plug()which is called conditionally when device is of typeTYPE_SPAPR_CPU_CORE.Given that ->plug() is called during realization of both individual CPU threads as well as their parent core, I thought handling the setup for them separately like the above is simpler, no ?
So, this bothered me a bit as well. I think having the hotplug handler for the threads is misleading, since it suggests you can individually hotplug them, when in fact the intention is just that this is part of the hotplug code path for a whole core.
My suggestion earlier was to have the core realize code itself perform this configuration on the sub-threads. However, Igor's suggestion of, essentially, an explicit loop over the threads in the core hotplug handler would be fine by me also.
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 v0 2/6] spapr: CPU core device
In reply to Bharata B RaoQuoted 241 lines · On Mon, 29 Feb 2016 11:20:19 +0530 Bharata B Rao <[email protected]>…
Quoted 217 lines · Michael Roth
Quoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 216 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +185
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); + object_property_add_str(obj, "slot", + spapr_cpu_core_prop_get_slot,Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 187
Quoted 2 lines
hw/ppc/spapr_cpu_core.c new file +2
-0+ spapr_cpu_core_prop_set_slot, + NULL);"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Quoted 6 lines
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Then what will happen to slot if there isn't any core/socket device to query it, i.e. cpu hasn't been plugged in yet?
To me slot looks like a machine belonged feature.
Quoted 4 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Bharata B RaoQuoted 262 lines · On Thu, 25 Feb 2016 21:52:41 +0530 Bharata B Rao <[email protected]>…
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.Signed-off-by Bharata B Rao <[email protected]>--- hw/core/machine.c | 19 +++++++++ hw/ppc/spapr.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 4 ++ qapi-schema.json | 85 +++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++ 5 files changed, 267 insertions(+)hw/core/machine.c +19
-0@@ -17,6 +17,25 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" +#include "qmp-commands.h" + +/* +* QMP: query-cpu-slots +* +* TODO: Ascertain if this is the right place to for this arch-neutral routine. +*/ +CPUSlotInfoList *qmp_query_cpu_slots (Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +if (!mc->cpu_slots) { +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; + } + +return mc->cpu_slots (ms); +}static char *machine_get_accel (Object *obj,Error **errp) {hw/ppc/spapr.c +112
-0@@ -2453,6 +2453,117 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)return cpu_index / smp_threads / smp_cores; } +static int spapr_cpuinfo_list (Object *obj,void *opaque) +{ +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); +CPUInfoList ***prev = opaque; + +if (object_dynamic_cast (obj,TYPE_CPU )) { +CPUInfoList *elem =g_new0 (CPUInfoList,1 ); +CPUInfo *s =g_new0 (CPUInfo,1 ); +CPUState *cpu =CPU (obj); +PowerPCCPU *pcpu =POWERPC_CPU (cpu); + + s->arch_id =ppc_get_vcpu_dt_id (pcpu); + s->type =g_strdup (object_get_typename (obj)); + s->thread = cpu->cpu_index; + s->has_thread = true; + s->core = cpu->cpu_index / smp_threads; + s->has_core = true; +if (mc->cpu_index_to_socket_id) { + s->socket = mc->cpu_index_to_socket_id (cpu->cpu_index); + }else { + s->socket = cpu->cpu_index / smp_threads / smp_cores; + } + s->has_socket = true; + s->node = cpu->numa_node; + s->has_node = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; + + elem->value = s; + elem->next =NULL ; + **prev = elem; + *prev = &elem->next; + } +object_child_foreach (obj, spapr_cpuinfo_list, opaque); +return 0 ; +} + +static CPUSlotInfoList *spapr_cpu_slots (MachineState *machine) +{ +CPUSlotInfoList *head =NULL ; +CPUSlotInfoList **prev = &head; +Object *root_container; +ObjectProperty *prop; +ObjectPropertyIterator iter; + +/* +* TODO: There surely must be a better/easier way to walk all +* the link properties of an object ? +*/ + root_container =container_get (object_get_root (),"/machine" ); +object_property_iter_init (&iter, root_container); + +while ((prop =object_property_iter_next (&iter))) { +Object *obj; +DeviceState *dev; +CPUSlotInfoList *elem; +CPUSlotInfo *s; +CPUInfoList *cpu_head =NULL ; +CPUInfoList **cpu_prev = &cpu_head; +sPAPRCPUCore *core; + +if (!strstart (prop->type,"link<" ,NULL )) { +continue ; + } + +if (!strstart (prop->name,SPAPR_MACHINE_CPU_CORE_PROP ,NULL )) { +continue ; + } + + elem =g_new0 (CPUSlotInfoList,1 ); + s =g_new0 (CPUSlotInfo,1 ); + + obj =object_property_get_link (root_container, prop->name,NULL ); +if (obj) { +/* Slot populated */ + dev =DEVICE (obj); + core =SPAPR_CPU_CORE (obj); + +if (dev->id) { + s->has_id = true; + s->id =g_strdup (dev->id); + } + s->realized =object_property_get_bool (obj,"realized" ,NULL ); + s->nr_cpus = core->nr_threads; + s->has_nr_cpus = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; +if (s->realized) { +spapr_cpuinfo_list (obj, &cpu_prev); + } + s->has_cpus = true; + }else { +/* Slot empty */ + s->has_id = false; + s->has_nr_cpus = false; + s->has_qom_path = false; + s->has_cpus = false; + s->realized = false; + } + s->type =g_strdup (TYPE_SPAPR_CPU_CORE ); + s->hotplug_granularity =g_strdup (SPAPR_MACHINE_CPU_CORE_PROP ); + s->slot_id =g_strdup (prop->name); + s->cpus = cpu_head; + elem->value = s; + elem->next =NULL ; + *prev = elem; + prev = &elem->next; + } +return head; +} +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -2482,6 +2593,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) hc->plug = spapr_machine_device_plug; hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; + mc->cpu_slots = spapr_cpu_slots; smc->dr_lmb_enabled = true; smc->dr_cpu_enabled = true;include/hw/boards.h +4
-0@@ -57,6 +57,9 @@ bool machine_mem_merge(MachineState *machine);* Set only by old machines because they need to keep * compatibility on code that exposed QEMU_VERSION to guests in * the past (and now use qemu_hw_version()). +* @cpu_slots: +* Provides information about populated and yet-to-be populated +* CPU slots in the machine. Used by QMP query-cpu-slots. */ struct MachineClass {/*< private >*/ @@ -99,6 +102,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + CPUSlotInfoList *(*cpu_slots)(MachineState *machine); };/** qapi-schema.json +57
-0@@ -4083,3 +4083,88 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUInfo: +# +# Information about CPUs +# +# @arch-id: Arch-specific ID for the CPU. +# +# @type: QOM type of the CPU. +# +# @thread: Thread ID of the CPU. +# +# @core: Core ID of the CPU. +# +# @socket: Socket ID of the CPU. +# +# @node: NUMA node to which the CPU belongs. +# +# @qom-path: QOM path of the CPU object +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch-id': 'int', + 'type': 'str', + '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom-path': 'str' + } +} + +## +# @CPUSlotInfo: +# +# Information about CPU Slots +# +# @id: Device ID of the CPU composite object that occupies the slot. +# +# @type: QOM type of the CPU composite object that occupies the slot. +# +# @hotplug-granularity: Granularity of CPU composite hotplug for this slot, +# can be thread, core or socket. +# +# @slot-id: Slot's identifier. +# +# @qom-path: QOM path of the CPU composite object that occupies the slot. +# +# @realized: A boolean that indicates whether the slot is filled or empty. +# +# @nr-cpus: Number of CPUs that are part of CPU composite object that occupies +# this slot. +# +# @cpus: An array of @CPUInfo elements where each element describes one +# CPU that is part of this slot's CPU composite object.
qapi-schema.json line 4152
Quoted 10 lines
qapi-schema.json +10
-0+# +# @type: QOM type +# +# Since: 2.6 +## + +{ 'struct': 'CPUSlotInfo', + 'data': { '*id': 'str', + 'type': 'str', + 'hotplug-granularity' : 'str',
Does it convey any useful info, if yes how it will be used by mgmt?
qapi-schema.json line 4155
Quoted 3 lines
qapi-schema.json +3
-0+ 'slot-id' : 'str', + '*qom-path': 'str', + 'realized': 'bool',
field's redundant, presence of qom-path answers this question
qapi-schema.json line 4157
Quoted 2 lines
qapi-schema.json +2
-0+ '*nr-cpus': 'int', + '*cpus' : ['CPUInfo']
I'd suggest to drop above 2 fields as it's impl dependent, qom-path already point's to socket/core/thread object and its internal composition can be explored by other means if needed.
Moreover 'CPUInfo' is confusing and sort of conflicts with existing 'CpuInfo'.
I'd drop CPUInfo altogether and introduce only 'CPUSlotInfo' here, existing thread enumeration's already implemented query-cpus.
qapi-schema.json line 4159
Quoted 2 lines
qapi-schema.json +2
-0+ } +}
What I miss here is that CPUSlotInfo doesn't provide any information to about where CPU might be hotplugged to.
Maybe use following tuple instead of slot-id?
{ 'struct': 'CPUSlotProperties',
'data': { '*node': 'int',
'*socket': 'int',
'*core': 'int',
'*thread': 'int' }
}
it's generic for the most targets, which should work for spapr, s390, x86, ARM and could be extended for other cases adding other board specific properties if it's needed.
The all mgmt would have to do for hotplug is to execute:
device_add ${type},${CPUSlotProperties}
Quoted 66 lines
qapi-schema.json +11
-0+ +## +# @query-cpu-slots: +# +# Returns information for all CPU slots +# +# Returns: a list of @CPUSlotInfo +# +# Since: 2.6 +## +{ 'command': 'query-cpu-slots', 'returns': ['CPUSlotInfo'] }qmp-commands.hx +47
-0@@ -4825,3 +4825,50 @@ Example: {"type": 0, "out-pport": 0, "pport": 0, "vlan-id": 3840, "pop-vlan": 1, "id": 251658240} ]} + +EQMP + + { + .name = "query-cpu-slots", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_query_cpu_slots, + }, + +SQMP +@query-cpu-slots +-------------------- + +Show CPU slots information + +Example: +-> { "execute": "query-cpu-slots" } +<- {"return": [{ + "slot-id": "core[2]", + "hotplug-granularity": "core", + "realized": false, + "type": "spapr-cpu-core" + }, + { + "slot-id": "core[1]", + "qom-path": "/machine/unattached/device[2]", + "hotplug-granularity": "core", + "realized": true, + "type": "spapr-cpu-core" + "nr-cpus": 2, + "cpus": [ + {"thread": 8, + "socket": 0, + "core": 1, + "arch-id": 8, + "qom-path": "/machine/unattached/device[2]/thread[0]", + "node": 0, + "type": "host-powerpc64-cpu"}, + {"thread": 9, + "socket": 0, + "core": 1, + "arch-id": 9, + "qom-path": "/machine/unattached/device[2]/thread[2]", + "node": 0, + "type": "host-powerpc64-cpu"}] + } + ]}
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Igor MammedovQuoted 247 lines · Igor Mammedov
Quoted 244 lines · On Mon, 29 Feb 2016 11:20:19 +0530 Bharata B Rao <[email protected]>…
Quoted 217 lines · Michael Roth
Quoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 216 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +185
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); + object_property_add_str(obj, "slot", + spapr_cpu_core_prop_get_slot,Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 187
Quoted 2 lines
hw/ppc/spapr_cpu_core.c new file +2
-0+ spapr_cpu_core_prop_set_slot, + NULL);"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
Quoted 6 lines
Quoted 3 lines
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Then what will happen to slot if there isn't any core/socket device to query it, i.e. cpu hasn't been plugged in yet?
To me slot looks like a machine belonged feature.
Yes slot belongs to the machine and it is represented by a link that is created b/n the machine object and the core object that sits in the slot.
In the context of this thread, slot is actually the slot name that identifies the machine slot which the core occupies or will occupy after hotplug. Thus slot name which is named slot here, it is a property of the core device.
(qemu) device_add spapr-cpu-core,slot=core[2]
^
Regards,
Bharata.
Quoted 5 lines
Quoted 5 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
Quoted 259 lines · On Mon, 29 Feb 2016 18:25:25 +0530 Bharata B Rao <[email protected]>…
Quoted 247 lines · Igor Mammedov
Quoted 244 lines · On Mon, 29 Feb 2016 11:20:19 +0530 Bharata B Rao <[email protected]>…
Quoted 217 lines · Michael Roth
Quoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 216 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +185
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); + object_property_add_str(obj, "slot", + spapr_cpu_core_prop_get_slot,Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 187
Quoted 2 lines
hw/ppc/spapr_cpu_core.c new file +2
-0+ spapr_cpu_core_prop_set_slot, + NULL);"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
Quoted 6 lines
Quoted 3 lines
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Then what will happen to slot if there isn't any core/socket device to query it, i.e. cpu hasn't been plugged in yet?
To me slot looks like a machine belonged feature.Yes slot belongs to the machine and it is represented by a link that is created b/n the machine object and the core object that sits in the slot.
Quoted 7 lines
In the context of this thread, slot is actually the slot name that identifies the machine slot which the core occupies or will occupy after hotplug. Thus slot name which is named slot here, it is a property of the core device.
(qemu)
device_addspapr-cpu-core,slot=core[2]^
Is 'slot' a term used by SPAPR on real hardware?
I'd thought that it's 'core', that's why I suggested to use 'core' for POWER as that matched real world concept, see
my other reply in "[RFC PATCH v0 4/6] spapr: CPU hotplug support" thread of this series.
Quoted 8 lines
Regards,
Bharata.Quoted 5 lines
Quoted 5 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
Quoted 5 lines · Igor Mammedov
Quoted 3 lines · On Mon, 29 Feb 2016 18:25:25 +0530 Bharata B Rao <[email protected]>…
Quoted 2 lines · Igor Mammedov
On Mon, 29 Feb 2016 11:20:19 +0530
Bharata B Rao <[email protected]> wrote:
[snip]
Quoted 34 lines
Quoted 34 lines
Quoted 23 lines
Quoted 23 lines
Quoted 5 lines
"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
Quoted 6 lines
Quoted 3 lines
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Then what will happen to slot if there isn't any core/socket device to query it, i.e. cpu hasn't been plugged in yet?
To me slot looks like a machine belonged feature.Yes slot belongs to the machine and it is represented by a link that is created b/n the machine object and the core object that sits in the slot.
Quoted 8 lines
Quoted 7 lines
In the context of this thread, slot is actually the slot name that identifies the machine slot which the core occupies or will occupy after hotplug. Thus slot name which is named slot here, it is a property of the core device.
(qemu)
device_addspapr-cpu-core,slot=core[2]^Is 'slot' a term used by SPAPR on real hardware?
So.. PAPR is a para-virtualized interface, so it never appears on real hardware.
But, no, "slot" is not a term used by PAPR.
Quoted 4 lines
I'd thought that it's 'core', that's why I suggested to use 'core' for POWER as that matched real world concept, see
my other reply in "[RFC PATCH v0 4/6] spapr: CPU hotplug support" thread of this series.
I don't think it uses "core" either, I believe it uses just "cpu" but meaning a multi-thread core, rather than a single logical cpu thread.
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 v0 4/6] spapr: CPU hotplug support
In reply to Bharata B RaoQuoted 46 lines · Bharata B Rao
Quoted 33 lines
Quoted 33 lines
hw/ppc/spapr_rtas.c +18
-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)) {Quoted 8 lines
hw/ppc/spapr_rtas.c static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_, · line 185
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+ cpu->env.spr[SPR_LPCR ] |=LPCR_ILE ; + } +} +Any particular reason for doing these things at
rtas_start_cpu()time, but other initialization at plug time? Could you consolidate it to one place or the other?Those board specific things that are needed to be done have been consolidated into
spapr_cpu_init()which will be called from the plug handler. We have discussed this earlier at:
Quoted 6 lines
https://lists.nongnu.org/archive/html/qemu-devel/2015-02/msg04399.html
It has been a while but there was a good reason why setting endianness here rather than in plug handler is necessary. W/o this LE hotplug on guests wouldn't work, I will dig up and come back on what exactly necessiated this change.
If we set LPCR_ILE in cpu->env.spr[SPR_LPCR] at plug time (from spapr_cpu_init()), there are at least two places later where it gets over-written. One is spapr_cpu_reset() and the other one when kvm_cpu_synchronize_state() is called from rtas_start_cpu(). We could probably issue a kvm_arch_put_registers(), but I found rtas_start_cpu() as a place where this change is guaranteed to get reflected.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Igor MammedovQuoted 267 lines · Igor Mammedov
Quoted 264 lines · On Mon, 29 Feb 2016 18:25:25 +0530 Bharata B Rao <[email protected]>…
Quoted 247 lines · Igor Mammedov
Quoted 244 lines · On Mon, 29 Feb 2016 11:20:19 +0530 Bharata B Rao <[email protected]>…
Quoted 217 lines · Michael Roth
Quoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 216 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +185
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); + object_property_add_str(obj, "slot", + spapr_cpu_core_prop_get_slot,Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 187
Quoted 2 lines
hw/ppc/spapr_cpu_core.c new file +2
-0+ spapr_cpu_core_prop_set_slot, + NULL);"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
Quoted 6 lines
Quoted 3 lines
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Then what will happen to slot if there isn't any core/socket device to query it, i.e. cpu hasn't been plugged in yet?
To me slot looks like a machine belonged feature.Yes slot belongs to the machine and it is represented by a link that is created b/n the machine object and the core object that sits in the slot.
In the context of this thread, slot is actually the slot name that identifies the machine slot which the core occupies or will occupy after hotplug. Thus slot name which is named slot here, it is a property of the core device.
Quoted 7 lines
Quoted 2 lines
(qemu)
device_addspapr-cpu-core,slot=core[2]^Is 'slot' a term used by SPAPR on real hardware?
I'd thought that it's 'core', that's why I suggested to use 'core' for POWER as that matched real world concept, see
my other reply in "[RFC PATCH v0 4/6] spapr: CPU hotplug support" thread of this series.
I don't see any reply from you to that thread. I guess you mean "[RFC PATCH v0 3/6] spapr: Represent boot CPUs as spapr-cpu-core devices" thread where you suggest to use CORE type rather than TYPE_CPU and enumerate threads under CORE type.
In case, it didn't come out clearly, I am indeed using core object and hotplugging at core granularity for sPAPR. The core sits in the machine slot.
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
Quoted 270 lines · On Tue, 1 Mar 2016 13:47:27 +0530 Bharata B Rao <[email protected]>…
Quoted 269 lines · Igor Mammedov
Quoted 266 lines · On Mon, 29 Feb 2016 18:25:25 +0530 Bharata B Rao <[email protected]>…
Quoted 247 lines · Igor Mammedov
Quoted 244 lines · On Mon, 29 Feb 2016 11:20:19 +0530 Bharata B Rao <[email protected]>…
Quoted 217 lines · Michael Roth
Quoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 216 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +185
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); + object_property_add_str(obj, "slot", + spapr_cpu_core_prop_get_slot,Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 187
Quoted 2 lines
hw/ppc/spapr_cpu_core.c new file +2
-0+ spapr_cpu_core_prop_set_slot, + NULL);"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
Quoted 6 lines
Quoted 3 lines
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Then what will happen to slot if there isn't any core/socket device to query it, i.e. cpu hasn't been plugged in yet?
To me slot looks like a machine belonged feature.Yes slot belongs to the machine and it is represented by a link that is created b/n the machine object and the core object that sits in the slot.
In the context of this thread, slot is actually the slot name that identifies the machine slot which the core occupies or will occupy after hotplug. Thus slot name which is named slot here, it is a property of the core device.
(qemu)
device_addspapr-cpu-core,slot=core[2]^
Quoted 8 lines
Quoted 5 lines
Is 'slot' a term used by SPAPR on real hardware?
I'd thought that it's 'core', that's why I suggested to use 'core' for POWER as that matched real world concept, see
my other reply in "[RFC PATCH v0 4/6] spapr: CPU hotplug support" thread of this series.I don't see any reply from you to that thread. I guess you mean "[RFC PATCH v0 3/6] spapr: Represent boot CPUs as spapr-cpu-core devices"
no it's another thread, sorry for mixing things up. it was thread about QMP interface:
http://lists.gnu.org/archive/html/qemu-devel/2016-02/msg06540.html
Quoted 5 lines
thread where you suggest to use CORE type rather than
TYPE_CPUand enumerate threads under CORE type.In case, it didn't come out clearly, I am indeed using core object and hotplugging at core granularity for sPAPR. The core sits in the machine slot.
There I was suggesting to handle only CORE at spapr_machine_device_plug, making core.realize() to complete underlying threads initialization if possible, and if it you have to do some wiring at machine level for threads then do it while handling CORE branch.
That way hotplug call-chain would look like:
device_add(core)
-> device_realize(core)
-> core_realize()-> {realize threads}
-> spapr_machine_device_plug(core)
connect to board internals for core (maybe threads) vs current way:
device_add(core)
-> device_realize(core)
-> core_realize()-> {realize threads}
-> device_realize(thread)
-> spapr_machine_device_plug(thread)
some board specific wiring
...
-> spapr_machine_device_plug(core)
connect to board internals the former is easier to read/follow
Quoted 4 lines
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Igor MammedovQuoted 268 lines · Igor Mammedov
Quoted 265 lines · On Thu, 25 Feb 2016 21:52:41 +0530 Bharata B Rao <[email protected]>…
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.Signed-off-by Bharata B Rao <[email protected]>--- hw/core/machine.c | 19 +++++++++ hw/ppc/spapr.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 4 ++ qapi-schema.json | 85 +++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++ 5 files changed, 267 insertions(+)hw/core/machine.c +19
-0@@ -17,6 +17,25 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" +#include "qmp-commands.h" + +/* +* QMP: query-cpu-slots +* +* TODO: Ascertain if this is the right place to for this arch-neutral routine. +*/ +CPUSlotInfoList *qmp_query_cpu_slots (Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +if (!mc->cpu_slots) { +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; + } + +return mc->cpu_slots (ms); +}static char *machine_get_accel (Object *obj,Error **errp) {hw/ppc/spapr.c +112
-0@@ -2453,6 +2453,117 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)return cpu_index / smp_threads / smp_cores; } +static int spapr_cpuinfo_list (Object *obj,void *opaque) +{ +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); +CPUInfoList ***prev = opaque; + +if (object_dynamic_cast (obj,TYPE_CPU )) { +CPUInfoList *elem =g_new0 (CPUInfoList,1 ); +CPUInfo *s =g_new0 (CPUInfo,1 ); +CPUState *cpu =CPU (obj); +PowerPCCPU *pcpu =POWERPC_CPU (cpu); + + s->arch_id =ppc_get_vcpu_dt_id (pcpu); + s->type =g_strdup (object_get_typename (obj)); + s->thread = cpu->cpu_index; + s->has_thread = true; + s->core = cpu->cpu_index / smp_threads; + s->has_core = true; +if (mc->cpu_index_to_socket_id) { + s->socket = mc->cpu_index_to_socket_id (cpu->cpu_index); + }else { + s->socket = cpu->cpu_index / smp_threads / smp_cores; + } + s->has_socket = true; + s->node = cpu->numa_node; + s->has_node = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; + + elem->value = s; + elem->next =NULL ; + **prev = elem; + *prev = &elem->next; + } +object_child_foreach (obj, spapr_cpuinfo_list, opaque); +return 0 ; +} + +static CPUSlotInfoList *spapr_cpu_slots (MachineState *machine) +{ +CPUSlotInfoList *head =NULL ; +CPUSlotInfoList **prev = &head; +Object *root_container; +ObjectProperty *prop; +ObjectPropertyIterator iter; + +/* +* TODO: There surely must be a better/easier way to walk all +* the link properties of an object ? +*/ + root_container =container_get (object_get_root (),"/machine" ); +object_property_iter_init (&iter, root_container); + +while ((prop =object_property_iter_next (&iter))) { +Object *obj; +DeviceState *dev; +CPUSlotInfoList *elem; +CPUSlotInfo *s; +CPUInfoList *cpu_head =NULL ; +CPUInfoList **cpu_prev = &cpu_head; +sPAPRCPUCore *core; + +if (!strstart (prop->type,"link<" ,NULL )) { +continue ; + } + +if (!strstart (prop->name,SPAPR_MACHINE_CPU_CORE_PROP ,NULL )) { +continue ; + } + + elem =g_new0 (CPUSlotInfoList,1 ); + s =g_new0 (CPUSlotInfo,1 ); + + obj =object_property_get_link (root_container, prop->name,NULL ); +if (obj) { +/* Slot populated */ + dev =DEVICE (obj); + core =SPAPR_CPU_CORE (obj); + +if (dev->id) { + s->has_id = true; + s->id =g_strdup (dev->id); + } + s->realized =object_property_get_bool (obj,"realized" ,NULL ); + s->nr_cpus = core->nr_threads; + s->has_nr_cpus = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; +if (s->realized) { +spapr_cpuinfo_list (obj, &cpu_prev); + } + s->has_cpus = true; + }else { +/* Slot empty */ + s->has_id = false; + s->has_nr_cpus = false; + s->has_qom_path = false; + s->has_cpus = false; + s->realized = false; + } + s->type =g_strdup (TYPE_SPAPR_CPU_CORE ); + s->hotplug_granularity =g_strdup (SPAPR_MACHINE_CPU_CORE_PROP ); + s->slot_id =g_strdup (prop->name); + s->cpus = cpu_head; + elem->value = s; + elem->next =NULL ; + *prev = elem; + prev = &elem->next; + } +return head; +} +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -2482,6 +2593,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) hc->plug = spapr_machine_device_plug; hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; + mc->cpu_slots = spapr_cpu_slots; smc->dr_lmb_enabled = true; smc->dr_cpu_enabled = true;include/hw/boards.h +4
-0@@ -57,6 +57,9 @@ bool machine_mem_merge(MachineState *machine);* Set only by old machines because they need to keep * compatibility on code that exposed QEMU_VERSION to guests in * the past (and now use qemu_hw_version()). +* @cpu_slots: +* Provides information about populated and yet-to-be populated +* CPU slots in the machine. Used by QMP query-cpu-slots. */ struct MachineClass {/*< private >*/ @@ -99,6 +102,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + CPUSlotInfoList *(*cpu_slots)(MachineState *machine); };/** qapi-schema.json +60
-0@@ -4083,3 +4083,88 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUInfo: +# +# Information about CPUs +# +# @arch-id: Arch-specific ID for the CPU. +# +# @type: QOM type of the CPU. +# +# @thread: Thread ID of the CPU. +# +# @core: Core ID of the CPU. +# +# @socket: Socket ID of the CPU. +# +# @node: NUMA node to which the CPU belongs. +# +# @qom-path: QOM path of the CPU object +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch-id': 'int', + 'type': 'str', + '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom-path': 'str' + } +} + +## +# @CPUSlotInfo: +# +# Information about CPU Slots +# +# @id: Device ID of the CPU composite object that occupies the slot. +# +# @type: QOM type of the CPU composite object that occupies the slot. +# +# @hotplug-granularity: Granularity of CPU composite hotplug for this slot, +# can be thread, core or socket. +# +# @slot-id: Slot's identifier. +# +# @qom-path: QOM path of the CPU composite object that occupies the slot. +# +# @realized: A boolean that indicates whether the slot is filled or empty. +# +# @nr-cpus: Number of CPUs that are part of CPU composite object that occupies +# this slot. +# +# @cpus: An array of @CPUInfo elements where each element describes one +# CPU that is part of this slot's CPU composite object. +# +# @type: QOM type +#
Quoted 8 lines
qapi-schema.json line 4152
Quoted 7 lines
qapi-schema.json +7
-0+# Since: 2.6 +## + +{ 'struct': 'CPUSlotInfo', + 'data': { '*id': 'str', + 'type': 'str', + 'hotplug-granularity' : 'str',Does it convey any useful info, if yes how it will be used by mgmt?
As I noted in the patch desc, this field is useless, will remove.
Quoted 5 lines
qapi-schema.json line 4155
Quoted 4 lines
qapi-schema.json +3
-0+ 'slot-id' : 'str', + '*qom-path': 'str', + 'realized': 'bool',field's redundant, presence of qom-path answers this question
Ok, makes sense.
Quoted 9 lines
qapi-schema.json line 4157
Quoted 3 lines
qapi-schema.json +2
-0+ '*nr-cpus': 'int', + '*cpus' : ['CPUInfo']I'd suggest to drop above 2 fields as it's impl dependent, qom-path already point's to socket/core/thread object and its internal composition can be explored by other means if needed.
Moreover 'CPUInfo' is confusing and sort of conflicts with existing 'CpuInfo'.
Ah I see, should change the naming if we eventually stick with this implementation.
Quoted 2 lines
I'd drop CPUInfo altogether and introduce only 'CPUSlotInfo' here, existing thread enumeration's already implemented query-cpus.
Ok.
Quoted 8 lines
qapi-schema.json line 4159
Quoted 3 lines
qapi-schema.json +2
-0+ } +}What I miss here is that CPUSlotInfo doesn't provide any information to about where CPU might be hotplugged to.
Maybe use following tuple instead of slot-id?
Quoted 7 lines
{ 'struct': 'CPUSlotProperties',
'data': { '*node': 'int','*socket': 'int', '*core': 'int', '*thread': 'int'}
}
Hmm not sure. If I undestand Andreas' proposal correctly, slot is the place where the CPU sits. Machine determines the type of the slot and it can be socket slot, core slot or thread slot based on the granularity of the hotplug supported by the machine. With this I don't see why anything else apart from slot-id/slot-name is required to figure out where to hoplug CPU.
In the current implementation, sPAPR hotplug is at core granularity. CPUSlotInfo.type advertises the type as spapr-cpu-core. The number of threads in the core and the CPU model of the threads are either machine default or specified by user during hotplug time.
I believe NUMA node should be the property of the slot. The information about which slots are part of which NUMA node should be known beforehand at machine init time. Hotplugging CPU thread, core or socket to a slot will make that thread, core or socket part of that NUMA node.
Quoted 3 lines
it's generic for the most targets, which should work for spapr, s390, x86, ARM and could be extended for other cases adding other board specific properties if it's needed.
I don't about ARM, but s390 doesn't care about topology iiuc.
For sPAPR, as I described above, we don't care about sockets and hence I believe we can live with hotplugging a core into a machine slot by referring to the slot-id.
I see that CPUSlotProperties that you are suggesting here would make sense for x86 depending on the granularity at which hotplug is done. I know there has been discussion on thread vs socket hotplug granularity for x86, has there been a consensus on what it is going to be ?
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to David GibsonQuoted 55 lines · On Tue, 1 Mar 2016 12:21:27 +1100 David Gibson <[email protected]>…
Quoted 5 lines · Igor Mammedov
Quoted 3 lines · On Mon, 29 Feb 2016 18:25:25 +0530 Bharata B Rao <[email protected]>…
Quoted 2 lines · Igor Mammedov
On Mon, 29 Feb 2016 11:20:19 +0530
Bharata B Rao <[email protected]> wrote:[snip]
Quoted 34 lines
Quoted 34 lines
Quoted 23 lines
Quoted 23 lines
Quoted 5 lines
"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
Quoted 6 lines
Quoted 3 lines
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Then what will happen to slot if there isn't any core/socket device to query it, i.e. cpu hasn't been plugged in yet?
To me slot looks like a machine belonged feature.Yes slot belongs to the machine and it is represented by a link that is created b/n the machine object and the core object that sits in the slot.
Quoted 8 lines
Quoted 7 lines
In the context of this thread, slot is actually the slot name that identifies the machine slot which the core occupies or will occupy after hotplug. Thus slot name which is named slot here, it is a property of the core device.
(qemu)
device_addspapr-cpu-core,slot=core[2]^Is 'slot' a term used by SPAPR on real hardware?
So.. PAPR is a para-virtualized interface, so it never appears on real hardware.
But, no, "slot" is not a term used by PAPR.
Quoted 7 lines
Quoted 4 lines
I'd thought that it's 'core', that's why I suggested to use 'core' for POWER as that matched real world concept, see
my other reply in "[RFC PATCH v0 4/6] spapr: CPU hotplug support" thread of this series.I don't think it uses "core" either, I believe it uses just "cpu" but meaning a multi-thread core, rather than a single logical cpu thread.
then calling property 'cpu' is fine or one could go by meaning and use 'core' property (reusing 'core' property)
Re: [Qemu-devel] [RFC PATCH v0 2/6] spapr: CPU core device
In reply to Igor MammedovQuoted 304 lines · Igor Mammedov
Quoted 270 lines · On Tue, 1 Mar 2016 13:47:27 +0530 Bharata B Rao <[email protected]>…
Quoted 269 lines · Igor Mammedov
Quoted 266 lines · On Mon, 29 Feb 2016 18:25:25 +0530 Bharata B Rao <[email protected]>…
Quoted 247 lines · Igor Mammedov
Quoted 244 lines · On Mon, 29 Feb 2016 11:20:19 +0530 Bharata B Rao <[email protected]>…
Quoted 217 lines · Michael Roth
Quoting Bharata B Rao (2016-02-25 10:22:38)
Quoted 216 lines
Add sPAPR specific CPU core device that is based on generic CPU core device. Creating this core device will result in creation of all the CPU thread devices that are part of this core.
Signed-off-by Bharata B Rao <[email protected]>--- hw/ppc/Makefile.objs | 1 + hw/ppc/spapr_cpu_core.c | 210 ++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 32 ++++++ 3 files changed, 243 insertions(+) create mode 100644 hw/ppc/spapr_cpu_core.c create mode 100644 include/hw/ppc/spapr_cpu_core.hhw/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 endifhw/ppc/spapr_cpu_core.c new file +185
-0@@ -0,0 +1,210 @@ +/* +* 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> + +static int spapr_cpu_core_realize_child (Object *child,void *opaque) +{ +Error **errp = opaque; + +object_property_set_bool (child, true,"realized" , errp); +if (*errp) { +return 1 ; + } +return 0 ; +} + +static void spapr_cpu_core_realize (DeviceState *dev,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev)); +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +Error *local_err =NULL ; + +if (!core->nr_threads) { +error_setg (errp,"nr_threads property can't be 0" ); +return ; + } + +if (!core->cpu_model) { +error_setg (errp,"cpu_model property isn't set" ); +return ; + } + +/* +* TODO: If slot isn't specified, plug this core into +* an existing empty slot. +*/ +if (!core->slot) { +error_setg (errp,"slot property isn't set" ); +return ; + } + +object_property_set_link (OBJECT (spapr),OBJECT (core), core->slot, + &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +object_child_foreach (OBJECT (dev), spapr_cpu_core_realize_child, errp); +} + +/* +* This creates the CPU threads for a given @core. +* +* In order to create the threads, we need two inputs - number of +* threads and the cpu_model. These are set as core object's properties. +* When both of them become available/set, this routine will be called from +* either property's set handler to create the threads. +* +* TODO: Dependence of threads creation on two properties is resulting +* in this not-so-clean way of creating threads from either of the +* property setters based on the order in which they get set. Check if +* this can be handled in a better manner. +*/ +static void spapr_cpu_core_create_threads (sPAPRCPUCore *core,Error **errp) +{ +int i; + +for (i =0 ; i < core->nr_threads; i++) { +char id[32 ]; +char type[32 ]; + +snprintf (type,sizeof (type),"%s-%s" , core->cpu_model, +TYPE_POWERPC_CPU ); +object_initialize (&core->threads[i],sizeof (core->threads[i]), type); + +snprintf (id,sizeof (id),"thread[%d]" , i); +object_property_add_child (OBJECT (core), id,OBJECT (&core->threads[i]), + errp); + } +} + +static char *spapr_cpu_core_prop_get_slot (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->slot; +} + +static void spapr_cpu_core_prop_set_slot (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + + core->slot =g_strdup (val); +} + +static char *spapr_cpu_core_prop_get_cpu_model (Object *obj,Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); + +return core->cpu_model; +} + +static void spapr_cpu_core_prop_set_cpu_model (Object *obj,const char *val, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +MachineState *machine =MACHINE (qdev_get_machine ()); + +/* +* cpu_model can't be different from what is specified with -cpu +*/ +if (strcmp (val, machine->cpu_model)) { +error_setg (errp,"cpu_model should be %s" , machine->cpu_model); +return ; + } + + core->cpu_model =g_strdup (val); +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_prop_get_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +int64_t value = core->nr_threads; + +visit_type_int (v, name, &value, errp); +} + +static void spapr_cpu_core_prop_set_nr_threads (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +sPAPRCPUCore *core =SPAPR_CPU_CORE (obj); +Error *local_err =NULL ; +int64_t value; + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* Allow only homogeneous configuration */ +if (value != smp_threads) { +error_setg (errp,"nr_threads should be %d" , smp_threads); +return ; + } + + core->nr_threads = value; + core->threads =g_malloc0 (core->nr_threads *sizeof (PowerPCCPU)); + +if (core->nr_threads && core->cpu_model) { +spapr_cpu_core_create_threads (core, errp); + } +} + +static void spapr_cpu_core_instance_init (Object *obj) +{ +object_property_add (obj,"nr_threads" ,"int" , + spapr_cpu_core_prop_get_nr_threads, + spapr_cpu_core_prop_set_nr_threads, +NULL ,NULL ,NULL ); +object_property_add_str (obj,"cpu_model" , + spapr_cpu_core_prop_get_cpu_model, + spapr_cpu_core_prop_set_cpu_model, +NULL ); + object_property_add_str(obj, "slot", + spapr_cpu_core_prop_get_slot,Quoted 8 lines
hw/ppc/spapr_cpu_core.c line 187
Quoted 2 lines
hw/ppc/spapr_cpu_core.c new file +2
-0+ spapr_cpu_core_prop_set_slot, + NULL);"slot" seems intended to be a machine-agnostic of mapping device types discovered from
qmp_query_cpu_slots()to an appropriate "bus" location, but here's it a field specific toTYPE_SPAPR_CPU_CORE. It seems like maybeTYPE_CPU_COREis a better place, but then on x86 I suppose it might beTYPE_CPU_SOCKETor something instead...Correct.
Quoted 11 lines
It almost seems like a
TYPE_INTERFACE_SLOTABLEwould be the right approach, but I don't know how we could expose that as a property. I guess it's somewhat implied that this "interface" exists ifqmp_query_cpu_slots()returns the type, but I wonder if something a bit more formal should be modeled to make the implementation requirements a bit clearer.Maybe have TYPE_CPU_{CORE,SOCKET} classes have a get_slot/set_slot class method, expose them via "slot" property, then have the defaults generate "not implemented" errors?
Yes makes sense. In fact David has often times said that generic properties/routines should be pushed to base class wherever possible.
Quoted 6 lines
Quoted 3 lines
I didn't do that in this first iteration to keep the generic changes as minimum as possible, but yes slot should be a property of the base class of core or socket.
Then what will happen to slot if there isn't any core/socket device to query it, i.e. cpu hasn't been plugged in yet?
To me slot looks like a machine belonged feature.Yes slot belongs to the machine and it is represented by a link that is created b/n the machine object and the core object that sits in the slot.
In the context of this thread, slot is actually the slot name that identifies the machine slot which the core occupies or will occupy after hotplug. Thus slot name which is named slot here, it is a property of the core device.
(qemu)
device_addspapr-cpu-core,slot=core[2]^Quoted 8 lines
Quoted 5 lines
Is 'slot' a term used by SPAPR on real hardware?
I'd thought that it's 'core', that's why I suggested to use 'core' for POWER as that matched real world concept, see
my other reply in "[RFC PATCH v0 4/6] spapr: CPU hotplug support" thread of this series.I don't see any reply from you to that thread. I guess you mean "[RFC PATCH v0 3/6] spapr: Represent boot CPUs as spapr-cpu-core devices"
no it's another thread, sorry for mixing things up. it was thread about QMP interface:
http://lists.gnu.org/archive/html/qemu-devel/2016-02/msg06540.htmlQuoted 5 lines
thread where you suggest to use CORE type rather than
TYPE_CPUand enumerate threads under CORE type.In case, it didn't come out clearly, I am indeed using core object and hotplugging at core granularity for sPAPR. The core sits in the machine slot.
There I was suggesting to handle only CORE at
spapr_machine_device_plug, makingcore.realize()to complete underlying threads initialization if possible, and if it you have to do some wiring at machine level for threads then do it while handling CORE branch.That way hotplug call-chain would look like:
device_add(core)-> device_realize(core) -> core_realize()-> {realize threads} -> spapr_machine_device_plug(core) connect to board internals for core (maybe threads)vs current way:
device_add(core)
Quoted 8 lines
-> device_realize(core)
-> core_realize()-> {realize threads}
-> device_realize(thread)
-> spapr_machine_device_plug(thread)
some board specific wiring
...
-> spapr_machine_device_plug(core)
connect to board internals Sure, I am changing this in next version.
Regards,
Bharata.
Quoted 10 lines · Bharata B Rao
Hi,
This is an attempt to implement CPU hotplug for PowerPC sPAPR based on the approach suggested by Andreas. While I say that, I should also explicitly add that I have tried to follow Andreas' suggestions to the best of my understanding and hence there could be bits which are still not as per expectations.
I have tried to model this similarly to what Andreas did for x86 an year back at
https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg04858.html
Andreas - Do you have any comments on this implementation ? Is it worth pursuing further in your view ?
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Bharata B RaoQuoted 322 lines · On Tue, 1 Mar 2016 14:39:51 +0530 Bharata B Rao <[email protected]>…
Quoted 268 lines · Igor Mammedov
Quoted 265 lines · On Thu, 25 Feb 2016 21:52:41 +0530 Bharata B Rao <[email protected]>…
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.Signed-off-by Bharata B Rao <[email protected]>--- hw/core/machine.c | 19 +++++++++ hw/ppc/spapr.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 4 ++ qapi-schema.json | 85 +++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++ 5 files changed, 267 insertions(+)hw/core/machine.c +19
-0@@ -17,6 +17,25 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" +#include "qmp-commands.h" + +/* +* QMP: query-cpu-slots +* +* TODO: Ascertain if this is the right place to for this arch-neutral routine. +*/ +CPUSlotInfoList *qmp_query_cpu_slots (Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +if (!mc->cpu_slots) { +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; + } + +return mc->cpu_slots (ms); +}static char *machine_get_accel (Object *obj,Error **errp) {hw/ppc/spapr.c +112
-0@@ -2453,6 +2453,117 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)return cpu_index / smp_threads / smp_cores; } +static int spapr_cpuinfo_list (Object *obj,void *opaque) +{ +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); +CPUInfoList ***prev = opaque; + +if (object_dynamic_cast (obj,TYPE_CPU )) { +CPUInfoList *elem =g_new0 (CPUInfoList,1 ); +CPUInfo *s =g_new0 (CPUInfo,1 ); +CPUState *cpu =CPU (obj); +PowerPCCPU *pcpu =POWERPC_CPU (cpu); + + s->arch_id =ppc_get_vcpu_dt_id (pcpu); + s->type =g_strdup (object_get_typename (obj)); + s->thread = cpu->cpu_index; + s->has_thread = true; + s->core = cpu->cpu_index / smp_threads; + s->has_core = true; +if (mc->cpu_index_to_socket_id) { + s->socket = mc->cpu_index_to_socket_id (cpu->cpu_index); + }else { + s->socket = cpu->cpu_index / smp_threads / smp_cores; + } + s->has_socket = true; + s->node = cpu->numa_node; + s->has_node = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; + + elem->value = s; + elem->next =NULL ; + **prev = elem; + *prev = &elem->next; + } +object_child_foreach (obj, spapr_cpuinfo_list, opaque); +return 0 ; +} + +static CPUSlotInfoList *spapr_cpu_slots (MachineState *machine) +{ +CPUSlotInfoList *head =NULL ; +CPUSlotInfoList **prev = &head; +Object *root_container; +ObjectProperty *prop; +ObjectPropertyIterator iter; + +/* +* TODO: There surely must be a better/easier way to walk all +* the link properties of an object ? +*/ + root_container =container_get (object_get_root (),"/machine" ); +object_property_iter_init (&iter, root_container); + +while ((prop =object_property_iter_next (&iter))) { +Object *obj; +DeviceState *dev; +CPUSlotInfoList *elem; +CPUSlotInfo *s; +CPUInfoList *cpu_head =NULL ; +CPUInfoList **cpu_prev = &cpu_head; +sPAPRCPUCore *core; + +if (!strstart (prop->type,"link<" ,NULL )) { +continue ; + } + +if (!strstart (prop->name,SPAPR_MACHINE_CPU_CORE_PROP ,NULL )) { +continue ; + } + + elem =g_new0 (CPUSlotInfoList,1 ); + s =g_new0 (CPUSlotInfo,1 ); + + obj =object_property_get_link (root_container, prop->name,NULL ); +if (obj) { +/* Slot populated */ + dev =DEVICE (obj); + core =SPAPR_CPU_CORE (obj); + +if (dev->id) { + s->has_id = true; + s->id =g_strdup (dev->id); + } + s->realized =object_property_get_bool (obj,"realized" ,NULL ); + s->nr_cpus = core->nr_threads; + s->has_nr_cpus = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; +if (s->realized) { +spapr_cpuinfo_list (obj, &cpu_prev); + } + s->has_cpus = true; + }else { +/* Slot empty */ + s->has_id = false; + s->has_nr_cpus = false; + s->has_qom_path = false; + s->has_cpus = false; + s->realized = false; + } + s->type =g_strdup (TYPE_SPAPR_CPU_CORE ); + s->hotplug_granularity =g_strdup (SPAPR_MACHINE_CPU_CORE_PROP ); + s->slot_id =g_strdup (prop->name); + s->cpus = cpu_head; + elem->value = s; + elem->next =NULL ; + *prev = elem; + prev = &elem->next; + } +return head; +} +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -2482,6 +2593,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) hc->plug = spapr_machine_device_plug; hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; + mc->cpu_slots = spapr_cpu_slots; smc->dr_lmb_enabled = true; smc->dr_cpu_enabled = true;include/hw/boards.h +4
-0@@ -57,6 +57,9 @@ bool machine_mem_merge(MachineState *machine);* Set only by old machines because they need to keep * compatibility on code that exposed QEMU_VERSION to guests in * the past (and now use qemu_hw_version()). +* @cpu_slots: +* Provides information about populated and yet-to-be populated +* CPU slots in the machine. Used by QMP query-cpu-slots. */ struct MachineClass {/*< private >*/ @@ -99,6 +102,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + CPUSlotInfoList *(*cpu_slots)(MachineState *machine); };/** qapi-schema.json +60
-0@@ -4083,3 +4083,88 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUInfo: +# +# Information about CPUs +# +# @arch-id: Arch-specific ID for the CPU. +# +# @type: QOM type of the CPU. +# +# @thread: Thread ID of the CPU. +# +# @core: Core ID of the CPU. +# +# @socket: Socket ID of the CPU. +# +# @node: NUMA node to which the CPU belongs. +# +# @qom-path: QOM path of the CPU object +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch-id': 'int', + 'type': 'str', + '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom-path': 'str' + } +} + +## +# @CPUSlotInfo: +# +# Information about CPU Slots +# +# @id: Device ID of the CPU composite object that occupies the slot. +# +# @type: QOM type of the CPU composite object that occupies the slot. +# +# @hotplug-granularity: Granularity of CPU composite hotplug for this slot, +# can be thread, core or socket. +# +# @slot-id: Slot's identifier. +# +# @qom-path: QOM path of the CPU composite object that occupies the slot. +# +# @realized: A boolean that indicates whether the slot is filled or empty. +# +# @nr-cpus: Number of CPUs that are part of CPU composite object that occupies +# this slot. +# +# @cpus: An array of @CPUInfo elements where each element describes one +# CPU that is part of this slot's CPU composite object. +# +# @type: QOM type +#Quoted 8 lines
qapi-schema.json line 4152
Quoted 7 lines
qapi-schema.json +7
-0+# Since: 2.6 +## + +{ 'struct': 'CPUSlotInfo', + 'data': { '*id': 'str', + 'type': 'str', + 'hotplug-granularity' : 'str',Does it convey any useful info, if yes how it will be used by mgmt?
As I noted in the patch desc, this field is useless, will remove.
Quoted 5 lines
qapi-schema.json line 4155
Quoted 4 lines
qapi-schema.json +3
-0+ 'slot-id' : 'str', + '*qom-path': 'str', + 'realized': 'bool',field's redundant, presence of qom-path answers this question
Ok, makes sense.
Quoted 9 lines
qapi-schema.json line 4157
Quoted 3 lines
qapi-schema.json +2
-0+ '*nr-cpus': 'int', + '*cpus' : ['CPUInfo']I'd suggest to drop above 2 fields as it's impl dependent, qom-path already point's to socket/core/thread object and its internal composition can be explored by other means if needed.
Moreover 'CPUInfo' is confusing and sort of conflicts with existing 'CpuInfo'.
Ah I see, should change the naming if we eventually stick with this implementation.
Quoted 2 lines
I'd drop CPUInfo altogether and introduce only 'CPUSlotInfo' here, existing thread enumeration's already implemented query-cpus.
Ok.
Quoted 8 lines
qapi-schema.json line 4159
Quoted 3 lines
qapi-schema.json +2
-0+ } +}What I miss here is that CPUSlotInfo doesn't provide any information to about where CPU might be hotplugged to.
Maybe use following tuple instead of slot-id?
Quoted 7 lines
{ 'struct': 'CPUSlotProperties',
'data': { '*node': 'int','*socket': 'int', '*core': 'int', '*thread': 'int'}
}
Quoted 6 lines
Hmm not sure. If I undestand Andreas' proposal correctly, slot is the place where the CPU sits. Machine determines the type of the slot and it can be socket slot, core slot or thread slot based on the granularity of the hotplug supported by the machine. With this I don't see why anything else apart from slot-id/slot-name is required to figure out where to hoplug CPU.
Of cause it's possible to create and keep at board level map of slot-names to whatever other info needed to create a CPU object at machine init time, and then make board somehow to apply it to the new CPU object before realizing it.
But it doesn't give mgmt any information whatsoever about where CPU is being hotplugged. So for x86/arm we would end up with adding yet another interface that would tell it. If CPUSlotProperties is used instead of slot-name, it could convey that information while keeping interface compatible with a range targets we care about and extendable to other targets in future.
Quoted 4 lines
In the current implementation, sPAPR hotplug is at core granularity. CPUSlotInfo.type advertises the type as spapr-cpu-core. The number of threads in the core and the CPU model of the threads are either machine default or specified by user during hotplug time.
now imagine extending in future sPAPR to support NUMA, which way would you extend interface, how would mgmt know which CPU belongs to what node?
As you may note in CPUSlotProperties fields are optional so target would use only ones it needs. For current sPAPR, query result could be something like this:
{
{
type: spapr-cpu-core
properties: { core: 0 }
qom-path: /machine/unattached/device[xxx]
}
{
type: spapr-cpu-core
properties: { core: 1 }
}
...
{
type: spapr-cpu-core
properties: { core: 0 } }
}
Later if numa was needed, the board could set 'numa' property as well. Would that work for sPAPR?
Quoted 4 lines
I believe NUMA node should be the property of the slot. The information about which slots are part of which NUMA node should be known beforehand at machine init time. Hotplugging CPU thread, core or socket to a slot will make that thread, core or socket part of that NUMA node.
As analogy PCI devices also have 'bus' property which is used to tell device_add machinery where to attach the device. The same goes for DIMM device which also has 'numa' option so mgmt could say to which node device is being plugged.
CPUSlotProperties is basically location where CPU is being plugged and in some cases location includes 'numa' property or some other. The difference vs slot-name is that CPUSlotProperties is more verbose and flexible and tries to describe location in natural for target therms.
Quoted 6 lines
Quoted 3 lines
it's generic for the most targets, which should work for spapr, s390, x86, ARM and could be extended for other cases adding other board specific properties if it's needed.
I don't about ARM, but s390 doesn't care about topology iiuc.
Quoted 8 lines
For sPAPR, as I described above, we don't care about sockets and hence I believe we can live with hotplugging a core into a machine slot by referring to the slot-id.
I see that CPUSlotProperties that you are suggesting here would make sense for x86 depending on the granularity at which hotplug is done. I know there has been discussion on thread vs socket hotplug granularity for x86, has there been a consensus on what it is going to be ?
I don't agree with switching to socket model on x86 for a number of reasons:
- it can't be done without breaking compatibility.
- from user pov, he/she would like to hotplug CPU at thread level to get necessary CPU horsepower without over-paying for over-provisioned threads. Limiting it to socket level would be crippling qemu based hypervisors in comparison to other hypervisors, which do it currently at thread level. Practice show that Linux and Windows handle thread level hotplug well enough perhaps because they try match ACPI spec where hotplug happens at thread level.
Am 01.03.2016 um 11:00 schrieb Bharata B Rao:
Quoted 9 lines · Bharata B Rao
Quoted 8 lines
Hi,
This is an attempt to implement CPU hotplug for PowerPC sPAPR based on the approach suggested by Andreas. While I say that, I should also explicitly add that I have tried to follow Andreas' suggestions to the best of my understanding and hence there could be bits which are still not as per expectations.
Quoted 5 lines
Quoted 2 lines
I have tried to model this similarly to what Andreas did for x86 an year back at
https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg04858.htmlAndreas - Do you have any comments on this implementation ? Is it worth pursuing further in your view ?
As indicated to some of you, I was absent last week - that means I did not yet read the flood of emails I got from David, Igor and others.
Maybe you can give a summary of open questions and problems on the call?
Regards,
Andreas
Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
Re: [Qemu-devel] [RFC PATCH v0 4/6] spapr: CPU hotplug support
In reply to Bharata B RaoQuoted 54 lines · Bharata B Rao
Quoted 46 lines · Bharata B Rao
Quoted 33 lines
Quoted 33 lines
hw/ppc/spapr_rtas.c +18
-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)) {Quoted 8 lines
hw/ppc/spapr_rtas.c static void rtas_query_cpu_stopped_state(PowerPCCPU *cpu_, · line 185
Quoted 4 lines
hw/ppc/spapr_rtas.c +4
-0+ cpu->env.spr[SPR_LPCR ] |=LPCR_ILE ; + } +} +Any particular reason for doing these things at
rtas_start_cpu()time, but other initialization at plug time? Could you consolidate it to one place or the other?Those board specific things that are needed to be done have been consolidated into
spapr_cpu_init()which will be called from the plug handler. We have discussed this earlier at:Quoted 6 lines
https://lists.nongnu.org/archive/html/qemu-devel/2015-02/msg04399.html
It has been a while but there was a good reason why setting endianness here rather than in plug handler is necessary. W/o this LE hotplug on guests wouldn't work, I will dig up and come back on what exactly necessiated this change.
Quoted 6 lines
If we set
LPCR_ILEin cpu->env.spr[SPR_LPCR] at plug time (fromspapr_cpu_init()), there are at least two places later where it gets over-written. One isspapr_cpu_reset()and the other one whenkvm_cpu_synchronize_state()is called fromrtas_start_cpu(). We could probably issue akvm_arch_put_registers(), but I foundrtas_start_cpu()as a place where this change is guaranteed to get reflected.
Ok, makes sense.
In that case can we move all, or nearly all, of the PAPR specific thread initialization to rtas_start_cpu()? Obviously we'd need a separate call to the same stuff for the boot cpu.
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 v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
In reply to Igor MammedovQuoted 368 lines · Igor Mammedov
Quoted 322 lines · On Tue, 1 Mar 2016 14:39:51 +0530 Bharata B Rao <[email protected]>…
Quoted 268 lines · Igor Mammedov
Quoted 265 lines · On Thu, 25 Feb 2016 21:52:41 +0530 Bharata B Rao <[email protected]>…
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.Signed-off-by Bharata B Rao <[email protected]>--- hw/core/machine.c | 19 +++++++++ hw/ppc/spapr.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 4 ++ qapi-schema.json | 85 +++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++ 5 files changed, 267 insertions(+)hw/core/machine.c +19
-0@@ -17,6 +17,25 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" +#include "qmp-commands.h" + +/* +* QMP: query-cpu-slots +* +* TODO: Ascertain if this is the right place to for this arch-neutral routine. +*/ +CPUSlotInfoList *qmp_query_cpu_slots (Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +if (!mc->cpu_slots) { +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; + } + +return mc->cpu_slots (ms); +}static char *machine_get_accel (Object *obj,Error **errp) {hw/ppc/spapr.c +112
-0@@ -2453,6 +2453,117 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)return cpu_index / smp_threads / smp_cores; } +static int spapr_cpuinfo_list (Object *obj,void *opaque) +{ +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); +CPUInfoList ***prev = opaque; + +if (object_dynamic_cast (obj,TYPE_CPU )) { +CPUInfoList *elem =g_new0 (CPUInfoList,1 ); +CPUInfo *s =g_new0 (CPUInfo,1 ); +CPUState *cpu =CPU (obj); +PowerPCCPU *pcpu =POWERPC_CPU (cpu); + + s->arch_id =ppc_get_vcpu_dt_id (pcpu); + s->type =g_strdup (object_get_typename (obj)); + s->thread = cpu->cpu_index; + s->has_thread = true; + s->core = cpu->cpu_index / smp_threads; + s->has_core = true; +if (mc->cpu_index_to_socket_id) { + s->socket = mc->cpu_index_to_socket_id (cpu->cpu_index); + }else { + s->socket = cpu->cpu_index / smp_threads / smp_cores; + } + s->has_socket = true; + s->node = cpu->numa_node; + s->has_node = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; + + elem->value = s; + elem->next =NULL ; + **prev = elem; + *prev = &elem->next; + } +object_child_foreach (obj, spapr_cpuinfo_list, opaque); +return 0 ; +} + +static CPUSlotInfoList *spapr_cpu_slots (MachineState *machine) +{ +CPUSlotInfoList *head =NULL ; +CPUSlotInfoList **prev = &head; +Object *root_container; +ObjectProperty *prop; +ObjectPropertyIterator iter; + +/* +* TODO: There surely must be a better/easier way to walk all +* the link properties of an object ? +*/ + root_container =container_get (object_get_root (),"/machine" ); +object_property_iter_init (&iter, root_container); + +while ((prop =object_property_iter_next (&iter))) { +Object *obj; +DeviceState *dev; +CPUSlotInfoList *elem; +CPUSlotInfo *s; +CPUInfoList *cpu_head =NULL ; +CPUInfoList **cpu_prev = &cpu_head; +sPAPRCPUCore *core; + +if (!strstart (prop->type,"link<" ,NULL )) { +continue ; + } + +if (!strstart (prop->name,SPAPR_MACHINE_CPU_CORE_PROP ,NULL )) { +continue ; + } + + elem =g_new0 (CPUSlotInfoList,1 ); + s =g_new0 (CPUSlotInfo,1 ); + + obj =object_property_get_link (root_container, prop->name,NULL ); +if (obj) { +/* Slot populated */ + dev =DEVICE (obj); + core =SPAPR_CPU_CORE (obj); + +if (dev->id) { + s->has_id = true; + s->id =g_strdup (dev->id); + } + s->realized =object_property_get_bool (obj,"realized" ,NULL ); + s->nr_cpus = core->nr_threads; + s->has_nr_cpus = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; +if (s->realized) { +spapr_cpuinfo_list (obj, &cpu_prev); + } + s->has_cpus = true; + }else { +/* Slot empty */ + s->has_id = false; + s->has_nr_cpus = false; + s->has_qom_path = false; + s->has_cpus = false; + s->realized = false; + } + s->type =g_strdup (TYPE_SPAPR_CPU_CORE ); + s->hotplug_granularity =g_strdup (SPAPR_MACHINE_CPU_CORE_PROP ); + s->slot_id =g_strdup (prop->name); + s->cpus = cpu_head; + elem->value = s; + elem->next =NULL ; + *prev = elem; + prev = &elem->next; + } +return head; +} +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -2482,6 +2593,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) hc->plug = spapr_machine_device_plug; hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; + mc->cpu_slots = spapr_cpu_slots; smc->dr_lmb_enabled = true; smc->dr_cpu_enabled = true;include/hw/boards.h +4
-0@@ -57,6 +57,9 @@ bool machine_mem_merge(MachineState *machine);* Set only by old machines because they need to keep * compatibility on code that exposed QEMU_VERSION to guests in * the past (and now use qemu_hw_version()). +* @cpu_slots: +* Provides information about populated and yet-to-be populated +* CPU slots in the machine. Used by QMP query-cpu-slots. */ struct MachineClass {/*< private >*/ @@ -99,6 +102,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + CPUSlotInfoList *(*cpu_slots)(MachineState *machine); };/** qapi-schema.json +60
-0@@ -4083,3 +4083,88 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUInfo: +# +# Information about CPUs +# +# @arch-id: Arch-specific ID for the CPU. +# +# @type: QOM type of the CPU. +# +# @thread: Thread ID of the CPU. +# +# @core: Core ID of the CPU. +# +# @socket: Socket ID of the CPU. +# +# @node: NUMA node to which the CPU belongs. +# +# @qom-path: QOM path of the CPU object +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch-id': 'int', + 'type': 'str', + '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom-path': 'str' + } +} + +## +# @CPUSlotInfo: +# +# Information about CPU Slots +# +# @id: Device ID of the CPU composite object that occupies the slot. +# +# @type: QOM type of the CPU composite object that occupies the slot. +# +# @hotplug-granularity: Granularity of CPU composite hotplug for this slot, +# can be thread, core or socket. +# +# @slot-id: Slot's identifier. +# +# @qom-path: QOM path of the CPU composite object that occupies the slot. +# +# @realized: A boolean that indicates whether the slot is filled or empty. +# +# @nr-cpus: Number of CPUs that are part of CPU composite object that occupies +# this slot. +# +# @cpus: An array of @CPUInfo elements where each element describes one +# CPU that is part of this slot's CPU composite object. +# +# @type: QOM type +#Quoted 8 lines
qapi-schema.json line 4152
Quoted 7 lines
qapi-schema.json +7
-0+# Since: 2.6 +## + +{ 'struct': 'CPUSlotInfo', + 'data': { '*id': 'str', + 'type': 'str', + 'hotplug-granularity' : 'str',Does it convey any useful info, if yes how it will be used by mgmt?
As I noted in the patch desc, this field is useless, will remove.
Quoted 5 lines
qapi-schema.json line 4155
Quoted 4 lines
qapi-schema.json +3
-0+ 'slot-id' : 'str', + '*qom-path': 'str', + 'realized': 'bool',field's redundant, presence of qom-path answers this question
Ok, makes sense.
Quoted 9 lines
qapi-schema.json line 4157
Quoted 3 lines
qapi-schema.json +2
-0+ '*nr-cpus': 'int', + '*cpus' : ['CPUInfo']I'd suggest to drop above 2 fields as it's impl dependent, qom-path already point's to socket/core/thread object and its internal composition can be explored by other means if needed.
Moreover 'CPUInfo' is confusing and sort of conflicts with existing 'CpuInfo'.
Ah I see, should change the naming if we eventually stick with this implementation.
Quoted 2 lines
I'd drop CPUInfo altogether and introduce only 'CPUSlotInfo' here, existing thread enumeration's already implemented query-cpus.
Ok.
Quoted 8 lines
qapi-schema.json line 4159
Quoted 3 lines
qapi-schema.json +2
-0+ } +}What I miss here is that CPUSlotInfo doesn't provide any information to about where CPU might be hotplugged to.
Maybe use following tuple instead of slot-id?
Quoted 7 lines
{ 'struct': 'CPUSlotProperties',
'data': { '*node': 'int','*socket': 'int', '*core': 'int', '*thread': 'int'}
}Quoted 6 lines
Hmm not sure. If I undestand Andreas' proposal correctly, slot is the place where the CPU sits. Machine determines the type of the slot and it can be socket slot, core slot or thread slot based on the granularity of the hotplug supported by the machine. With this I don't see why anything else apart from slot-id/slot-name is required to figure out where to hoplug CPU.
Of cause it's possible to create and keep at board level map of slot-names to whatever other info needed to create a CPU object at machine init time, and then make board somehow to apply it to the new CPU object before realizing it.
But it doesn't give mgmt any information whatsoever about where CPU is being hotplugged. So for x86/arm we would end up with adding yet another interface that would tell it. If CPUSlotProperties is used instead of slot-name, it could convey that information while keeping interface compatible with a range targets we care about and extendable to other targets in future.
Quoted 4 lines
In the current implementation, sPAPR hotplug is at core granularity. CPUSlotInfo.type advertises the type as spapr-cpu-core. The number of threads in the core and the CPU model of the threads are either machine default or specified by user during hotplug time.
now imagine extending in future sPAPR to support NUMA, which way would you extend interface, how would mgmt know which CPU belongs to what node?
As you may note in CPUSlotProperties fields are optional so target would use only ones it needs. For current sPAPR, query result could be something like this:
{
{ type: spapr-cpu-core properties: { core: 0 } qom-path: /machine/unattached/device[xxx] } { type: spapr-cpu-core properties: { core: 1 } } ... { type: spapr-cpu-core properties: { core: 0 }
Quoted 5 lines
}
}Later if numa was needed, the board could set 'numa' property as well. Would that work for sPAPR?
It could work, however I am finding it difficult to reconcile this with the machine object to core links that I have in this implementation which I believe is what Andreas originally suggested. Such a link essentially represents a slot and it has a name associated with it which identifies the location where the core is plugged.
Now in order to incorporate CPUSlotProperties, these properties must be tied to a slot/location object which in the present implementation doesn't exist. So are you suggesting that we create slot/location object (abstract ?) that has CPUSlotProperties ? If so, then I guess we don't need machine object to core object links ?
Regards,
Bharata.
Re: [Qemu-devel] [RFC PATCH v0 5/6] qmp, spapr: Show hot-plugged/pluggable CPU slots in the Machine
Quoted 381 lines · On Thu, 3 Mar 2016 15:00:32 +0530 Bharata B Rao <[email protected]>…
Quoted 368 lines · Igor Mammedov
Quoted 322 lines · On Tue, 1 Mar 2016 14:39:51 +0530 Bharata B Rao <[email protected]>…
Quoted 268 lines · Igor Mammedov
Quoted 265 lines · On Thu, 25 Feb 2016 21:52:41 +0530 Bharata B Rao <[email protected]>…
Implement query cpu-slots that provides information about hot-plugged as well as hot-pluggable CPU slots that the machine supports.
TODO: As Eric suggested use enum for type instead of str.
TODO: @hotplug-granularity probably isn't required.Signed-off-by Bharata B Rao <[email protected]>--- hw/core/machine.c | 19 +++++++++ hw/ppc/spapr.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/boards.h | 4 ++ qapi-schema.json | 85 +++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 47 ++++++++++++++++++++++ 5 files changed, 267 insertions(+)hw/core/machine.c +19
-0@@ -17,6 +17,25 @@#include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" +#include "qmp-commands.h" + +/* +* QMP: query-cpu-slots +* +* TODO: Ascertain if this is the right place to for this arch-neutral routine. +*/ +CPUSlotInfoList *qmp_query_cpu_slots (Error **errp) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +if (!mc->cpu_slots) { +error_setg (errp,QERR_UNSUPPORTED ); +return NULL ; + } + +return mc->cpu_slots (ms); +}static char *machine_get_accel (Object *obj,Error **errp) {hw/ppc/spapr.c +112
-0@@ -2453,6 +2453,117 @@ static unsigned spapr_cpu_index_to_socket_id(unsigned cpu_index)return cpu_index / smp_threads / smp_cores; } +static int spapr_cpuinfo_list (Object *obj,void *opaque) +{ +MachineClass *mc =MACHINE_GET_CLASS (qdev_get_machine ()); +CPUInfoList ***prev = opaque; + +if (object_dynamic_cast (obj,TYPE_CPU )) { +CPUInfoList *elem =g_new0 (CPUInfoList,1 ); +CPUInfo *s =g_new0 (CPUInfo,1 ); +CPUState *cpu =CPU (obj); +PowerPCCPU *pcpu =POWERPC_CPU (cpu); + + s->arch_id =ppc_get_vcpu_dt_id (pcpu); + s->type =g_strdup (object_get_typename (obj)); + s->thread = cpu->cpu_index; + s->has_thread = true; + s->core = cpu->cpu_index / smp_threads; + s->has_core = true; +if (mc->cpu_index_to_socket_id) { + s->socket = mc->cpu_index_to_socket_id (cpu->cpu_index); + }else { + s->socket = cpu->cpu_index / smp_threads / smp_cores; + } + s->has_socket = true; + s->node = cpu->numa_node; + s->has_node = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; + + elem->value = s; + elem->next =NULL ; + **prev = elem; + *prev = &elem->next; + } +object_child_foreach (obj, spapr_cpuinfo_list, opaque); +return 0 ; +} + +static CPUSlotInfoList *spapr_cpu_slots (MachineState *machine) +{ +CPUSlotInfoList *head =NULL ; +CPUSlotInfoList **prev = &head; +Object *root_container; +ObjectProperty *prop; +ObjectPropertyIterator iter; + +/* +* TODO: There surely must be a better/easier way to walk all +* the link properties of an object ? +*/ + root_container =container_get (object_get_root (),"/machine" ); +object_property_iter_init (&iter, root_container); + +while ((prop =object_property_iter_next (&iter))) { +Object *obj; +DeviceState *dev; +CPUSlotInfoList *elem; +CPUSlotInfo *s; +CPUInfoList *cpu_head =NULL ; +CPUInfoList **cpu_prev = &cpu_head; +sPAPRCPUCore *core; + +if (!strstart (prop->type,"link<" ,NULL )) { +continue ; + } + +if (!strstart (prop->name,SPAPR_MACHINE_CPU_CORE_PROP ,NULL )) { +continue ; + } + + elem =g_new0 (CPUSlotInfoList,1 ); + s =g_new0 (CPUSlotInfo,1 ); + + obj =object_property_get_link (root_container, prop->name,NULL ); +if (obj) { +/* Slot populated */ + dev =DEVICE (obj); + core =SPAPR_CPU_CORE (obj); + +if (dev->id) { + s->has_id = true; + s->id =g_strdup (dev->id); + } + s->realized =object_property_get_bool (obj,"realized" ,NULL ); + s->nr_cpus = core->nr_threads; + s->has_nr_cpus = true; + s->qom_path =object_get_canonical_path (obj); + s->has_qom_path = true; +if (s->realized) { +spapr_cpuinfo_list (obj, &cpu_prev); + } + s->has_cpus = true; + }else { +/* Slot empty */ + s->has_id = false; + s->has_nr_cpus = false; + s->has_qom_path = false; + s->has_cpus = false; + s->realized = false; + } + s->type =g_strdup (TYPE_SPAPR_CPU_CORE ); + s->hotplug_granularity =g_strdup (SPAPR_MACHINE_CPU_CORE_PROP ); + s->slot_id =g_strdup (prop->name); + s->cpus = cpu_head; + elem->value = s; + elem->next =NULL ; + *prev = elem; + prev = &elem->next; + } +return head; +} +static void spapr_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);@@ -2482,6 +2593,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) hc->plug = spapr_machine_device_plug; hc->unplug = spapr_machine_device_unplug; mc->cpu_index_to_socket_id = spapr_cpu_index_to_socket_id; + mc->cpu_slots = spapr_cpu_slots; smc->dr_lmb_enabled = true; smc->dr_cpu_enabled = true;include/hw/boards.h +4
-0@@ -57,6 +57,9 @@ bool machine_mem_merge(MachineState *machine);* Set only by old machines because they need to keep * compatibility on code that exposed QEMU_VERSION to guests in * the past (and now use qemu_hw_version()). +* @cpu_slots: +* Provides information about populated and yet-to-be populated +* CPU slots in the machine. Used by QMP query-cpu-slots. */ struct MachineClass {/*< private >*/ @@ -99,6 +102,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);unsigned (*cpu_index_to_socket_id)(unsigned cpu_index); + CPUSlotInfoList *(*cpu_slots)(MachineState *machine); };/** qapi-schema.json +60
-0@@ -4083,3 +4083,88 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @CPUInfo: +# +# Information about CPUs +# +# @arch-id: Arch-specific ID for the CPU. +# +# @type: QOM type of the CPU. +# +# @thread: Thread ID of the CPU. +# +# @core: Core ID of the CPU. +# +# @socket: Socket ID of the CPU. +# +# @node: NUMA node to which the CPU belongs. +# +# @qom-path: QOM path of the CPU object +# +# Since: 2.6 +## + +{ 'struct': 'CPUInfo', + 'data': { 'arch-id': 'int', + 'type': 'str', + '*thread': 'int', + '*core': 'int', + '*socket' : 'int', + '*node' : 'int', + '*qom-path': 'str' + } +} + +## +# @CPUSlotInfo: +# +# Information about CPU Slots +# +# @id: Device ID of the CPU composite object that occupies the slot. +# +# @type: QOM type of the CPU composite object that occupies the slot. +# +# @hotplug-granularity: Granularity of CPU composite hotplug for this slot, +# can be thread, core or socket. +# +# @slot-id: Slot's identifier. +# +# @qom-path: QOM path of the CPU composite object that occupies the slot. +# +# @realized: A boolean that indicates whether the slot is filled or empty. +# +# @nr-cpus: Number of CPUs that are part of CPU composite object that occupies +# this slot. +# +# @cpus: An array of @CPUInfo elements where each element describes one +# CPU that is part of this slot's CPU composite object. +# +# @type: QOM type +#Quoted 8 lines
qapi-schema.json line 4152
Quoted 7 lines
qapi-schema.json +7
-0+# Since: 2.6 +## + +{ 'struct': 'CPUSlotInfo', + 'data': { '*id': 'str', + 'type': 'str', + 'hotplug-granularity' : 'str',Does it convey any useful info, if yes how it will be used by mgmt?
As I noted in the patch desc, this field is useless, will remove.
Quoted 5 lines
qapi-schema.json line 4155
Quoted 4 lines
qapi-schema.json +3
-0+ 'slot-id' : 'str', + '*qom-path': 'str', + 'realized': 'bool',field's redundant, presence of qom-path answers this question
Ok, makes sense.
Quoted 9 lines
qapi-schema.json line 4157
Quoted 3 lines
qapi-schema.json +2
-0+ '*nr-cpus': 'int', + '*cpus' : ['CPUInfo']I'd suggest to drop above 2 fields as it's impl dependent, qom-path already point's to socket/core/thread object and its internal composition can be explored by other means if needed.
Moreover 'CPUInfo' is confusing and sort of conflicts with existing 'CpuInfo'.
Ah I see, should change the naming if we eventually stick with this implementation.
Quoted 2 lines
I'd drop CPUInfo altogether and introduce only 'CPUSlotInfo' here, existing thread enumeration's already implemented query-cpus.
Ok.
Quoted 8 lines
qapi-schema.json line 4159
Quoted 3 lines
qapi-schema.json +2
-0+ } +}What I miss here is that CPUSlotInfo doesn't provide any information to about where CPU might be hotplugged to.
Maybe use following tuple instead of slot-id?
Quoted 7 lines
{ 'struct': 'CPUSlotProperties',
'data': { '*node': 'int','*socket': 'int', '*core': 'int', '*thread': 'int'}
}Quoted 6 lines
Hmm not sure. If I undestand Andreas' proposal correctly, slot is the place where the CPU sits. Machine determines the type of the slot and it can be socket slot, core slot or thread slot based on the granularity of the hotplug supported by the machine. With this I don't see why anything else apart from slot-id/slot-name is required to figure out where to hoplug CPU.
Of cause it's possible to create and keep at board level map of slot-names to whatever other info needed to create a CPU object at machine init time, and then make board somehow to apply it to the new CPU object before realizing it.
But it doesn't give mgmt any information whatsoever about where CPU is being hotplugged. So for x86/arm we would end up with adding yet another interface that would tell it. If CPUSlotProperties is used instead of slot-name, it could convey that information while keeping interface compatible with a range targets we care about and extendable to other targets in future.
Quoted 4 lines
In the current implementation, sPAPR hotplug is at core granularity. CPUSlotInfo.type advertises the type as spapr-cpu-core. The number of threads in the core and the CPU model of the threads are either machine default or specified by user during hotplug time.
now imagine extending in future sPAPR to support NUMA, which way would you extend interface, how would mgmt know which CPU belongs to what node?
As you may note in CPUSlotProperties fields are optional so target would use only ones it needs. For current sPAPR, query result could be something like this:
{
{ type: spapr-cpu-core properties: { core: 0 } qom-path: /machine/unattached/device[xxx] } { type: spapr-cpu-core properties: { core: 1 } } ... { type: spapr-cpu-core properties: { core: 0 }Quoted 5 lines
}
}Later if numa was needed, the board could set 'numa' property as well. Would that work for sPAPR?
It could work, however I am finding it difficult to reconcile this with the machine object to core links that I have in this implementation which I believe is what Andreas originally suggested. Such a link essentially represents a slot and it has a name associated with it which identifies the location where the core is plugged.
Quoted 5 lines
Now in order to incorporate CPUSlotProperties, these properties must be tied to a slot/location object which in the present implementation doesn't exist. So are you suggesting that we create slot/location object (abstract ?) that has CPUSlotProperties ? If so, then I guess we don't need machine object to core object links ?
I consider links as QOM interface to access Existing CPUs and they links are more or less useless when it comes to possible CPUs. If you really have to have links, you can associate them with cores instead of slots, so it would look like:
/machine/
-> cpu-core[0]
-> cpu-core[1]
...I'm not suggesting anything related to QOM interface or QOM in general when we discussing QMP interface in this patch. On contrary this QMP query should be QOM agnostic so each target could implement it regardless of what QOM model it uses.
So CPUSlotProperties is a pure QMP construct not tied to QOM and it's up to machine callback to return CPUs layout description like it has been proposed in https://patchwork.ozlabs.org/patch/583036/
I think in that thread, I've succeed in convincing Eduardo and David to set aside QOM interface and implement only QMP command. (Perhaps looking through that thread will convince you too if you re-read it). I'll repost that patch taking in account comments on that and this mail-thread using CPUSlotProperties.
That way we separate interface issue from QOM interface, making QOM modeling a target implementation detail. Then each target can implement it's own QOM device model (including links if it wishes) to play with but still use common QMP interface which will not be affected by it.
So mgmt would get stable well described/documented interface, and we could eventually move with device_add based CPU hotplug from stalemate point. QOM interface would be left for future exercise or as experimental thing until it became at parity with QMP one and had time settle down more or less.
Quoted 4 lines
Regards,
Bharata.