s390x: CPU Topology
Subsystems (2)
v14 cover s390x: CPU Topology
Hi,
This new series adds three features:
1) the implementation of drawers and books in the topology geometry and adds polarization and dedication as topology modifiers.
2) The Maximum Nested topology level (MNEST) can be read with SCLP read info.
3) Dynamic modification of the CPU topology using the QEMU monitor.
Implementation discussions
==========================
CPU models
----------
Since the facility 11, S390_FEAT_CONFIGURATION_TOPOLOGY is already in the CPU model for old QEMU we could not activate it as usual from KVM but needed a KVM capability: KVM_CAP_S390_CPU_TOPOLOGY. Checking and enabling this capability enables facility 11, S390_FEAT_CONFIGURATION_TOPOLOGY.
It is the responsibility of the admin to ensure the same CPU model for source and target host in a migration.
Migration
---------
When the target guest is started, the Multi-processor Topology Change Report (MTCR) bit is set during the creation of the vCPU by KVM. We do not need to migrate its state, in the worst case, the target guest will see the MTCR and actualize its view of the topology without necessity, but this will be done only one time.
Reset
-----
Reseting the topology is done during subsystem reset, the polarization is reset to horizontal polarization.
Topology attributes
-------------------
The topology attributes are carried by the CPU object and defined on object creation.
In the case the new attributes, socket, book, drawer, dedicated, polarity are not provided QEMU provides defaults values.
- Geometry defaults
The geometry default are based on the core-id of the core to fill the geometry in a monotone way starting with drawer 0, book 0, and filling socket 0 with the number of cores per socket, then filling socket 1, socket 2 ... etc until the book is complete and all books until the first drawer is complete before starting with the next drawer.
This allows to keep existing start scripts and Libvirt existing interface until it is extended.
- Modifiers defaults
Default polarization is horizontal
Default dedication is not dedicated.
Dynamic topology modification
-----------------------------
QAPI interface is extended with:
- a command: 'change-topology'
- a query: 'query-topology'
- a event: 'POLARITY_CHANGE'
The admin may use query-topology to verify the topology provided to the guest and change-topology to modify it.
The event POLARITY_CHANGE is sent when the guest uses the PTF instruction to request a polarization change. In that case, the admin is supposed to modify the CPU provisioning accordingly.
Testing
=======
To use the QEMU patches, you will need Linux V6-rc1 or newer, or use the following Linux mainline patches:
f5ecfee94493 2022-07-20 KVM: s390: resetting the Topology-Change-Report 24fe0195bc19 2022-07-20 KVM: s390: guest support for topology function 0130337ec45b 2022-07-20 KVM: s390: Cleanup ipte lock access and SIIF fac..
Currently this code is for KVM only, I have no idea if it is interesting to provide a TCG patch. If ever it will be done in another series.
Documentation
=============
To have a better understanding of the S390x CPU Topology and its implementation in QEMU you can have a look at the documentation in the last patch of this series.
The admin will want to match the host and the guest topology, taking into account that the guest does not recognize multithreading. Consequently, two vCPU assigned to threads of the same real CPU should preferably be assigned to the same socket of the guest machine.
Regards,
Pierre
Pierre Morel (11):
s390x/cpu topology: adding s390 specificities to CPU topology s390x/cpu topology: add topology entries on CPU hotplug target/s390x/cpu topology: handle STSI(15) and build the SYSIB s390x/sclp: reporting the maximum nested topology entries s390x/cpu topology: resetting the Topology-Change-Report s390x/cpu topology: interception of PTF instruction target/s390x/cpu topology: activating CPU topology qapi/s390/cpu topology: change-topology monitor command qapi/s390/cpu topology: monitor query topology information qapi/s390/cpu topology: POLARITY_CHANGE qapi event docs/s390x/cpu topology: document s390x cpu topology
docs/system/s390x/cpu-topology.rst | 292 ++++++++++++++ docs/system/target-s390x.rst | 1 + qapi/machine-target.json | 116 ++++++ qapi/machine.json | 14 +- include/hw/boards.h | 10 +- include/hw/s390x/cpu-topology.h | 77 ++++ include/hw/s390x/s390-virtio-ccw.h | 6 + include/hw/s390x/sclp.h | 4 +- include/monitor/hmp.h | 2 + target/s390x/cpu.h | 86 ++++ target/s390x/kvm/kvm_s390x.h | 1 + hw/core/machine-smp.c | 48 ++- hw/core/machine.c | 4 + hw/s390x/cpu-topology.c | 604 +++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 13 + hw/s390x/sclp.c | 4 + softmmu/vl.c | 6 + target/s390x/cpu-sysemu.c | 29 ++ target/s390x/cpu.c | 10 + target/s390x/cpu_models.c | 1 + target/s390x/kvm/cpu_topology.c | 136 +++++++ target/s390x/kvm/kvm.c | 46 ++- hmp-commands-info.hx | 16 + hmp-commands.hx | 16 + hw/s390x/meson.build | 1 + qemu-options.hx | 6 +- target/s390x/kvm/meson.build | 3 +- 27 files changed, 1537 insertions(+), 15 deletions(-) create mode 100644 docs/system/s390x/cpu-topology.rst create mode 100644 include/hw/s390x/cpu-topology.h create mode 100644 hw/s390x/cpu-topology.c create mode 100644 target/s390x/kvm/cpu_topology.c
Signature · 160 lines
2.31.1 Since v13: - Suppress the topology device to simplify the code (Cedric) - moved reset of MTCR from device reset into subsystem reset and removed previous reviewed-by from Nico and Janis - No need for Migration - No need for machine dependencies (Christian, Thomas) - Adding all features, drawer/book and dynamic (Cedric) - since v12 - suppress new CPU flag "disable-topology" just use ctop - no use of special fields in CCW machine or in CPU - modifications in documentation - insert documentation in tree (Cedric) - moved cpu-topology.c from target/s390 to target/s390/kvm to compile smoothly (without topology) for TCG (Cedric) - since v11 - new CPU flag "disable-topology" I would have take "topology" if I was able to have it false on default. (Christian, Thomas) - Build the topology during the interception of the STSI instruction. (Cedric) - return CC3 in case the calculated SYSIB length is greater than 4096. (Janis) - minor corections on documentation - since v10 - change machine attribute "topology-disable" to "topology" (Cedric) - Add preliminary patch for machine properties (Cedric) - Use next machine as 7.2 (Cedric / Connie) - Remove unecessary mutex (Thomas) - use ENOTSUP return value for kvm_s390_topology_set_mtcr() (Cedric) - Add explanation on container and cpu TLEs (Thomas) - use again cpu and socket count in topology structure (Cedric) - Suppress the S390TopoTLE structure and integrate the TLE masks to the socket structure. (-) - the STSI instruction now finds the topology from the machine (Cedric) - since v9 - remove books and drawers - remove thread denying and replace with a merge of cores * threads to specify the CPUs available to the guest - add a class option to avoid topology on older machines (Cedric) - Allocate a SYSIB buffer of the maximal length to avoid overflow. (Nico, Janis) - suppress redundancy of smp parameters in topology and use directly the machine smp structure - Early check for topology support (Cedric) - since v8 - Linux patches are now mainline - simplification of the implementation (Janis) - Migration, new machine definition (Thomas) - Documentation - since v7 - Coherence with the Linux patch series changes for MTCR get (Pierre) - check return values during new CPU creation (Thomas) - Improving codding style and argument usages (Thomas) - since v6 - Changes on smp args in qemu-options (Daniel) - changed comments in machine.jason (Daniel) - Added reset (Janosch) - since v5 - rebasing on newer QEMU version - reworked most lines above 80 characters. - since v4 - Added drawer and books to topology - Added numa topology - Added documentation - since v3 - Added migration (Thomas) - Separated STSI instruction from KVM to prepare TCG (Thomas) - Take care of endianess to prepare TCG (Thomas) - Added comments on STSI CPU container and PFT instruction (Thomas) - Moved enabling the instructions as the last patch (Thomas)
PATCH v14 1/11 s390x/cpu topology: adding s390 specificities to CPU topology
S390 adds two new SMP levels, drawers and books to the CPU topology.
The S390 CPU have specific toplogy features like dedication and polarity to give to the guest indications on the host vCPUs scheduling and help the guest take the best decisions on the scheduling of threads on the vCPUs.
Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and polarity,
--- qapi/machine.json | 14 ++++++++-- include/hw/boards.h | 10 ++++++- include/hw/s390x/cpu-topology.h | 23 ++++++++++++++++ target/s390x/cpu.h | 6 +++++ hw/core/machine-smp.c | 48 ++++++++++++++++++++++++++++----- hw/core/machine.c | 4 +++ hw/s390x/s390-virtio-ccw.c | 2 ++ softmmu/vl.c | 6 +++++ target/s390x/cpu.c | 10 +++++++ qemu-options.hx | 6 +++-- 10 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 include/hw/s390x/cpu-topology.h
qapi/machine.json +12 -2
@@ -900,13 +900,15 @@ # a CPU is being hotplugged. # # @node-id: NUMA node ID the CPU belongs to -# @socket-id: socket number within node/board the CPU belongs to +# @drawer-id: drawer number within node/board the CPU belongs to +# @book-id: book number within drawer/node/board the CPU belongs to +# @socket-id: socket number within book/node/board the CPU belongs to # @die-id: die number within socket the CPU belongs to (since 4.1) # @cluster-id: cluster number within die the CPU belongs to (since 7.1) # @core-id: core number within cluster the CPU belongs to # @thread-id: thread number within core the CPU belongs to # -# Note: currently there are 6 properties that could be present +# Note: currently there are 8 properties that could be present # but management should be prepared to pass through other # properties with device_add command to allow for future # interface extension. This also requires the filed names to be kept in
@@ -916,6 +918,8 @@ ## { 'struct': 'CpuInstanceProperties', 'data': { '*node-id': 'int', + '*drawer-id': 'int', + '*book-id': 'int', '*socket-id': 'int', '*die-id': 'int', '*cluster-id': 'int',
@@ -1465,6 +1469,10 @@ # # @cpus: number of virtual CPUs in the virtual machine # +# @drawers: number of drawers in the CPU topology +# +# @books: number of books in the CPU topology +# # @sockets: number of sockets in the CPU topology # # @dies: number of dies per socket in the CPU topology
@@ -1481,6 +1489,8 @@ ## { 'struct': 'SMPConfiguration', 'data': { '*cpus': 'int', + '*drawers': 'int', + '*books': 'int', '*sockets': 'int', '*dies': 'int', '*clusters': 'int',
include/hw/boards.h +9 -1
@@ -130,11 +130,15 @@ typedef struct {* @prefer_sockets - whether sockets are preferred over cores in smp parsing * @dies_supported - whether dies are supported by the machine * @clusters_supported - whether clusters are supported by the machine +* @books_supported - whether books are supported by the machine +* @drawers_supported - whether drawers are supported by the machine */ typedef struct {bool prefer_sockets;bool dies_supported;bool clusters_supported; +bool books_supported; +bool drawers_supported; }SMPCompatProps ;/**
@@ -299,7 +303,9 @@ typedef struct DeviceMemoryState {/** * CpuTopology: * @cpus: the number of present logical processors on the machine -* @sockets: the number of sockets on the machine +* @drawers: the number of drawers on the machine +* @books: the number of books in one drawer +* @sockets: the number of sockets in one book * @dies: the number of dies in one socket * @clusters: the number of clusters in one die * @cores: the number of cores in one cluster
@@ -308,6 +314,8 @@ typedef struct DeviceMemoryState {*/ typedef struct CpuTopology { unsigned int cpus; + unsigned int drawers; + unsigned int books; unsigned int sockets; unsigned int dies; unsigned int clusters;
include/hw/s390x/cpu-topology.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* CPU Topology +* +* Copyright IBM Corp. 2022 +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ +#ifndef HW_S390X_CPU_TOPOLOGY_H +#define HW_S390X_CPU_TOPOLOGY_H + +#define S390_TOPOLOGY_CPU_IFL 0x03 + +#define S390_TOPOLOGY_POLARITY_HORIZONTAL 0x00 +#define S390_TOPOLOGY_POLARITY_VERTICAL_LOW 0x01 +#define S390_TOPOLOGY_POLARITY_VERTICAL_MEDIUM 0x02 +#define S390_TOPOLOGY_POLARITY_VERTICAL_HIGH 0x03 + +#define S390_TOPOLOGY_SHARED 0x00 +#define S390_TOPOLOGY_DEDICATED 0x01 + +#endif
target/s390x/cpu.h +6 -0
@@ -131,6 +131,12 @@ struct CPUArchState {#if !defined(CONFIG_USER_ONLY )uint32_t core_id;/* PoP "CPU address", same as cpu_index */ +int32_t socket_id; +int32_t book_id; +int32_t drawer_id; +int32_t dedicated; +int32_t polarity; +int32_t cpu_type;uint64_t cpuid;#endif
hw/core/machine-smp.c +41 -7
105 lines not on this page · raw message
hw/core/machine.c +4 -0
@@ -827,6 +827,8 @@ static void machine_get_smp(Object *obj, Visitor *v, const char *name,MachineState *ms =MACHINE (obj);SMPConfiguration *config = &(SMPConfiguration ){ .has_cpus = true, .cpus = ms->smp.cpus, + .has_drawers = true, .drawers = ms->smp.drawers, + .has_books = true, .books = ms->smp.books, .has_sockets = true, .sockets = ms->smp.sockets, .has_dies = true, .dies = ms->smp.dies, .has_clusters = true, .clusters = ms->smp.clusters,
@@ -1092,6 +1094,8 @@ static void machine_initfn(Object *obj)/* default to mc->default_cpus */ ms->smp.cpus = mc->default_cpus; ms->smp.max_cpus = mc->default_cpus; + ms->smp.drawers =1 ; + ms->smp.books =1 ; ms->smp.sockets =1 ; ms->smp.dies =1 ; ms->smp.clusters =1 ;
hw/s390x/s390-virtio-ccw.c +2 -0
@@ -733,6 +733,8 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) mc->no_sdcard =1 ; mc->max_cpus =S390_MAX_CPUS ; mc->has_hotpluggable_cpus = true; + mc->smp_props.books_supported = true; + mc->smp_props.drawers_supported = true;assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = s390_get_hotplug_handler; mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
softmmu/vl.c +6 -0
@@ -724,6 +724,12 @@ static QemuOptsList qemu_smp_opts = { { .name = "cpus", .type = QEMU_OPT_NUMBER, + }, { + .name = "drawers", + .type = QEMU_OPT_NUMBER, + }, { + .name = "books", + .type = QEMU_OPT_NUMBER, }, { .name = "sockets", .type = QEMU_OPT_NUMBER,
target/s390x/cpu.c +10 -0
@@ -35,6 +35,7 @@#include "fpu/softfloat-helpers.h" #include "disas/capstone.h" #include "sysemu/tcg.h" +#include "hw/s390x/cpu-topology.h" #define CR0_RESET 0xE0UL#define CR14_RESET 0xC2000000UL;
@@ -257,6 +258,15 @@ static gchar *s390_gdb_arch_name(CPUState *cs)static Property s390x_cpu_properties[] = { #if !defined(CONFIG_USER_ONLY)DEFINE_PROP_UINT32 ("core-id" ,S390CPU , env.core_id,0 ), +DEFINE_PROP_INT32 ("socket-id" ,S390CPU , env.socket_id,-1 ), +DEFINE_PROP_INT32 ("book-id" ,S390CPU , env.book_id,-1 ), +DEFINE_PROP_INT32 ("drawer-id" ,S390CPU , env.drawer_id,-1 ), +DEFINE_PROP_INT32 ("dedicated" ,S390CPU , env.dedicated, +S390_TOPOLOGY_SHARED ), +DEFINE_PROP_INT32 ("polarity" ,S390CPU , env.polarity, +S390_TOPOLOGY_POLARITY_HORIZONTAL ), +DEFINE_PROP_INT32 ("cpu-type" ,S390CPU , env.cpu_type, +S390_TOPOLOGY_CPU_IFL ), #endifDEFINE_PROP_END_OF_LIST () };
qemu-options.hx +4 -2
@@ -250,11 +250,13 @@ SRST ERST DEF("smp", HAS_ARG, QEMU_OPTION_smp, - "-smp [[cpus=]n][,maxcpus=maxcpus][,sockets=sockets][,dies=dies][,clusters=clusters][,cores=cores][,threads=threads]\n" + "-smp [[cpus=]n][,maxcpus=maxcpus][,drawers=drawers][,books=books][,sockets=sockets][,dies=dies][,clusters=clusters][,cores=cores][,threads=threads]\n" " set the number of initial CPUs to 'n' [default=1]\n" " maxcpus= maximum number of total CPUs, including\n" " offline CPUs for hotplug, etc\n" - " sockets= number of sockets on the machine board\n" + " drawers= number of drawers on the machine board\n" + " books= number of books in one drawer\n" + " sockets= number of sockets in one book\n" " dies= number of dies in one socket\n" " clusters= number of clusters in one die\n" " cores= number of cores in one cluster\n"
Signature · 1 line
2.31.1
Re: [PATCH v14 01/11] s390x/cpu topology: adding s390 specificities to CPU topology
Quoted 12 lines · Pierre Morel
S390 adds two new SMP levels, drawers and books to the CPU topology.
The S390 CPU have specific toplogy features like dedication and polarity to give to the guest indications on the host vCPUs scheduling and help the guest take the best decisions on the scheduling of threads on the vCPUs.Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and polarity,
Signed-off-by Pierre Morel <[email protected]>---
...
qapi/machine.json line 905
Quoted 12 lines
qapi/machine.json +3
-1@@ -900,13 +900,15 @@ # a CPU is being hotplugged. # # @node-id: NUMA node ID the CPU belongs to -# @socket-id: socket number within node/board the CPU belongs to +# @drawer-id: drawer number within node/board the CPU belongs to +# @book-id: book number within drawer/node/board the CPU belongs to +# @socket-id: socket number within book/node/board the CPU belongs to
I think the new entries need a "(since 8.0)" comment (similar to die-id and cluster-id below).
Other question: Do we have "node-id"s on s390x? If not, is that similar to books or drawers, i.e. just another word? If so, we should maybe rather re-use "nodes" instead of introducing a new name for the same thing?
Quoted 20 lines
qapi/machine.json +3
-1# @die-id: die number within socket the CPU belongs to (since 4.1) # @cluster-id: cluster number within die the CPU belongs to (since 7.1) # @core-id: core number within cluster the CPU belongs to # @thread-id: thread number within core the CPU belongs to # -# Note: currently there are 6 properties that could be present +# Note: currently there are 8 properties that could be present # but management should be prepared to pass through other # properties with device_add command to allow for future # interface extension. This also requires the filed names to be kept in@@ -916,6 +918,8 @@ ## { 'struct': 'CpuInstanceProperties', 'data': { '*node-id': 'int', + '*drawer-id': 'int', + '*book-id': 'int', '*socket-id': 'int', '*die-id': 'int', '*cluster-id': 'int',
qapi/machine.json line 1475
Quoted 7 lines
qapi/machine.json +4
-0@@ -1465,6 +1469,10 @@ # # @cpus: number of virtual CPUs in the virtual machine # +# @drawers: number of drawers in the CPU topology +# +# @books: number of books in the CPU topology +#
These also need a "(since 8.0)" comment at the end.
Quoted 12 lines
qapi/machine.json +2
-0# @sockets: number of sockets in the CPU topology # # @dies: number of dies per socket in the CPU topology@@ -1481,6 +1489,8 @@ ## { 'struct': 'SMPConfiguration', 'data': { '*cpus': 'int', + '*drawers': 'int', + '*books': 'int', '*sockets': 'int', '*dies': 'int', '*clusters': 'int',
...
qemu-options.hx SRST · line 253
Quoted 10 lines
qemu-options.hx +1
-1@@ -250,11 +250,13 @@ SRST ERST DEF("smp", HAS_ARG, QEMU_OPTION_smp, - "-smp [[cpus=]n][,maxcpus=maxcpus][,sockets=sockets][,dies=dies][,clusters=clusters][,cores=cores][,threads=threads]\n" + "-smp [[cpus=]n][,maxcpus=maxcpus][,drawers=drawers][,books=books][,sockets=sockets][,dies=dies][,clusters=clusters][,cores=cores][,threads=threads]\n"
This line now got too long. Please add a newline inbetween.
qemu-options.hx SRST · line 262
Quoted 10 lines
qemu-options.hx +3
-1" set the number of initial CPUs to 'n' [default=1]\n" " maxcpus= maximum number of total CPUs, including\n" " offline CPUs for hotplug, etc\n" - " sockets= number of sockets on the machine board\n" + " drawers= number of drawers on the machine board\n" + " books= number of books in one drawer\n" + " sockets= number of sockets in one book\n" " dies= number of dies in one socket\n" " clusters= number of clusters in one die\n" " cores= number of cores in one cluster\n"
Thomas
Re: [PATCH v14 01/11] s390x/cpu topology: adding s390 specificities to CPU topology
Quoted 14 lines · Thomas Huth
Quoted 12 lines · Pierre Morel
S390 adds two new SMP levels, drawers and books to the CPU topology.
The S390 CPU have specific toplogy features like dedication and polarity to give to the guest indications on the host vCPUs scheduling and help the guest take the best decisions on the scheduling of threads on the vCPUs.Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and polarity,
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 14 lines
qapi/machine.json line 905
Quoted 12 lines
qapi/machine.json +3
-1@@ -900,13 +900,15 @@ # a CPU is being hotplugged. # # @node-id: NUMA node ID the CPU belongs to -# @socket-id: socket number within node/board the CPU belongs to +# @drawer-id: drawer number within node/board the CPU belongs to +# @book-id: book number within drawer/node/board the CPU belongs to +# @socket-id: socket number within book/node/board the CPU belongs toI think the new entries need a "(since 8.0)" comment (similar to die-id and cluster-id below).
right
Quoted 2 lines
Other question: Do we have "node-id"s on s390x? If not, is that similar to books or drawers, i.e. just another word? If so, we should maybe rather re-use "nodes" instead of introducing a new name for the same thing?
We have theoretically nodes-id on s390x, it is the level 5 of the topology, above drawers. Currently it is not used in s390x topology, the maximum level returned to a LPAR host is 4. I suppose that it adds a possibility to link several s390x with a fast network.
Quoted 22 lines
Quoted 22 lines
qapi/machine.json +3
-1# @die-id: die number within socket the CPU belongs to (since 4.1) # @cluster-id: cluster number within die the CPU belongs to (since 7.1) # @core-id: core number within cluster the CPU belongs to # @thread-id: thread number within core the CPU belongs to # -# Note: currently there are 6 properties that could be present +# Note: currently there are 8 properties that could be present # but management should be prepared to pass through other # properties with device_add command to allow for future # interface extension. This also requires the filed names to be kept in@@ -916,6 +918,8 @@ ## { 'struct': 'CpuInstanceProperties', 'data': { '*node-id': 'int', + '*drawer-id': 'int', + '*book-id': 'int', '*socket-id': 'int', '*die-id': 'int', '*cluster-id': 'int',@@ -1465,6 +1469,10 @@ #
Quoted 8 lines
qapi/machine.json line 1475
Quoted 6 lines
qapi/machine.json +4
-0# @cpus: number of virtual CPUs in the virtual machine # +# @drawers: number of drawers in the CPU topology +# +# @books: number of books in the CPU topology +#These also need a "(since 8.0)" comment at the end.
right again, I will add this.
Quoted 14 lines
Quoted 13 lines
qapi/machine.json +2
-0# @sockets: number of sockets in the CPU topology # # @dies: number of dies per socket in the CPU topology@@ -1481,6 +1489,8 @@ ## { 'struct': 'SMPConfiguration', 'data': { '*cpus': 'int', + '*drawers': 'int', + '*books': 'int', '*sockets': 'int', '*dies': 'int', '*clusters': 'int',...
Quoted 13 lines
Quoted 11 lines
qemu-options.hx +0
-0@@ -250,11 +250,13 @@ SRSTERST
DEF("smp",HAS_ARG,QEMU_OPTION_smp,
- "-smp [[cpus=]n][,maxcpus=maxcpus][,sockets=sockets][,dies=dies][,clusters=clusters][,cores=cores][,threads=threads]\n"
+ "-smp [[cpus=]n][,maxcpus=maxcpus][,drawers=drawers][,books=books][,sockets=sockets][,dies=dies][,clusters=clusters][,cores=cores][,threads=threads]\n"This line now got too long. Please add a newline inbetween.
OK
Thanks.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 01/11] s390x/cpu topology: adding s390 specificities to CPU topology
Quoted 2 lines · Pierre Morel
On 1/10/23 12:37, Thomas Huth wrote:
...
Quoted 5 lines
Quoted 1 line
Other question: Do we have "node-id"s on s390x? If not, is that similar to books or drawers, i.e. just another word? If so, we should maybe rather re-use "nodes" instead of introducing a new name for the same thing?
We have theoretically nodes-id on s390x, it is the level 5 of the topology, above drawers. Currently it is not used in s390x topology, the maximum level returned to a LPAR host is 4. I suppose that it adds a possibility to link several s390x with a fast network.
Ok, thanks. So if nodes are indeed a concept on top of the other layers, and we do not really support these on s390x yet, should we maybe forbid them on s390x like we recently did with the "threads" in the recent machine types? ... to avoid that users try to use them with the wrong expectations?
Thomas
Re: [PATCH v14 01/11] s390x/cpu topology: adding s390 specificities to CPU topology
In reply to Pierre MorelQuoted 25 lines · Pierre Morel
S390 adds two new SMP levels, drawers and books to the CPU topology.
The S390 CPU have specific toplogy features like dedication and polarity to give to the guest indications on the host vCPUs scheduling and help the guest take the best decisions on the scheduling of threads on the vCPUs.Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and polarity,
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine.json | 14 ++++++++-- include/hw/boards.h | 10 ++++++- include/hw/s390x/cpu-topology.h | 23 ++++++++++++++++ target/s390x/cpu.h | 6 +++++ hw/core/machine-smp.c | 48 ++++++++++++++++++++++++++++----- hw/core/machine.c | 4 +++ hw/s390x/s390-virtio-ccw.c | 2 ++ softmmu/vl.c | 6 +++++ target/s390x/cpu.c | 10 +++++++ qemu-options.hx | 6 +++-- 10 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 include/hw/s390x/cpu-topology.h
[...]
target/s390x/cpu.h struct CPUArchState { · line 138
Quoted 13 lines
target/s390x/cpu.h +5
-0@@ -131,6 +131,12 @@ struct CPUArchState {#if !defined(CONFIG_USER_ONLY )uint32_t core_id;/* PoP "CPU address", same as cpu_index */ +int32_t socket_id; +int32_t book_id; +int32_t drawer_id; +int32_t dedicated; +int32_t polarity;
If I understood the architecture correctly, the polarity is a property of the configuration, not the cpus. So this should be vertical_entitlement, and there should be a machine (?) property specifying if the polarity is horizontal or vertical.
Quoted 4 lines
target/s390x/cpu.h +1
-0+int32_t cpu_type;uint64_t cpuid;#endif
[...]
Re: [PATCH v14 01/11] s390x/cpu topology: adding s390 specificities to CPU topology
Quoted 34 lines · Nina Schoetterl-Glausch
Quoted 25 lines · Pierre Morel
S390 adds two new SMP levels, drawers and books to the CPU topology.
The S390 CPU have specific toplogy features like dedication and polarity to give to the guest indications on the host vCPUs scheduling and help the guest take the best decisions on the scheduling of threads on the vCPUs.Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and polarity,
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine.json | 14 ++++++++-- include/hw/boards.h | 10 ++++++- include/hw/s390x/cpu-topology.h | 23 ++++++++++++++++ target/s390x/cpu.h | 6 +++++ hw/core/machine-smp.c | 48 ++++++++++++++++++++++++++++----- hw/core/machine.c | 4 +++ hw/s390x/s390-virtio-ccw.c | 2 ++ softmmu/vl.c | 6 +++++ target/s390x/cpu.c | 10 +++++++ qemu-options.hx | 6 +++-- 10 files changed, 117 insertions(+), 12 deletions(-)create mode 100644
include/hw/s390x/cpu-topology.h[...]
Quoted 6 lines
target/s390x/cpu.h +0
-0@@ -131,6 +131,12 @@ struct CPUArchState {
Quoted 11 lines
target/s390x/cpu.h struct CPUArchState { · line 138
Quoted 7 lines
target/s390x/cpu.h +5
-0#if !defined(CONFIG_USER_ONLY )uint32_t core_id;/* PoP "CPU address", same as cpu_index */ +int32_t socket_id; +int32_t book_id; +int32_t drawer_id; +int32_t dedicated; +int32_t polarity;If I understood the architecture correctly, the polarity is a property of the configuration, not the cpus. So this should be
vertical_entitlement, and there should be a machine (?) property specifying if the polarity is horizontal or vertical.
You are right, considering PTF only, the documentation says PTF([01]) does the following:
"... a process is initiated to place all CPUs in the configuration into the polarization specified by the function code, ..."
So on one side the polarization property is explicitly set on the CPU, and on the other side all CPU are supposed to be in the same polarization state.
So yes we can make the horizontal/vertical a machine property.
However, we do not need to set this tunable as the documentation says that the machine always start with horizontal polarization.
On the other hand the documentation mixes a lot vertical with different entitlement and horizontal polarization, for TLE order and slacks so I prefer to keep the complete description of the polarization as CPU properties in case we miss something.
PTF([01]) are no performance bottle neck and the number of CPU is likely to be small, even a maximum of 248 is possible KVM warns above 16 CPU so the loop for setting all CPU inside PTF interception is not very problematic I think.
Doing like you say should simplify PTF interception (no loop) but complicates (some more if/else) TLE handling and QMP information display on CPU. So I will have a look at the implications and answer again on this.
Thanks,
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 01/11] s390x/cpu topology: adding s390 specificities to CPU topology
Quoted 51 lines · Pierre Morel
Quoted 34 lines · Nina Schoetterl-Glausch
Quoted 25 lines · Pierre Morel
S390 adds two new SMP levels, drawers and books to the CPU topology.
The S390 CPU have specific toplogy features like dedication and polarity to give to the guest indications on the host vCPUs scheduling and help the guest take the best decisions on the scheduling of threads on the vCPUs.Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and polarity,
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine.json | 14 ++++++++-- include/hw/boards.h | 10 ++++++- include/hw/s390x/cpu-topology.h | 23 ++++++++++++++++ target/s390x/cpu.h | 6 +++++ hw/core/machine-smp.c | 48 ++++++++++++++++++++++++++++----- hw/core/machine.c | 4 +++ hw/s390x/s390-virtio-ccw.c | 2 ++ softmmu/vl.c | 6 +++++ target/s390x/cpu.c | 10 +++++++ qemu-options.hx | 6 +++-- 10 files changed, 117 insertions(+), 12 deletions(-)create mode 100644
include/hw/s390x/cpu-topology.h[...]
Quoted 6 lines
target/s390x/cpu.h +0
-0@@ -131,6 +131,12 @@ struct CPUArchState {Quoted 11 lines
target/s390x/cpu.h struct CPUArchState { · line 138
Quoted 7 lines
target/s390x/cpu.h +5
-0#if !defined(CONFIG_USER_ONLY )uint32_t core_id;/* PoP "CPU address", same as cpu_index */ +int32_t socket_id; +int32_t book_id; +int32_t drawer_id; +int32_t dedicated; +int32_t polarity;If I understood the architecture correctly, the polarity is a property of the configuration, not the cpus. So this should be
vertical_entitlement, and there should be a machine (?) property specifying if the polarity is horizontal or vertical.You are right, considering PTF only, the documentation says
PTF([01])does the following:
Quoted 6 lines
"... a process is initiated to place all CPUs in the configuration into the polarization specified by the function code, ..."
So on one side the polarization property is explicitly set on the CPU, and on the other side all CPU are supposed to be in the same polarization state.
I'm worried about STSI showing both horizontal and vertical CPUs at the same time. I don't know if this is allowed.
If it is not, you need a way to switch between those atomically, which is harder if every CPU has this property.
Quoted 10 lines
So yes we can make the horizontal/vertical a machine property. However, we do not need to set this tunable as the documentation says that the machine always start with horizontal polarization.
On the other hand the documentation mixes a lot vertical with different entitlement and horizontal polarization, for TLE order and slacks so I prefer to keep the complete description of the polarization as CPU properties in case we miss something.
Quoted 4 lines
PTF([01])are no performance bottle neck and the number of CPU is likely to be small, even a maximum of 248 is possible KVM warns above 16 CPU so the loop for setting all CPU inside PTF interception is not very problematic I think.
Yeah, I'm not worried about that.
Quoted 11 lines
Doing like you say should simplify PTF interception (no loop) but complicates (some more if/else) TLE handling and QMP information display on CPU.
So I will have a look at the implications and answer again on this.Thanks,
Regards,
Pierre
Re: [PATCH v14 01/11] s390x/cpu topology: adding s390 specificities to CPU topology
Quoted 55 lines · Nina Schoetterl-Glausch
Quoted 54 lines · Pierre Morel
Quoted 34 lines · Nina Schoetterl-Glausch
Quoted 25 lines · Pierre Morel
S390 adds two new SMP levels, drawers and books to the CPU topology.
The S390 CPU have specific toplogy features like dedication and polarity to give to the guest indications on the host vCPUs scheduling and help the guest take the best decisions on the scheduling of threads on the vCPUs.Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and polarity,
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine.json | 14 ++++++++-- include/hw/boards.h | 10 ++++++- include/hw/s390x/cpu-topology.h | 23 ++++++++++++++++ target/s390x/cpu.h | 6 +++++ hw/core/machine-smp.c | 48 ++++++++++++++++++++++++++++----- hw/core/machine.c | 4 +++ hw/s390x/s390-virtio-ccw.c | 2 ++ softmmu/vl.c | 6 +++++ target/s390x/cpu.c | 10 +++++++ qemu-options.hx | 6 +++-- 10 files changed, 117 insertions(+), 12 deletions(-)create mode 100644
include/hw/s390x/cpu-topology.h[...]
Quoted 6 lines
target/s390x/cpu.h +0
-0@@ -131,6 +131,12 @@ struct CPUArchState {Quoted 11 lines
target/s390x/cpu.h struct CPUArchState { · line 138
Quoted 7 lines
target/s390x/cpu.h +5
-0#if !defined(CONFIG_USER_ONLY )uint32_t core_id;/* PoP "CPU address", same as cpu_index */ +int32_t socket_id; +int32_t book_id; +int32_t drawer_id; +int32_t dedicated; +int32_t polarity;If I understood the architecture correctly, the polarity is a property of the configuration, not the cpus. So this should be
vertical_entitlement, and there should be a machine (?) property specifying if the polarity is horizontal or vertical.You are right, considering PTF only, the documentation says
PTF([01])does the following:"... a process is initiated to place all CPUs in the configuration into the polarization specified by the function code, ..."
Quoted 8 lines
Quoted 3 lines
So on one side the polarization property is explicitly set on the CPU, and on the other side all CPU are supposed to be in the same polarization state.
I'm worried about STSI showing both horizontal and vertical CPUs at the same time. I don't know if this is allowed.
If it is not, you need a way to switch between those atomically, which is harder if every CPU has this property.
The documentation explicitly provides the order in which to show the TLE when both vertical and horizontal TLE are display inside the SYSIB. So it seems expected by the architecture.
I understand that it is because the documentation says that the instruction finished before all the CPU did change polarity.
But I think you are right on the point that:
- It is only transitional
- it does not make sense for my point of view to have both at the same time.
In QEMU, as these are two interceptions we will always finish the PTF interception before we start the STSI interception, so we will never see this happen.
Question are:
1) Should we do better than the architecture?
2) If yes, are we sure it is better?
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 01/11] s390x/cpu topology: adding s390 specificities to CPU topology
In reply to Pierre MorelQuoted 16 lines · Pierre Morel
Quoted 13 lines · Nina Schoetterl-Glausch
Quoted 12 lines · Pierre Morel
S390 adds two new SMP levels, drawers and books to the CPU topology.
The S390 CPU have specific toplogy features like dedication and polarity to give to the guest indications on the host vCPUs scheduling and help the guest take the best decisions on the scheduling of threads on the vCPUs.Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and polarity,
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 1 line
PTF([01])are no performance bottle neck and the number of CPU is likely to be small, even a maximum of 248 is possible KVM warns above 16 CPU so the loop for setting all CPU inside PTF interception is not very problematic I think.
KVM warns if you try to use more than the number of physical CPUs that you have, not at hard-coded 16 CPUs. So if you've got an LPAR with 248 CPUs, it's perfectly fine to use also 248 CPUs for your guest.
Thomas
PATCH v14 2/11 s390x/cpu topology: add topology entries on CPU hotplug
In reply to Pierre MorelThe topology information are attributes of the CPU and are specified during the CPU device creation.
On hot plug, we gather the topology information on the core, creates a list of topology entries, each entry contains a single core mask of each core with identical topology and finaly we orders the list in topological order.
The topological order is, from higher to lower priority:
- physical topology
- drawer
- book
- socket
- core origin, offset in 64bit increment from core 0.
- modifier attributes
- CPU type
- polarization entitlement
- dedication
The possibility to insert a CPU in a mask is dependent on the number of cores allowed in a socket, a book or a drawer, the checking is done during the hot plug of the CPU to have an immediate answer.
If the complete topology is not specified, the core is added in the physical topology based on its core ID and it gets defaults values for the modifier attributes.
This way, starting QEMU without specifying the topology can still get some adventage of the CPU topology.
--- include/hw/s390x/cpu-topology.h | 48 ++++++ hw/s390x/cpu-topology.c | 293 ++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 10 ++ hw/s390x/meson.build | 1 + 4 files changed, 352 insertions(+) create mode 100644 hw/s390x/cpu-topology.c
include/hw/s390x/cpu-topology.h +48 -0
@@ -10,7 +10,11 @@#ifndef HW_S390X_CPU_TOPOLOGY_H #define HW_S390X_CPU_TOPOLOGY_H +#include "qemu/queue.h" +#include "hw/boards.h" +#define S390_TOPOLOGY_CPU_IFL 0x03 +#define S390_TOPOLOGY_MAX_ORIGIN ((63 + S390_MAX_CPUS) / 64)#define S390_TOPOLOGY_POLARITY_HORIZONTAL 0x00#define S390_TOPOLOGY_POLARITY_VERTICAL_LOW 0x01
@@ -20,4 +24,48 @@#define S390_TOPOLOGY_SHARED 0x00#define S390_TOPOLOGY_DEDICATED 0x01 +typedef union s390_topology_id { +uint64_t id; +struct { +uint64_t level_6:8 ;/* byte 0 BE */ +uint64_t level_5:8 ;/* byte 1 BE */ +uint64_t drawer:8 ;/* byte 2 BE */ +uint64_t book:8 ;/* byte 3 BE */ +uint64_t socket:8 ;/* byte 4 BE */ +uint64_t rsrv:5 ; +uint64_t d:1 ; +uint64_t p:2 ;/* byte 5 BE */ +uint64_t type:8 ;/* byte 6 BE */ +uint64_t origin:2 ; +uint64_t core:6 ;/* byte 7 BE */ + }; +}s390_topology_id ; +#define TOPO_CPU_MASK 0x000000000000003fUL + +typedef struct S390TopologyEntry { +s390_topology_id id; +QTAILQ_ENTRY (S390TopologyEntry) next; +uint64_t mask; +}S390TopologyEntry ; + +typedef struct S390Topology { + QTAILQ_HEAD(, S390TopologyEntry) list; +uint8_t *sockets; +CpuTopology *smp; +}S390Topology ; + +#ifdef CONFIG_KVM +bool s390_has_topology (void ); +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +#else +static inline bool s390_has_topology (void ) +{ +return false; +} +static inline void s390_topology_set_cpu (MachineState *ms, +S390CPU *cpu, +Error **errp) {} +#endif +extern S390Topology s390_topology; +#endif
hw/s390x/cpu-topology.c new file +293 -0
293 lines not on this page · raw message
hw/s390x/s390-virtio-ccw.c +10 -0
@@ -44,6 +44,7 @@#include "hw/s390x/pv.h" #include "migration/blocker.h" #include "qapi/visitor.h" +#include "hw/s390x/cpu-topology.h" static Error *pv_mig_blocker;
@@ -310,10 +311,19 @@ static void s390_cpu_plug(HotplugHandler *hotplug_dev, {MachineState *ms =MACHINE (hotplug_dev);S390CPU *cpu =S390_CPU (dev); +Error *local_err =NULL ;g_assert (!ms->possible_cpus->cpus[cpu->env.core_id].cpu); ms->possible_cpus->cpus[cpu->env.core_id].cpu =OBJECT (dev); +if (s390_has_topology ()) { +s390_topology_set_cpu (ms, cpu, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } +if (dev->hotplugged) {raise_irq_cpu_hotplug (); }
hw/s390x/meson.build +1 -0
@@ -24,6 +24,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files( 's390-stattrib-kvm.c', 'pv.c', 's390-pci-kvm.c', + 'cpu-topology.c', )) s390x_ss.add(when: 'CONFIG_TCG', if_true: files( 'tod-tcg.c',
Signature · 1 line
2.31.1
Re: [PATCH v14 02/11] s390x/cpu topology: add topology entries on CPU hotplug
Quoted 23 lines · Pierre Morel
The topology information are attributes of the CPU and are specified during the CPU device creation.
On hot plug, we gather the topology information on the core, creates a list of topology entries, each entry contains a single core mask of each core with identical topology and finaly we orders the list in topological order.
The topological order is, from higher to lower priority:
- physical topology
- drawer
- book
- socket
- core origin, offset in 64bit increment from core 0.
- modifier attributes
- CPU type
- polarization entitlement
- dedicationThe possibility to insert a CPU in a mask is dependent on the number of cores allowed in a socket, a book or a drawer, the checking is done during the hot plug of the CPU to have an immediate answer.
Quoted 6 lines
If the complete topology is not specified, the core is added in the physical topology based on its core ID and it gets defaults values for the modifier attributes.
This way, starting QEMU without specifying the topology can still get some adventage of the CPU topology.
s/adventage/advantage/
Quoted 35 lines
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 48 ++++++ hw/s390x/cpu-topology.c | 293 ++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 10 ++ hw/s390x/meson.build | 1 + 4 files changed, 352 insertions(+)create mode 100644
hw/s390x/cpu-topology.cinclude/hw/s390x/cpu-topology.h +10
-0@@ -10,7 +10,11 @@#ifndef HW_S390X_CPU_TOPOLOGY_H #define HW_S390X_CPU_TOPOLOGY_H +#include "qemu/queue.h" +#include "hw/boards.h" +#define S390_TOPOLOGY_CPU_IFL 0x03 +#define S390_TOPOLOGY_MAX_ORIGIN ((63 + S390_MAX_CPUS) / 64)#define S390_TOPOLOGY_POLARITY_HORIZONTAL 0x00#define S390_TOPOLOGY_POLARITY_VERTICAL_LOW 0x01@@ -20,4 +24,48 @@#define S390_TOPOLOGY_SHARED 0x00#define S390_TOPOLOGY_DEDICATED 0x01 +typedef union s390_topology_id { + uint64_t id; + struct { + uint64_t level_6:8; /* byte 0 BE */ + uint64_t level_5:8; /* byte 1 BE */ + uint64_t drawer:8; /* byte 2 BE */
include/hw/s390x/cpu-topology.h line 42
Quoted 10 lines
include/hw/s390x/cpu-topology.h +10
-0+ uint64_t book:8; /* byte 3 BE */ + uint64_t socket:8; /* byte 4 BE */ + uint64_t rsrv:5; + uint64_t d:1; + uint64_t p:2; /* byte 5 BE */ + uint64_t type:8; /* byte 6 BE */ + uint64_t origin:2; + uint64_t core:6; /* byte 7 BE */ + }; +} s390_topology_id;
Bitmasks are OK for code that will definitely only ever work with KVM ... but this will certainly fail completely if we ever try to get it running with TCG later. Do we care? ... if so, you should certainly avoid a bitfield here. Especially since most of the fields are 8-bit anyway and could easily be represented by a "uint8_t" variable. Otherwise, just ignore my comment.
include/hw/s390x/cpu-topology.h line 53
Quoted 11 lines
include/hw/s390x/cpu-topology.h +11
-0+#define TOPO_CPU_MASK 0x000000000000003fUL + +typedef struct S390TopologyEntry { +s390_topology_id id; +QTAILQ_ENTRY (S390TopologyEntry) next; +uint64_t mask; +}S390TopologyEntry ; + +typedef struct S390Topology { + QTAILQ_HEAD(, S390TopologyEntry) list; + uint8_t *sockets;
So this "uint8_t" basically is a hidden limit of a maximum of 256 sockets that can be used for per book? Do we check that limit somewhere? (I looked for it, but I didn't spot such a check)
Quoted 24 lines
include/hw/s390x/cpu-topology.h +17
-0+ CpuTopology *smp; +} S390Topology; + +#ifdef CONFIG_KVM +bool s390_has_topology (void ); +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +#else +static inline bool s390_has_topology (void ) +{ +return false; +} +static inline void s390_topology_set_cpu (MachineState *ms, +S390CPU *cpu, +Error **errp) {} +#endif +extern S390Topology s390_topology; +#endif hw/s390x/cpu-topology.c new file +0
-0
hw/s390x/cpu-topology.c line 4
Quoted 4 lines
hw/s390x/cpu-topology.c new file +4
-0@@ -0,0 +1,293 @@ +/* +* CPU Topology +* +* Copyright IBM Corp. 2022
Want to update to 2023 now?
Quoted 31 lines
hw/s390x/cpu-topology.c new file +31
-0+* Author(s): Pierre Morel <[email protected]> + +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/qdev-properties.h" +#include "hw/boards.h" +#include "qemu/typedefs.h" +#include "target/s390x/cpu.h" +#include "hw/s390x/s390-virtio-ccw.h" +#include "hw/s390x/cpu-topology.h" + +/* +* s390_topology is used to keep the topology information. +* .list: queue the topology entries inside which +* we keep the information on the CPU topology. +* +* .smp: keeps track of the machine topology. +* +* .socket: tracks information on the count of cores per socket. +* +*/ +S390Topology s390_topology = { + .list =QTAILQ_HEAD_INITIALIZER (s390_topology.list), + .sockets =NULL ,/* will be initialized after the cpu model is realized */ +};
hw/s390x/cpu-topology.c
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+ +/** +* s390_socket_nb: +* @id: s390_topology_id +* +* Returns the socket number used inside the socket array. +*/ +static int s390_socket_nb (s390_topology_id id) +{ + return (id.socket + 1) * (id.book + 1) * (id.drawer + 1); > +}
I think there might be an off-by-one error in here - you likely need a "- 1" at the very end.
For example, assume that we have one socket, one book and one drawer, so id.socket, id.book and id.drawer would all be 0. The function then returns 1 ...
hw/s390x/cpu-topology.c line 74
Quoted 8 lines
hw/s390x/cpu-topology.c new file +8
-0+static void s390_topology_init (MachineState *ms) +{ +CpuTopology *smp = &ms->smp; + + s390_topology.smp = smp; +if (!s390_topology.sockets) { + s390_topology.sockets =g_new0 (uint8_t, smp->sockets * + smp->books * smp->drawers);
... but here you only allocated one byte. So you later access s390_topology.sockets[s390_socket_nb(id)], i.e. s390_topology.sockets[1] which is out of bounds.
hw/s390x/cpu-topology.c line 55
Quoted 2 lines
hw/s390x/cpu-topology.c new file +2
-0+ } +}
Thomas
Re: [PATCH v14 02/11] s390x/cpu topology: add topology entries on CPU hotplug
Quoted 47 lines · Thomas Huth
Quoted 23 lines · Pierre Morel
The topology information are attributes of the CPU and are specified during the CPU device creation.
On hot plug, we gather the topology information on the core, creates a list of topology entries, each entry contains a single core mask of each core with identical topology and finaly we orders the list in topological order.
The topological order is, from higher to lower priority:
- physical topology
- drawer
- book
- socket
- core origin, offset in 64bit increment from core 0.
- modifier attributes
- CPU type
- polarization entitlement
- dedicationThe possibility to insert a CPU in a mask is dependent on the number of cores allowed in a socket, a book or a drawer, the checking is done during the hot plug of the CPU to have an immediate answer.
Quoted 6 lines
If the complete topology is not specified, the core is added in the physical topology based on its core ID and it gets defaults values for the modifier attributes.
This way, starting QEMU without specifying the topology can still get some adventage of the CPU topology.
s/adventage/advantage/
Quoted 14 lines
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 48 ++++++ hw/s390x/cpu-topology.c | 293 ++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 10 ++ hw/s390x/meson.build | 1 + 4 files changed, 352 insertions(+)create mode 100644
hw/s390x/cpu-topology.cinclude/hw/s390x/cpu-topology.h +0
-0
[...]
Quoted 7 lines
include/hw/s390x/cpu-topology.h line 53
Quoted 3 lines
include/hw/s390x/cpu-topology.h +3
-0+typedef struct S390Topology { + QTAILQ_HEAD(, S390TopologyEntry) list; + uint8_t *sockets;So this "
uint8_t" basically is a hidden limit of a maximum of 256 sockets that can be used for per book? Do we check that limit somewhere? (I looked for it, but I didn't spot such a check)
S390_MAX_CPUS < 256. Might be a good idea to have a build time assert for that. And one cannot have more sockets that maxcpus.
Quoted 23 lines
Quoted 23 lines
include/hw/s390x/cpu-topology.h +17
-0+ CpuTopology *smp; +} S390Topology; + +#ifdef CONFIG_KVM +bool s390_has_topology (void ); +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +#else +static inline bool s390_has_topology (void ) +{ +return false; +} +static inline void s390_topology_set_cpu (MachineState *ms, +S390CPU *cpu, +Error **errp) {} +#endif +extern S390Topology s390_topology; +#endif hw/s390x/cpu-topology.c new file +0
-1--- /dev/null
Quoted 8 lines
hw/s390x/cpu-topology.c line 4
Quoted 6 lines
+++
b/hw/s390x/cpu-topology.chw/s390x/cpu-topology.c new file +4
-0@@ -0,0 +1,293 @@ +/* +* CPU Topology +* +* Copyright IBM Corp. 2022 Want to update to 2023 now?
It's the year of first publication, and I'd guess this is a derivative work of what was published to the mailing list last year.
Quoted 1 line
Re: [PATCH v14 02/11] s390x/cpu topology: add topology entries on CPU hotplug
In reply to Thomas HuthQuoted 69 lines · Thomas Huth
Quoted 23 lines · Pierre Morel
The topology information are attributes of the CPU and are specified during the CPU device creation.
On hot plug, we gather the topology information on the core, creates a list of topology entries, each entry contains a single core mask of each core with identical topology and finaly we orders the list in topological order.
The topological order is, from higher to lower priority:
- physical topology
- drawer
- book
- socket
- core origin, offset in 64bit increment from core 0.
- modifier attributes
- CPU type
- polarization entitlement
- dedicationThe possibility to insert a CPU in a mask is dependent on the number of cores allowed in a socket, a book or a drawer, the checking is done during the hot plug of the CPU to have an immediate answer.
Quoted 6 lines
If the complete topology is not specified, the core is added in the physical topology based on its core ID and it gets defaults values for the modifier attributes.
This way, starting QEMU without specifying the topology can still get some adventage of the CPU topology.
s/adventage/advantage/
Quoted 36 lines
Signed-off-by Pierre Morel <[email protected]>---
include/hw/s390x/cpu-topology.h| 48 ++++++ hw/s390x/cpu-topology.c | 293 ++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 10 ++ hw/s390x/meson.build | 1 +4 files changed, 352 insertions(+)create mode 100644
hw/s390x/cpu-topology.cinclude/hw/s390x/cpu-topology.h +14
-0@@ -10,7 +10,11 @@ #ifndef HW_S390X_CPU_TOPOLOGY_H #define HW_S390X_CPU_TOPOLOGY_H +#include "qemu/queue.h" +#include "hw/boards.h" + #define S390_TOPOLOGY_CPU_IFL 0x03 +#define S390_TOPOLOGY_MAX_ORIGIN ((63 + S390_MAX_CPUS) / 64) #define S390_TOPOLOGY_POLARITY_HORIZONTAL 0x00 #define S390_TOPOLOGY_POLARITY_VERTICAL_LOW 0x01@@ -20,4 +24,48 @@ #define S390_TOPOLOGY_SHARED 0x00 #define S390_TOPOLOGY_DEDICATED 0x01 +typedef union s390_topology_id { + uint64_t id; + struct { + uint64_t level_6:8; /* byte 0 BE */ + uint64_t level_5:8; /* byte 1 BE */ + uint64_t drawer:8; /* byte 2 BE */ + uint64_t book:8; /* byte 3 BE */ + uint64_t socket:8; /* byte 4 BE */ + uint64_t rsrv:5; + uint64_t d:1;
Quoted 8 lines
include/hw/s390x/cpu-topology.h line 42
Quoted 6 lines
include/hw/s390x/cpu-topology.h +6
-0+ uint64_t p:2; /* byte 5 BE */ + uint64_t type:8; /* byte 6 BE */ + uint64_t origin:2; + uint64_t core:6; /* byte 7 BE */ + }; +} s390_topology_id;Bitmasks are OK for code that will definitely only ever work with KVM ... but this will certainly fail completely if we ever try to get it running with TCG later. Do we care? ... if so, you should certainly avoid a bitfield here. Especially since most of the fields are 8-bit anyway and could easily be represented by a "
uint8_t" variable. Otherwise, just ignore my comment.
The goal of using a bit mask here is not to use it with KVM but to have an easy way to order the TLE using the natural order of the placement of the fields in the uint64_t However, if I remove the two unused levels 5 and 6 I can use uint8_t for all the entries.
I doubt we use the levels 5 and 6 in a short future.
So I switch on 1 uint8_t for each entry.
...
Quoted 58 lines
hw/s390x/cpu-topology.c line 4
Quoted 10 lines
hw/s390x/cpu-topology.c new file +4
-0@@ -0,0 +1,293 @@ +/* +* CPU Topology +* +* Copyright IBM Corp. 2022 Want to update to 2023 now?
Quoted 33 lines
hw/s390x/cpu-topology.c new file +3
-0+* Author(s): Pierre Morel <[email protected]> + +* This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */hw/s390x/cpu-topology.c new file +24
-0+ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/qdev-properties.h" +#include "hw/boards.h" +#include "qemu/typedefs.h" +#include "target/s390x/cpu.h" +#include "hw/s390x/s390-virtio-ccw.h" +#include "hw/s390x/cpu-topology.h" + +/* +* s390_topology is used to keep the topology information. +* .list: queue the topology entries inside which +* we keep the information on the CPU topology. +* +* .smp: keeps track of the machine topology. +* +* .socket: tracks information on the count of cores per socket. +* +*/ +S390Topology s390_topology = { + .list = QTAILQ_HEAD_INITIALIZER(s390_topology.list), + .sockets = NULL, /* will be initialized after the cpu model isrealized */
hw/s390x/cpu-topology.c new file +1
-0+};hw/s390x/cpu-topology.c
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+ +/** +* s390_socket_nb: +* @id: s390_topology_id +* +* Returns the socket number used inside the socket array. +*/ +static int s390_socket_nb (s390_topology_id id) +{ + return (id.socket + 1) * (id.book + 1) * (id.drawer + 1); > +}I think there might be an off-by-one error in here - you likely need a "- 1" at the very end.
Quoted 1 line
For example, assume that we have one socket, one book and one drawer, so id.socket, id.book and id.drawer would all be 0. The function then returns 1 ...
hum, I fear it is even more false than that but thanks for pointing this error.
/o\
return (id.drawer * s390_topology.smp.books + id.book) *
s390_topology.smp.sockets + id.socket;
Quoted 11 lines
hw/s390x/cpu-topology.c line 74
Quoted 9 lines
hw/s390x/cpu-topology.c new file +8
-0+static void s390_topology_init (MachineState *ms) +{ + CpuTopology *smp = &ms->smp; + + s390_topology.smp = smp; + if (!s390_topology.sockets) { + s390_topology.sockets = g_new0(uint8_t, smp->sockets * + smp->books * smp->drawers);... but here you only allocated one byte. So you later access s390_topology.sockets[s390_socket_nb(id)], i.e. s390_topology.sockets[1] which is out of bounds.
Yes, thanks.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 02/11] s390x/cpu topology: add topology entries on CPU hotplug
In reply to Pierre MorelQuoted 6 lines · Pierre Morel
The topology information are attributes of the CPU and are specified during the CPU device creation.
On hot plug, we gather the topology information on the core, creates a list of topology entries, each entry contains a single core mask of each core with identical topology and finaly we
s/finaly/finally/
Quoted 1 line
orders the list in topological order.
s/orders/order/
Quoted 55 lines
The topological order is, from higher to lower priority:
- physical topology
- drawer
- book
- socket
- core origin, offset in 64bit increment from core 0.
- modifier attributes
- CPU type
- polarization entitlement
- dedicationThe possibility to insert a CPU in a mask is dependent on the number of cores allowed in a socket, a book or a drawer, the checking is done during the hot plug of the CPU to have an immediate answer.
If the complete topology is not specified, the core is added in the physical topology based on its core ID and it gets defaults values for the modifier attributes.
This way, starting QEMU without specifying the topology can still get some adventage of the CPU topology.
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 48 ++++++ hw/s390x/cpu-topology.c | 293 ++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 10 ++ hw/s390x/meson.build | 1 + 4 files changed, 352 insertions(+) create mode 100644 hw/s390x/cpu-topology.cinclude/hw/s390x/cpu-topology.h +7
-0@@ -10,7 +10,11 @@#ifndef HW_S390X_CPU_TOPOLOGY_H #define HW_S390X_CPU_TOPOLOGY_H +#include "qemu/queue.h" +#include "hw/boards.h" +#define S390_TOPOLOGY_CPU_IFL 0x03 +#define S390_TOPOLOGY_MAX_ORIGIN ((63 + S390_MAX_CPUS) / 64)#define S390_TOPOLOGY_POLARITY_HORIZONTAL 0x00#define S390_TOPOLOGY_POLARITY_VERTICAL_LOW 0x01@@ -20,4 +24,48 @@#define S390_TOPOLOGY_SHARED 0x00#define S390_TOPOLOGY_DEDICATED 0x01 +typedef union s390_topology_id { + uint64_t id; + struct {
include/hw/s390x/cpu-topology.h line 39
Quoted 10 lines
include/hw/s390x/cpu-topology.h +10
-0+ uint64_t level_6:8; /* byte 0 BE */ + uint64_t level_5:8; /* byte 1 BE */ + uint64_t drawer:8; /* byte 2 BE */ + uint64_t book:8; /* byte 3 BE */ + uint64_t socket:8; /* byte 4 BE */ + uint64_t rsrv:5; + uint64_t d:1; + uint64_t p:2; /* byte 5 BE */ + uint64_t type:8; /* byte 6 BE */ + uint64_t origin:2;
This is two bits because it's the core divided by 64, and we have 248 cores at most? Where is this set?
include/hw/s390x/cpu-topology.h line 42
Quoted 3 lines
include/hw/s390x/cpu-topology.h +3
-0+ uint64_t core:6; /* byte 7 BE */ + }; +} s390_topology_id;
This struct seems to do double duty, 1. it represents a cpu and 2. a topology entry. You also use it for sorting.
I would suggest to just use a cpu object when referring to a specific cpu and put the relevant fields directly into the topology entry.
You get rid of the bit field that way.
You'd then need a comparison function for a cpu object and a topology entry. As long as that isn't the only type pair that shouldn't be too ugly.
Quoted 59 lines
include/hw/s390x/cpu-topology.h +28
-0+#define TOPO_CPU_MASK 0x000000000000003fUL + +typedef struct S390TopologyEntry { +s390_topology_id id; +QTAILQ_ENTRY (S390TopologyEntry) next; +uint64_t mask; +}S390TopologyEntry ; + +typedef struct S390Topology { + QTAILQ_HEAD(, S390TopologyEntry) list; +uint8_t *sockets; +CpuTopology *smp; +}S390Topology ; + +#ifdef CONFIG_KVM +bool s390_has_topology (void ); +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +#else +static inline bool s390_has_topology (void ) +{ +return false; +} +static inline void s390_topology_set_cpu (MachineState *ms, +S390CPU *cpu, +Error **errp) {} +#endif +extern S390Topology s390_topology; +#endif hw/s390x/cpu-topology.c new file +24
-0@@ -0,0 +1,293 @@ +/* +* CPU Topology +* +* Copyright IBM Corp. 2022 +* Author(s): Pierre Morel <[email protected]> + +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/qdev-properties.h" +#include "hw/boards.h" +#include "qemu/typedefs.h" +#include "target/s390x/cpu.h" +#include "hw/s390x/s390-virtio-ccw.h" +#include "hw/s390x/cpu-topology.h" + +/* +* s390_topology is used to keep the topology information. +* .list: queue the topology entries inside which
hw/s390x/cpu-topology.c line 34
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+* we keep the information on the CPU topology. +* +* .smp: keeps track of the machine topology. +* +* .socket: tracks information on the count of cores per socket. +* +*/ +S390Topology s390_topology = { + .list =QTAILQ_HEAD_INITIALIZER (s390_topology.list), + .sockets =NULL ,/* will be initialized after the cpu model is realized */
I guess you should do the same for .smp then also.
hw/s390x/cpu-topology.c line 45
Quoted 11 lines
hw/s390x/cpu-topology.c new file +11
-0+}; + +/** +* s390_socket_nb: +* @id: s390_topology_id +* +* Returns the socket number used inside the socket array. +*/ +static int s390_socket_nb (s390_topology_id id) +{ +return (id.socket +1 ) * (id.book +1 ) * (id.drawer +1 );
This calculation doesn't make a whole lot of sense to me.
It's symmetric with regards to the variables, so (s=0 b=1 d=1)
will have the same result as (s=1 b=0 d=1).
You want the "global" socket number right?
So that would be (drawer * books_per_drawer + book) * sockets_per_book + socket.
Quoted 17 lines
hw/s390x/cpu-topology.c new file +17
-0+} + +/** +* s390_has_topology: +* +* Return value: if the topology is supported by the machine. +*/ +bool s390_has_topology (void ) +{ +return false; +} + +/** +* s390_topology_init: +* @ms: the machine state where the machine topology is defined +* +* Keep track of the machine topology.
hw/s390x/cpu-topology.c line 72
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+* Allocate an array to keep the count of cores per socket. +* The index of the array starts at socket 0 from book 0 and +* drawer 0 up to the maximum allowed by the machine topology. +*/ +static void s390_topology_init (MachineState *ms) +{ +CpuTopology *smp = &ms->smp; + + s390_topology.smp = smp; +if (!s390_topology.sockets) {
Is this function being called multiple times, or why the if? Use an assert instead?
Quoted 25 lines
hw/s390x/cpu-topology.c new file +25
-0+ s390_topology.sockets =g_new0 (uint8_t, smp->sockets * + smp->books * smp->drawers); + } +} + +/** +* s390_topology_from_cpu: +* @cpu: The S390CPU +* +* Initialize the topology id from the CPU environment. +*/ +static s390_topology_id s390_topology_from_cpu (S390CPU *cpu) +{ +s390_topology_id topology_id; + + topology_id.core = cpu->env.core_id; + topology_id.type = cpu->env.cpu_type; + topology_id.p = cpu->env.polarity; + topology_id.d = cpu->env.dedicated; + topology_id.socket = cpu->env.socket_id; + topology_id.book = cpu->env.book_id; + topology_id.drawer = cpu->env.drawer_id; + +return topology_id; +}
hw/s390x/cpu-topology.c line 107
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+ +/** +* s390_topology_set_entry: +* @entry: Topology entry to setup +* @id: topology id to use for the setup +* +* Set the core bit inside the topology mask and +* increments the number of cores for the socket. +*/ +static void s390_topology_set_entry(S390TopologyEntry *entry,
Not sure if I like the name, what it does is to add a cpu to the entry.
hw/s390x/cpu-topology.c line 110
Quoted 3 lines
hw/s390x/cpu-topology.c new file +3
-0+ s390_topology_id id) +{ +set_bit (63 - id.core, &entry->mask);
You need to subtract the origin first or that might be negative.
Quoted 50 lines
hw/s390x/cpu-topology.c new file +50
-0+ s390_topology.sockets[s390_socket_nb (id)]++; +} + +/** +* s390_topology_new_entry: +* @id: s390_topology_id to add +* +* Allocate a new entry and initialize it. +* +* returns the newly allocated entry. +*/ +static S390TopologyEntry *s390_topology_new_entry (s390_topology_id id) +{ +S390TopologyEntry *entry; + + entry =g_malloc0 (sizeof (S390TopologyEntry)); + entry->id.id = id.id & ~TOPO_CPU_MASK ; +s390_topology_set_entry (entry, id); + +return entry; +} + +/** +* s390_topology_insert: +* +* @id: s390_topology_id to insert. +* +* Parse the topology list to find if the entry already +* exist and add the core in it. +* If it does not exist, allocate a new entry and insert +* it in the queue from lower id to greater id. +*/ +static void s390_topology_insert (s390_topology_id id) +{ +S390TopologyEntry *entry; +S390TopologyEntry *tmp =NULL ; +uint64_t new_id; + + new_id = id.id & ~TOPO_CPU_MASK ; + +/* First CPU to add to an entry */ +if (QTAILQ_EMPTY (&s390_topology.list)) { + entry =s390_topology_new_entry (id); +QTAILQ_INSERT_HEAD (&s390_topology.list, entry, next); +return ; + } + + QTAILQ_FOREACH(tmp, &s390_topology.list, next) { +if (new_id == tmp->id.id) { +s390_topology_set_entry (tmp, id);
hw/s390x/cpu-topology.c line 170
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+return ; + }else if (new_id < tmp->id.id) { + entry =s390_topology_new_entry (id); +QTAILQ_INSERT_BEFORE (tmp, entry, next); +return ; + } + } + + entry =s390_topology_new_entry (id); +QTAILQ_INSERT_TAIL (&s390_topology.list, entry, next);
Consider adding a sentinel entry "at infinity", then that whole code would simplify.
Quoted 76 lines
hw/s390x/cpu-topology.c new file +76
-0+} + +/** +* s390_topology_check: +* @errp: Error pointer +* id: s390_topology_id to be verified +* +* The function checks if the topology id fits inside the +* system topology. +*/ +static void s390_topology_check (Error **errp,s390_topology_id id) +{ +CpuTopology *smp = s390_topology.smp; + +if (id.socket > smp->sockets) { +error_setg (errp,"Unavailable socket: %d" , id.socket); +return ; + } +if (id.book > smp->books) { +error_setg (errp,"Unavailable book: %d" , id.book); +return ; + } +if (id.drawer > smp->drawers) { +error_setg (errp,"Unavailable drawer: %d" , id.drawer); +return ; + } +if (id.type !=S390_TOPOLOGY_CPU_IFL ) { +error_setg (errp,"Unknown cpu type: %d" , id.type); +return ; + } +/* Polarity and dedication can never be wrong */ +} + +/** +* s390_topology_cpu_default: +* @errp: Error pointer +* @cpu: pointer to a S390CPU +* +* Setup the default topology for unset attributes. +* +* The function accept only all all default values or all set values +* for the geometry topology. +* +* The function calculates the (drawer_id, book_id, socket_id) +* topology by filling the cores starting from the first socket +* (0, 0, 0) up to the last (smp->drawers, smp->books, smp->sockets). +* +*/ +static void s390_topology_cpu_default (Error **errp,S390CPU *cpu) +{ +CpuTopology *smp = s390_topology.smp; +CPUS390XState *env = &cpu->env; + +/* All geometry topology attributes must be set or all unset */ +if ((env->socket_id <0 || env->book_id <0 || env->drawer_id <0 ) && + (env->socket_id >=0 || env->book_id >=0 || env->drawer_id >=0 )) { +error_setg (errp, +"Please define all or none of the topology geometry attributes" ); +return ; + } + +/* Check if one of the geometry topology is unset */ +if (env->socket_id <0 ) { +/* Calculate default geometry topology attributes */ + env->socket_id = (env->core_id / smp->cores) % smp->sockets; + env->book_id = (env->core_id / (smp->sockets * smp->cores)) % + smp->books; + env->drawer_id = (env->core_id / + (smp->books * smp->sockets * smp->cores)) % + smp->drawers; + } +} + +/** +* s390_topology_set_cpu: +* @ms: MachineState used to initialize the topology structure on
hw/s390x/cpu-topology.c line 256
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+* first call. +* @cpu: the new S390CPU to insert in the topology structure +* @errp: the error pointer +* +* Called from CPU Hotplug to check and setup the CPU attributes +* before to insert the CPU in the topology. +*/ +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp) +{ +Error *local_error =NULL ;
Can't you just use ERRP_GUARD ?
hw/s390x/cpu-topology.c line 261
Quoted 5 lines
hw/s390x/cpu-topology.c new file +5
-0+s390_topology_id id; + +/* +* We do not want to initialize the topology if the cpu model +* does not support topology consequently, we have to wait for
", consequently," I think. Could you do the initialization some where else, after you know what the cpu model is? Not that I object to doing it this way.
Quoted 76 lines
hw/s390x/cpu-topology.c new file +32
-0+* the first CPU to be realized, which realizes the CPU model +* to initialize the topology structures. +* +* s390_topology_set_cpu() is called from the cpu hotplug. +*/ +if (!s390_topology.sockets) { +s390_topology_init (ms); + } + +s390_topology_cpu_default (&local_error, cpu); +if (local_error) { +error_propagate (errp, local_error); +return ; + } + + id =s390_topology_from_cpu (cpu); + +/* Check for space on the socket */ +if (s390_topology.sockets[s390_socket_nb (id)] >= + s390_topology.smp->sockets) { +error_setg (&local_error,"No more space on socket" ); +return ; + } + +s390_topology_check (&local_error, id); +if (local_error) { +error_propagate (errp, local_error); +return ; + } + +s390_topology_insert (id); +}hw/s390x/s390-virtio-ccw.c +10
-0@@ -44,6 +44,7 @@#include "hw/s390x/pv.h" #include "migration/blocker.h" #include "qapi/visitor.h" +#include "hw/s390x/cpu-topology.h" static Error *pv_mig_blocker;@@ -310,10 +311,19 @@ static void s390_cpu_plug(HotplugHandler *hotplug_dev, {MachineState *ms =MACHINE (hotplug_dev);S390CPU *cpu =S390_CPU (dev); +Error *local_err =NULL ;g_assert (!ms->possible_cpus->cpus[cpu->env.core_id].cpu); ms->possible_cpus->cpus[cpu->env.core_id].cpu =OBJECT (dev); +if (s390_has_topology ()) { +s390_topology_set_cpu (ms, cpu, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + } +if (dev->hotplugged) {raise_irq_cpu_hotplug (); }hw/s390x/meson.build +1
-0@@ -24,6 +24,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files( 's390-stattrib-kvm.c', 'pv.c', 's390-pci-kvm.c', + 'cpu-topology.c', )) s390x_ss.add(when: 'CONFIG_TCG', if_true: files( 'tod-tcg.c',
Re: [PATCH v14 02/11] s390x/cpu topology: add topology entries on CPU hotplug
Quoted 8 lines · Nina Schoetterl-Glausch
Quoted 6 lines · Pierre Morel
The topology information are attributes of the CPU and are specified during the CPU device creation.
On hot plug, we gather the topology information on the core, creates a list of topology entries, each entry contains a single core mask of each core with identical topology and finaly we
s/finaly/finally/
thx
Quoted 2 lines
Quoted 1 line
orders the list in topological order.
s/orders/order/
thx
Quoted 52 lines
Quoted 52 lines
The topological order is, from higher to lower priority:
- physical topology
- drawer
- book
- socket
- core origin, offset in 64bit increment from core 0.
- modifier attributes
- CPU type
- polarization entitlement
- dedicationThe possibility to insert a CPU in a mask is dependent on the number of cores allowed in a socket, a book or a drawer, the checking is done during the hot plug of the CPU to have an immediate answer.
If the complete topology is not specified, the core is added in the physical topology based on its core ID and it gets defaults values for the modifier attributes.
This way, starting QEMU without specifying the topology can still get some adventage of the CPU topology.
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 48 ++++++ hw/s390x/cpu-topology.c | 293 ++++++++++++++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 10 ++ hw/s390x/meson.build | 1 + 4 files changed, 352 insertions(+)create mode 100644
hw/s390x/cpu-topology.cinclude/hw/s390x/cpu-topology.h +4
-0@@ -10,7 +10,11 @@#ifndef HW_S390X_CPU_TOPOLOGY_H #define HW_S390X_CPU_TOPOLOGY_H +#include "qemu/queue.h" +#include "hw/boards.h" +#define S390_TOPOLOGY_CPU_IFL 0x03 +#define S390_TOPOLOGY_MAX_ORIGIN ((63 + S390_MAX_CPUS) / 64)#define S390_TOPOLOGY_POLARITY_HORIZONTAL 0x00#define S390_TOPOLOGY_POLARITY_VERTICAL_LOW 0x01@@ -20,4 +24,48 @@#define S390_TOPOLOGY_SHARED 0x00#define S390_TOPOLOGY_DEDICATED 0x01
Quoted 16 lines
include/hw/s390x/cpu-topology.h line 39
Quoted 13 lines
include/hw/s390x/cpu-topology.h +13
-0+typedef union s390_topology_id { + uint64_t id; + struct { + uint64_t level_6:8; /* byte 0 BE */ + uint64_t level_5:8; /* byte 1 BE */ + uint64_t drawer:8; /* byte 2 BE */ + uint64_t book:8; /* byte 3 BE */ + uint64_t socket:8; /* byte 4 BE */ + uint64_t rsrv:5; + uint64_t d:1; + uint64_t p:2; /* byte 5 BE */ + uint64_t type:8; /* byte 6 BE */ + uint64_t origin:2;This is two bits because it's the core divided by 64, and we have 248 cores at most? Where is this set?
right, must be set so does the core offset in the mask.
Quoted 9 lines
include/hw/s390x/cpu-topology.h line 42
Quoted 4 lines
include/hw/s390x/cpu-topology.h +3
-0+ uint64_t core:6; /* byte 7 BE */ + }; +} s390_topology_id;This struct seems to do double duty, 1. it represents a cpu and 2. a topology entry. You also use it for sorting.
I would suggest to just use a cpu object when referring to a specific cpu and put the relevant fields directly into the topology entry.
Yes, I can remove the core:6.
After Thomas comment I will change all the bit field for uint8_t.
I think we should not use the real topology entry here if we want to use TGE in the future.
Quoted 67 lines
You get rid of the bit field that way.
You'd then need a comparison function for a cpu object and a topology entry. As long as that isn't the only type pair that shouldn't be too ugly.Quoted 63 lines
include/hw/s390x/cpu-topology.h +28
-0+#define TOPO_CPU_MASK 0x000000000000003fUL + +typedef struct S390TopologyEntry { +s390_topology_id id; +QTAILQ_ENTRY (S390TopologyEntry) next; +uint64_t mask; +}S390TopologyEntry ; + +typedef struct S390Topology { + QTAILQ_HEAD(, S390TopologyEntry) list; +uint8_t *sockets; +CpuTopology *smp; +}S390Topology ; + +#ifdef CONFIG_KVM +bool s390_has_topology (void ); +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +#else +static inline bool s390_has_topology (void ) +{ +return false; +} +static inline void s390_topology_set_cpu (MachineState *ms, +S390CPU *cpu, +Error **errp) {} +#endif +extern S390Topology s390_topology; +#endif hw/s390x/cpu-topology.c new file +28
-0@@ -0,0 +1,293 @@ +/* +* CPU Topology +* +* Copyright IBM Corp. 2022 +* Author(s): Pierre Morel <[email protected]> + +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/qdev-properties.h" +#include "hw/boards.h" +#include "qemu/typedefs.h" +#include "target/s390x/cpu.h" +#include "hw/s390x/s390-virtio-ccw.h" +#include "hw/s390x/cpu-topology.h" + +/* +* s390_topology is used to keep the topology information. +* .list: queue the topology entries inside which +* we keep the information on the CPU topology. +* +* .smp: keeps track of the machine topology. +*
Quoted 8 lines
hw/s390x/cpu-topology.c line 34
Quoted 6 lines
hw/s390x/cpu-topology.c new file +6
-0+* .socket: tracks information on the count of cores per socket. +* +*/ +S390Topology s390_topology = { + .list =QTAILQ_HEAD_INITIALIZER (s390_topology.list), + .sockets =NULL ,/* will be initialized after the cpu model is realized */ I guess you should do the same for .smp then also.
OK
Quoted 10 lines
Quoted 10 lines
hw/s390x/cpu-topology.c new file +9
-0+}; + +/** +* s390_socket_nb: +* @id: s390_topology_id +* +* Returns the socket number used inside the socket array. +*/ +static int s390_socket_nb (s390_topology_id id)
Quoted 8 lines
hw/s390x/cpu-topology.c line 45
Quoted 2 lines
hw/s390x/cpu-topology.c new file +2
-0+{ +return (id.socket +1 ) * (id.book +1 ) * (id.drawer +1 );This calculation doesn't make a whole lot of sense to me.
It's symmetric with regards to the variables, so (s=0 b=1 d=1)
will have the same result as (s=1 b=0 d=1).
You want the "global" socket number right?
So that would be (drawer *books_per_drawer+ book) *sockets_per_book+ socket.
yes, already changed
Quoted 23 lines
Quoted 23 lines
hw/s390x/cpu-topology.c new file +22
-0+} + +/** +* s390_has_topology: +* +* Return value: if the topology is supported by the machine. +*/ +bool s390_has_topology (void ) +{ +return false; +} + +/** +* s390_topology_init: +* @ms: the machine state where the machine topology is defined +* +* Keep track of the machine topology. +* Allocate an array to keep the count of cores per socket. +* The index of the array starts at socket 0 from book 0 and +* drawer 0 up to the maximum allowed by the machine topology. +*/ +static void s390_topology_init (MachineState *ms)
Quoted 8 lines
hw/s390x/cpu-topology.c line 72
Quoted 5 lines
hw/s390x/cpu-topology.c new file +5
-0+{ +CpuTopology *smp = &ms->smp; + + s390_topology.smp = smp; +if (!s390_topology.sockets) {Is this function being called multiple times, or why the if? Use an assert instead?
I forgot to remove this test.
The caller already check this.
Quoted 30 lines
Quoted 30 lines
hw/s390x/cpu-topology.c new file +29
-0+ s390_topology.sockets =g_new0 (uint8_t, smp->sockets * + smp->books * smp->drawers); + } +} + +/** +* s390_topology_from_cpu: +* @cpu: The S390CPU +* +* Initialize the topology id from the CPU environment. +*/ +static s390_topology_id s390_topology_from_cpu (S390CPU *cpu) +{ +s390_topology_id topology_id; + + topology_id.core = cpu->env.core_id; + topology_id.type = cpu->env.cpu_type; + topology_id.p = cpu->env.polarity; + topology_id.d = cpu->env.dedicated; + topology_id.socket = cpu->env.socket_id; + topology_id.book = cpu->env.book_id; + topology_id.drawer = cpu->env.drawer_id; + +return topology_id; +} + +/** +* s390_topology_set_entry: +* @entry: Topology entry to setup
Quoted 8 lines
hw/s390x/cpu-topology.c line 107
Quoted 6 lines
hw/s390x/cpu-topology.c new file +6
-0+* @id: topology id to use for the setup +* +* Set the core bit inside the topology mask and +* increments the number of cores for the socket. +*/ +static void s390_topology_set_entry(S390TopologyEntry *entry,Not sure if I like the name, what it does is to add a cpu to the entry.
s390_topology_add_cpu_to_entry() ?
Quoted 6 lines
hw/s390x/cpu-topology.c line 110
Quoted 4 lines
hw/s390x/cpu-topology.c new file +3
-0+ s390_topology_id id) +{ +set_bit (63 - id.core, &entry->mask);You need to subtract the origin first or that might be negative.
yes, origin is not handled correctly
Quoted 56 lines
Quoted 56 lines
hw/s390x/cpu-topology.c new file +55
-0+ s390_topology.sockets[s390_socket_nb (id)]++; +} + +/** +* s390_topology_new_entry: +* @id: s390_topology_id to add +* +* Allocate a new entry and initialize it. +* +* returns the newly allocated entry. +*/ +static S390TopologyEntry *s390_topology_new_entry (s390_topology_id id) +{ +S390TopologyEntry *entry; + + entry =g_malloc0 (sizeof (S390TopologyEntry)); + entry->id.id = id.id & ~TOPO_CPU_MASK ; +s390_topology_set_entry (entry, id); + +return entry; +} + +/** +* s390_topology_insert: +* +* @id: s390_topology_id to insert. +* +* Parse the topology list to find if the entry already +* exist and add the core in it. +* If it does not exist, allocate a new entry and insert +* it in the queue from lower id to greater id. +*/ +static void s390_topology_insert (s390_topology_id id) +{ +S390TopologyEntry *entry; +S390TopologyEntry *tmp =NULL ; +uint64_t new_id; + + new_id = id.id & ~TOPO_CPU_MASK ; + +/* First CPU to add to an entry */ +if (QTAILQ_EMPTY (&s390_topology.list)) { + entry =s390_topology_new_entry (id); +QTAILQ_INSERT_HEAD (&s390_topology.list, entry, next); +return ; + } + + QTAILQ_FOREACH(tmp, &s390_topology.list, next) { +if (new_id == tmp->id.id) { +s390_topology_set_entry (tmp, id); +return ; + }else if (new_id < tmp->id.id) { + entry =s390_topology_new_entry (id); +QTAILQ_INSERT_BEFORE (tmp, entry, next); +return ;
Quoted 8 lines
hw/s390x/cpu-topology.c line 170
Quoted 5 lines
hw/s390x/cpu-topology.c new file +5
-0+ } + } + + entry =s390_topology_new_entry (id); +QTAILQ_INSERT_TAIL (&s390_topology.list, entry, next);Consider adding a sentinel entry "at infinity", then that whole code would simplify.
looks good, thanks.
Quoted 81 lines
Quoted 81 lines
hw/s390x/cpu-topology.c new file +80
-0+} + +/** +* s390_topology_check: +* @errp: Error pointer +* id: s390_topology_id to be verified +* +* The function checks if the topology id fits inside the +* system topology. +*/ +static void s390_topology_check (Error **errp,s390_topology_id id) +{ +CpuTopology *smp = s390_topology.smp; + +if (id.socket > smp->sockets) { +error_setg (errp,"Unavailable socket: %d" , id.socket); +return ; + } +if (id.book > smp->books) { +error_setg (errp,"Unavailable book: %d" , id.book); +return ; + } +if (id.drawer > smp->drawers) { +error_setg (errp,"Unavailable drawer: %d" , id.drawer); +return ; + } +if (id.type !=S390_TOPOLOGY_CPU_IFL ) { +error_setg (errp,"Unknown cpu type: %d" , id.type); +return ; + } +/* Polarity and dedication can never be wrong */ +} + +/** +* s390_topology_cpu_default: +* @errp: Error pointer +* @cpu: pointer to a S390CPU +* +* Setup the default topology for unset attributes. +* +* The function accept only all all default values or all set values +* for the geometry topology. +* +* The function calculates the (drawer_id, book_id, socket_id) +* topology by filling the cores starting from the first socket +* (0, 0, 0) up to the last (smp->drawers, smp->books, smp->sockets). +* +*/ +static void s390_topology_cpu_default (Error **errp,S390CPU *cpu) +{ +CpuTopology *smp = s390_topology.smp; +CPUS390XState *env = &cpu->env; + +/* All geometry topology attributes must be set or all unset */ +if ((env->socket_id <0 || env->book_id <0 || env->drawer_id <0 ) && + (env->socket_id >=0 || env->book_id >=0 || env->drawer_id >=0 )) { +error_setg (errp, +"Please define all or none of the topology geometry attributes" ); +return ; + } + +/* Check if one of the geometry topology is unset */ +if (env->socket_id <0 ) { +/* Calculate default geometry topology attributes */ + env->socket_id = (env->core_id / smp->cores) % smp->sockets; + env->book_id = (env->core_id / (smp->sockets * smp->cores)) % + smp->books; + env->drawer_id = (env->core_id / + (smp->books * smp->sockets * smp->cores)) % + smp->drawers; + } +} + +/** +* s390_topology_set_cpu: +* @ms: MachineState used to initialize the topology structure on +* first call. +* @cpu: the new S390CPU to insert in the topology structure +* @errp: the error pointer +*
Quoted 8 lines
hw/s390x/cpu-topology.c line 256
Quoted 6 lines
hw/s390x/cpu-topology.c new file +6
-0+* Called from CPU Hotplug to check and setup the CPU attributes +* before to insert the CPU in the topology. +*/ +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp) +{ +Error *local_error =NULL ;Can't you just use
ERRP_GUARD?
I do not think it is necessary and I find it obfuscating. So, should I?
Quoted 10 lines
hw/s390x/cpu-topology.c line 261
Quoted 6 lines
hw/s390x/cpu-topology.c new file +5
-0+s390_topology_id id; + +/* +* We do not want to initialize the topology if the cpu model +* does not support topology consequently, we have to wait for ", consequently," I think. Could you do the initialization some where else, after you know what the cpu model is? Not that I object to doing it this way.
I did not find a better place, it must be done after the CPU model is initialize and before the first CPU is created. The cpu model is initialized during the early creation of the first cpu.
Any idea?
Thanks.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 02/11] s390x/cpu topology: add topology entries on CPU hotplug
Quoted 3 lines · Pierre Morel
Quoted 1 line · Nina Schoetterl-Glausch
[...]
Quoted 12 lines
Quoted 11 lines
hw/s390x/cpu-topology.c line 107
Quoted 9 lines
hw/s390x/cpu-topology.c new file +9
-0+/** +* s390_topology_set_entry: +* @entry: Topology entry to setup +* @id: topology id to use for the setup +* +* Set the core bit inside the topology mask and +* increments the number of cores for the socket. +*/ +static void s390_topology_set_entry(S390TopologyEntry *entry,Not sure if I like the name, what it does is to add a cpu to the entry.
Quoted 1 line
s390_topology_add_cpu_to_entry()?
Yeah, that's better.
[...]
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
hw/s390x/cpu-topology.c new file +3
-0+/** +* s390_topology_set_cpu: +* @ms: MachineState used to initialize the topology structure on hw/s390x/cpu-topology.c line 256
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+* first call. +* @cpu: the new S390CPU to insert in the topology structure +* @errp: the error pointer +* +* Called from CPU Hotplug to check and setup the CPU attributes +* before to insert the CPU in the topology. +*/ +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp) +{ +Error *local_error =NULL ;Can't you just use
ERRP_GUARD?
Quoted 2 lines
I do not think it is necessary and I find it obfuscating. So, should I?
/*
* Propagate error object (if any) from @local_err to @dst_errp.
[...]
* Please use ERRP_GUARD() instead when possible.
* Please don't error_propagate(&error_fatal, ...), use
* error_report_err() and exit(), because that's more obvious. */
void error_propagate(Error **dst_errp, Error *local_err);
So I'd say yes.
Quoted 23 lines
Quoted 11 lines
hw/s390x/cpu-topology.c line 261
Quoted 7 lines
hw/s390x/cpu-topology.c new file +5
-0+s390_topology_id id; + +/* +* We do not want to initialize the topology if the cpu model +* does not support topology consequently, we have to wait for ", consequently," I think. Could you do the initialization some where else, after you know what the cpu model is? Not that I object to doing it this way.
I did not find a better place, it must be done after the CPU model is initialize and before the first CPU is created.
The cpu model is initialized during the early creation of the first cpu.Any idea?
Thanks.
Regards,
Pierre
Re: [PATCH v14 02/11] s390x/cpu topology: add topology entries on CPU hotplug
Quoted 52 lines · Nina Schoetterl-Glausch
Quoted 3 lines · Pierre Morel
Quoted 1 line · Nina Schoetterl-Glausch
[...]
Quoted 12 lines
Quoted 11 lines
hw/s390x/cpu-topology.c line 107
Quoted 9 lines
hw/s390x/cpu-topology.c new file +9
-0+/** +* s390_topology_set_entry: +* @entry: Topology entry to setup +* @id: topology id to use for the setup +* +* Set the core bit inside the topology mask and +* increments the number of cores for the socket. +*/ +static void s390_topology_set_entry(S390TopologyEntry *entry,Not sure if I like the name, what it does is to add a cpu to the entry.
Quoted 1 line
s390_topology_add_cpu_to_entry()?Yeah, that's better.
[...]
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
hw/s390x/cpu-topology.c new file +3
-0+/** +* s390_topology_set_cpu: +* @ms: MachineState used to initialize the topology structure on hw/s390x/cpu-topology.c line 256
Quoted 10 lines
hw/s390x/cpu-topology.c new file +10
-0+* first call. +* @cpu: the new S390CPU to insert in the topology structure +* @errp: the error pointer +* +* Called from CPU Hotplug to check and setup the CPU attributes +* before to insert the CPU in the topology. +*/ +void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp) +{ +Error *local_error =NULL ;Can't you just use
ERRP_GUARD?Quoted 2 lines
I do not think it is necessary and I find it obfuscating. So, should I?
/*
* Propagate error object (if any) from @local_err to @dst_errp.
[...]
* Please useERRP_GUARD()instead when possible.
* Please don'terror_propagate(&error_fatal, ...), use
*error_report_err()andexit(), because that's more obvious. */
voiderror_propagate(Error **dst_errp, Error *local_err);
Quoted 1 line
So I'd say yes.
OK, you are right it is better.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 3/11 target/s390x/cpu topology: handle STSI(15) and build the SYSIB
In reply to Pierre MorelOn interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
--- include/hw/s390x/cpu-topology.h | 3 + include/hw/s390x/sclp.h | 1 + target/s390x/cpu.h | 78 ++++++++++++++++++ target/s390x/kvm/cpu_topology.c | 136 ++++++++++++++++++++++++++++++++ target/s390x/kvm/kvm.c | 5 +- target/s390x/kvm/meson.build | 3 +- 6 files changed, 224 insertions(+), 2 deletions(-) create mode 100644 target/s390x/kvm/cpu_topology.c
include/hw/s390x/cpu-topology.h +3 -0
@@ -41,6 +41,9 @@ typedef union s390_topology_id { }; } s390_topology_id;#define TOPO_CPU_MASK 0x000000000000003fUL +#define TOPO_SOCKET_MASK 0x0000ffffff000000UL +#define TOPO_BOOK_MASK 0x0000ffff00000000UL +#define TOPO_DRAWER_MASK 0x0000ff0000000000UL typedef struct S390TopologyEntry { s390_topology_id id;
include/hw/s390x/sclp.h +1 -0
@@ -112,6 +112,7 @@ typedef struct CPUEntry { }QEMU_PACKED CPUEntry;#define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 +#define SCLP_READ_SCP_INFO_MNEST 2 typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax;
target/s390x/cpu.h +78 -0
93 lines not on this page · raw message
target/s390x/kvm/cpu_topology.c new file +136 -0
136 lines not on this page · raw message
target/s390x/kvm/kvm.c +4 -1
@@ -1919,9 +1919,12 @@ static int handle_stsi(S390CPU *cpu)if (run->s390_stsi.sel1 !=2 || run->s390_stsi.sel2 !=2 ) {return 0 ; } -/* Only sysib 3.2.2 needs post-handling for now. */ insert_stsi_3_2_2 (cpu, run->s390_stsi.addr, run->s390_stsi.ar);return 0 ; +case 15 : +insert_stsi_15_1_x (cpu, run->s390_stsi.sel2, run->s390_stsi.addr, + run->s390_stsi.ar); +return 0 ;default :return 0 ; }
target/s390x/kvm/meson.build +2 -1
@@ -1,6 +1,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files( - 'kvm.c' + 'kvm.c', + 'cpu_topology.c' ), if_false: files( 'stubs.c' ))
Signature · 1 line
2.31.1
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
Quoted 5 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 42 lines
target/s390x/cpu.h +24
-0@@ -561,6 +561,25 @@ typedef struct SysIB_322 { } SysIB_322;QEMU_BUILD_BUG_ON (sizeof (SysIB_322) !=4096 ); +#define S390_TOPOLOGY_MAG 6 +#define S390_TOPOLOGY_MAG6 0 +#define S390_TOPOLOGY_MAG5 1 +#define S390_TOPOLOGY_MAG4 2 +#define S390_TOPOLOGY_MAG3 3 +#define S390_TOPOLOGY_MAG2 4 +#define S390_TOPOLOGY_MAG1 5 +/* Configuration topology */ +typedef struct SysIB_151x { +uint8_t reserved0[2 ]; +uint16_t length; +uint8_t mag[S390_TOPOLOGY_MAG ]; +uint8_t reserved1; +uint8_t mnest; +uint32_t reserved2; +char tle[]; +} QEMU_PACKED QEMU_ALIGNED(8) SysIB_151x; +QEMU_BUILD_BUG_ON (sizeof (SysIB_151x) !=16 ); + typedef union SysIB { SysIB_111 sysib_111; SysIB_121 sysib_121;@@ -568,9 +587,68 @@ typedef union SysIB {SysIB_221 sysib_221;SysIB_222 sysib_222;SysIB_322 sysib_322; +SysIB_151x sysib_151x; } SysIB;QEMU_BUILD_BUG_ON (sizeof (SysIB) !=4096 ); +/* +* CPU Topology List provided by STSI with fc=15 provides a list +* of two different Topology List Entries (TLE) types to specify +* the topology hierarchy.
target/s390x/cpu.h typedef union SysIB { · line 607
Quoted 10 lines
target/s390x/cpu.h +10
-0+* +* - Container Topology List Entry +* Defines a container to contain other Topology List Entries +* of any type, nested containers or CPU. +* - CPU Topology List Entry +* Specifies the CPUs position, type, entitlement and polarization +* of the CPUs contained in the last Container TLE. +* +* There can be theoretically up to five levels of containers, QEMU +* uses only one level, the socket level.
I guess that sentence needs an update again, now that you've re-added the books and drawers?
Quoted 6 lines
target/s390x/cpu.h +6
-0+* A container of with a nesting level (NL) greater than 1 can only +* contain another container of nesting level NL-1. +* +* A container of nesting level 1 (socket), contains as many CPU TLE +* as needed to describe the position and qualities of all CPUs inside +* the container.
target/s390x/cpu.h typedef union SysIB { · line 624
Quoted 10 lines
target/s390x/cpu.h +10
-0+* The qualities of a CPU are polarization, entitlement and type. +* +* The CPU TLE defines the position of the CPUs of identical qualities +* using a 64bits mask which first bit has its offset defined by +* the CPU address orgin field of the CPU TLE like in: +* CPU address = origin * 64 + bit position within the mask +* +*/ +/* Container type Topology List Entry */ +/* Container type Topology List Entry */
Duplicated comment.
Quoted 4 lines
target/s390x/cpu.h +4
-0+typedef struct SysIBTl_container { + uint8_t nl; + uint8_t reserved[6]; + uint8_t id;
target/s390x/cpu.h typedef union SysIB { · line 638
Quoted 10 lines
target/s390x/cpu.h +10
-0+} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_container; +QEMU_BUILD_BUG_ON(sizeof(SysIBTl_container) != 8); + +/* CPU type Topology List Entry */ +typedef struct SysIBTl_cpu { +uint8_t nl; +uint8_t reserved0[3 ]; + uint8_t reserved1:5; + uint8_t dedicated:1; + uint8_t polarity:2;
Hmmm, yet another bitfield...
Quoted 22 lines
target/s390x/cpu.h +13
-0+uint8_t type; +uint16_t origin; +uint64_t mask; +} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_cpu; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_cpu) !=16 ); + +/* Max size of a SYSIB structure is when all CPU are alone in a container */ +#define S390_TOPOLOGY_SYSIB_SIZE (sizeof(SysIB_151x) + \ + S390_MAX_CPUS * (sizeof(SysIBTl_container) + \ + sizeof(SysIBTl_cpu))) + +void insert_stsi_15_1_x (S390CPU *cpu,int sel2,__u64 addr,uint8_t ar); +/* MMU defines */ #define ASCE_ORIGIN (~0xfffULL)/* segment table origin */ #define ASCE_SUBSPACE 0x200/* subspace group control */ target/s390x/kvm/cpu_topology.c new file +0
-0
target/s390x/kvm/cpu_topology.c line 4
Quoted 4 lines
target/s390x/kvm/cpu_topology.c new file +4
-0@@ -0,0 +1,136 @@ +/* +* QEMU S390x CPU Topology +* +* Copyright IBM Corp. 2022
Happy new year?
Quoted 16 lines
target/s390x/kvm/cpu_topology.c new file +16
-0+* Author(s): Pierre Morel <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/s390x/pv.h" +#include "hw/sysbus.h" +#include "hw/s390x/sclp.h" +#include "hw/s390x/cpu-topology.h" + +static char *fill_container (char *p,int level,int id) +{ +SysIBTl_container *tle = (SysIBTl_container *)p;
target/s390x/kvm/cpu_topology.c line 30
Quoted 10 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+ + tle->nl = level; + tle->id = id; +return p +sizeof (*tle); +} + +static char *fill_tle_cpu (char *p,S390TopologyEntry *entry) +{ +SysIBTl_cpu *tle = (SysIBTl_cpu *)p; +s390_topology_id topology_id = entry->id;
What about the reserved fields? Should they get set to 0 ?
target/s390x/kvm/cpu_topology.c line 37
Quoted 6 lines
target/s390x/kvm/cpu_topology.c new file +6
-0+ tle->nl =0 ; + tle->dedicated = topology_id.d; + tle->polarity = topology_id.p; + tle->type = topology_id.type; + tle->origin = topology_id.origin; + tle->mask =cpu_to_be64 (entry->mask);
So here you're already taking care of swapping the endianess in case we ever run this code with TCG, too ... so I think it would be great to also eliminate the bitfield in SysIBTl_cpu to be really on the safe side.
Quoted 2 lines
target/s390x/kvm/cpu_topology.c new file +2
-0+return p +sizeof (*tle); +}
...
Quoted 6 lines
target/s390x/kvm/cpu_topology.c new file +6
-0+void insert_stsi_15_1_x (S390CPU *cpu,int sel2,__u64 addr,uint8_t ar) +{ +union { +char place_holder[S390_TOPOLOGY_SYSIB_SIZE ]; +SysIB_151x sysib; + } buffer QEMU_ALIGNED(8) = {};
target/s390x/kvm/cpu_topology.c line 128
Quoted 10 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+int len; + +if (!s390_has_topology () || sel2 <2 || sel2 >SCLP_READ_SCP_INFO_MNEST ) { +setcc (cpu,3 ); +return ; + } + + len =setup_stsi (cpu, &buffer.sysib, sel2); + +if (len >4096 ) {
Maybe use TARGET_PAGE_SIZE instead of 4096 ?
target/s390x/kvm/cpu_topology.c line 134
Quoted 6 lines
target/s390x/kvm/cpu_topology.c new file +6
-0+setcc (cpu,3 ); +return ; + } + + buffer.sysib.length =cpu_to_be16 (len); +s390_cpu_virt_mem_write (cpu, addr, ar, &buffer.sysib, len);
Is this supposed to work with protected guests, too? If so, I think you likely need to use s390_cpu_pv_mem_write() for protected guests?
Thomas
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
Quoted 6 lines · Thomas Huth
Quoted 5 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 20 lines
Quoted 13 lines
target/s390x/kvm/cpu_topology.c new file +9
-0+void insert_stsi_15_1_x(S390CPU *cpu, int sel2, __u64 addr, uint8_t ar) +{ + union { + char place_holder[S390_TOPOLOGY_SYSIB_SIZE]; + SysIB_151x sysib; + } buffer QEMU_ALIGNED(8) = {}; + int len; + + if (!s390_has_topology() || sel2 < 2 || sel2 >
SCLP_READ_SCP_INFO_MNEST) {
+setcc(cpu, 3);
+ return;
+ }target/s390x/kvm/cpu_topology.c line 128
Quoted 4 lines
target/s390x/kvm/cpu_topology.c new file +4
-0+ + len = setup_stsi(cpu, &buffer.sysib, sel2); + + if (len > 4096) {Maybe use
TARGET_PAGE_SIZEinstead of 4096 ?
Quoted 8 lines
Quoted 6 lines
+
setcc(cpu, 3);
+ return;
+ }
+
+ buffer.sysib.length =cpu_to_be16(len);
+s390_cpu_virt_mem_write(cpu, addr, ar, &buffer.sysib, len);Is this supposed to work with protected guests, too? If so, I think you likely need to use
s390_cpu_pv_mem_write()for protected guests?
I now saw in a later patch that the topology feature gets disabled for protected guests - so never mind, please ignore my question here.
Thomas
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
In reply to Thomas HuthQuoted 7 lines · Thomas Huth
Quoted 5 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>---
[...]
Quoted 10 lines
Quoted 10 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+void insert_stsi_15_1_x (S390CPU *cpu,int sel2,__u64 addr,uint8_t ar) +{ +union { +char place_holder[S390_TOPOLOGY_SYSIB_SIZE ]; +SysIB_151x sysib; + } buffer QEMU_ALIGNED(8) = {}; +int len; + +if (!s390_has_topology () || sel2 <2 || sel2 >SCLP_READ_SCP_INFO_MNEST ) { +setcc (cpu,3 );
Quoted 8 lines
target/s390x/kvm/cpu_topology.c line 128
Quoted 6 lines
target/s390x/kvm/cpu_topology.c new file +6
-0+return ; + } + + len =setup_stsi (cpu, &buffer.sysib, sel2); + +if (len >4096 ) {Maybe use
TARGET_PAGE_SIZEinstead of 4096 ?
sizeof(SysIB) would be preferable IMO.
Quoted 4 lines
Quoted 4 lines
target/s390x/kvm/cpu_topology.c new file +3
-0+setcc (cpu,3 ); +return ; + }
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
Quoted 29 lines · Nina Schoetterl-Glausch
Quoted 7 lines · Thomas Huth
Quoted 5 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>---
[...]
Quoted 10 lines
Quoted 10 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+void insert_stsi_15_1_x (S390CPU *cpu,int sel2,__u64 addr,uint8_t ar) +{ +union { +char place_holder[S390_TOPOLOGY_SYSIB_SIZE ]; +SysIB_151x sysib; + } buffer QEMU_ALIGNED(8) = {}; +int len; + +if (!s390_has_topology () || sel2 <2 || sel2 >SCLP_READ_SCP_INFO_MNEST ) { +setcc (cpu,3 );Quoted 8 lines
target/s390x/kvm/cpu_topology.c line 128
Quoted 6 lines
target/s390x/kvm/cpu_topology.c new file +6
-0+return ; + } + + len =setup_stsi (cpu, &buffer.sysib, sel2); + +if (len >4096 ) {Maybe use
TARGET_PAGE_SIZEinstead of 4096 ?
Quoted 1 line
sizeof(SysIB) would be preferable IMO.
Yes better
Thanks,
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
In reply to Thomas HuthQuoted 51 lines · Thomas Huth
Quoted 5 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 44 lines
target/s390x/cpu.h +28
-0@@ -561,6 +561,25 @@ typedef struct SysIB_322 { } SysIB_322; QEMU_BUILD_BUG_ON(sizeof(SysIB_322) != 4096); +#define S390_TOPOLOGY_MAG 6 +#define S390_TOPOLOGY_MAG6 0 +#define S390_TOPOLOGY_MAG5 1 +#define S390_TOPOLOGY_MAG4 2 +#define S390_TOPOLOGY_MAG3 3 +#define S390_TOPOLOGY_MAG2 4 +#define S390_TOPOLOGY_MAG1 5 +/* Configuration topology */ +typedef struct SysIB_151x { + uint8_t reserved0[2]; + uint16_t length; + uint8_t mag[S390_TOPOLOGY_MAG]; + uint8_t reserved1; + uint8_t mnest; + uint32_t reserved2; + char tle[]; +} QEMU_PACKED QEMU_ALIGNED(8) SysIB_151x; +QEMU_BUILD_BUG_ON (sizeof (SysIB_151x) !=16 ); + typedef union SysIB { SysIB_111 sysib_111; SysIB_121 sysib_121;@@ -568,9 +587,68 @@ typedef union SysIB { SysIB_221 sysib_221; SysIB_222 sysib_222; SysIB_322 sysib_322; + SysIB_151x sysib_151x; } SysIB; QEMU_BUILD_BUG_ON(sizeof(SysIB) != 4096); +/* +* CPU Topology List provided by STSI with fc=15 provides a list +* of two different Topology List Entries (TLE) types to specify +* the topology hierarchy. +* +* - Container Topology List Entry +* Defines a container to contain other Topology List Entries +* of any type, nested containers or CPU.
Quoted 8 lines
target/s390x/cpu.h typedef union SysIB { · line 607
Quoted 6 lines
target/s390x/cpu.h +6
-0+ * - CPU Topology List Entry + * Specifies the CPUs position, type, entitlement and polarization + * of the CPUs contained in the last Container TLE. + * + * There can be theoretically up to five levels of containers, QEMU + * uses only one level, the socket level.I guess that sentence needs an update again, now that you've re-added the books and drawers?
yes
Quoted 11 lines
Quoted 11 lines
target/s390x/cpu.h +10
-0+* A container of with a nesting level (NL) greater than 1 can only +* contain another container of nesting level NL-1. +* +* A container of nesting level 1 (socket), contains as many CPU TLE +* as needed to describe the position and qualities of all CPUs inside +* the container. +* The qualities of a CPU are polarization, entitlement and type. +* +* The CPU TLE defines the position of the CPUs of identical qualities +* using a 64bits mask which first bit has its offset defined by
Quoted 8 lines
target/s390x/cpu.h typedef union SysIB { · line 624
Quoted 6 lines
target/s390x/cpu.h +6
-0+* the CPU address orgin field of the CPU TLE like in: +* CPU address = origin * 64 + bit position within the mask +* +*/ +/* Container type Topology List Entry */ +/* Container type Topology List Entry */ Duplicated comment.
OK
Quoted 17 lines
Quoted 5 lines
target/s390x/cpu.h +4
-0+typedef struct SysIBTl_container { + uint8_t nl; + uint8_t reserved[6]; + uint8_t id;target/s390x/cpu.h typedef union SysIB { · line 638
Quoted 10 lines
target/s390x/cpu.h +10
-0+} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_container; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_container) !=8 ); + +/* CPU type Topology List Entry */ +typedef struct SysIBTl_cpu { + uint8_t nl; + uint8_t reserved0[3]; + uint8_t reserved1:5; + uint8_t dedicated:1; + uint8_t polarity:2;Hmmm, yet another bitfield...
Yes, this is the firmware interface.
If it makes problem I can use masks and logic arithmetic
Quoted 24 lines
Quoted 24 lines
target/s390x/cpu.h +7
-0+ uint8_t type; + uint16_t origin; + uint64_t mask; +} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_cpu; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_cpu) !=16 ); + +/* Max size of a SYSIB structure is when all CPU are alone in a container */
+#defineS390_TOPOLOGY_SYSIB_SIZE(sizeof(SysIB_151x)
+ \
+S390_MAX_CPUS* (sizeof(SysIBTl_container)+ \
+sizeof(SysIBTl_cpu)))target/s390x/cpu.h +3
-0+ +void insert_stsi_15_1_x (S390CPU *cpu,int sel2,__u64 addr,uint8_t ar); +/* MMU defines */
#define ASCE_ORIGIN (~0xfffULL) /* segment table origin */ #define ASCE_SUBSPACE 0x200 /* subspace group control */target/s390x/kvm/cpu_topology.c new file +0
-1--- /dev/null
Quoted 8 lines
target/s390x/kvm/cpu_topology.c line 4
Quoted 6 lines
+++
b/target/s390x/kvm/cpu_topology.ctarget/s390x/kvm/cpu_topology.c new file +4
-0@@ -0,0 +1,136 @@ +/* +* QEMU S390x CPU Topology +* +* Copyright IBM Corp. 2022 Happy new year?
So after Nina's comment what do I do?
let it be 22 because I started last year or update because what is important is when it comes into mainline?
Quoted 22 lines
Quoted 22 lines
target/s390x/kvm/cpu_topology.c new file +3
-0+* Author(s): Pierre Morel <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */target/s390x/kvm/cpu_topology.c new file +14
-0+#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/s390x/pv.h" +#include "hw/sysbus.h" +#include "hw/s390x/sclp.h" +#include "hw/s390x/cpu-topology.h" + +static char *fill_container (char *p,int level,int id) +{ + SysIBTl_container *tle = (SysIBTl_container *)p; + + tle->nl = level; + tle->id = id; + return p + sizeof(*tle);
Quoted 8 lines
target/s390x/kvm/cpu_topology.c line 30
Quoted 6 lines
target/s390x/kvm/cpu_topology.c new file +6
-0+} + +static char *fill_tle_cpu (char *p,S390TopologyEntry *entry) +{ + SysIBTl_cpu *tle = (SysIBTl_cpu *)p; + s390_topology_id topology_id = entry->id;What about the reserved fields? Should they get set to 0 ?
Good question.
I forgot this after changing the allocation.
It must be 0.
I will do that during the allocation.
Quoted 9 lines
Quoted 7 lines
+
tle->nl= 0;
+tle->dedicated= topology_id.d;
+tle->polarity= topology_id.p;
+tle->type= topology_id.type;
+tle->origin= topology_id.origin;
+tle->mask=cpu_to_be64(entry->mask);So here you're already taking care of swapping the endianess in case we ever run this code with TCG, too ... so I think it would be great to also eliminate the bitfield in
SysIBTl_cputo be really on the safe side.
OK.
Quoted 15 lines
Quoted 3 lines
+ return p +
sizeof(*tle);
+}...
Quoted 11 lines
target/s390x/kvm/cpu_topology.c new file +9
-0+void insert_stsi_15_1_x(S390CPU *cpu, int sel2, __u64 addr, uint8_t ar) +{ + union { + char place_holder[S390_TOPOLOGY_SYSIB_SIZE]; + SysIB_151x sysib; + } buffer QEMU_ALIGNED(8) = {}; + int len; + + if (!s390_has_topology() || sel2 < 2 || sel2 >
SCLP_READ_SCP_INFO_MNEST) {
+setcc(cpu, 3);
Quoted 8 lines
target/s390x/kvm/cpu_topology.c line 128
Quoted 6 lines
+ return;
+ }target/s390x/kvm/cpu_topology.c new file +4
-0+ + len = setup_stsi(cpu, &buffer.sysib, sel2); + + if (len > 4096) {Maybe use
TARGET_PAGE_SIZEinstead of 4096 ?
I am not sure about this, even TARGET_PAGE_SIZE will probably never change, this is the maximal SYSIB size, probably related to page size but... What about defining it in the cpu.h as
#define SYSIB_MAX_SIZE TARGET_PAGE_SIZE
?
Quoted 9 lines
Quoted 7 lines
+
setcc(cpu, 3);
+ return;
+ }
+
+ buffer.sysib.length =cpu_to_be16(len);
+s390_cpu_virt_mem_write(cpu, addr, ar, &buffer.sysib, len);Is this supposed to work with protected guests, too? If so, I think you likely need to use
s390_cpu_pv_mem_write()for protected guests?
it is not supposed to work with protected guests.
Thanks.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
Quoted 9 lines · Pierre Morel
Quoted 6 lines · Thomas Huth
Quoted 5 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
target/s390x/cpu.h +8
-0+typedef struct SysIBTl_container { + uint8_t nl; + uint8_t reserved[6]; + uint8_t id; +} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_container; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_container) !=8 ); + +/* CPU type Topology List Entry */ Quoted 8 lines
Quoted 6 lines
+typedef struct
SysIBTl_cpu{
+uint8_tnl;
+uint8_treserved0[3];
+uint8_treserved1:5;
+uint8_tdedicated:1;
+uint8_tpolarity:2;Hmmm, yet another bitfield...
Quoted 2 lines
Yes, this is the firmware interface.
If it makes problem I can use masks and logic arithmetic
It depends ... if we are sure that this will ever only be used with KVM on real s390x hardware, then bitfields are OK. If we think that this is something that could be implemented in TCG, too, I'd scratch the bitfields and use logic arithmetic instead...
I'm not too experienced with this CPU topology stuff, but it sounds like it could be implemented in TCG without too much efforts one day, too, so I'd rather go with the logic arithmetic immediately instead if it is not too annoying for you right now.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
target/s390x/kvm/cpu_topology.c new file +0
-1--- /dev/nullQuoted 8 lines
target/s390x/kvm/cpu_topology.c line 4
Quoted 6 lines
+++
b/target/s390x/kvm/cpu_topology.ctarget/s390x/kvm/cpu_topology.c new file +4
-0@@ -0,0 +1,136 @@ +/* +* QEMU S390x CPU Topology +* +* Copyright IBM Corp. 2022 Happy new year?
Quoted 2 lines
So after Nina's comment what do I do?
let it be 22 because I started last year or update because what is important is when it comes into mainline?
Honestly, I don't have a really good clue either... But keeping 2022 is certainly fine for me, too.
Thomas
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
Quoted 28 lines · Thomas Huth
Quoted 9 lines · Pierre Morel
Quoted 6 lines · Thomas Huth
Quoted 5 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
target/s390x/cpu.h +4
-0+typedef struct SysIBTl_container { + uint8_t nl; + uint8_t reserved[6]; + uint8_t id;target/s390x/cpu.h typedef union SysIB { · line 638
Quoted 10 lines
target/s390x/cpu.h +10
-0+} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_container; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_container) !=8 ); + +/* CPU type Topology List Entry */ +typedef struct SysIBTl_cpu { + uint8_t nl; + uint8_t reserved0[3]; + uint8_t reserved1:5; + uint8_t dedicated:1; + uint8_t polarity:2;Hmmm, yet another bitfield...
Quoted 7 lines
Quoted 2 lines
Yes, this is the firmware interface.
If it makes problem I can use masks and logic arithmeticIt depends ... if we are sure that this will ever only be used with KVM on real s390x hardware, then bitfields are OK. If we think that this is something that could be implemented in TCG, too, I'd scratch the bitfields and use logic arithmetic instead...
Is there something like linux' bitfield.h in qemu?
In this case it's only two fields, and not too complicated, but I imagine it could get quite ugly to do it manually in other cases.
Quoted 29 lines
I'm not too experienced with this CPU topology stuff, but it sounds like it could be implemented in TCG without too much efforts one day, too, so I'd rather go with the logic arithmetic immediately instead if it is not too annoying for you right now.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
target/s390x/kvm/cpu_topology.c new file +0
-1--- /dev/nullQuoted 8 lines
target/s390x/kvm/cpu_topology.c line 4
Quoted 6 lines
+++
b/target/s390x/kvm/cpu_topology.ctarget/s390x/kvm/cpu_topology.c new file +4
-0@@ -0,0 +1,136 @@ +/* +* QEMU S390x CPU Topology +* +* Copyright IBM Corp. 2022 Happy new year?
Quoted 3 lines
So after Nina's comment what do I do?
let it be 22 because I started last year or update because what is important is when it comes into mainline?Honestly, I don't have a really good clue either... But keeping 2022 is certainly fine for me, too.
Thomas
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
Quoted 32 lines · Nina Schoetterl-Glausch
Quoted 31 lines · Thomas Huth
Quoted 9 lines · Pierre Morel
Quoted 6 lines · Thomas Huth
Quoted 5 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
target/s390x/cpu.h +8
-0+typedef struct SysIBTl_container { + uint8_t nl; + uint8_t reserved[6]; + uint8_t id; +} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_container; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_container) !=8 ); + +/* CPU type Topology List Entry */ Quoted 8 lines
Quoted 6 lines
+typedef struct
SysIBTl_cpu{
+uint8_tnl;
+uint8_treserved0[3];
+uint8_treserved1:5;
+uint8_tdedicated:1;
+uint8_tpolarity:2;Hmmm, yet another bitfield...
Yes, this is the firmware interface.
If it makes problem I can use masks and logic arithmetic
Quoted 13 lines
Quoted 4 lines
It depends ... if we are sure that this will ever only be used with KVM on real s390x hardware, then bitfields are OK. If we think that this is something that could be implemented in TCG, too, I'd scratch the bitfields and use logic arithmetic instead...
Is there something like linux'
bitfield.hin qemu?
In this case it's only two fields, and not too complicated, but I imagine it could get quite ugly to do it manually in other cases.Quoted 5 lines
I'm not too experienced with this CPU topology stuff, but it sounds like it could be implemented in TCG without too much efforts one day, too, so I'd rather go with the logic arithmetic immediately instead if it is not too annoying for you right now.
No problem, I changed all fields to uint8_t and it fits in a uint64_t so I have only a single bit and a single mask to define.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
target/s390x/kvm/cpu_topology.c line 4
Quoted 12 lines
target/s390x/kvm/cpu_topology.c new file +4
-0@@ -0,0 +1,136 @@ +/* +* QEMU S390x CPU Topology +* +* Copyright IBM Corp. 2022 Happy new year?
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
So after Nina's comment what do I do?
let it be 22 because I started last year or update because what is important is when it comes into mainline?Honestly, I don't have a really good clue either... But keeping 2022 is certainly fine for me, too.
OK then I keep 2022
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
In reply to Pierre MorelQuoted 123 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 3 + include/hw/s390x/sclp.h | 1 + target/s390x/cpu.h | 78 ++++++++++++++++++ target/s390x/kvm/cpu_topology.c | 136 ++++++++++++++++++++++++++++++++ target/s390x/kvm/kvm.c | 5 +- target/s390x/kvm/meson.build | 3 +- 6 files changed, 224 insertions(+), 2 deletions(-) create mode 100644 target/s390x/kvm/cpu_topology.cinclude/hw/s390x/cpu-topology.h +3
-0@@ -41,6 +41,9 @@ typedef union s390_topology_id { }; } s390_topology_id;#define TOPO_CPU_MASK 0x000000000000003fUL +#define TOPO_SOCKET_MASK 0x0000ffffff000000UL +#define TOPO_BOOK_MASK 0x0000ffff00000000UL +#define TOPO_DRAWER_MASK 0x0000ff0000000000UL typedef struct S390TopologyEntry { s390_topology_id id;include/hw/s390x/sclp.h +1
-0@@ -112,6 +112,7 @@ typedef struct CPUEntry { }QEMU_PACKED CPUEntry;#define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 +#define SCLP_READ_SCP_INFO_MNEST 2 typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax;target/s390x/cpu.h +65
-0@@ -561,6 +561,25 @@ typedef struct SysIB_322 { } SysIB_322;QEMU_BUILD_BUG_ON (sizeof (SysIB_322) !=4096 ); +#define S390_TOPOLOGY_MAG 6 +#define S390_TOPOLOGY_MAG6 0 +#define S390_TOPOLOGY_MAG5 1 +#define S390_TOPOLOGY_MAG4 2 +#define S390_TOPOLOGY_MAG3 3 +#define S390_TOPOLOGY_MAG2 4 +#define S390_TOPOLOGY_MAG1 5 +/* Configuration topology */ +typedef struct SysIB_151x { +uint8_t reserved0[2 ]; +uint16_t length; +uint8_t mag[S390_TOPOLOGY_MAG ]; +uint8_t reserved1; +uint8_t mnest; +uint32_t reserved2; +char tle[]; +} QEMU_PACKED QEMU_ALIGNED(8) SysIB_151x; +QEMU_BUILD_BUG_ON (sizeof (SysIB_151x) !=16 ); + typedef union SysIB { SysIB_111 sysib_111; SysIB_121 sysib_121;@@ -568,9 +587,68 @@ typedef union SysIB {SysIB_221 sysib_221;SysIB_222 sysib_222;SysIB_322 sysib_322; +SysIB_151x sysib_151x; } SysIB;QEMU_BUILD_BUG_ON (sizeof (SysIB) !=4096 ); +/* +* CPU Topology List provided by STSI with fc=15 provides a list +* of two different Topology List Entries (TLE) types to specify +* the topology hierarchy. +* +* - Container Topology List Entry +* Defines a container to contain other Topology List Entries +* of any type, nested containers or CPU. +* - CPU Topology List Entry +* Specifies the CPUs position, type, entitlement and polarization +* of the CPUs contained in the last Container TLE. +* +* There can be theoretically up to five levels of containers, QEMU +* uses only one level, the socket level. +* +* A container of with a nesting level (NL) greater than 1 can only +* contain another container of nesting level NL-1. +* +* A container of nesting level 1 (socket), contains as many CPU TLE +* as needed to describe the position and qualities of all CPUs inside +* the container. +* The qualities of a CPU are polarization, entitlement and type. +* +* The CPU TLE defines the position of the CPUs of identical qualities +* using a 64bits mask which first bit has its offset defined by +* the CPU address orgin field of the CPU TLE like in: +* CPU address = origin * 64 + bit position within the mask +* +*/ +/* Container type Topology List Entry */ +/* Container type Topology List Entry */ +typedef struct SysIBTl_container { +uint8_t nl; +uint8_t reserved[6 ]; +uint8_t id; +} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_container; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_container) !=8 ); + +/* CPU type Topology List Entry */ +typedef struct SysIBTl_cpu { + uint8_t nl; + uint8_t reserved0[3]; + uint8_t reserved1:5; + uint8_t dedicated:1; + uint8_t polarity:2;
target/s390x/cpu.h typedef union SysIB { · line 648
Quoted 10 lines
target/s390x/cpu.h +10
-0+uint8_t type; +uint16_t origin; +uint64_t mask; +} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_cpu; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_cpu) !=16 ); + +/* Max size of a SYSIB structure is when all CPU are alone in a container */ +#define S390_TOPOLOGY_SYSIB_SIZE (sizeof(SysIB_151x) + \ + S390_MAX_CPUS * (sizeof(SysIBTl_container) + \ + sizeof(SysIBTl_cpu)))
I don't think this is accurate anymore, if you have drawers and books. In that case you could have 3 containers per 1 cpu.
You could also use the maxcpus number at runtime instead of S390_MAX_CPUS. I also think you could do sizeof(SysIB) + sizeof(SysIBTl_cpu) if you check if the sysib overflows 4k while building it.
Quoted 38 lines
target/s390x/cpu.h +3
-0+ +void insert_stsi_15_1_x (S390CPU *cpu,int sel2,__u64 addr,uint8_t ar); +/* MMU defines */ #define ASCE_ORIGIN (~0xfffULL)/* segment table origin */ #define ASCE_SUBSPACE 0x200/* subspace group control */ target/s390x/kvm/cpu_topology.c new file +26
-0@@ -0,0 +1,136 @@ +/* +* QEMU S390x CPU Topology +* +* Copyright IBM Corp. 2022 +* Author(s): Pierre Morel <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/s390x/pv.h" +#include "hw/sysbus.h" +#include "hw/s390x/sclp.h" +#include "hw/s390x/cpu-topology.h" + +static char *fill_container (char *p,int level,int id) +{ +SysIBTl_container *tle = (SysIBTl_container *)p; + + tle->nl = level; + tle->id = id; +return p +sizeof (*tle); +} +
target/s390x/kvm/cpu_topology.c line 36
Quoted 10 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+static char *fill_tle_cpu (char *p,S390TopologyEntry *entry) +{ +SysIBTl_cpu *tle = (SysIBTl_cpu *)p; +s390_topology_id topology_id = entry->id; + + tle->nl =0 ; + tle->dedicated = topology_id.d; + tle->polarity = topology_id.p; + tle->type = topology_id.type; + tle->origin = topology_id.origin;
You need to multiply that value by 64, no?
And convert it to BE.
target/s390x/kvm/cpu_topology.c line 46
Quoted 10 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+ tle->mask =cpu_to_be64 (entry->mask); +return p +sizeof (*tle); +} + +static char *s390_top_set_level (char *p,int level) +{ +S390TopologyEntry *entry; +uint64_t last_socket =-1UL ; +uint64_t last_book =-1UL ; +uint64_t last_drawer =-1UL ;
-1UL looks funny to me, but there is nothing wrong with it. But I don't see a reason not to use int and initialize it with -1.
Quoted 25 lines
target/s390x/kvm/cpu_topology.c new file +25
-0+int drawer_cnt =0 ; +int book_cnt =0 ; +int socket_cnt =0 ; + + QTAILQ_FOREACH(entry, &s390_topology.list, next) { + +if (level >3 && (last_drawer != entry->id.drawer)) { + book_cnt =0 ; + socket_cnt =0 ; + p =fill_container (p,3 , drawer_cnt++); + last_drawer = entry->id.id &TOPO_DRAWER_MASK ; + p =fill_container (p,2 , book_cnt++); + last_book = entry->id.id &TOPO_BOOK_MASK ; + p =fill_container (p,1 , socket_cnt++); + last_socket = entry->id.id &TOPO_SOCKET_MASK ; + p =fill_tle_cpu (p, entry); + }else if (level >2 && (last_book != + (entry->id.id &TOPO_BOOK_MASK ))) { + socket_cnt =0 ; + p =fill_container (p,2 , book_cnt++); + last_book = entry->id.id &TOPO_BOOK_MASK ; + p =fill_container (p,1 , socket_cnt++); + last_socket = entry->id.id &TOPO_SOCKET_MASK ; + p =fill_tle_cpu (p, entry); + }else if (last_socket != (entry->id.id &TOPO_SOCKET_MASK )) {
target/s390x/kvm/cpu_topology.c line 81
Quoted 10 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+ p =fill_container (p,1 , socket_cnt++); + last_socket = entry->id.id &TOPO_SOCKET_MASK ; + p =fill_tle_cpu (p, entry); + }else { + p =fill_tle_cpu (p, entry); + } + } + +return p; +}
I think you can do this a bit more readable and reduce redundancy. Pseudo code:
foreach entry:
bool drawer_change = last_drawer != current_drawer bool book_change = drawer_change || last_book != current_book bool socket_change = book_change || last_socket != current_socket
if (level > 3 && drawer_change)
reset book id
fill drawer container
drawer id++
if (level > 2 && book_change)
reset socket id
fill book container
book id++
if (socket_change)
fill socket container
socket id++
fill cpu entry
update last_drawer, _book, _socket
You can also check after after every fill if the buffer has been overflowed, that is if the function wrote more than sizeof(SysIB) - sizeof(SysIB_151x) bytes. Or you check it once at the end if you increase the size of the buffer a bit. Then you don't need to allocate the absolute maximum.
I think you could also use global ids for the containers.
So directly use the drawer id from the entry,
use (drawer id * smp.books) + book id, and so on.
If you update last_* after setting *_changed you don't need to maintain ids, you can just use last_*.
[...]
Re: [PATCH v14 03/11] target/s390x/cpu topology: handle STSI(15) and build the SYSIB
Quoted 132 lines · Nina Schoetterl-Glausch
Quoted 131 lines · Pierre Morel
On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 3 + include/hw/s390x/sclp.h | 1 + target/s390x/cpu.h | 78 ++++++++++++++++++ target/s390x/kvm/cpu_topology.c | 136 ++++++++++++++++++++++++++++++++ target/s390x/kvm/kvm.c | 5 +- target/s390x/kvm/meson.build | 3 +- 6 files changed, 224 insertions(+), 2 deletions(-)create mode 100644
target/s390x/kvm/cpu_topology.cinclude/hw/s390x/cpu-topology.h +3
-0@@ -41,6 +41,9 @@ typedef union s390_topology_id { }; } s390_topology_id;#define TOPO_CPU_MASK 0x000000000000003fUL +#define TOPO_SOCKET_MASK 0x0000ffffff000000UL +#define TOPO_BOOK_MASK 0x0000ffff00000000UL +#define TOPO_DRAWER_MASK 0x0000ff0000000000UL typedef struct S390TopologyEntry { s390_topology_id id;include/hw/s390x/sclp.h +1
-0@@ -112,6 +112,7 @@ typedef struct CPUEntry { }QEMU_PACKED CPUEntry;#define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 +#define SCLP_READ_SCP_INFO_MNEST 2 typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax;target/s390x/cpu.h +73
-0@@ -561,6 +561,25 @@ typedef struct SysIB_322 { } SysIB_322;QEMU_BUILD_BUG_ON (sizeof (SysIB_322) !=4096 ); +#define S390_TOPOLOGY_MAG 6 +#define S390_TOPOLOGY_MAG6 0 +#define S390_TOPOLOGY_MAG5 1 +#define S390_TOPOLOGY_MAG4 2 +#define S390_TOPOLOGY_MAG3 3 +#define S390_TOPOLOGY_MAG2 4 +#define S390_TOPOLOGY_MAG1 5 +/* Configuration topology */ +typedef struct SysIB_151x { +uint8_t reserved0[2 ]; +uint16_t length; +uint8_t mag[S390_TOPOLOGY_MAG ]; +uint8_t reserved1; +uint8_t mnest; +uint32_t reserved2; +char tle[]; +} QEMU_PACKED QEMU_ALIGNED(8) SysIB_151x; +QEMU_BUILD_BUG_ON (sizeof (SysIB_151x) !=16 ); + typedef union SysIB { SysIB_111 sysib_111; SysIB_121 sysib_121;@@ -568,9 +587,68 @@ typedef union SysIB {SysIB_221 sysib_221;SysIB_222 sysib_222;SysIB_322 sysib_322; +SysIB_151x sysib_151x; } SysIB;QEMU_BUILD_BUG_ON (sizeof (SysIB) !=4096 ); +/* +* CPU Topology List provided by STSI with fc=15 provides a list +* of two different Topology List Entries (TLE) types to specify +* the topology hierarchy. +* +* - Container Topology List Entry +* Defines a container to contain other Topology List Entries +* of any type, nested containers or CPU. +* - CPU Topology List Entry +* Specifies the CPUs position, type, entitlement and polarization +* of the CPUs contained in the last Container TLE. +* +* There can be theoretically up to five levels of containers, QEMU +* uses only one level, the socket level. +* +* A container of with a nesting level (NL) greater than 1 can only +* contain another container of nesting level NL-1. +* +* A container of nesting level 1 (socket), contains as many CPU TLE +* as needed to describe the position and qualities of all CPUs inside +* the container. +* The qualities of a CPU are polarization, entitlement and type. +* +* The CPU TLE defines the position of the CPUs of identical qualities +* using a 64bits mask which first bit has its offset defined by +* the CPU address orgin field of the CPU TLE like in: +* CPU address = origin * 64 + bit position within the mask +* +*/ +/* Container type Topology List Entry */ +/* Container type Topology List Entry */ +typedef struct SysIBTl_container { +uint8_t nl; +uint8_t reserved[6 ]; +uint8_t id; +} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_container; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_container) !=8 ); + +/* CPU type Topology List Entry */ +typedef struct SysIBTl_cpu { +uint8_t nl; +uint8_t reserved0[3 ]; +uint8_t reserved1:5 ; +uint8_t dedicated:1 ; +uint8_t polarity:2 ; +uint8_t type; +uint16_t origin; +uint64_t mask; +} QEMU_PACKED QEMU_ALIGNED(8) SysIBTl_cpu; +QEMU_BUILD_BUG_ON (sizeof (SysIBTl_cpu) !=16 ); + +/* Max size of a SYSIB structure is when all CPU are alone in a container */ +#define S390_TOPOLOGY_SYSIB_SIZE (sizeof(SysIB_151x) + \
Quoted 8 lines
target/s390x/cpu.h typedef union SysIB { · line 648
Quoted 2 lines
target/s390x/cpu.h +2
-0+S390_MAX_CPUS * (sizeof (SysIBTl_container) + \ + sizeof(SysIBTl_cpu)))I don't think this is accurate anymore, if you have drawers and books. In that case you could have 3 containers per 1 cpu.
You could also use the maxcpus number at runtime instead ofS390_MAX_CPUS. I also think you could do sizeof(SysIB) +sizeof(SysIBTl_cpu)if you check if the sysib overflows 4k while building it.
Right.
And I think your other proposal here under is better
Quoted 44 lines
Quoted 44 lines
target/s390x/cpu.h +3
-0+ +void insert_stsi_15_1_x (S390CPU *cpu,int sel2,__u64 addr,uint8_t ar); +/* MMU defines */ #define ASCE_ORIGIN (~0xfffULL)/* segment table origin */ #define ASCE_SUBSPACE 0x200/* subspace group control */ target/s390x/kvm/cpu_topology.c new file +31
-0@@ -0,0 +1,136 @@ +/* +* QEMU S390x CPU Topology +* +* Copyright IBM Corp. 2022 +* Author(s): Pierre Morel <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ +#include "qemu/osdep.h" +#include "cpu.h" +#include "hw/s390x/pv.h" +#include "hw/sysbus.h" +#include "hw/s390x/sclp.h" +#include "hw/s390x/cpu-topology.h" + +static char *fill_container (char *p,int level,int id) +{ +SysIBTl_container *tle = (SysIBTl_container *)p; + + tle->nl = level; + tle->id = id; +return p +sizeof (*tle); +} + +static char *fill_tle_cpu (char *p,S390TopologyEntry *entry) +{ +SysIBTl_cpu *tle = (SysIBTl_cpu *)p; +s390_topology_id topology_id = entry->id; +
Quoted 8 lines
target/s390x/kvm/cpu_topology.c line 36
Quoted 5 lines
target/s390x/kvm/cpu_topology.c new file +5
-0+ tle->nl =0 ; + tle->dedicated = topology_id.d; + tle->polarity = topology_id.p; + tle->type = topology_id.type; + tle->origin = topology_id.origin;You need to multiply that value by 64, no?
And convert it to BE.
Yes right, I already had this error, I must have lost it in a rebase.
Quoted 79 lines
target/s390x/kvm/cpu_topology.c line 46
Quoted 11 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+ tle->mask =cpu_to_be64 (entry->mask); +return p +sizeof (*tle); +} + +static char *s390_top_set_level (char *p,int level) +{ +S390TopologyEntry *entry; +uint64_t last_socket =-1UL ; +uint64_t last_book =-1UL ; +uint64_t last_drawer =-1UL ;-1UL looks funny to me, but there is nothing wrong with it. But I don't see a reason not to use int and initialize it with -1.
Quoted 25 lines
target/s390x/kvm/cpu_topology.c new file +25
-0+int drawer_cnt =0 ; +int book_cnt =0 ; +int socket_cnt =0 ; + + QTAILQ_FOREACH(entry, &s390_topology.list, next) { + +if (level >3 && (last_drawer != entry->id.drawer)) { + book_cnt =0 ; + socket_cnt =0 ; + p =fill_container (p,3 , drawer_cnt++); + last_drawer = entry->id.id &TOPO_DRAWER_MASK ; + p =fill_container (p,2 , book_cnt++); + last_book = entry->id.id &TOPO_BOOK_MASK ; + p =fill_container (p,1 , socket_cnt++); + last_socket = entry->id.id &TOPO_SOCKET_MASK ; + p =fill_tle_cpu (p, entry); + }else if (level >2 && (last_book != + (entry->id.id &TOPO_BOOK_MASK ))) { + socket_cnt =0 ; + p =fill_container (p,2 , book_cnt++); + last_book = entry->id.id &TOPO_BOOK_MASK ; + p =fill_container (p,1 , socket_cnt++); + last_socket = entry->id.id &TOPO_SOCKET_MASK ; + p =fill_tle_cpu (p, entry); + }else if (last_socket != (entry->id.id &TOPO_SOCKET_MASK )) {target/s390x/kvm/cpu_topology.c line 81
Quoted 10 lines
target/s390x/kvm/cpu_topology.c new file +10
-0+ p =fill_container (p,1 , socket_cnt++); + last_socket = entry->id.id &TOPO_SOCKET_MASK ; + p =fill_tle_cpu (p, entry); + }else { + p =fill_tle_cpu (p, entry); + } + } + +return p; +}I think you can do this a bit more readable and reduce redundancy. Pseudo code:
foreach entry:
booldrawer_change=last_drawer!=current_drawerboolbook_change=drawer_change||last_book!=current_bookboolsocket_change=book_change||last_socket!=current_socketif (level > 3 &&
drawer_change)
reset book id
fill drawer container
drawer id++
if (level > 2 &&book_change)
reset socket id
fill book container
book id++
if (socket_change)
fill socket container
socket id++
fill cpu entryupdate
last_drawer,_book,_socketYou can also check after after every fill if the buffer has been overflowed, that is if the function wrote more than sizeof(SysIB) -
sizeof(SysIB_151x)bytes. Or you check it once at the end if you increase the size of the buffer a bit. Then you don't need to allocate the absolute maximum.
Quoted 5 lines
I think you could also use global ids for the containers.
So directly use the drawer id from the entry,
use (drawer id * smp.books) + book id, and so on.
If you update last_* after setting*_changedyou don't need to maintain ids, you can just use last_*.
OK, seems better to me
Thanks
Regards,
Pierre
Quoted 3 lines
[...]
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 4/11 s390x/sclp: reporting the maximum nested topology entries
In reply to Pierre MorelThe maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Currently, SCLP READ SCP INFO reports MNEST = 0, which is the equivalent of reporting the default value of 2.
Let's use the default SCLP value of 2 and increase this value in the future patches implementing higher levels.
--- include/hw/s390x/sclp.h | 5 +++-- hw/s390x/sclp.c | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)
include/hw/s390x/sclp.h +3 -2
@@ -112,12 +112,13 @@ typedef struct CPUEntry { }QEMU_PACKED CPUEntry;#define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 -#define SCLP_READ_SCP_INFO_MNEST 2 +#define SCLP_READ_SCP_INFO_MNEST 4 typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; uint8_t rnsize; - uint8_t _reserved1[16 - 11]; /* 11-15 */ + uint8_t _reserved1[15 - 11]; /* 11-14 */ + uint8_t stsi_parm; /* 15-16 */ uint16_t entries_cpu; /* 16-17 */ uint16_t offset_cpu; /* 18-19 */ uint8_t _reserved2[24 - 20]; /* 20-23 */
hw/s390x/sclp.c +4 -0
@@ -20,6 +20,7 @@#include "hw/s390x/event-facility.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/ipl.h" +#include "hw/s390x/cpu-topology.h" static inline SCLPDevice *get_sclp_device (void ) {
@@ -125,6 +126,9 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)/* CPU information */ prepare_cpu_entries (machine, entries_start, &cpu_count); +if (s390_has_topology ()) { + read_info->stsi_parm =SCLP_READ_SCP_INFO_MNEST ; + } read_info->entries_cpu =cpu_to_be16 (cpu_count); read_info->offset_cpu =cpu_to_be16 (offset_cpu); read_info->highest_cpu =cpu_to_be16 (machine->smp.max_cpus -1 );
Signature · 1 line
2.31.1
Re: [PATCH v14 04/11] s390x/sclp: reporting the maximum nested topology entries
Quoted 7 lines · Pierre Morel
The maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Currently, SCLP READ SCP INFO reports MNEST = 0, which is the equivalent of reporting the default value of 2.
Let's use the default SCLP value of 2 and increase this value in the future patches implementing higher levels.
I'm confused ... so does a SCLP value of 2 mean a MNEST level of 4 ?
Quoted 11 lines
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/sclp.h | 5 +++-- hw/s390x/sclp.c | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)include/hw/s390x/sclp.h +0
-0
include/hw/s390x/sclp.h typedef struct CPUEntry { · line 115
Quoted 5 lines
include/hw/s390x/sclp.h +1
-1@@ -112,12 +112,13 @@ typedef struct CPUEntry { }QEMU_PACKED CPUEntry;#define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 -#define SCLP_READ_SCP_INFO_MNEST 2 +#define SCLP_READ_SCP_INFO_MNEST 4
... since you update it to 4 here.
Quoted 23 lines
include/hw/s390x/sclp.h +2
-1typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; uint8_t rnsize; - uint8_t _reserved1[16 - 11]; /* 11-15 */ + uint8_t _reserved1[15 - 11]; /* 11-14 */ + uint8_t stsi_parm; /* 15-16 */ uint16_t entries_cpu; /* 16-17 */ uint16_t offset_cpu; /* 18-19 */ uint8_t _reserved2[24 - 20]; /* 20-23 */hw/s390x/sclp.c +1
-0@@ -20,6 +20,7 @@#include "hw/s390x/event-facility.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/ipl.h" +#include "hw/s390x/cpu-topology.h" static inline SCLPDevice *get_sclp_device (void ) {
hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 130
Quoted 5 lines
hw/s390x/sclp.c +2
-0@@ -125,6 +126,9 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)/* CPU information */ prepare_cpu_entries (machine, entries_start, &cpu_count); +if (s390_has_topology ()) { + read_info->stsi_parm =SCLP_READ_SCP_INFO_MNEST ;
This seems to be in contradiction to what you've said in the commit description - you set it to 4 and not to 2.
Thomas
Quoted 4 lines
hw/s390x/sclp.c +1
-0+ } read_info->entries_cpu =cpu_to_be16 (cpu_count); read_info->offset_cpu =cpu_to_be16 (offset_cpu); read_info->highest_cpu =cpu_to_be16 (machine->smp.max_cpus -1 );
Re: [PATCH v14 04/11] s390x/sclp: reporting the maximum nested topology entries
Quoted 10 lines · Thomas Huth
Quoted 7 lines · Pierre Morel
The maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Currently, SCLP READ SCP INFO reports MNEST = 0, which is the equivalent of reporting the default value of 2.
Let's use the default SCLP value of 2 and increase this value in the future patches implementing higher levels.I'm confused ... so does a SCLP value of 2 mean a MNEST level of 4 ?
Sorry, I forgot to change this.
MNEST = 0 means no MNEST support and only socket is supported so it is like MNEST = 2.
MNEST != 0 set the maximum nested level and correct values may be 2,3 or 4.
But this setting to 4 should already have been done in previous patch where we introduced the books and drawers.
I change the commit message with:
---
s390x/sclp: reporting the maximum nested topology entries
The maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Let's return this information to the guest.
---
Quoted 7 lines
Quoted 7 lines
Signed-off-by Pierre Morel <[email protected]>---
include/hw/s390x/sclp.h| 5 +++--
hw/s390x/sclp.c | 4 ++++2 files changed, 7 insertions(+), 2 deletions(-)
Quoted 11 lines
include/hw/s390x/sclp.h typedef struct CPUEntry { · line 114
Quoted 9 lines
include/hw/s390x/sclp.h +1
-1@@ -112,12 +112,13 @@ typedef struct CPUEntry { } QEMU_PACKED CPUEntry; #define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 -#define SCLP_READ_SCP_INFO_MNEST 2 +#define SCLP_READ_SCP_INFO_MNEST 4... since you update it to 4 here.
Yes, in fact this should be set in the previous patch already to 4. So I will do that.
Quoted 22 lines
Quoted 22 lines
include/hw/s390x/sclp.h +2
-1typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; uint8_t rnsize; - uint8_t _reserved1[16 - 11]; /* 11-15 */ + uint8_t _reserved1[15 - 11]; /* 11-14 */ + uint8_t stsi_parm; /* 15-16 */
uint16_tentries_cpu; /* 16-17 */uint16_toffset_cpu; /* 18-19 */ uint8_t _reserved2[24 - 20]; /* 20-23 */hw/s390x/sclp.c +1
-0@@ -20,6 +20,7 @@ #include "hw/s390x/event-facility.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/ipl.h" +#include "hw/s390x/cpu-topology.h" static inline SCLPDevice *get_sclp_device(void) {
Quoted 8 lines
hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB · line 130
Quoted 6 lines
hw/s390x/sclp.c +2
-0@@ -125,6 +126,9 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) /* CPU information */ prepare_cpu_entries(machine, entries_start, &cpu_count); + if (s390_has_topology()) { + read_info->stsi_parm = SCLP_READ_SCP_INFO_MNEST;This seems to be in contradiction to what you've said in the commit description - you set it to 4 and not to 2.
Yes, I change the commit message.
Thanks.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 04/11] s390x/sclp: reporting the maximum nested topology entries
Quoted 11 lines · Pierre Morel
Quoted 9 lines · Thomas Huth
Quoted 7 lines · Pierre Morel
The maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Currently, SCLP READ SCP INFO reports MNEST = 0, which is the equivalent of reporting the default value of 2.
Let's use the default SCLP value of 2 and increase this value in the future patches implementing higher levels.
Quoted 8 lines
Quoted 1 line
I'm confused ... so does a SCLP value of 2 mean a MNEST level of 4 ?
Sorry, I forgot to change this.
MNEST = 0 means no MNEST support and only socket is supported so it is like MNEST = 2.
MNEST != 0 set the maximum nested level and correct values may be 2,3 or 4. But this setting to 4 should already have been done in previous patch where we introduced the books and drawers.
I think setting it to 4 here is fine/preferable, since 2 is the default unless you tell the guest that more are available, which you do in this patch. It's only the commit description that is confusing.
Quoted 72 lines
I change the commit message with:
---
s390x/sclp: reporting the maximum nested topology entriesThe maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Let's return this information to the guest.
---Quoted 7 lines
Quoted 7 lines
Signed-off-by Pierre Morel <[email protected]>---
include/hw/s390x/sclp.h| 5 +++--
hw/s390x/sclp.c | 4 ++++2 files changed, 7 insertions(+), 2 deletions(-)Quoted 11 lines
include/hw/s390x/sclp.h typedef struct CPUEntry { · line 114
Quoted 9 lines
include/hw/s390x/sclp.h +1
-1@@ -112,12 +112,13 @@ typedef struct CPUEntry { } QEMU_PACKED CPUEntry; #define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 -#define SCLP_READ_SCP_INFO_MNEST 2 +#define SCLP_READ_SCP_INFO_MNEST 4... since you update it to 4 here.
Yes, in fact this should be set in the previous patch already to 4. So I will do that.
Quoted 23 lines
Quoted 23 lines
include/hw/s390x/sclp.h +2
-1typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; uint8_t rnsize; - uint8_t _reserved1[16 - 11]; /* 11-15 */ + uint8_t _reserved1[15 - 11]; /* 11-14 */ + uint8_t stsi_parm; /* 15-16 */
uint16_tentries_cpu; /* 16-17 */uint16_toffset_cpu; /* 18-19 */ uint8_t _reserved2[24 - 20]; /* 20-23 */hw/s390x/sclp.c +1
-0@@ -20,6 +20,7 @@ #include "hw/s390x/event-facility.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/ipl.h" +#include "hw/s390x/cpu-topology.h" static inline SCLPDevice *get_sclp_device(void) {@@ -125,6 +126,9 @@ static void read_SCP_info(SCLPDevice *sclp, SCCBQuoted 8 lines
hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 130
Quoted 5 lines
hw/s390x/sclp.c +2
-0*sccb) /* CPU information */ prepare_cpu_entries(machine, entries_start, &cpu_count); + if (s390_has_topology()) { + read_info->stsi_parm = SCLP_READ_SCP_INFO_MNEST;This seems to be in contradiction to what you've said in the commit description - you set it to 4 and not to 2.
Yes, I change the commit message.
Thanks.
Regards,
Pierre
Re: [PATCH v14 04/11] s390x/sclp: reporting the maximum nested topology entries
Quoted 21 lines · Nina Schoetterl-Glausch
Quoted 11 lines · Pierre Morel
Quoted 9 lines · Thomas Huth
Quoted 7 lines · Pierre Morel
The maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Currently, SCLP READ SCP INFO reports MNEST = 0, which is the equivalent of reporting the default value of 2.
Let's use the default SCLP value of 2 and increase this value in the future patches implementing higher levels.Quoted 8 lines
Quoted 1 line
I'm confused ... so does a SCLP value of 2 mean a MNEST level of 4 ?
Sorry, I forgot to change this.
MNEST = 0 means no MNEST support and only socket is supported so it is like MNEST = 2.
MNEST != 0 set the maximum nested level and correct values may be 2,3 or 4. But this setting to 4 should already have been done in previous patch where we introduced the books and drawers.
Quoted 3 lines
I think setting it to 4 here is fine/preferable, since 2 is the default unless you tell the guest that more are available, which you do in this patch. It's only the commit description that is confusing.
Yes.
Only the commit message is confusing, it is to be set on 4 in this patch.
I change the commit message to:
---
s390x/sclp: reporting the maximum nested topology entries
The maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Let change the MNEST value from 2 to 4 in the SCLP READ INFO structure now that we support books and drawers.
---
is it OK ?
Regards,
Pierre
Quoted 74 lines
Quoted 73 lines
I change the commit message with:
---
s390x/sclp: reporting the maximum nested topology entriesThe maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Let's return this information to the guest.
---Quoted 7 lines
Quoted 7 lines
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/sclp.h | 5 +++-- hw/s390x/sclp.c | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)Quoted 11 lines
include/hw/s390x/sclp.h typedef struct CPUEntry { · line 114
Quoted 9 lines
include/hw/s390x/sclp.h +1
-1@@ -112,12 +112,13 @@ typedef struct CPUEntry { } QEMU_PACKED CPUEntry; #define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 -#define SCLP_READ_SCP_INFO_MNEST 2 +#define SCLP_READ_SCP_INFO_MNEST 4... since you update it to 4 here.
Yes, in fact this should be set in the previous patch already to 4. So I will do that.
Quoted 23 lines
Quoted 23 lines
include/hw/s390x/sclp.h +2
-1typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; uint8_t rnsize; - uint8_t _reserved1[16 - 11]; /* 11-15 */ + uint8_t _reserved1[15 - 11]; /* 11-14 */ + uint8_t stsi_parm; /* 15-16 */ uint16_t entries_cpu; /* 16-17 */ uint16_t offset_cpu; /* 18-19 */ uint8_t _reserved2[24 - 20]; /* 20-23 */hw/s390x/sclp.c +1
-0@@ -20,6 +20,7 @@ #include "hw/s390x/event-facility.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/ipl.h" +#include "hw/s390x/cpu-topology.h" static inline SCLPDevice *get_sclp_device(void) {@@ -125,6 +126,9 @@ static void read_SCP_info(SCLPDevice *sclp, SCCBQuoted 8 lines
hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 130
Quoted 5 lines
hw/s390x/sclp.c +2
-0*sccb) /* CPU information */ prepare_cpu_entries(machine, entries_start, &cpu_count); + if (s390_has_topology()) { + read_info->stsi_parm = SCLP_READ_SCP_INFO_MNEST;This seems to be in contradiction to what you've said in the commit description - you set it to 4 and not to 2.
Yes, I change the commit message.
Thanks.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 04/11] s390x/sclp: reporting the maximum nested topology entries
In reply to Pierre MorelQuoted 9 lines · Pierre Morel
The maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Currently, SCLP READ SCP INFO reports MNEST = 0, which is the equivalent of reporting the default value of 2.
Let's use the default SCLP value of 2 and increase this value in the future patches implementing higher levels.Signed-off-by Pierre Morel <[email protected]>
if you address the issues Thomas found with the commit description and the nits below.
Quoted 12 lines
--- include/hw/s390x/sclp.h | 5 +++-- hw/s390x/sclp.c | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)include/hw/s390x/sclp.h +0
-0@@ -112,12 +112,13 @@ typedef struct CPUEntry { }QEMU_PACKED CPUEntry;
include/hw/s390x/sclp.h typedef struct CPUEntry { · line 121
Quoted 10 lines
include/hw/s390x/sclp.h +3
-2#define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 -#define SCLP_READ_SCP_INFO_MNEST 2 +#define SCLP_READ_SCP_INFO_MNEST 4 typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; uint8_t rnsize; - uint8_t _reserved1[16 - 11]; /* 11-15 */ + uint8_t _reserved1[15 - 11]; /* 11-14 */ + uint8_t stsi_parm; /* 15-16 */
The numbering here is the same as the one in the arch doc, instead of the maybe more usual one where the right number is exclusive. So 15-16 looks like a two byte field, so just do 15 or just drop it.
Quoted 16 lines
include/hw/s390x/sclp.h +0
-0uint16_t entries_cpu;/* 16-17 */ uint16_t offset_cpu;/* 18-19 */ uint8_t _reserved2[24 -20 ];/* 20-23 */ hw/s390x/sclp.c +1
-0@@ -20,6 +20,7 @@#include "hw/s390x/event-facility.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/ipl.h" +#include "hw/s390x/cpu-topology.h" static inline SCLPDevice *get_sclp_device (void ) {
hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 131
Quoted 6 lines
hw/s390x/sclp.c +3
-0@@ -125,6 +126,9 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)/* CPU information */ prepare_cpu_entries (machine, entries_start, &cpu_count); +if (s390_has_topology ()) { + read_info->stsi_parm =SCLP_READ_SCP_INFO_MNEST ; + }
Maybe move that up a bit, not sure if it belongs under the CPU information section. I'd leave prepare_cpu_entries and read_info->entries_cpu = adjacent in any case.
Quoted 3 lines
hw/s390x/sclp.c +0
-0read_info->entries_cpu =cpu_to_be16 (cpu_count); read_info->offset_cpu =cpu_to_be16 (offset_cpu); read_info->highest_cpu =cpu_to_be16 (machine->smp.max_cpus -1 );
Re: [PATCH v14 04/11] s390x/sclp: reporting the maximum nested topology entries
Quoted 9 lines · Nina Schoetterl-Glausch
Quoted 8 lines · Pierre Morel
The maximum nested topology entries is used by the guest to know how many nested topology are available on the machine.
Currently, SCLP READ SCP INFO reports MNEST = 0, which is the equivalent of reporting the default value of 2.
Let's use the default SCLP value of 2 and increase this value in the future patches implementing higher levels.
Quoted 5 lines
Quoted 1 line
Signed-off-by Pierre Morel <[email protected]>Reviewed-by Nina Schoetterl-Glausch <[email protected]>if you address the issues Thomas found with the commit description and the nits below.
Thanks.
Quoted 13 lines
Quoted 13 lines
--- include/hw/s390x/sclp.h | 5 +++-- hw/s390x/sclp.c | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)include/hw/s390x/sclp.h +0
-0@@ -112,12 +112,13 @@ typedef struct CPUEntry { }QEMU_PACKED CPUEntry;
Quoted 14 lines
include/hw/s390x/sclp.h typedef struct CPUEntry { · line 121
Quoted 10 lines
include/hw/s390x/sclp.h +3
-2#define SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET 128 -#define SCLP_READ_SCP_INFO_MNEST 2 +#define SCLP_READ_SCP_INFO_MNEST 4 typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; uint8_t rnsize; - uint8_t _reserved1[16 - 11]; /* 11-15 */ + uint8_t _reserved1[15 - 11]; /* 11-14 */ + uint8_t stsi_parm; /* 15-16 */The numbering here is the same as the one in the arch doc, instead of the maybe more usual one where the right number is exclusive. So 15-16 looks like a two byte field, so just do 15 or just drop it.
Yes right, thanks.
Quoted 18 lines
Quoted 18 lines
include/hw/s390x/sclp.h +0
-0uint16_t entries_cpu;/* 16-17 */ uint16_t offset_cpu;/* 18-19 */ uint8_t _reserved2[24 -20 ];/* 20-23 */ hw/s390x/sclp.c +1
-0@@ -20,6 +20,7 @@#include "hw/s390x/event-facility.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/ipl.h" +#include "hw/s390x/cpu-topology.h" static inline SCLPDevice *get_sclp_device (void ) {@@ -125,6 +126,9 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
Quoted 9 lines
hw/s390x/sclp.c static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb) · line 131
Quoted 5 lines
hw/s390x/sclp.c +3
-0/* CPU information */ prepare_cpu_entries (machine, entries_start, &cpu_count); +if (s390_has_topology ()) { + read_info->stsi_parm =SCLP_READ_SCP_INFO_MNEST ; + }Maybe move that up a bit, not sure if it belongs under the CPU information section. I'd leave
prepare_cpu_entriesandread_info->entries_cpu= adjacent in any case.
Yes, I do that.
Thanks,
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 5/11 s390x/cpu topology: resetting the Topology-Change-Report
In reply to Pierre MorelDuring a subsystem reset the Topology-Change-Report is cleared by the machine.
Let's ask KVM to clear the Modified Topology Change Report (MTCR) bit of the SCA in the case of a subsystem reset.
--- target/s390x/cpu.h | 1 + target/s390x/kvm/kvm_s390x.h | 1 + hw/s390x/s390-virtio-ccw.c | 1 + target/s390x/cpu-sysemu.c | 13 +++++++++++++ target/s390x/kvm/kvm.c | 17 +++++++++++++++++ 5 files changed, 33 insertions(+)
target/s390x/cpu.h +1 -0
@@ -863,6 +863,7 @@ void s390_enable_css_support(S390CPU *cpu);void s390_do_cpu_set_diag318 (CPUState *cs,run_on_cpu_data arg);int s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch_id,int vq,bool assign); +void s390_cpu_topology_reset (void );#ifndef CONFIG_USER_ONLY unsigned int s390_cpu_set_state (uint8_t cpu_state,S390CPU *cpu);#else
target/s390x/kvm/kvm_s390x.h +1 -0
@@ -47,5 +47,6 @@ void kvm_s390_crypto_reset(void);void kvm_s390_restart_interrupt (S390CPU *cpu);void kvm_s390_stop_interrupt (S390CPU *cpu);void kvm_s390_set_diag318 (CPUState *cs,uint64_t diag318_info); +int kvm_s390_topology_set_mtcr (uint64_t attr);#endif /* KVM_S390X_H */
hw/s390x/s390-virtio-ccw.c +1 -0
@@ -122,6 +122,7 @@ static void subsystem_reset(void)device_cold_reset (dev); } } +s390_cpu_topology_reset (); }static int virtio_ccw_hcall_notify (const uint64_t *args)
target/s390x/cpu-sysemu.c +13 -0
@@ -306,3 +306,16 @@ void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg)kvm_s390_set_diag318 (cs, arg.host_ulong); } } + +void s390_cpu_topology_reset (void ) +{ +int ret; + +if (kvm_enabled ()) { + ret =kvm_s390_topology_set_mtcr (0 ); +if (ret) { +error_report ("Failed to set Modified Topology Change Report: %s" , +strerror (-ret)); + } + } +}
target/s390x/kvm/kvm.c +17 -0
@@ -2592,6 +2592,23 @@ int kvm_s390_get_zpci_op(void)return cap_zpci_op; } +int kvm_s390_topology_set_mtcr (uint64_t attr) +{ +struct kvm_device_attr attribute = { + .group =KVM_S390_VM_CPU_TOPOLOGY , + .attr = attr, + }; + +if (!s390_has_feat (S390_FEAT_CONFIGURATION_TOPOLOGY )) { +return 0 ; + } +if (!kvm_vm_check_attr (kvm_state,KVM_S390_VM_CPU_TOPOLOGY , attr)) { +return -ENOTSUP ; + } + +return kvm_vm_ioctl (kvm_state,KVM_SET_DEVICE_ATTR , &attribute); +} +void kvm_arch_accel_class_init (ObjectClass *oc) { }
Signature · 1 line
2.31.1
Re: [PATCH v14 05/11] s390x/cpu topology: resetting the Topology-Change-Report
Quoted 7 lines · Pierre Morel
During a subsystem reset the Topology-Change-Report is cleared by the machine.
Let's ask KVM to clear the Modified Topology Change Report (MTCR) bit of the SCA in the case of a subsystem reset.Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 16 lines
target/s390x/kvm/kvm_s390x.h +1
-0@@ -47,5 +47,6 @@ void kvm_s390_crypto_reset(void);void kvm_s390_restart_interrupt (S390CPU *cpu);void kvm_s390_stop_interrupt (S390CPU *cpu);void kvm_s390_set_diag318 (CPUState *cs,uint64_t diag318_info); +int kvm_s390_topology_set_mtcr (uint64_t attr);#endif /* KVM_S390X_H */ hw/s390x/s390-virtio-ccw.c +0
-0
hw/s390x/s390-virtio-ccw.c static void subsystem_reset(void) · line 126
Quoted 5 lines
hw/s390x/s390-virtio-ccw.c +1
-0@@ -122,6 +122,7 @@ static void subsystem_reset(void)device_cold_reset (dev); } } +s390_cpu_topology_reset (); }
Would it make sense to add a "if (s390_has_topology())" check around the new line?
Anyway:
Re: [PATCH v14 05/11] s390x/cpu topology: resetting the Topology-Change-Report
Quoted 23 lines · Thomas Huth
Quoted 7 lines · Pierre Morel
During a subsystem reset the Topology-Change-Report is cleared by the machine.
Let's ask KVM to clear the Modified Topology Change Report (MTCR) bit of the SCA in the case of a subsystem reset.Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 14 lines
target/s390x/kvm/kvm_s390x.h +1
-0@@ -47,5 +47,6 @@ void kvm_s390_crypto_reset(void); void kvm_s390_restart_interrupt(S390CPU *cpu); void kvm_s390_stop_interrupt(S390CPU *cpu); void kvm_s390_set_diag318(CPUState *cs, uint64_t diag318_info); +int kvm_s390_topology_set_mtcr (uint64_t attr); #endif /* KVM_S390X_H */hw/s390x/s390-virtio-ccw.c +0
-0
Quoted 8 lines
hw/s390x/s390-virtio-ccw.c static void subsystem_reset(void) · line 126
Quoted 6 lines
hw/s390x/s390-virtio-ccw.c +1
-0@@ -122,6 +122,7 @@ static void subsystem_reset(void) device_cold_reset(dev); } } + s390_cpu_topology_reset(); }Would it make sense to add a "if (
s390_has_topology())" check around the new line?
Yes I think you are right, otherwise we may get a warning if the kernel does not support resetting the topology.
Quoted 5 lines
Anyway:
Reviewed-by Thomas Huth <[email protected]>
Thanks,
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 6/11 s390x/cpu topology: interception of PTF instruction
In reply to Pierre MorelWhen the host supports the CPU topology facility, the PTF instruction with function code 2 is interpreted by the SIE, provided that the userland hypervizor activates the interpretation by using the KVM_CAP_S390_CPU_TOPOLOGY KVM extension.
The PTF instructions with function code 0 and 1 are intercepted and must be emulated by the userland hypervizor.
During RESET all CPU of the configuration are placed in horizontal polarity.
--- include/hw/s390x/cpu-topology.h | 3 + include/hw/s390x/s390-virtio-ccw.h | 6 ++ target/s390x/cpu.h | 1 + hw/s390x/cpu-topology.c | 92 ++++++++++++++++++++++++++++++ target/s390x/cpu-sysemu.c | 16 ++++++ target/s390x/kvm/kvm.c | 11 ++++ 6 files changed, 129 insertions(+)
include/hw/s390x/cpu-topology.h +3 -0
@@ -55,11 +55,13 @@ typedef struct S390Topology { QTAILQ_HEAD(, S390TopologyEntry) list;uint8_t *sockets;CpuTopology *smp; +int polarity; } S390Topology;#ifdef CONFIG_KVM bool s390_has_topology (void );void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +void s390_topology_set_polarity (int polarity);#else static inline bool s390_has_topology (void ) {
@@ -68,6 +70,7 @@ static inline bool s390_has_topology(void)static inline void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp) {} +static inline void s390_topology_set_polarity (int polarity) {}#endif extern S390Topology s390_topology;
include/hw/s390x/s390-virtio-ccw.h +6 -0
@@ -30,6 +30,12 @@ struct S390CcwMachineState {uint8_t loadparm[8 ]; }; +#define S390_PTF_REASON_NONE (0x00 << 8) +#define S390_PTF_REASON_DONE (0x01 << 8) +#define S390_PTF_REASON_BUSY (0x02 << 8) +#define S390_TOPO_FC_MASK 0xffUL +void s390_handle_ptf (S390CPU *cpu,uint8_t r1,uintptr_t ra); +struct S390CcwMachineClass {/*< private >*/ MachineClass parent_class;
target/s390x/cpu.h +1 -0
@@ -864,6 +864,7 @@ void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg);int s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch_id,int vq,bool assign);void s390_cpu_topology_reset (void ); +void s390_cpu_topology_set (void );#ifndef CONFIG_USER_ONLY unsigned int s390_cpu_set_state (uint8_t cpu_state,S390CPU *cpu);#else
hw/s390x/cpu-topology.c +92 -0
98 lines not on this page · raw message
target/s390x/cpu-sysemu.c +16 -0
@@ -37,6 +37,7 @@#include "sysemu/sysemu.h" #include "sysemu/tcg.h" #include "hw/core/sysemu-cpu-ops.h" +#include "hw/s390x/cpu-topology.h" /* S390CPUClass::load_normal() */ static void s390_cpu_load_normal (CPUState *s)
@@ -311,6 +312,8 @@ void s390_cpu_topology_reset(void) {int ret; +s390_topology_set_polarity (S390_TOPOLOGY_POLARITY_HORIZONTAL ); +if (kvm_enabled ()) { ret =kvm_s390_topology_set_mtcr (0 );if (ret) {
@@ -319,3 +322,16 @@ void s390_cpu_topology_reset(void) } } } + +void s390_cpu_topology_set (void ) +{ +int ret; + +if (kvm_enabled ()) { + ret =kvm_s390_topology_set_mtcr (1 ); +if (ret) { +error_report ("Failed to set Modified Topology Change Report: %s" , +strerror (-ret)); + } + } +}
target/s390x/kvm/kvm.c +11 -0
@@ -96,6 +96,7 @@#define PRIV_B9_EQBS 0x9c#define PRIV_B9_CLP 0xa0 +#define PRIV_B9_PTF 0xa2#define PRIV_B9_PCISTG 0xd0#define PRIV_B9_PCILG 0xd2#define PRIV_B9_RPCIT 0xd3
@@ -1464,6 +1465,13 @@ static int kvm_mpcifc_service_call(S390CPU *cpu, struct kvm_run *run) } } +static void kvm_handle_ptf (S390CPU *cpu,struct kvm_run *run) +{ +uint8_t r1 = (run->s390_sieic.ipb >>20 ) &0x0f ; + +s390_handle_ptf (cpu, r1,RA_IGNORED ); +} +static int handle_b9 (S390CPU *cpu,struct kvm_run *run,uint8_t ipa1) {int r =0 ;
@@ -1481,6 +1489,9 @@ static int handle_b9(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1)case PRIV_B9_RPCIT : r =kvm_rpcit_service_call (cpu, run);break ; +case PRIV_B9_PTF : +kvm_handle_ptf (cpu, run); +break ;case PRIV_B9_EQBS :/* just inject exception */ r =-1 ;
Signature · 1 line
2.31.1
Re: [PATCH v14 06/11] s390x/cpu topology: interception of PTF instruction
Quoted 69 lines · Pierre Morel
When the host supports the CPU topology facility, the PTF instruction with function code 2 is interpreted by the SIE, provided that the userland hypervizor activates the interpretation by using the
KVM_CAP_S390_CPU_TOPOLOGYKVM extension.The PTF instructions with function code 0 and 1 are intercepted and must be emulated by the userland hypervizor.
During RESET all CPU of the configuration are placed in horizontal polarity.
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 3 + include/hw/s390x/s390-virtio-ccw.h | 6 ++ target/s390x/cpu.h | 1 + hw/s390x/cpu-topology.c | 92 ++++++++++++++++++++++++++++++ target/s390x/cpu-sysemu.c | 16 ++++++ target/s390x/kvm/kvm.c | 11 ++++ 6 files changed, 129 insertions(+)include/hw/s390x/cpu-topology.h +3
-0@@ -55,11 +55,13 @@ typedef struct S390Topology { QTAILQ_HEAD(, S390TopologyEntry) list;uint8_t *sockets;CpuTopology *smp; +int polarity; } S390Topology;#ifdef CONFIG_KVM bool s390_has_topology (void );void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +void s390_topology_set_polarity (int polarity);#else static inline bool s390_has_topology (void ) {@@ -68,6 +70,7 @@ static inline bool s390_has_topology(void)static inline void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp) {} +static inline void s390_topology_set_polarity (int polarity) {}#endif extern S390Topology s390_topology;include/hw/s390x/s390-virtio-ccw.h +6
-0@@ -30,6 +30,12 @@ struct S390CcwMachineState {uint8_t loadparm[8 ]; }; +#define S390_PTF_REASON_NONE (0x00 << 8) +#define S390_PTF_REASON_DONE (0x01 << 8) +#define S390_PTF_REASON_BUSY (0x02 << 8) +#define S390_TOPO_FC_MASK 0xffUL +void s390_handle_ptf (S390CPU *cpu,uint8_t r1,uintptr_t ra); +struct S390CcwMachineClass {/*< private >*/ MachineClass parent_class;target/s390x/cpu.h +0
-0
target/s390x/cpu.h void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg); · line 867
Quoted 4 lines
target/s390x/cpu.h +1
-0@@ -864,6 +864,7 @@ void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg);int s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch_id,int vq,bool assign);void s390_cpu_topology_reset (void ); +void s390_cpu_topology_set (void );
I don't like this name much, it's nondescript.s390_cpu_topology_set_modified ?
Quoted 13 lines
target/s390x/cpu.h +0
-0#ifndef CONFIG_USER_ONLY unsigned int s390_cpu_set_state (uint8_t cpu_state,S390CPU *cpu);#else hw/s390x/cpu-topology.c +2
-0@@ -97,6 +97,98 @@ static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) }/** +* s390_topology_set_polarity +* @polarity: horizontal or vertical
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 111
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+* +* Changes the polarity of all the CPU in the configuration. +* +* If the dedicated CPU modifier attribute is set a vertical +* polarization is always high (Architecture). +* Otherwise we decide to set it as medium. +* +* Once done, advertise a topology change. +*/ +void s390_topology_set_polarity (int polarity)
I don't like that this function ignores what kind of vertical polarization is passed, it's confusing.
That seems like a further reason to split horizontal/vertical from the entitlement.
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 113
Quoted 2 lines
hw/s390x/cpu-topology.c +2
-0+{ +S390TopologyEntry *entry;
I also expected this function to set s390_topology.polarization, but it doesn't.
Quoted 15 lines
hw/s390x/cpu-topology.c +15
-0+ + QTAILQ_FOREACH(entry, &s390_topology.list, next) { +if (polarity ==S390_TOPOLOGY_POLARITY_HORIZONTAL ) { + entry->id.p = polarity; + }else { +if (entry->id.d) { + entry->id.p =S390_TOPOLOGY_POLARITY_VERTICAL_HIGH ; + }else { + entry->id.p =S390_TOPOLOGY_POLARITY_VERTICAL_MEDIUM ; + } + } + } +s390_cpu_topology_set (); +} +
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 138
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+/* +* s390_handle_ptf: +* +* @register 1: contains the function code +* +* Function codes 0 and 1 handle the CPU polarization. +* We assume an horizontal topology, the only one supported currently +* by Linux, consequently we answer to function code 0, requesting +* horizontal polarization that it is already the current polarization +* and reject vertical polarization request without further explanation.
This comment is outdated, right? Same for those in the function body.
Quoted 32 lines
hw/s390x/cpu-topology.c +32
-0+* +* Function code 2 is handling topology changes and is interpreted +* by the SIE. +*/ +void s390_handle_ptf (S390CPU *cpu,uint8_t r1,uintptr_t ra) +{ +CPUS390XState *env = &cpu->env; +uint64_t reg = env->regs[r1]; +uint8_t fc = reg &S390_TOPO_FC_MASK ; + +if (!s390_has_feat (S390_FEAT_CONFIGURATION_TOPOLOGY )) { +s390_program_interrupt (env,PGM_OPERATION , ra); +return ; + } + +if (env->psw.mask &PSW_MASK_PSTATE ) { +s390_program_interrupt (env,PGM_PRIVILEGED , ra); +return ; + } + +if (reg & ~S390_TOPO_FC_MASK ) { +s390_program_interrupt (env,PGM_SPECIFICATION , ra); +return ; + } + +switch (fc) { +case 0 :/* Horizontal polarization is already set */ +if (s390_topology.polarity ==S390_TOPOLOGY_POLARITY_HORIZONTAL ) { + env->regs[r1] |=S390_PTF_REASON_DONE ; +setcc (cpu,2 ); + }else { +s390_topology_set_polarity (S390_TOPOLOGY_POLARITY_HORIZONTAL );
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 180
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+ s390_topology.polarity =S390_TOPOLOGY_POLARITY_HORIZONTAL ; +setcc (cpu,0 ); + } +break ; +case 1 :/* Vertical polarization is not supported */ +if (s390_topology.polarity !=S390_TOPOLOGY_POLARITY_HORIZONTAL ) { + env->regs[r1] |=S390_PTF_REASON_DONE ; +setcc (cpu,2 ); + }else { +s390_topology_set_polarity (S390_TOPOLOGY_POLARITY_VERTICAL_LOW );
This is why I said it's confusing, nothing gets set to LOW.
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 181
Quoted 1 line
hw/s390x/cpu-topology.c +1
-0+ s390_topology.polarity =S390_TOPOLOGY_POLARITY_VERTICAL_LOW ;
Why LOW here?
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 188
Quoted 7 lines
hw/s390x/cpu-topology.c +7
-0+setcc (cpu,0 ); + } +break ; +default : +/* Note that fc == 2 is interpreted by the SIE */ +s390_program_interrupt (env,PGM_SPECIFICATION , ra); + }
You can simplify this by doing:
int new_polarity;
switch (fc) {
case 0:
new_polarity = S390_TOPOLOGY_POLARITY_HORIZONTAL; break; case 1: new_polarity = S390_TOPOLOGY_POLARITY_VERTICAL_?; break; default: /* Note that fc == 2 is interpreted by the SIE */ s390_program_interrupt(env, PGM_SPECIFICATION, ra); return; }
if same polarity:
rc done, rejected
else
set polarity, initiated
Might be a good idea to turn the polarity values into an enum.
Quoted 1 line
hw/s390x/cpu-topology.c +1
-0+}
[...]
Re: [PATCH v14 06/11] s390x/cpu topology: interception of PTF instruction
Quoted 69 lines · Nina Schoetterl-Glausch
Quoted 68 lines · Pierre Morel
When the host supports the CPU topology facility, the PTF instruction with function code 2 is interpreted by the SIE, provided that the userland hypervizor activates the interpretation by using the
KVM_CAP_S390_CPU_TOPOLOGYKVM extension.The PTF instructions with function code 0 and 1 are intercepted and must be emulated by the userland hypervizor.
During RESET all CPU of the configuration are placed in horizontal polarity.
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 3 + include/hw/s390x/s390-virtio-ccw.h | 6 ++ target/s390x/cpu.h | 1 + hw/s390x/cpu-topology.c | 92 ++++++++++++++++++++++++++++++ target/s390x/cpu-sysemu.c | 16 ++++++ target/s390x/kvm/kvm.c | 11 ++++ 6 files changed, 129 insertions(+)include/hw/s390x/cpu-topology.h +3
-0@@ -55,11 +55,13 @@ typedef struct S390Topology { QTAILQ_HEAD(, S390TopologyEntry) list;uint8_t *sockets;CpuTopology *smp; +int polarity; } S390Topology;#ifdef CONFIG_KVM bool s390_has_topology (void );void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +void s390_topology_set_polarity (int polarity);#else static inline bool s390_has_topology (void ) {@@ -68,6 +70,7 @@ static inline bool s390_has_topology(void)static inline void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp) {} +static inline void s390_topology_set_polarity (int polarity) {}#endif extern S390Topology s390_topology;include/hw/s390x/s390-virtio-ccw.h +6
-0@@ -30,6 +30,12 @@ struct S390CcwMachineState {uint8_t loadparm[8 ]; }; +#define S390_PTF_REASON_NONE (0x00 << 8) +#define S390_PTF_REASON_DONE (0x01 << 8) +#define S390_PTF_REASON_BUSY (0x02 << 8) +#define S390_TOPO_FC_MASK 0xffUL +void s390_handle_ptf (S390CPU *cpu,uint8_t r1,uintptr_t ra); +struct S390CcwMachineClass {/*< private >*/ MachineClass parent_class;target/s390x/cpu.h +0
-0
Quoted 8 lines
target/s390x/cpu.h void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg); · line 867
Quoted 5 lines
target/s390x/cpu.h +1
-0@@ -864,6 +864,7 @@ void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg);int s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch_id,int vq,bool assign);void s390_cpu_topology_reset (void ); +void s390_cpu_topology_set (void );I don't like this name much, it's nondescript.
s390_cpu_topology_set_modified?
yes, better.
Quoted 20 lines
Quoted 20 lines
target/s390x/cpu.h +0
-0#ifndef CONFIG_USER_ONLY unsigned int s390_cpu_set_state (uint8_t cpu_state,S390CPU *cpu);#else hw/s390x/cpu-topology.c +8
-0@@ -97,6 +97,98 @@ static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) }/** +* s390_topology_set_polarity +* @polarity: horizontal or vertical +* +* Changes the polarity of all the CPU in the configuration. +* +* If the dedicated CPU modifier attribute is set a vertical +* polarization is always high (Architecture). +* Otherwise we decide to set it as medium.
Quoted 8 lines
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 111
Quoted 4 lines
hw/s390x/cpu-topology.c +4
-0+* +* Once done, advertise a topology change. +*/ +void s390_topology_set_polarity (int polarity)I don't like that this function ignores what kind of vertical polarization is passed, it's confusing.
That seems like a further reason to split horizontal/vertical from the entitlement.
OK, you are right.
I remove this function and put the s390_cpu_topology_set() inside the handle_ptf()
Quoted 78 lines
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 113
Quoted 3 lines
hw/s390x/cpu-topology.c +2
-0+{ +S390TopologyEntry *entry;I also expected this function to set s390_topology.polarization, but it doesn't.
Quoted 15 lines
hw/s390x/cpu-topology.c +15
-0+ + QTAILQ_FOREACH(entry, &s390_topology.list, next) { +if (polarity ==S390_TOPOLOGY_POLARITY_HORIZONTAL ) { + entry->id.p = polarity; + }else { +if (entry->id.d) { + entry->id.p =S390_TOPOLOGY_POLARITY_VERTICAL_HIGH ; + }else { + entry->id.p =S390_TOPOLOGY_POLARITY_VERTICAL_MEDIUM ; + } + } + } +s390_cpu_topology_set (); +} +hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 138
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+/* +* s390_handle_ptf: +* +* @register 1: contains the function code +* +* Function codes 0 and 1 handle the CPU polarization. +* We assume an horizontal topology, the only one supported currently +* by Linux, consequently we answer to function code 0, requesting +* horizontal polarization that it is already the current polarization +* and reject vertical polarization request without further explanation. This comment is outdated, right? Same for those in the function body.
Quoted 32 lines
hw/s390x/cpu-topology.c +32
-0+* +* Function code 2 is handling topology changes and is interpreted +* by the SIE. +*/ +void s390_handle_ptf (S390CPU *cpu,uint8_t r1,uintptr_t ra) +{ +CPUS390XState *env = &cpu->env; +uint64_t reg = env->regs[r1]; +uint8_t fc = reg &S390_TOPO_FC_MASK ; + +if (!s390_has_feat (S390_FEAT_CONFIGURATION_TOPOLOGY )) { +s390_program_interrupt (env,PGM_OPERATION , ra); +return ; + } + +if (env->psw.mask &PSW_MASK_PSTATE ) { +s390_program_interrupt (env,PGM_PRIVILEGED , ra); +return ; + } + +if (reg & ~S390_TOPO_FC_MASK ) { +s390_program_interrupt (env,PGM_SPECIFICATION , ra); +return ; + } + +switch (fc) { +case 0 :/* Horizontal polarization is already set */ +if (s390_topology.polarity ==S390_TOPOLOGY_POLARITY_HORIZONTAL ) { + env->regs[r1] |=S390_PTF_REASON_DONE ; +setcc (cpu,2 ); + }else { +s390_topology_set_polarity (S390_TOPOLOGY_POLARITY_HORIZONTAL );hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 180
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+ s390_topology.polarity =S390_TOPOLOGY_POLARITY_HORIZONTAL ; +setcc (cpu,0 ); + } +break ; +case 1 :/* Vertical polarization is not supported */ +if (s390_topology.polarity !=S390_TOPOLOGY_POLARITY_HORIZONTAL ) { + env->regs[r1] |=S390_PTF_REASON_DONE ; +setcc (cpu,2 ); + }else { +s390_topology_set_polarity (S390_TOPOLOGY_POLARITY_VERTICAL_LOW );This is why I said it's confusing, nothing gets set to LOW.
Quoted 3 lines
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 181
Quoted 1 line
hw/s390x/cpu-topology.c +1
-0+ s390_topology.polarity =S390_TOPOLOGY_POLARITY_VERTICAL_LOW ;Why LOW here?
I wanted something not being S390_TOPOLOGY_POLARITY_HORIZONTAL and did not want to define a S390_TOPOLOGY_POLARITY_VERTICAL.
OK I define S390_TOPOLOGY_POLARITY_HORIZONTAL=0 and ..._VERTICAL=1
Quoted 30 lines
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 188
Quoted 8 lines
hw/s390x/cpu-topology.c +7
-0+setcc (cpu,0 ); + } +break ; +default : +/* Note that fc == 2 is interpreted by the SIE */ +s390_program_interrupt (env,PGM_SPECIFICATION , ra); + }You can simplify this by doing:
int
new_polarity;
switch (fc) {
case 0:new_polarity = S390_TOPOLOGY_POLARITY_HORIZONTAL; break; case 1: new_polarity = S390_TOPOLOGY_POLARITY_VERTICAL_?; break; default: /* Note that fc == 2 is interpreted by the SIE */ s390_program_interrupt(env, PGM_SPECIFICATION, ra); return; }if same polarity:
rc done, rejected
else
set polarity, initiated
Quoted 5 lines
Might be a good idea to turn the polarity values into an enum.
Quoted 1 line
hw/s390x/cpu-topology.c +1
-0+}[...]
Even I never really understood the added value of an enum I can do this.
Thanks,
regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 06/11] s390x/cpu topology: interception of PTF instruction
In reply to Nina Schoetterl-GlauschQuoted 97 lines · Nina Schoetterl-Glausch
Quoted 69 lines · Pierre Morel
When the host supports the CPU topology facility, the PTF instruction with function code 2 is interpreted by the SIE, provided that the userland hypervizor activates the interpretation by using the
KVM_CAP_S390_CPU_TOPOLOGYKVM extension.The PTF instructions with function code 0 and 1 are intercepted and must be emulated by the userland hypervizor.
During RESET all CPU of the configuration are placed in horizontal polarity.
Signed-off-by Pierre Morel <[email protected]>--- include/hw/s390x/cpu-topology.h | 3 + include/hw/s390x/s390-virtio-ccw.h | 6 ++ target/s390x/cpu.h | 1 + hw/s390x/cpu-topology.c | 92 ++++++++++++++++++++++++++++++ target/s390x/cpu-sysemu.c | 16 ++++++ target/s390x/kvm/kvm.c | 11 ++++ 6 files changed, 129 insertions(+)include/hw/s390x/cpu-topology.h +3
-0@@ -55,11 +55,13 @@ typedef struct S390Topology { QTAILQ_HEAD(, S390TopologyEntry) list;uint8_t *sockets;CpuTopology *smp; +int polarity; } S390Topology;#ifdef CONFIG_KVM bool s390_has_topology (void );void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp); +void s390_topology_set_polarity (int polarity);#else static inline bool s390_has_topology (void ) {@@ -68,6 +70,7 @@ static inline bool s390_has_topology(void)static inline void s390_topology_set_cpu (MachineState *ms,S390CPU *cpu,Error **errp) {} +static inline void s390_topology_set_polarity (int polarity) {}#endif extern S390Topology s390_topology;include/hw/s390x/s390-virtio-ccw.h +6
-0@@ -30,6 +30,12 @@ struct S390CcwMachineState {uint8_t loadparm[8 ]; }; +#define S390_PTF_REASON_NONE (0x00 << 8) +#define S390_PTF_REASON_DONE (0x01 << 8) +#define S390_PTF_REASON_BUSY (0x02 << 8) +#define S390_TOPO_FC_MASK 0xffUL +void s390_handle_ptf (S390CPU *cpu,uint8_t r1,uintptr_t ra); +struct S390CcwMachineClass {/*< private >*/ MachineClass parent_class;target/s390x/cpu.h +0
-0target/s390x/cpu.h void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg); · line 867
Quoted 4 lines
target/s390x/cpu.h +1
-0@@ -864,6 +864,7 @@ void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg);int s390_assign_subch_ioeventfd (EventNotifier *notifier,uint32_t sch_id,int vq,bool assign);void s390_cpu_topology_reset (void ); +void s390_cpu_topology_set (void );I don't like this name much, it's nondescript.
s390_cpu_topology_set_modified?Quoted 19 lines
target/s390x/cpu.h +0
-0#ifndef CONFIG_USER_ONLY unsigned int s390_cpu_set_state (uint8_t cpu_state,S390CPU *cpu);#else hw/s390x/cpu-topology.c +8
-0@@ -97,6 +97,98 @@ static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) }/** +* s390_topology_set_polarity +* @polarity: horizontal or vertical +* +* Changes the polarity of all the CPU in the configuration. +* +* If the dedicated CPU modifier attribute is set a vertical +* polarization is always high (Architecture). +* Otherwise we decide to set it as medium.
Quoted 9 lines
hw/s390x/cpu-topology.c static s390_topology_id s390_topology_from_cpu(S390CPU *cpu) · line 111
Quoted 4 lines
hw/s390x/cpu-topology.c +4
-0+* +* Once done, advertise a topology change. +*/ +void s390_topology_set_polarity (int polarity)I don't like that this function ignores what kind of vertical polarization is passed, it's confusing.
That seems like a further reason to split horizontal/vertical from the entitlement.
Yes.
I will also make the ordering of the TLE at the last moment instead of doing it during hotplug or QAPI command.
This is something Cedric proposed some time ago and I think it is right, it will be easier to do it once in STSI than on every change of topology, hotplug, QAPI and polarization change with PTF.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 7/11 target/s390x/cpu topology: activating CPU topology
In reply to Pierre MorelThe KVM capability, KVM_CAP_S390_CPU_TOPOLOGY is used to activate the S390_FEAT_CONFIGURATION_TOPOLOGY feature and the topology facility for the guest in the case the topology is available in QEMU and in KVM.
The feature is disabled by default and fenced for SE (secure execution).
--- hw/s390x/cpu-topology.c | 2 +- target/s390x/cpu_models.c | 1 + target/s390x/kvm/kvm.c | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-)
hw/s390x/cpu-topology.c +1 -1
@@ -52,7 +52,7 @@ static int s390_socket_nb(s390_topology_id id)*/ bool s390_has_topology (void ) { -return false; +return s390_has_feat (S390_FEAT_CONFIGURATION_TOPOLOGY ); }/**
target/s390x/cpu_models.c +1 -0
@@ -253,6 +253,7 @@ bool s390_has_feat(S390Feat feat)case S390_FEAT_SIE_CMMA :case S390_FEAT_SIE_PFMFI :case S390_FEAT_SIE_IBS : +case S390_FEAT_CONFIGURATION_TOPOLOGY :return false;break ;default :
target/s390x/kvm/kvm.c +13 -0
@@ -2470,6 +2470,19 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)set_bit (S390_FEAT_UNPACK , model->features); } +/* +* If we have support for CPU Topology prevent overrule +* S390_FEAT_CONFIGURATION_TOPOLOGY with S390_FEAT_DISABLE_CPU_TOPOLOGY +* implemented in KVM, activate the CPU TOPOLOGY feature. +*/ +if (kvm_check_extension (kvm_state,KVM_CAP_S390_CPU_TOPOLOGY )) { +if (kvm_vm_enable_cap (kvm_state,KVM_CAP_S390_CPU_TOPOLOGY ,0 ) <0 ) { +error_setg (errp,"KVM: Error enabling KVM_CAP_S390_CPU_TOPOLOGY" ); +return ; + } +set_bit (S390_FEAT_CONFIGURATION_TOPOLOGY , model->features); + } +/* We emulate a zPCI bus and AEN, therefore we don't need HW support */ set_bit (S390_FEAT_ZPCI , model->features);set_bit (S390_FEAT_ADAPTER_EVENT_NOTIFICATION , model->features);
Signature · 1 line
2.31.1
Re: [PATCH v14 07/11] target/s390x/cpu topology: activating CPU topology
Quoted 1 line · Pierre Morel
The KVM capability,
KVM_CAP_S390_CPU_TOPOLOGYis used to
Remove the "," in above line?
Quoted 2 lines
activate the
S390_FEAT_CONFIGURATION_TOPOLOGYfeature and the topology facility for the guest in the case the topology
I'd like to suggest to add "in the host CPU model" after "facility".
Quoted 42 lines
is available in QEMU and in KVM.
The feature is disabled by default and fenced for SE (secure execution).
Signed-off-by Pierre Morel <[email protected]>--- hw/s390x/cpu-topology.c | 2 +- target/s390x/cpu_models.c | 1 + target/s390x/kvm/kvm.c | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-)hw/s390x/cpu-topology.c +1
-1@@ -52,7 +52,7 @@ static int s390_socket_nb(s390_topology_id id)*/ bool s390_has_topology (void ) { -return false; +return s390_has_feat (S390_FEAT_CONFIGURATION_TOPOLOGY ); }/** target/s390x/cpu_models.c +1
-0@@ -253,6 +253,7 @@ bool s390_has_feat(S390Feat feat)case S390_FEAT_SIE_CMMA :case S390_FEAT_SIE_PFMFI :case S390_FEAT_SIE_IBS : +case S390_FEAT_CONFIGURATION_TOPOLOGY :return false;break ;default :target/s390x/kvm/kvm.c +0
-0
target/s390x/kvm/kvm.c void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp) · line 2475
Quoted 6 lines
target/s390x/kvm/kvm.c +3
-0@@ -2470,6 +2470,19 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)set_bit (S390_FEAT_UNPACK , model->features); } +/* +* If we have support for CPU Topology prevent overrule +* S390_FEAT_CONFIGURATION_TOPOLOGY with S390_FEAT_DISABLE_CPU_TOPOLOGY
That S390_FEAT_DISABLE_CPU_TOPOLOGY looks like a leftover from v12 ?
Apart from that, patch looks fine to me now.
Thomas
Quoted 13 lines
target/s390x/kvm/kvm.c +10
-0+* implemented in KVM, activate the CPU TOPOLOGY feature. +*/ +if (kvm_check_extension (kvm_state,KVM_CAP_S390_CPU_TOPOLOGY )) { +if (kvm_vm_enable_cap (kvm_state,KVM_CAP_S390_CPU_TOPOLOGY ,0 ) <0 ) { +error_setg (errp,"KVM: Error enabling KVM_CAP_S390_CPU_TOPOLOGY" ); +return ; + } +set_bit (S390_FEAT_CONFIGURATION_TOPOLOGY , model->features); + } +/* We emulate a zPCI bus and AEN, therefore we don't need HW support */ set_bit (S390_FEAT_ZPCI , model->features);set_bit (S390_FEAT_ADAPTER_EVENT_NOTIFICATION , model->features);
Re: [PATCH v14 07/11] target/s390x/cpu topology: activating CPU topology
Quoted 4 lines · Thomas Huth
Quoted 1 line · Pierre Morel
The KVM capability,
KVM_CAP_S390_CPU_TOPOLOGYis used toRemove the "," in above line?
OK
Quoted 5 lines
Quoted 3 lines
activate the
S390_FEAT_CONFIGURATION_TOPOLOGYfeature and the topology facility for the guest in the case the topologyI'd like to suggest to add "in the host CPU model" after "facility".
Yes, thanks.
Quoted 43 lines
Quoted 43 lines
is available in QEMU and in KVM.
The feature is disabled by default and fenced for SE (secure execution).
Signed-off-by Pierre Morel <[email protected]>---
hw/s390x/cpu-topology.c | 2 +-
target/s390x/cpu_models.c| 1 +
target/s390x/kvm/kvm.c | 13 +++++++++++++3 files changed, 15 insertions(+), 1 deletion(-)hw/s390x/cpu-topology.c +1
-1@@ -52,7 +52,7 @@ static int s390_socket_nb(s390_topology_id id)*/ bool s390_has_topology(void) { - return false; + return s390_has_feat(S390_FEAT_CONFIGURATION_TOPOLOGY); } /**target/s390x/cpu_models.c +0
-0@@ -253,6 +253,7 @@ bool s390_has_feat(S390Feat feat)case
S390_FEAT_SIE_CMMA:
caseS390_FEAT_SIE_PFMFI:
caseS390_FEAT_SIE_IBS:
+ caseS390_FEAT_CONFIGURATION_TOPOLOGY:
return false;
break;
default:target/s390x/kvm/kvm.c +0
-0@@ -2470,6 +2470,19 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
Quoted 8 lines
Quoted 6 lines
target/s390x/kvm/kvm.c +3
-0set_bit(S390_FEAT_UNPACK, model->features); } + /* +* If we have support for CPU Topology prevent overrule +* S390_FEAT_CONFIGURATION_TOPOLOGY with
S390_FEAT_DISABLE_CPU_TOPOLOGYThat
S390_FEAT_DISABLE_CPU_TOPOLOGYlooks like a leftover from v12 ?
Right, sorry, I remove it and change the comment for:
/*
* If we have kernel support for CPU Topology indicate the
* configuration-topology facility.
*/
Quoted 22 lines
Apart from that, patch looks fine to me now.
Thomas
Quoted 15 lines
+ * implemented in KVM, activate the CPU TOPOLOGY feature.
+ */
+ if (kvm_check_extension(kvm_state, KVM_CAP_S390_CPU_TOPOLOGY)) { + if (kvm_vm_enable_cap(kvm_state,KVM_CAP_S390_CPU_TOPOLOGY,
0) < 0) {
+error_setg(errp, "KVM: Error enabling KVM_CAP_S390_CPU_TOPOLOGY");
+ return;
+ }
+set_bit(S390_FEAT_CONFIGURATION_TOPOLOGY, model->features); + }
+
/* We emulate a zPCI bus and AEN, therefore we don't need HW support */set_bit(S390_FEAT_ZPCI, model->features);set_bit(S390_FEAT_ADAPTER_EVENT_NOTIFICATION, model->features);
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 8/11 qapi/s390/cpu topology: change-topology monitor command
In reply to Pierre MorelThe modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
--- qapi/machine-target.json | 29 ++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 141 +++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 16 +++++ 4 files changed, 187 insertions(+)
qapi/machine-target.json +29 -0
@@ -342,3 +342,32 @@ 'TARGET_S390X', 'TARGET_MIPS', 'TARGET_LOONGARCH64' ] } } + +## +# @change-topology: +# +# @core: the vCPU ID to be moved +# @socket: the destination socket where to move the vCPU +# @book: the destination book where to move the vCPU +# @drawer: the destination drawer where to move the vCPU +# @polarity: optional polarity, default is last polarity set by the guest +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# Modifies the topology by moving the CPU inside the topology +# tree or by changing a modifier attribute of a CPU. +# +# Returns: Nothing on success, the reason on failure. +# +# Since: <next qemu stable release, eg. 1.0> +## +{ 'command': 'change-topology', + 'data': { + 'core': 'int', + 'socket': 'int', + 'book': 'int', + 'drawer': 'int', + '*polarity': 'int', + '*dedicated': 'bool' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}
include/monitor/hmp.h +1 -0
@@ -144,5 +144,6 @@ void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Error **));void hmp_info_stats (Monitor *mon,const QDict *qdict);void hmp_pcie_aer_inject_error (Monitor *mon,const QDict *qdict); +void hmp_change_topology (Monitor *mon,const QDict *qdict);#endif
hw/s390x/cpu-topology.c +141 -0
156 lines not on this page · raw message
hmp-commands.hx +16 -0
@@ -1815,3 +1815,19 @@ SRST Dump the FDT in dtb format to *filename*. ERST #endif + +#if defined(TARGET_S390X) && defined(CONFIG_KVM) + { + .name = "change-topology", + .args_type = "core:l,socket:l,book:l,drawer:l,polarity:l?,dedicated:b?", + .params = "core socket book drawer [polarity] [dedicated]", + .help = "Move CPU 'core' to 'socket/book/drawer' " + "optionaly modifies polarity and dedication", + .cmd = hmp_change_topology, + }, + +SRST +``change-topology`` *core* *socket* *book* *drawer* *polarity* *dedicated* + Moves the CPU *core* to *socket* *book* *drawer* with *polarity* *dedicated*. +ERST +#endif
Signature · 1 line
2.31.1
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
Quoted 2 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
s/commands/command/
Quoted 2 lines
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously
s/hypervizor/hypervisor/
Quoted 3 lines
moved the CPU.
The same command allows to modifiy the CPU attributes modifiers
s/modifiy/modify/
Quoted 5 lines
like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Hmm, who is supposed to call this QMP command in the future? Will there be a new daemon monitoring the CPU changes in the host? Or will there be a libvirt addition for this? ... Seems like I still miss the big picture here...
Thomas
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
Quoted 17 lines · Thomas Huth
Quoted 2 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
s/commands/command/
Quoted 2 lines
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously
s/hypervizor/hypervisor/
Quoted 3 lines
moved the CPU.
The same command allows to modifiy the CPU attributes modifiers
s/modifiy/modify/
Quoted 7 lines
Quoted 5 lines
like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Hmm, who is supposed to call this QMP command in the future? Will there be a new daemon monitoring the CPU changes in the host? Or will there be a libvirt addition for this? ... Seems like I still miss the big picture here...
Or if this is just about to provide an API for future experiments, I'd rather suggest to introduce the new commands with a "x-" prefix to mark them as experimental (so we would also not need to go through the deprecation process in case they don't work out as expected in the future).
Thomas
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
In reply to Thomas HuthQuoted 5 lines · Thomas Huth
Quoted 2 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
s/commands/command/
thx
Quoted 5 lines
Quoted 3 lines
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously
s/hypervizor/hypervisor/
yes, thx
Quoted 6 lines
Quoted 4 lines
moved the CPU.
The same command allows to modifiy the CPU attributes modifiers
s/modifiy/modify/
thx
Quoted 11 lines
Quoted 6 lines
like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Hmm, who is supposed to call this QMP command in the future? Will there be a new daemon monitoring the CPU changes in the host? Or will there be a libvirt addition for this? ... Seems like I still miss the big picture here...
Thomas
The first idea is to provide a daemon that could get the information on real CPU from the host sysfs and to specify the vCPU topology according to the real CPU.
There could be a libvirt command for this too.
The big picture is to provide the guest OS with the real topology so that the guest OS can make decisions on the scheduling.
I think that a daemon is perfect I can not imagine anything else than the alternative:
1) Do not specify anything and let things go more or less random as today by setting the cores in socket,book,drawer in an incremental way.
2) specifying the exact topology
So I do not see the point to let the user or even libvirt specify a random topology if it is specified it must be exact.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
In reply to Pierre MorelQuoted 28 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 29 ++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 141 +++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 16 +++++ 4 files changed, 187 insertions(+)qapi/machine-target.json +0
-0@@ -342,3 +342,32 @@ 'TARGET_S390X',
qapi/machine-target.json line 352
Quoted 10 lines
qapi/machine-target.json +8
-0'TARGET_MIPS', 'TARGET_LOONGARCH64' ] } } + +## +# @change-topology: +# +# @core: the vCPU ID to be moved +# @socket: the destination socket where to move the vCPU +# @book: the destination book where to move the vCPU +# @drawer: the destination drawer where to move the vCPU
This movement can be done while the guest OS is running ? What happens to guest OS apps ? Every I know will read topology once and assume it never changes at runtime.
What's the use case for wanting to re-arrange topology in this manner ? It feels like its going to be a recipe for hard to diagnose problems, as much code in libvirt and apps above will assuming the vCPU IDs are assigned sequentially starting from node=0,book=0,drawer=0,socket=0,core=0, incrementing core, then incrementing socket, then incrementing drawer, etc.
qapi/machine-target.json line 363
Quoted 11 lines
qapi/machine-target.json +11
-0+# @polarity: optional polarity, default is last polarity set by the guest +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# Modifies the topology by moving the CPU inside the topology +# tree or by changing a modifier attribute of a CPU. +# +# Returns: Nothing on success, the reason on failure. +# +# Since: <next qemu stable release, eg. 1.0> +## +{ 'command': 'change-topology',
'set-cpu-topology'
qapi/machine-target.json line 373
Quoted 10 lines
qapi/machine-target.json +10
-0+ 'data': { + 'core': 'int', + 'socket': 'int', + 'book': 'int', + 'drawer': 'int', + '*polarity': 'int', + '*dedicated': 'bool' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
Quoted 35 lines · Daniel P. Berrangé
Quoted 34 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 29 ++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 141 +++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 16 +++++ 4 files changed, 187 insertions(+)qapi/machine-target.json +4
-0@@ -342,3 +342,32 @@ 'TARGET_S390X', 'TARGET_MIPS', 'TARGET_LOONGARCH64' ] } } + +## +# @change-topology: +#
Quoted 8 lines
qapi/machine-target.json line 352
Quoted 4 lines
qapi/machine-target.json +4
-0+# @core: the vCPU ID to be moved +# @socket: the destination socket where to move the vCPU +# @book: the destination book where to move the vCPU +# @drawer: the destination drawer where to move the vCPUThis movement can be done while the guest OS is running ? What happens to guest OS apps ? Every I know will read topology once and assume it never changes at runtime.
Yes this can change while the guest is running.
The S390 Logical PARtition, where the Linux runs is already a first level of virtualization and the lpar CPU are already virtual CPU which can be moved from one real CPU to another, the guest is at a second level of virtualization.
On the LPAR host an admin can check the topology.
A lpar CPU can be moved to another real CPU because of multiple reasons: maintenance, failure, other decision from the first level hypervisor that I do not know, may be scheduling balancing.
There is a mechanism for the OS in which is running in LPAR to set a flag for the guest on a topology change. The guest use a specific instruction to get this flag.
This instruction PTF(2) is interpreted by the firmware and does not appear in this patch series but in Linux patch series.
So we have, real CPU <-> lpar CPU <-> vCPU
Quoted 8 lines
What's the use case for wanting to re-arrange topology in this manner ? It feels like its going to be a recipe for hard to diagnose problems, as much code in libvirt and apps above will assuming the vCPU IDs are assigned sequentially starting from node=0,book=0,drawer=0,socket=0,core=0, incrementing core, then incrementing socket, then incrementing drawer, etc.
The goal to rearrange the vCPU is to give the guest the knowledge of the topology so it can takes benefit of it.
If a lpar CPU moved to another real CPU in another drawer we must move the guest vCPU to another drawer so the guest OS can take the best scheduling decisions.
Per default, if nothing is specified on the creation of a vCPU, the creation is done exactly like you said, starting from (0,0,0,0) and incrementing.
There are two possibility to set a vCPU at its place:
1) on creation by specifying the drawer,book,socket for a specific core-id
2) with this QAPI command to move the CPU while it is running.
Note that the core-id and the CPU address do not change when moving the CPU so that there is no problem with scheduling, all we do is to provide the topology up to the guest when it asks.
The period of checking by the Linux kernel if there is a change and if there is a need to ask the topology is one minute.
The migration of CPU is not supposed to happen very often, (not every day).
Quoted 14 lines
qapi/machine-target.json line 363
Quoted 12 lines
qapi/machine-target.json +11
-0+# @polarity: optional polarity, default is last polarity set by the guest +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# Modifies the topology by moving the CPU inside the topology +# tree or by changing a modifier attribute of a CPU. +# +# Returns: Nothing on success, the reason on failure. +# +# Since: <next qemu stable release, eg. 1.0> +## +{ 'command': 'change-topology','set-cpu-topology'
OK, yes looks better.
Quoted 13 lines
qapi/machine-target.json line 373
Quoted 11 lines
qapi/machine-target.json +10
-0+ 'data': { + 'core': 'int', + 'socket': 'int', + 'book': 'int', + 'drawer': 'int', + '*polarity': 'int', + '*dedicated': 'bool' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}
Quoted 2 lines
With regards,
Daniel
Thanks,
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
In reply to Pierre MorelQuoted 91 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 29 ++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 141 +++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 16 +++++ 4 files changed, 187 insertions(+)qapi/machine-target.json +29
-0@@ -342,3 +342,32 @@ 'TARGET_S390X', 'TARGET_MIPS', 'TARGET_LOONGARCH64' ] } } + +## +# @change-topology: +# +# @core: the vCPU ID to be moved +# @socket: the destination socket where to move the vCPU +# @book: the destination book where to move the vCPU +# @drawer: the destination drawer where to move the vCPU +# @polarity: optional polarity, default is last polarity set by the guest +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# Modifies the topology by moving the CPU inside the topology +# tree or by changing a modifier attribute of a CPU. +# +# Returns: Nothing on success, the reason on failure. +# +# Since: <next qemu stable release, eg. 1.0> +## +{ 'command': 'change-topology', + 'data': { + 'core': 'int', + 'socket': 'int', + 'book': 'int', + 'drawer': 'int', + '*polarity': 'int', + '*dedicated': 'bool' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}include/monitor/hmp.h +1
-0@@ -144,5 +144,6 @@ void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Error **));void hmp_info_stats (Monitor *mon,const QDict *qdict);void hmp_pcie_aer_inject_error (Monitor *mon,const QDict *qdict); +void hmp_change_topology (Monitor *mon,const QDict *qdict);#endif hw/s390x/cpu-topology.c +6
-0@@ -18,6 +18,10 @@#include "target/s390x/cpu.h" #include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/cpu-topology.h" +#include "qapi/qapi-commands-machine-target.h" +#include "qapi/qmp/qdict.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" /* * s390_topology is used to keep the topology information. @@ -203,6 +207,21 @@ static void s390_topology_set_entry(S390TopologyEntry *entry, s390_topology.sockets[s390_socket_nb (id)]++; } +/** +* s390_topology_clear_entry:
hw/s390x/cpu-topology.c static void s390_topology_set_entry(S390TopologyEntry *entry, · line 221
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+* @entry: Topology entry to setup +* @id: topology id to use for the setup +* +* Clear the core bit inside the topology mask and +* decrements the number of cores for the socket. +*/ +static void s390_topology_clear_entry (S390TopologyEntry *entry, +s390_topology_id id) +{ +clear_bit (63 - id.core, &entry->mask);
This doesn't take the origin into account.
hw/s390x/cpu-topology.c static void s390_topology_set_entry(S390TopologyEntry *entry, · line 222
Quoted 1 line
hw/s390x/cpu-topology.c +1
-0+ s390_topology.sockets[s390_socket_nb (id)]--;
I suppose this function cannot run concurrently, so the same CPU doesn't get removed twice.
Quoted 10 lines
hw/s390x/cpu-topology.c +3
-0+} +/** * s390_topology_new_entry: * @id: s390_topology_id to add @@ -383,3 +402,125 @@ void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp)s390_topology_insert (id); } +
hw/s390x/cpu-topology.c void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp) · line 415
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+/* +* qmp and hmp implementations +*/ + +static S390TopologyEntry *s390_topology_core_to_entry (int core) +{ +S390TopologyEntry *entry; + + QTAILQ_FOREACH(entry, &s390_topology.list, next) { +if (entry->mask & (1UL << (63 - core))) {
origin here also.
hw/s390x/cpu-topology.c void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp) · line 419
Quoted 4 lines
hw/s390x/cpu-topology.c +4
-0+return entry; + } + } +return NULL ;
This should not return NULL unless the core id is invalid. Might be better to validate that somewhere else.
hw/s390x/cpu-topology.c void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp) · line 429
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+} + +static void s390_change_topology (Error **errp,int64_t core,int64_t socket, +int64_t book,int64_t drawer, +int64_t polarity,bool dedicated) +{ +S390TopologyEntry *entry; +s390_topology_id new_id; +s390_topology_id old_id; +Error *local_error =NULL ;
I think you could use ERRP_GUARD here also.
Quoted 60 lines
hw/s390x/cpu-topology.c +60
-0+ +/* Get the old entry */ + entry =s390_topology_core_to_entry (core); +if (!entry) { +error_setg (errp,"No core %ld" , core); +return ; + } + +/* Compute old topology id */ + old_id = entry->id; + old_id.core = core; + +/* Compute new topology id */ + new_id = entry->id; + new_id.core = core; + new_id.socket = socket; + new_id.book = book; + new_id.drawer = drawer; + new_id.p = polarity; + new_id.d = dedicated; + new_id.type =S390_TOPOLOGY_CPU_IFL ; + +/* Same topology entry, nothing to do */ +if (entry->id.id == new_id.id) { +return ; + } + +/* Check for space on the socket if ids are different */ +if ((s390_socket_nb (old_id) !=s390_socket_nb (new_id)) && + (s390_topology.sockets[s390_socket_nb (new_id)] >= + s390_topology.smp->sockets)) { +error_setg (errp,"No more space on this socket" ); +return ; + } + +/* Verify the new topology */ +s390_topology_check (&local_error, new_id); +if (local_error) { +error_propagate (errp, local_error); +return ; + } + +/* Clear the old topology */ +s390_topology_clear_entry (entry, old_id); + +/* Insert the new topology */ +s390_topology_insert (new_id); + +/* Remove unused entry */ +if (!entry->mask) { +QTAILQ_REMOVE (&s390_topology.list, entry, next); +g_free (entry); + } + +/* Advertise the topology change */ +s390_cpu_topology_set (); +} + +void qmp_change_topology(int64_t core, int64_t socket, + int64_t book, int64_t drawer,
hw/s390x/cpu-topology.c void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp) · line 499
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+ bool has_polarity, int64_t polarity, + bool has_dedicated, bool dedicated, + Error **errp) +{ + Error *local_err = NULL; + +if (!s390_has_topology ()) { +error_setg (&local_err,"This machine doesn't support topology" ); +return ; + }
Do you really want to ignore has_polarity and has_dedicated here? What happens in this case?
Quoted 51 lines
hw/s390x/cpu-topology.c +27
-0+s390_change_topology (&local_err, core, socket, book, drawer, + polarity, dedicated); +if (local_err) { +error_propagate (errp, local_err); + } +} + +void hmp_change_topology (Monitor *mon,const QDict *qdict) +{ +const int64_t core =qdict_get_int (qdict,"core" ); +const int64_t socket =qdict_get_int (qdict,"socket" ); +const int64_t book =qdict_get_int (qdict,"book" ); +const int64_t drawer =qdict_get_int (qdict,"drawer" ); +bool has_polarity =qdict_haskey (qdict,"polarity" ); +const int64_t polarity =qdict_get_try_int (qdict,"polarity" ,0 ); +bool has_dedicated =qdict_haskey (qdict,"dedicated" ); +const bool dedicated =qdict_get_try_bool (qdict,"dedicated" , false); +Error *local_err =NULL ; + +qmp_change_topology (core, socket, book, drawer, + has_polarity, polarity, + has_dedicated, dedicated, + &local_err); +if (hmp_handle_error (mon, local_err)) { +return ; + } +}hmp-commands.hx +16
-0@@ -1815,3 +1815,19 @@ SRST Dump the FDT in dtb format to *filename*. ERST #endif + +#if defined(TARGET_S390X) && defined(CONFIG_KVM) + { + .name = "change-topology", + .args_type = "core:l,socket:l,book:l,drawer:l,polarity:l?,dedicated:b?", + .params = "core socket book drawer [polarity] [dedicated]", + .help = "Move CPU 'core' to 'socket/book/drawer' " + "optionaly modifies polarity and dedication", + .cmd = hmp_change_topology, + }, + +SRST +``change-topology`` *core* *socket* *book* *drawer* *polarity* *dedicated* + Moves the CPU *core* to *socket* *book* *drawer* with *polarity* *dedicated*. +ERST +#endif
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
Quoted 17 lines · Nina Schoetterl-Glausch
Quoted 16 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 34 lines
Quoted 21 lines
hw/s390x/cpu-topology.c +6
-0@@ -18,6 +18,10 @@#include "target/s390x/cpu.h" #include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/cpu-topology.h" +#include "qapi/qapi-commands-machine-target.h" +#include "qapi/qmp/qdict.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" /* * s390_topology is used to keep the topology information. @@ -203,6 +207,21 @@ static void s390_topology_set_entry(S390TopologyEntry *entry, s390_topology.sockets[s390_socket_nb (id)]++; } +/** +* s390_topology_clear_entry: hw/s390x/cpu-topology.c static void s390_topology_set_entry(S390TopologyEntry *entry, · line 221
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+* @entry: Topology entry to setup +* @id: topology id to use for the setup +* +* Clear the core bit inside the topology mask and +* decrements the number of cores for the socket. +*/ +static void s390_topology_clear_entry (S390TopologyEntry *entry, +s390_topology_id id) +{ +clear_bit (63 - id.core, &entry->mask);This doesn't take the origin into account.
Quoted 3 lines
hw/s390x/cpu-topology.c static void s390_topology_set_entry(S390TopologyEntry *entry, · line 222
Quoted 1 line
hw/s390x/cpu-topology.c +1
-0+ s390_topology.sockets[s390_socket_nb (id)]--;I suppose this function cannot run concurrently, so the same CPU doesn't get removed twice.
QEMU has the so-called BQL - the Big Qemu Lock. Instructions handlers are normally called with the lock taken, see qemu_mutex_lock_iothread() in target/s390x/kvm/kvm.c.
(if you feel unsure, you can add a "assert(qemu_mutex_iothread_locked())" statement, but I think it is not necessary here)
Thomas
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
Quoted 53 lines · Thomas Huth
Quoted 17 lines · Nina Schoetterl-Glausch
Quoted 16 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 34 lines
Quoted 21 lines
hw/s390x/cpu-topology.c +6
-0@@ -18,6 +18,10 @@#include "target/s390x/cpu.h" #include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/cpu-topology.h" +#include "qapi/qapi-commands-machine-target.h" +#include "qapi/qmp/qdict.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" /* * s390_topology is used to keep the topology information. @@ -203,6 +207,21 @@ static void s390_topology_set_entry(S390TopologyEntry *entry, s390_topology.sockets[s390_socket_nb (id)]++; } +/** +* s390_topology_clear_entry: hw/s390x/cpu-topology.c static void s390_topology_set_entry(S390TopologyEntry *entry, · line 221
Quoted 10 lines
hw/s390x/cpu-topology.c +10
-0+* @entry: Topology entry to setup +* @id: topology id to use for the setup +* +* Clear the core bit inside the topology mask and +* decrements the number of cores for the socket. +*/ +static void s390_topology_clear_entry (S390TopologyEntry *entry, +s390_topology_id id) +{ +clear_bit (63 - id.core, &entry->mask);This doesn't take the origin into account.
Quoted 7 lines
Quoted 3 lines
hw/s390x/cpu-topology.c static void s390_topology_set_entry(S390TopologyEntry *entry, · line 222
Quoted 1 line
hw/s390x/cpu-topology.c +1
-0+ s390_topology.sockets[s390_socket_nb (id)]--;I suppose this function cannot run concurrently, so the same CPU doesn't get removed twice.
QEMU has the so-called BQL - the Big Qemu Lock. Instructions handlers are normally called with the lock taken, see
qemu_mutex_lock_iothread()intarget/s390x/kvm/kvm.c.
That is good to know, but is that the relevant lock here?
We don't want to concurrent qmp commands. I looked at the code and it's pretty complicated.
Quoted 6 lines
(if you feel unsure, you can add a "assert(qemu_mutex_iothread_locked())" statement, but I think it is not necessary here)
Thomas
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
Quoted 19 lines · Nina Schoetterl-Glausch
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nina Schoetterl-Glausch
Quoted 16 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+ s390_topology.sockets[s390_socket_nb(id)]--;
I suppose this function cannot run concurrently, so the same CPU doesn't get removed twice.
QEMU has the so-called BQL - the Big Qemu Lock. Instructions handlers are normally called with the lock taken, see
qemu_mutex_lock_iothread()intarget/s390x/kvm/kvm.c.That is good to know, but is that the relevant lock here?
We don't want to concurrent qmp commands. I looked at the code and it's pretty complicated.
Not sure, but I believe that QMP commands are executed from the main iothread, so I think this should be safe? ... CC:-ing some more people who might know the correct answer.
Thomas
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
Quoted 29 lines · Thomas Huth
Quoted 19 lines · Nina Schoetterl-Glausch
Quoted 18 lines · Thomas Huth
Quoted 17 lines · Nina Schoetterl-Glausch
Quoted 16 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+ s390_topology.sockets[s390_socket_nb(id)]--;
I suppose this function cannot run concurrently, so the same CPU doesn't get removed twice.
QEMU has the so-called BQL - the Big Qemu Lock. Instructions handlers are normally called with the lock taken, see
qemu_mutex_lock_iothread()intarget/s390x/kvm/kvm.c.
Quoted 7 lines
Quoted 2 lines
That is good to know, but is that the relevant lock here?
We don't want to concurrent qmp commands. I looked at the code and it's pretty complicated.Not sure, but I believe that QMP commands are executed from the main iothread, so I think this should be safe? ... CC:-ing some more people who might know the correct answer.
Thomas
That is what I understand from the doc too.
See:docs/devel/qapi-code-gen.rst
One must specify allow-oob:true to avoid the BQL, default is false.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
In reply to Thomas HuthAm 18.01.2023 um 11:53 hat Thomas Huth geschrieben:
Quoted 29 lines · Nina Schoetterl-Glausch
Quoted 19 lines · Thomas Huth
Quoted 18 lines · Nina Schoetterl-Glausch
Quoted 17 lines · Pierre Morel
Quoted 16 lines
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+ s390_topology.sockets[s390_socket_nb(id)]--;
I suppose this function cannot run concurrently, so the same CPU doesn't get removed twice.
QEMU has the so-called BQL - the Big Qemu Lock. Instructions handlers are normally called with the lock taken, see
qemu_mutex_lock_iothread()intarget/s390x/kvm/kvm.c.
Quoted 6 lines
Quoted 2 lines
That is good to know, but is that the relevant lock here?
We don't want to concurrent qmp commands. I looked at the code and it's pretty complicated.Not sure, but I believe that QMP commands are executed from the main iothread, so I think this should be safe? ... CC:-ing some more people who might know the correct answer.
In general yes, QMP commands are processed one after another in the main thread while holding the BQL. And I think this is the relevant case for you.
The exception is out-of-band commands, which I think run in the monitor thread while some other (normal) command could be processed. OOB commands are quite limited in what they are allowed to do, though, and there aren't many of them. They are mainly meant to fix situations where something (including other QMP commands) got stuck.
Kevin
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
Quoted 41 lines · Kevin Wolf
Am 18.01.2023 um 11:53 hat Thomas Huth geschrieben:
Quoted 29 lines · Nina Schoetterl-Glausch
Quoted 19 lines · Thomas Huth
Quoted 18 lines · Nina Schoetterl-Glausch
Quoted 17 lines · Pierre Morel
Quoted 16 lines
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+ s390_topology.sockets[s390_socket_nb(id)]--;
I suppose this function cannot run concurrently, so the same CPU doesn't get removed twice.
QEMU has the so-called BQL - the Big Qemu Lock. Instructions handlers are normally called with the lock taken, see
qemu_mutex_lock_iothread()intarget/s390x/kvm/kvm.c.Quoted 6 lines
Quoted 2 lines
That is good to know, but is that the relevant lock here?
We don't want to concurrent qmp commands. I looked at the code and it's pretty complicated.Not sure, but I believe that QMP commands are executed from the main iothread, so I think this should be safe? ... CC:-ing some more people who might know the correct answer.
In general yes, QMP commands are processed one after another in the main thread while holding the BQL. And I think this is the relevant case for you.
Quoted 8 lines
The exception is out-of-band commands, which I think run in the monitor thread while some other (normal) command could be processed. OOB commands are quite limited in what they are allowed to do, though, and there aren't many of them. They are mainly meant to fix situations where something (including other QMP commands) got stuck.
Kevin
Thanks Kevin,
regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 08/11] qapi/s390/cpu topology: change-topology monitor command
In reply to Nina Schoetterl-GlauschQuoted 90 lines · Nina Schoetterl-Glausch
Quoted 89 lines · Pierre Morel
The modification of the CPU attributes are done through a monitor commands.
It allows to move the core inside the topology tree to optimise the cache usage in the case the host's hypervizor previously moved the CPU.
The same command allows to modifiy the CPU attributes modifiers like polarization entitlement and the dedicated attribute to notify the guest if the host admin modified scheduling or dedication of a vCPU.
With this knowledge the guest has the possibility to optimize the usage of the vCPUs.
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 29 ++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 141 +++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 16 +++++ 4 files changed, 187 insertions(+)qapi/machine-target.json +29
-0@@ -342,3 +342,32 @@ 'TARGET_S390X', 'TARGET_MIPS', 'TARGET_LOONGARCH64' ] } } + +## +# @change-topology: +# +# @core: the vCPU ID to be moved +# @socket: the destination socket where to move the vCPU +# @book: the destination book where to move the vCPU +# @drawer: the destination drawer where to move the vCPU +# @polarity: optional polarity, default is last polarity set by the guest +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# Modifies the topology by moving the CPU inside the topology +# tree or by changing a modifier attribute of a CPU. +# +# Returns: Nothing on success, the reason on failure. +# +# Since: <next qemu stable release, eg. 1.0> +## +{ 'command': 'change-topology', + 'data': { + 'core': 'int', + 'socket': 'int', + 'book': 'int', + 'drawer': 'int', + '*polarity': 'int', + '*dedicated': 'bool' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}include/monitor/hmp.h +1
-0@@ -144,5 +144,6 @@ void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Error **));void hmp_info_stats (Monitor *mon,const QDict *qdict);void hmp_pcie_aer_inject_error (Monitor *mon,const QDict *qdict); +void hmp_change_topology (Monitor *mon,const QDict *qdict);#endif hw/s390x/cpu-topology.c +4
-0@@ -18,6 +18,10 @@#include "target/s390x/cpu.h" #include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/cpu-topology.h" +#include "qapi/qapi-commands-machine-target.h" +#include "qapi/qmp/qdict.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" /* * s390_topology is used to keep the topology information. @@ -203,6 +207,21 @@ static void s390_topology_set_entry(S390TopologyEntry *entry, s390_topology.sockets[s390_socket_nb (id)]++; }
Quoted 14 lines
hw/s390x/cpu-topology.c static void s390_topology_set_entry(S390TopologyEntry *entry, · line 221
Quoted 12 lines
hw/s390x/cpu-topology.c +12
-0+/** +* s390_topology_clear_entry: +* @entry: Topology entry to setup +* @id: topology id to use for the setup +* +* Clear the core bit inside the topology mask and +* decrements the number of cores for the socket. +*/ +static void s390_topology_clear_entry (S390TopologyEntry *entry, +s390_topology_id id) +{ +clear_bit (63 - id.core, &entry->mask);This doesn't take the origin into account.
Yes, this error has been done everywhere, I modify this.
Quoted 4 lines
hw/s390x/cpu-topology.c static void s390_topology_set_entry(S390TopologyEntry *entry, · line 222
Quoted 2 lines
hw/s390x/cpu-topology.c +1
-0+ s390_topology.sockets[s390_socket_nb (id)]--;I suppose this function cannot run concurrently, so the same CPU doesn't get removed twice.
This is only called on a change of topology and the qapi commands are serialized by the BQL.
Quoted 8 lines
Quoted 8 lines
hw/s390x/cpu-topology.c +2
-0+} +/** * s390_topology_new_entry: * @id: s390_topology_id to add @@ -383,3 +402,125 @@ void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp)
Quoted 15 lines
hw/s390x/cpu-topology.c void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp) · line 415
Quoted 13 lines
hw/s390x/cpu-topology.c +11
-0s390_topology_insert (id); } + +/* +* qmp and hmp implementations +*/ + +static S390TopologyEntry *s390_topology_core_to_entry (int core) +{ +S390TopologyEntry *entry; + + QTAILQ_FOREACH(entry, &s390_topology.list, next) { +if (entry->mask & (1UL << (63 - core))) {origin here also.
yes
Quoted 7 lines
hw/s390x/cpu-topology.c void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp) · line 419
Quoted 5 lines
hw/s390x/cpu-topology.c +4
-0+return entry; + } + } +return NULL ;This should not return NULL unless the core id is invalid.
yes
Quoted 1 line
Might be better to validate that somewhere else.
How?
I can use CPU_FOREACH() but it would be quite the same and I will need to rerun a loop for setting the topology anyway.
Quoted 13 lines
hw/s390x/cpu-topology.c void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp) · line 429
Quoted 11 lines
hw/s390x/cpu-topology.c +10
-0+} + +static void s390_change_topology (Error **errp,int64_t core,int64_t socket, +int64_t book,int64_t drawer, +int64_t polarity,bool dedicated) +{ +S390TopologyEntry *entry; +s390_topology_id new_id; +s390_topology_id old_id; +Error *local_error =NULL ;I think you could use
ERRP_GUARDhere also.
You are right, I could.
Should I ?
I do not need it and find it obfuscating but if you insist I can do it.
Quoted 65 lines
Quoted 65 lines
hw/s390x/cpu-topology.c +65
-0+ +/* Get the old entry */ + entry =s390_topology_core_to_entry (core); +if (!entry) { +error_setg (errp,"No core %ld" , core); +return ; + } + +/* Compute old topology id */ + old_id = entry->id; + old_id.core = core; + +/* Compute new topology id */ + new_id = entry->id; + new_id.core = core; + new_id.socket = socket; + new_id.book = book; + new_id.drawer = drawer; + new_id.p = polarity; + new_id.d = dedicated; + new_id.type =S390_TOPOLOGY_CPU_IFL ; + +/* Same topology entry, nothing to do */ +if (entry->id.id == new_id.id) { +return ; + } + +/* Check for space on the socket if ids are different */ +if ((s390_socket_nb (old_id) !=s390_socket_nb (new_id)) && + (s390_topology.sockets[s390_socket_nb (new_id)] >= + s390_topology.smp->sockets)) { +error_setg (errp,"No more space on this socket" ); +return ; + } + +/* Verify the new topology */ +s390_topology_check (&local_error, new_id); +if (local_error) { +error_propagate (errp, local_error); +return ; + } + +/* Clear the old topology */ +s390_topology_clear_entry (entry, old_id); + +/* Insert the new topology */ +s390_topology_insert (new_id); + +/* Remove unused entry */ +if (!entry->mask) { +QTAILQ_REMOVE (&s390_topology.list, entry, next); +g_free (entry); + } + +/* Advertise the topology change */ +s390_cpu_topology_set (); +} + +void qmp_change_topology (int64_t core,int64_t socket, +int64_t book,int64_t drawer, +bool has_polarity,int64_t polarity, +bool has_dedicated,bool dedicated, +Error **errp) +{ +Error *local_err =NULL ;
Quoted 8 lines
hw/s390x/cpu-topology.c void s390_topology_set_cpu(MachineState *ms, S390CPU *cpu, Error **errp) · line 499
Quoted 5 lines
hw/s390x/cpu-topology.c +5
-0+ +if (!s390_has_topology ()) { +error_setg (&local_err,"This machine doesn't support topology" ); +return ; + }Do you really want to ignore
has_polarityandhas_dedicatedhere? What happens in this case?
no, seems I forgot to check it.
Thanks,
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 9/11 qapi/s390/cpu topology: monitor query topology information
In reply to Pierre MorelReporting the current topology informations to the admin through the QEMU monitor.
--- qapi/machine-target.json | 66 ++++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 76 ++++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 16 +++++++++ 4 files changed, 159 insertions(+)
qapi/machine-target.json +66 -0
@@ -371,3 +371,69 @@ }, 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } } + +## +# @S390CpuTopology: +# +# CPU Topology information +# +# @drawer: the destination drawer where to move the vCPU +# +# @book: the destination book where to move the vCPU +# +# @socket: the destination socket where to move the vCPU +# +# @polarity: optional polarity, default is last polarity set by the guest +# +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# @origin: offset of the first bit of the core mask +# +# @mask: mask of the cores sharing the same topology +# +# Since: 8.0 +## +{ 'struct': 'S390CpuTopology', + 'data': { + 'drawer': 'int', + 'book': 'int', + 'socket': 'int', + 'polarity': 'int', + 'dedicated': 'bool', + 'origin': 'int', + 'mask': 'str' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +} + +## +# @query-topology: +# +# Return information about CPU Topology +# +# Returns a @CpuTopology instance describing the CPU Toplogy +# being currently used by QEMU. +# +# Since: 8.0 +# +# Example: +# +# -> { "execute": "cpu-topology" } +# <- {"return": [ +# { +# "drawer": 0, +# "book": 0, +# "socket": 0, +# "polarity": 0, +# "dedicated": true, +# "origin": 0, +# "mask": 0xc000000000000000, +# }, +# ] +# } +# +## +{ 'command': 'query-topology', + 'returns': ['S390CpuTopology'], + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}
include/monitor/hmp.h +1 -0
@@ -145,5 +145,6 @@ void hmp_human_readable_text_helper(Monitor *mon,void hmp_info_stats (Monitor *mon,const QDict *qdict);void hmp_pcie_aer_inject_error (Monitor *mon,const QDict *qdict);void hmp_change_topology (Monitor *mon,const QDict *qdict); +void hmp_query_topology (Monitor *mon,const QDict *qdict);#endif
hw/s390x/cpu-topology.c +76 -0
79 lines not on this page · raw message
hmp-commands-info.hx +16 -0
@@ -993,3 +993,19 @@ SRST ``info virtio-queue-element`` *path* *queue* [*index*] Display element of a given virtio queue ERST + +#if defined(TARGET_S390X) && defined(CONFIG_KVM) + { + .name = "query-topology", + .args_type = "", + .params = "", + .help = "Show information about CPU topology", + .cmd = hmp_query_topology, + .flags = "p", + }, + +SRST + ``info query-topology`` + Show information about CPU topology +ERST +#endif
Signature · 1 line
2.31.1
Re: [PATCH v14 09/11] qapi/s390/cpu topology: monitor query topology information
Quoted 5 lines · Pierre Morel
Reporting the current topology informations to the admin through the QEMU monitor.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 11 lines
hmp-commands-info.hx +3
-0@@ -993,3 +993,19 @@ SRST ``info virtio-queue-element`` *path* *queue* [*index*] Display element of a given virtio queue ERST + +#if defined(TARGET_S390X) && defined(CONFIG_KVM) + {
hmp-commands-info.hx SRST · line 1008
Quoted 10 lines
hmp-commands-info.hx +10
-0+ .name = "query-topology", + .args_type = "", + .params = "", + .help = "Show information about CPU topology", + .cmd = hmp_query_topology, + .flags = "p", + }, + +SRST + ``info query-topology``
"info query-topology" sounds weird ... I'd maybe rather call it only "info topology" or "info cpu-topology" here.
Thomas
Quoted 3 lines
hmp-commands-info.hx +3
-0+ Show information about CPU topology +ERST +#endif
Re: [PATCH v14 09/11] qapi/s390/cpu topology: monitor query topology information
Quoted 22 lines · Thomas Huth
Quoted 5 lines · Pierre Morel
Reporting the current topology informations to the admin through the QEMU monitor.
Signed-off-by Pierre Morel <[email protected]>---
...
Quoted 15 lines
hmp-commands-info.hx +0
-0@@ -993,3 +993,19 @@ SRST``info virtio-queue-element`` *path* *queue* [*index*] Display element of a given virtio queue ERST
hmp-commands-info.hx +7
-0+ +#if defined(TARGET_S390X) && defined(CONFIG_KVM) + { + .name = "query-topology", + .args_type = "", + .params = "", + .help = "Show information about CPU topology",
Quoted 8 lines
hmp-commands-info.hx SRST · line 1008
Quoted 6 lines
+ .cmd =
hmp_query_topology,
+ .flags = "p",
+ },hmp-commands-info.hx +3
-0+ +SRST + ``info query-topology``"info query-topology" sounds weird ... I'd maybe rather call it only "info topology" or "info cpu-topology" here.
info cpu-topology looks good for me.
thanks.
Regards,
Pierre
Quoted 8 lines
Thomas
Quoted 3 lines
+ Show information about CPU topology
hmp-commands-info.hx +2
-0+ERST +#endif
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 09/11] qapi/s390/cpu topology: monitor query topology information
In reply to Pierre MorelQuoted 75 lines · Pierre Morel
Reporting the current topology informations to the admin through the QEMU monitor.
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 66 ++++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 76 ++++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 16 +++++++++ 4 files changed, 159 insertions(+)qapi/machine-target.json +56
-0@@ -371,3 +371,69 @@ }, 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } } + +## +# @S390CpuTopology: +# +# CPU Topology information +# +# @drawer: the destination drawer where to move the vCPU +# +# @book: the destination book where to move the vCPU +# +# @socket: the destination socket where to move the vCPU +# +# @polarity: optional polarity, default is last polarity set by the guest +# +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# @origin: offset of the first bit of the core mask +# +# @mask: mask of the cores sharing the same topology +# +# Since: 8.0 +## +{ 'struct': 'S390CpuTopology', + 'data': { + 'drawer': 'int', + 'book': 'int', + 'socket': 'int', + 'polarity': 'int', + 'dedicated': 'bool', + 'origin': 'int', + 'mask': 'str' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +} + +## +# @query-topology: +# +# Return information about CPU Topology +# +# Returns a @CpuTopology instance describing the CPU Toplogy +# being currently used by QEMU. +# +# Since: 8.0 +# +# Example: +# +# -> { "execute": "cpu-topology" } +# <- {"return": [ +# { +# "drawer": 0, +# "book": 0, +# "socket": 0, +# "polarity": 0, +# "dedicated": true, +# "origin": 0,
qapi/machine-target.json line 439
Quoted 10 lines
qapi/machine-target.json +10
-0+# "mask": 0xc000000000000000, +# }, +# ] +# } +# +## +{ 'command': 'query-topology', + 'returns': ['S390CpuTopology'], + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}
IIUC, you're using @mask as a way to compress the array returned from query-topology, so that it doesn't have any repeated elements with the same data. I guess I can understand that desire when the core count can get very large, this can have a large saving.
The downside of using @mask, is that now you require the caller to parse the string to turn it into a bitmask and expand the data. Generally this is considered a bit of an anti-pattern in QAPI design - we don't want callers to have to further parse the data to extract information, we want to directly consumable from the parsed JSON doc.
We already have 'query-cpus-fast' wich returns one entry for each CPU. In fact why do we need to add query-topology at all. Can't we just add book-id / drawer-id / polarity / dedicated to the query-cpus-fast result ?
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v14 09/11] qapi/s390/cpu topology: monitor query topology information
On Thu, 2023-01-12 at 12:10 +0000, Daniel P. Berrangé wrote
[...]
Quoted 5 lines
We already have 'query-cpus-fast' wich returns one entry for each CPU. In fact why do we need to add query-topology at all. Can't we just add book-id / drawer-id / polarity / dedicated to the query-cpus-fast result ?
Is there an existing command for setting cpu properties, also?
Quoted 3 lines
With regards,
Daniel
Re: [PATCH v14 09/11] qapi/s390/cpu topology: monitor query topology information
Quoted 10 lines · Nina Schoetterl-Glausch
On Thu, 2023-01-12 at 12:10 +0000, Daniel P. Berrangé wrote
[...]
Quoted 5 lines
We already have 'query-cpus-fast' wich returns one entry for each CPU. In fact why do we need to add query-topology at all. Can't we just add book-id / drawer-id / polarity / dedicated to the query-cpus-fast result ?
Is there an existing command for setting cpu properties, also?
No, there's nothing applicable that I recall for runtime property changes on CPUs.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v14 09/11] qapi/s390/cpu topology: monitor query topology information
In reply to Daniel P. BerrangéQuoted 92 lines · Daniel P. Berrangé
Quoted 75 lines · Pierre Morel
Reporting the current topology informations to the admin through the QEMU monitor.
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 66 ++++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 76 ++++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 16 +++++++++ 4 files changed, 159 insertions(+)qapi/machine-target.json +56
-0@@ -371,3 +371,69 @@ }, 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } } + +## +# @S390CpuTopology: +# +# CPU Topology information +# +# @drawer: the destination drawer where to move the vCPU +# +# @book: the destination book where to move the vCPU +# +# @socket: the destination socket where to move the vCPU +# +# @polarity: optional polarity, default is last polarity set by the guest +# +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# @origin: offset of the first bit of the core mask +# +# @mask: mask of the cores sharing the same topology +# +# Since: 8.0 +## +{ 'struct': 'S390CpuTopology', + 'data': { + 'drawer': 'int', + 'book': 'int', + 'socket': 'int', + 'polarity': 'int', + 'dedicated': 'bool', + 'origin': 'int', + 'mask': 'str' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +} + +## +# @query-topology: +# +# Return information about CPU Topology +# +# Returns a @CpuTopology instance describing the CPU Toplogy +# being currently used by QEMU. +# +# Since: 8.0 +# +# Example: +# +# -> { "execute": "cpu-topology" } +# <- {"return": [ +# { +# "drawer": 0, +# "book": 0, +# "socket": 0, +# "polarity": 0, +# "dedicated": true, +# "origin": 0,qapi/machine-target.json line 439
Quoted 10 lines
qapi/machine-target.json +10
-0+# "mask": 0xc000000000000000, +# }, +# ] +# } +# +## +{ 'command': 'query-topology', + 'returns': ['S390CpuTopology'], + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}IIUC, you're using @mask as a way to compress the array returned from query-topology, so that it doesn't have any repeated elements with the same data. I guess I can understand that desire when the core count can get very large, this can have a large saving.
Quoted 6 lines
The downside of using @mask, is that now you require the caller to parse the string to turn it into a bitmask and expand the data. Generally this is considered a bit of an anti-pattern in QAPI design - we don't want callers to have to further parse the data to extract information, we want to directly consumable from the parsed JSON doc.
Not exactly, the mask is computed by the firmware to provide it to the guest and is already available when querying the topology. But I understand that for the QAPI user the mask is not the right solution, standard coma separated values like (1,3,5,7-11) would be much easier to read.
Quoted 5 lines
We already have 'query-cpus-fast' wich returns one entry for each CPU. In fact why do we need to add query-topology at all. Can't we just add book-id / drawer-id / polarity / dedicated to the query-cpus-fast result ?
Yes we can, I think we should, however when there are a lot of CPU it will be complicated to find the CPU sharing the same socket and the same attributes. I think having both would be interesting.
What do you think?
regards,
Pierre
Quoted 3 lines
With regards,
Daniel
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 09/11] qapi/s390/cpu topology: monitor query topology information
Quoted 102 lines · Pierre Morel
Quoted 92 lines · Daniel P. Berrangé
Quoted 75 lines · Pierre Morel
Reporting the current topology informations to the admin through the QEMU monitor.
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 66 ++++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 76 ++++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 16 +++++++++ 4 files changed, 159 insertions(+)qapi/machine-target.json +56
-0@@ -371,3 +371,69 @@ }, 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } } + +## +# @S390CpuTopology: +# +# CPU Topology information +# +# @drawer: the destination drawer where to move the vCPU +# +# @book: the destination book where to move the vCPU +# +# @socket: the destination socket where to move the vCPU +# +# @polarity: optional polarity, default is last polarity set by the guest +# +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# @origin: offset of the first bit of the core mask +# +# @mask: mask of the cores sharing the same topology +# +# Since: 8.0 +## +{ 'struct': 'S390CpuTopology', + 'data': { + 'drawer': 'int', + 'book': 'int', + 'socket': 'int', + 'polarity': 'int', + 'dedicated': 'bool', + 'origin': 'int', + 'mask': 'str' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +} + +## +# @query-topology: +# +# Return information about CPU Topology +# +# Returns a @CpuTopology instance describing the CPU Toplogy +# being currently used by QEMU. +# +# Since: 8.0 +# +# Example: +# +# -> { "execute": "cpu-topology" } +# <- {"return": [ +# { +# "drawer": 0, +# "book": 0, +# "socket": 0, +# "polarity": 0, +# "dedicated": true, +# "origin": 0,qapi/machine-target.json line 439
Quoted 10 lines
qapi/machine-target.json +10
-0+# "mask": 0xc000000000000000, +# }, +# ] +# } +# +## +{ 'command': 'query-topology', + 'returns': ['S390CpuTopology'], + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}IIUC, you're using @mask as a way to compress the array returned from query-topology, so that it doesn't have any repeated elements with the same data. I guess I can understand that desire when the core count can get very large, this can have a large saving.
Quoted 6 lines
The downside of using @mask, is that now you require the caller to parse the string to turn it into a bitmask and expand the data. Generally this is considered a bit of an anti-pattern in QAPI design - we don't want callers to have to further parse the data to extract information, we want to directly consumable from the parsed JSON doc.
Quoted 5 lines
Not exactly, the mask is computed by the firmware to provide it to the guest and is already available when querying the topology.
But I understand that for the QAPI user the mask is not the right solution, standard coma separated values like (1,3,5,7-11) would be much easier to read.
That is still inventing a second level data format for an attribute that needs to be parsed, and its arguably more complex.
Quoted 8 lines
Quoted 4 lines
We already have 'query-cpus-fast' wich returns one entry for each CPU. In fact why do we need to add query-topology at all. Can't we just add book-id / drawer-id / polarity / dedicated to the query-cpus-fast result ?
Yes we can, I think we should, however when there are a lot of CPU it will be complicated to find the CPU sharing the same socket and the same attributes.
It shouldn't be that hard to populate a hash table, using the set of socket + attributes you want as the hash key.
Quoted 1 line
I think having both would be interesting.
IMHO this is undesirable if we can make query-cpus-fast report sufficient information, as it gives a maint burden to QEMU and is confusing to consumers to QEMU to have multiple commands with largely overlapping functionality.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v14 09/11] qapi/s390/cpu topology: monitor query topology information
Quoted 103 lines · Daniel P. Berrangé
Quoted 102 lines · Pierre Morel
Quoted 98 lines · Daniel P. Berrangé
Quoted 75 lines · Pierre Morel
Reporting the current topology informations to the admin through the QEMU monitor.
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 66 ++++++++++++++++++++++++++++++++++ include/monitor/hmp.h | 1 + hw/s390x/cpu-topology.c | 76 ++++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 16 +++++++++ 4 files changed, 159 insertions(+)qapi/machine-target.json +56
-0@@ -371,3 +371,69 @@ }, 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } } + +## +# @S390CpuTopology: +# +# CPU Topology information +# +# @drawer: the destination drawer where to move the vCPU +# +# @book: the destination book where to move the vCPU +# +# @socket: the destination socket where to move the vCPU +# +# @polarity: optional polarity, default is last polarity set by the guest +# +# @dedicated: optional, if the vCPU is dedicated to a real CPU +# +# @origin: offset of the first bit of the core mask +# +# @mask: mask of the cores sharing the same topology +# +# Since: 8.0 +## +{ 'struct': 'S390CpuTopology', + 'data': { + 'drawer': 'int', + 'book': 'int', + 'socket': 'int', + 'polarity': 'int', + 'dedicated': 'bool', + 'origin': 'int', + 'mask': 'str' + }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +} + +## +# @query-topology: +# +# Return information about CPU Topology +# +# Returns a @CpuTopology instance describing the CPU Toplogy +# being currently used by QEMU. +# +# Since: 8.0 +# +# Example: +# +# -> { "execute": "cpu-topology" } +# <- {"return": [ +# { +# "drawer": 0, +# "book": 0, +# "socket": 0, +# "polarity": 0, +# "dedicated": true, +# "origin": 0,qapi/machine-target.json line 439
Quoted 10 lines
qapi/machine-target.json +10
-0+# "mask": 0xc000000000000000, +# }, +# ] +# } +# +## +{ 'command': 'query-topology', + 'returns': ['S390CpuTopology'], + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } +}IIUC, you're using @mask as a way to compress the array returned from query-topology, so that it doesn't have any repeated elements with the same data. I guess I can understand that desire when the core count can get very large, this can have a large saving.
The downside of using @mask, is that now you require the caller to parse the string to turn it into a bitmask and expand the data. Generally this is considered a bit of an anti-pattern in QAPI design - we don't want callers to have to further parse the data to extract information, we want to directly consumable from the parsed JSON doc.
Quoted 8 lines
Quoted 5 lines
Not exactly, the mask is computed by the firmware to provide it to the guest and is already available when querying the topology.
But I understand that for the QAPI user the mask is not the right solution, standard coma separated values like (1,3,5,7-11) would be much easier to read.That is still inventing a second level data format for an attribute that needs to be parsed, and its arguably more complex.
OK, I think I am too focused on my vision of the topology. I add the new attributes to the query-cpus-fast
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
We already have 'query-cpus-fast' wich returns one entry for each CPU. In fact why do we need to add query-topology at all. Can't we just add book-id / drawer-id / polarity / dedicated to the query-cpus-fast result ?
Quoted 6 lines
Quoted 3 lines
Yes we can, I think we should, however when there are a lot of CPU it will be complicated to find the CPU sharing the same socket and the same attributes.
It shouldn't be that hard to populate a hash table, using the set of socket + attributes you want as the hash key.
It is not a problem.
Quoted 7 lines
Quoted 2 lines
I think having both would be interesting.
IMHO this is undesirable if we can make query-cpus-fast report sufficient information, as it gives a maint burden to QEMU and is confusing to consumers to QEMU to have multiple commands with largely overlapping functionality.
right.
Thanks Daniel.
Regards,
Pierre
Quoted 4 lines
With regards,
Daniel
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 10/11 qapi/s390/cpu topology: POLARITY_CHANGE qapi event
In reply to Pierre MorelWhen the guest asks to change the polarity this change is forwarded to the admin using QAPI.
The admin is supposed to take according decisions concerning CPU provisioning.
--- qapi/machine-target.json | 21 +++++++++++++++++++++ hw/s390x/cpu-topology.c | 2 ++ 2 files changed, 23 insertions(+)
qapi/machine-target.json +21 -0
@@ -437,3 +437,24 @@ 'returns': ['S390CpuTopology'], 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } } + +## +# @POLARITY_CHANGE: +# +# Emitted when the guest asks to change the polarity. +# +# @polarity: polarity specified by the guest +# +# Since: 8.0 +# +# Example: +# +# <- { "event": "POLARITY_CHANGE", +# "data": { "polarity": 0 }, +# "timestamp": { "seconds": 1401385907, "microseconds": 422329 } } +# +## +{ 'event': 'POLARITY_CHANGE', + 'data': { 'polarity': 'int' }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM'] } +}
hw/s390x/cpu-topology.c +2 -0
@@ -19,6 +19,7 @@#include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/cpu-topology.h" #include "qapi/qapi-commands-machine-target.h" +#include "qapi/qapi-events-machine-target.h" #include "qapi/qmp/qdict.h" #include "monitor/hmp.h" #include "monitor/monitor.h"
@@ -128,6 +129,7 @@ void s390_topology_set_polarity(int polarity) } }s390_cpu_topology_set (); +qapi_event_send_polarity_change (polarity); }/*
Signature · 1 line
2.31.1
Re: [PATCH v14 10/11] qapi/s390/cpu topology: POLARITY_CHANGE qapi event
Quoted 4 lines · Pierre Morel
When the guest asks to change the polarity this change is forwarded to the admin using QAPI.
The admin is supposed to take according decisions concerning CPU provisioning.
I somehow doubt that an average admin will monitor QEMU for such events ... so this rather should be handled by upper layers like libvirt one day?
Quoted 11 lines
Signed-off-by Pierre Morel <[email protected]>--- qapi/machine-target.json | 21 +++++++++++++++++++++ hw/s390x/cpu-topology.c | 2 ++ 2 files changed, 23 insertions(+)qapi/machine-target.json +0
-0
qapi/machine-target.json line 442
Quoted 6 lines
qapi/machine-target.json +3
-0@@ -437,3 +437,24 @@ 'returns': ['S390CpuTopology'], 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } } + +## +# @POLARITY_CHANGE:
I'd maybe rather call it CPU_POLARITY_CHANGE ... in case "polarity" is one day also used for some other devices.
qapi/machine-target.json line 446
Quoted 4 lines
qapi/machine-target.json +4
-0+# +# Emitted when the guest asks to change the polarity. +# +# @polarity: polarity specified by the guest
Please elaborate: Where does the value come from (the PTF instruction)? Which values are possible?
Thomas
Quoted 34 lines
qapi/machine-target.json +14
-0+# +# Since: 8.0 +# +# Example: +# +# <- { "event": "POLARITY_CHANGE", +# "data": { "polarity": 0 }, +# "timestamp": { "seconds": 1401385907, "microseconds": 422329 } } +# +## +{ 'event': 'POLARITY_CHANGE', + 'data': { 'polarity': 'int' }, + 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM'] } +}hw/s390x/cpu-topology.c +2
-0@@ -19,6 +19,7 @@#include "hw/s390x/s390-virtio-ccw.h" #include "hw/s390x/cpu-topology.h" #include "qapi/qapi-commands-machine-target.h" +#include "qapi/qapi-events-machine-target.h" #include "qapi/qmp/qdict.h" #include "monitor/hmp.h" #include "monitor/monitor.h" @@ -128,6 +129,7 @@ void s390_topology_set_polarity(int polarity) } }s390_cpu_topology_set (); +qapi_event_send_polarity_change (polarity); }/*
Re: [PATCH v14 10/11] qapi/s390/cpu topology: POLARITY_CHANGE qapi event
Quoted 7 lines · Thomas Huth
Quoted 4 lines · Pierre Morel
When the guest asks to change the polarity this change is forwarded to the admin using QAPI.
The admin is supposed to take according decisions concerning CPU provisioning.I somehow doubt that an average admin will monitor QEMU for such events ... so this rather should be handled by upper layers like libvirt one day?
Yes.
Quoted 7 lines
Quoted 7 lines
Signed-off-by Pierre Morel <[email protected]>---
qapi/machine-target.json| 21 +++++++++++++++++++++ hw/s390x/cpu-topology.c | 2 ++2 files changed, 23 insertions(+)
Quoted 13 lines
qapi/machine-target.json line 442
Quoted 11 lines
qapi/machine-target.json +3
-0@@ -437,3 +437,24 @@ 'returns': ['S390CpuTopology'], 'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] } } + +## +# @POLARITY_CHANGE:I'd maybe rather call it
CPU_POLARITY_CHANGE... in case "polarity" is one day also used for some other devices.
OK, right.
Quoted 7 lines
qapi/machine-target.json line 446
Quoted 5 lines
qapi/machine-target.json +4
-0+# +# Emitted when the guest asks to change the polarity. +# +# @polarity: polarity specified by the guestPlease elaborate: Where does the value come from (the PTF instruction)? Which values are possible?
Yes what about:
# @polarity: the guest can specify with the PTF instruction a horizontal
# or a vertical polarity.
# On horizontal polarity the host is expected to provision
# the vCPU equally. # On vertical polarity the host can provision each vCPU # differently # The guest can get information on the provisioning with # the STSI(15) instruction.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 10/11] qapi/s390/cpu topology: POLARITY_CHANGE qapi event
Quoted 3 lines · Pierre Morel
Quoted 1 line · Thomas Huth
On 05/01/2023 15.53, Pierre Morel wrote:
...>>> +#
Quoted 10 lines
Quoted 5 lines
qapi/machine-target.json line 446
Quoted 3 lines
qapi/machine-target.json +3
-0+# Emitted when the guest asks to change the polarity. +# +# @polarity: polarity specified by the guestPlease elaborate: Where does the value come from (the PTF instruction)? Which values are possible?
Yes what about:
# @polarity: the guest can specify with the PTF instruction a horizontal # or a vertical polarity.
Maybe something like: "The guest can tell the host (via the PTF instruction) whether a CPU should have horizontal or vertical polarity." ?
Quoted 2 lines
# On horizontal polarity the host is expected to provision # the vCPU equally.
Maybe: "all vCPUs equally" ?
Or: "each vCPU equally" ?
Quoted 4 lines
# On vertical polarity the host can provision each vCPU # differently
# The guest can get information on the provisioning with # the STSI(15) instruction.
Thomas
Re: [PATCH v14 10/11] qapi/s390/cpu topology: POLARITY_CHANGE qapi event
Quoted 5 lines · Thomas Huth
Quoted 3 lines · Pierre Morel
Quoted 1 line · Thomas Huth
On 05/01/2023 15.53, Pierre Morel wrote:
...>>> +#
OK
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
qapi/machine-target.json line 446
Quoted 3 lines
qapi/machine-target.json +3
-0+# Emitted when the guest asks to change the polarity. +# +# @polarity: polarity specified by the guestPlease elaborate: Where does the value come from (the PTF instruction)? Which values are possible?
Quoted 6 lines
Quoted 4 lines
Yes what about:
# @polarity: the guest can specify with the PTF instruction a horizontal # or a vertical polarity.
Maybe something like: "The guest can tell the host (via the PTF instruction) whether a CPU should have horizontal or vertical polarity." ?
Yes thanks, much better.
Quoted 6 lines
Quoted 3 lines
# On horizontal polarity the host is expected to provision # the vCPU equally.
Maybe: "all vCPUs equally" ?
Or: "each vCPU equally" ?
yes, thx.
Quoted 8 lines
Quoted 5 lines
# On vertical polarity the host can provision each vCPU # differently
# The guest can get information on the provisioning with # the STSI(15) instruction.Thomas
I make the changes.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
PATCH v14 11/11 docs/s390x/cpu topology: document s390x cpu topology
In reply to Pierre MorelAdd some basic examples for the definition of cpu topology in s390x.
--- docs/system/s390x/cpu-topology.rst | 292 +++++++++++++++++++++++++++++ docs/system/target-s390x.rst | 1 + 2 files changed, 293 insertions(+) create mode 100644 docs/system/s390x/cpu-topology.rst
docs/system/s390x/cpu-topology.rst new file +292 -0
@@ -0,0 +1,292 @@ +CPU Topology on s390x +===================== + +CPU Topology on S390x provides up to 5 levels of topology containers: +nodes, drawers, books, sockets and CPUs. +While the higher level containers, Containers Topology List Entries, +(Containers TLE) define a tree hierarchy, the lowest level of topology +definition, the CPU Topology List Entry (CPU TLE), provides the placement +of the CPUs inside the parent container. + +Currently QEMU CPU topology uses a single level of container: the sockets. + +For backward compatibility, threads can be declared on the ``-smp`` command +line. They will be seen as CPUs by the guest as long as multithreading +is not really supported by QEMU for S390. + +Beside the topological tree, S390x provides 3 CPU attributes: +- CPU type +- polarity entitlement +- dedication + +Prerequisites +------------- + +To use CPU Topology a Linux QEMU/KVM machine providing the CPU Topology facility +(STFLE bit 11) is required. + +However, since this facility has been enabled by default in an early version +of QEMU, we use a capability, ``KVM_CAP_S390_CPU_TOPOLOGY``, to notify KVM +QEMU use of the CPU Topology. + +Enabling CPU topology +--------------------- + +Currently, CPU topology is only enabled in the host model. + +Enabling CPU topology in a CPU model is done by setting the CPU flag +``ctop`` to ``on`` like in: + +.. code-block:: bash + + -cpu gen16b,ctop=on + +Having the topology disabled by default allows migration between +old and new QEMU without adding new flags. + +Default topology usage +---------------------- + +The CPU Topology, can be specified on the QEMU command line +with the ``-smp`` or the ``-device`` QEMU command arguments +without using any new attributes. +In this case, the topology will be calculated by simply adding +to the topology the cores based on the core-id starting with +core-0 at position 0 of socket-0, book-0, drawer-0 with default +modifier attributes: horizontal polarity and no dedication. + +In the following machine we define 8 sockets with 4 cores each. +Note that S390 QEMU machines do not implement multithreading. + +.. code-block:: bash + + $ qemu-system-s390x -m 2G \ + -cpu gen16b,ctop=on \ + -smp cpus=5,sockets=8,cores=4,maxcpus=32 \ + -device host-s390x-cpu,core-id=14 \ + +New CPUs can be plugged using the device_add hmp command like in: + +.. code-block:: bash + + (qemu) device_add gen16b-s390x-cpu,core-id=9 + +The core-id defines the placement of the core in the topology by +starting with core 0 in socket 0 up to maxcpus. + +In the example above: + +* There are 5 CPUs provided to the guest with the ``-smp`` command line + They will take the core-ids 0,1,2,3,4 + As we have 4 cores in a socket, we have 4 CPUs provided + to the guest in socket 0, with core-ids 0,1,2,3. + The last cpu, with core-id 4, will be on socket 1. + +* the core with ID 14 provided by the ``-device`` command line will + be placed in socket 3, with core-id 14 + +* the core with ID 9 provided by the ``device_add`` qmp command will + be placed in socket 2, with core-id 9 + +Note that the core ID is machine wide and the CPU TLE masks provided +by the STSI instruction will be written in a big endian mask: + +* in socket 0: 0xf000000000000000 (core id 0,1,2,3) +* in socket 1: 0x0800000000000000 (core id 4) +* in socket 2: 0x0040000000000000 (core id 9) +* in socket 3: 0x0002000000000000 (core id 14) + +Defining the topology on command line +------------------------------------- + +The topology can be defined entirely during the CPU definition, +with the exception of CPU 0 which must be defined with the -smp +argument. + +For example, here we set the position of the cores 1,2,3 on +drawer 1, book 1, socket 2 and cores 0,9 and 14 on drawer 0, +book 0, socket 0 with all horizontal polarity and not dedicated. +The core 4, will be set on its default position on socket 1 +(since we have 4 core per socket) and we define it with dedication and +vertical high entitlement. + +.. code-block:: bash + + $ qemu-system-s390x -m 2G \ + -cpu gen16b,ctop=on \ + -smp cpus=1,sockets=8,cores=4,maxcpus=32 \ + \ + -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=1 \ + -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=2 \ + -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=3 \ + \ + -device gen16b-s390x-cpu,drawer-id=0,book-id=0,socket-id=0,core-id=9 \ + -device gen16b-s390x-cpu,drawer-id=0,book-id=0,socket-id=0,core-id=14 \ + \ + -device gen16b-s390x-cpu,core-id=4,dedicated=on,polarity=3 \ + +Polarity and dedication +----------------------- + +Polarity can be of two types: horizontal or vertical. + +The horizontal polarization specifies that all guest's vCPUs get +almost the same amount of provisioning of real CPU by the host. + +The vertical polarization specifies that guest's vCPU can get +different real CPU provisions: + +- a vCPU with Vertical high entitlement specifies that this + vCPU gets 100% of the real CPU provisioning. + +- a vCPU with Vertical medium entitlement specifies that this + vCPU shares the real CPU with other vCPU. + +- a vCPU with Vertical low entitlement specifies that this + vCPU only get real CPU provisioning when no other vCPU need it. + +In the case a vCPU with vertical high entitlement does not use +the real CPU, the unused "slack" can be dispatched to other vCPU +with medium or low entitlement. + +The host indicates to the guest how the real CPU resources are +provided to the vCPUs through the SYSIB with two polarity bits +inside the CPU TLE. + +Bits d - Polarization +0 0 Horizontal +0 1 Vertical low entitlement +1 0 Vertical medium entitlement +1 1 Vertical high entitlement + +A subsystem reset puts all vCPU of the configuration into the +horizontal polarization. + +The admin specifies the dedicated bit when the vCPU is dedicated +to a single real CPU. + +As for the Linux admin, the dedicated bit is an indication on the +affinity of a vCPU for a real CPU while the entitlement indicates the +sharing or exclusivity of use. + +QAPI interface for topology +--------------------------- + +Let's start QEMU with the following command: + +.. code-block:: bash + + sudo /usr/local/bin/qemu-system-s390x \ + -enable-kvm \ + -cpu z14,ctop=on \ + -smp 1,drawers=3,books=3,sockets=2,cores=2,maxcpus=36 \ + \ + -device z14-s390x-cpu,core-id=19,polarity=3 \ + -device z14-s390x-cpu,core-id=11,polarity=1 \ + -device z14-s390x-cpu,core-id=12,polarity=3 \ + ... + +and see the result when using of the QAPI interface. + +query-topology ++++++++++++++++ + +The command cpu-topology allows the admin to query the topology +tree and modifier for all configured vCPU. + +.. code-block:: QMP + + -> { "execute": "query-topology" } + {"return": + [ + { + "origin": 0, + "dedicated": false, + "book": 0, + "socket": 0, + "drawer": 0, + "polarity": 0, + "mask": "0x8000000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 2, + "socket": 1, + "drawer": 0, + "polarity": 1, + "mask": "0x0010000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 0, + "socket": 0, + "drawer": 1, + "polarity": 3, + "mask": "0x0008000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 1, + "socket": 1, + "drawer": 1, + "polarity": 3, + "mask": "0x0000100000000000" + } + ] + } + +change-topology ++++++++++++++++ + +The command change-topology allows the admin to modify the topology +tree or the topology modifiers of a vCPU in the configuration. + +.. code-block:: QMP + + -> { "execute": "change-topology", + "arguments": { + "core": 11, + "socket": 0, + "book": 0, + "drawer": 0, + "polarity": 0, + "dedicated": false + } + } + <- {"return": {}} + + +event POLARITY_CHANGE ++++++++++++++++++++++ + +When a guest is requesting a modification of the polarity, +QEMU sends a POLARITY_CHANGE event. + +When requesting the change, the guest only specifies horizontal or +vertical polarity. +The dedication and fine grain vertical entitlement depends on admin +to set according to its response to this event. + +Note that a vertical polarized dedicated vCPU can only have a high +entitlement, this gives 6 possibilities for a vCPU polarity: + +- Horizontal +- Horizontal dedicated +- Vertical low +- Vertical medium +- Vertical high +- Vertical high dedicated + +Example of the event received when the guest issues PTF(0) to request +an horizontal polarity: + +.. code-block:: QMP + + <- { "event": "POLARITY_CHANGE", + "data": { "polarity": 0 }, + "timestamp": { "seconds": 1401385907, "microseconds": 422329 } } + +
docs/system/target-s390x.rst +1 -0
@@ -33,3 +33,4 @@ Architectural features .. toctree:: s390x/bootdevices s390x/protvirt + s390x/cpu-topology
Signature · 1 line
2.31.1
Re: [PATCH v14 11/11] docs/s390x/cpu topology: document s390x cpu topology
Quoted 16 lines · Pierre Morel
Add some basic examples for the definition of cpu topology in s390x.
Signed-off-by Pierre Morel <[email protected]>--- docs/system/s390x/cpu-topology.rst | 292 +++++++++++++++++++++++++++++ docs/system/target-s390x.rst | 1 + 2 files changed, 293 insertions(+)create mode 100644
docs/system/s390x/cpu-topology.rstdocs/system/s390x/cpu-topology.rst new file +0
-0
docs/system/s390x/cpu-topology.rst line 4
Quoted 4 lines
docs/system/s390x/cpu-topology.rst new file +4
-0@@ -0,0 +1,292 @@ +CPU Topology on s390x +===================== + +CPU Topology on S390x provides up to 5 levels of topology containers:
You sometimes write "Topology" with a capital T, sometimes lower case ... I'd suggest to write it lower case consistently everywhere.
docs/system/s390x/cpu-topology.rst line 5
Quoted 1 line
docs/system/s390x/cpu-topology.rst new file +1
-0+nodes, drawers, books, sockets and CPUs.
Hmm, so here you mention that "nodes" are usable on s390x, too? ... in another spot below, you don't mention these anymore...
docs/system/s390x/cpu-topology.rst line 15
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+While the higher level containers, Containers Topology List Entries, +(Containers TLE) define a tree hierarchy, the lowest level of topology +definition, the CPU Topology List Entry (CPU TLE), provides the placement +of the CPUs inside the parent container. + +Currently QEMU CPU topology uses a single level of container: the sockets. + +For backward compatibility, threads can be declared on the ``-smp`` command +line. They will be seen as CPUs by the guest as long as multithreading +is not really supported by QEMU for S390.
Maybe mention that threads are not allowed with machine types >= 7.2 anymore?
Quoted 4 lines
docs/system/s390x/cpu-topology.rst new file +4
-0+Beside the topological tree, S390x provides 3 CPU attributes: +- CPU type +- polarity entitlement +- dedication
docs/system/s390x/cpu-topology.rst line 30
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+ +Prerequisites +------------- + +To use CPU Topology a Linux QEMU/KVM machine providing the CPU Topology facility +(STFLE bit 11) is required. + +However, since this facility has been enabled by default in an early version +of QEMU, we use a capability, ``KVM_CAP_S390_CPU_TOPOLOGY``, to notify KVM +QEMU use of the CPU Topology.
Has it? I thought bit 11 was not enabled by default in the past?
docs/system/s390x/cpu-topology.rst line 35
Quoted 4 lines
docs/system/s390x/cpu-topology.rst new file +4
-0+Enabling CPU topology +--------------------- + +Currently, CPU topology is only enabled in the host model.
add a "by default if support is available in the host kernel" at the end of the sentence?
Quoted 9 lines
docs/system/s390x/cpu-topology.rst new file +9
-0+Enabling CPU topology in a CPU model is done by setting the CPU flag +``ctop`` to ``on`` like in: + +.. code-block:: bash + + -cpu gen16b,ctop=on + +Having the topology disabled by default allows migration between +old and new QEMU without adding new flags.
docs/system/s390x/cpu-topology.rst line 55
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+ +Default topology usage +---------------------- + +The CPU Topology, can be specified on the QEMU command line +with the ``-smp`` or the ``-device`` QEMU command arguments +without using any new attributes. +In this case, the topology will be calculated by simply adding +to the topology the cores based on the core-id starting with +core-0 at position 0 of socket-0, book-0, drawer-0 with default
... here you don't mention "nodes" anymore (which you still mentioned at the beginning of the doc).
docs/system/s390x/cpu-topology.rst line 59
Quoted 4 lines
docs/system/s390x/cpu-topology.rst new file +4
-0+modifier attributes: horizontal polarity and no dedication. + +In the following machine we define 8 sockets with 4 cores each. +Note that S390 QEMU machines do not implement multithreading.
I'd use s390x instead of S390 to avoid confusion with 31-bit machines.
Quoted 27 lines
docs/system/s390x/cpu-topology.rst new file +27
-0+.. code-block:: bash + + $ qemu-system-s390x -m 2G \ + -cpu gen16b,ctop=on \ + -smp cpus=5,sockets=8,cores=4,maxcpus=32 \ + -device host-s390x-cpu,core-id=14 \ + +New CPUs can be plugged using the device_add hmp command like in: + +.. code-block:: bash + + (qemu) device_add gen16b-s390x-cpu,core-id=9 + +The core-id defines the placement of the core in the topology by +starting with core 0 in socket 0 up to maxcpus. + +In the example above: + +* There are 5 CPUs provided to the guest with the ``-smp`` command line + They will take the core-ids 0,1,2,3,4 + As we have 4 cores in a socket, we have 4 CPUs provided + to the guest in socket 0, with core-ids 0,1,2,3. + The last cpu, with core-id 4, will be on socket 1. + +* the core with ID 14 provided by the ``-device`` command line will + be placed in socket 3, with core-id 14 +
docs/system/s390x/cpu-topology.rst line 97
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+* the core with ID 9 provided by the ``device_add`` qmp command will + be placed in socket 2, with core-id 9 + +Note that the core ID is machine wide and the CPU TLE masks provided +by the STSI instruction will be written in a big endian mask: + +* in socket 0: 0xf000000000000000 (core id 0,1,2,3) +* in socket 1: 0x0800000000000000 (core id 4) +* in socket 2: 0x0040000000000000 (core id 9) +* in socket 3: 0x0002000000000000 (core id 14)
Hmm, who's supposed to be the audience of this documentation? Users? Developers? For a doc in docs/system/ I'd expect this to be a documentation for users, so this seems to be way too much of implementation detail here already. If this is supposed to be a doc for developers instead, the file should likely rather go into doc/devel/ instead. Or maybe you want both? ... then you should split the information in here in two files, I think, one in docs/system/ and one in docs/devel/ .
Quoted 21 lines
docs/system/s390x/cpu-topology.rst new file +21
-0+Defining the topology on command line +------------------------------------- + +The topology can be defined entirely during the CPU definition, +with the exception of CPU 0 which must be defined with the -smp +argument. + +For example, here we set the position of the cores 1,2,3 on +drawer 1, book 1, socket 2 and cores 0,9 and 14 on drawer 0, +book 0, socket 0 with all horizontal polarity and not dedicated. +The core 4, will be set on its default position on socket 1 +(since we have 4 core per socket) and we define it with dedication and +vertical high entitlement. + +.. code-block:: bash + + $ qemu-system-s390x -m 2G \ + -cpu gen16b,ctop=on \ + -smp cpus=1,sockets=8,cores=4,maxcpus=32 \ + \ + -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=1 \
docs/system/s390x/cpu-topology.rst line 129
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+ -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=2 \ + -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=3 \ + \ + -device gen16b-s390x-cpu,drawer-id=0,book-id=0,socket-id=0,core-id=9 \ + -device gen16b-s390x-cpu,drawer-id=0,book-id=0,socket-id=0,core-id=14 \ + \ + -device gen16b-s390x-cpu,core-id=4,dedicated=on,polarity=3 \ + +Polarity and dedication +-----------------------
Since you are using the terms "polarity" and "dedication" in the previous paragraphs already, it might make sense to move this section here earlier in the document to teach the users about this first, before using the terms in the other paragraphs?
docs/system/s390x/cpu-topology.rst line 137
Quoted 7 lines
docs/system/s390x/cpu-topology.rst new file +7
-0+Polarity can be of two types: horizontal or vertical. + +The horizontal polarization specifies that all guest's vCPUs get +almost the same amount of provisioning of real CPU by the host. + +The vertical polarization specifies that guest's vCPU can get +different real CPU provisions:
Please remove one space between "different" and "real".
docs/system/s390x/cpu-topology.rst line 143
Quoted 5 lines
docs/system/s390x/cpu-topology.rst new file +5
-0+- a vCPU with Vertical high entitlement specifies that this + vCPU gets 100% of the real CPU provisioning. + +- a vCPU with Vertical medium entitlement specifies that this + vCPU shares the real CPU with other vCPU.
"with *one* other vCPU" or rather "with other vCPU*s*" ?
Quoted 7 lines
docs/system/s390x/cpu-topology.rst new file +7
-0+ +- a vCPU with Vertical low entitlement specifies that this + vCPU only get real CPU provisioning when no other vCPU need it. + +In the case a vCPU with vertical high entitlement does not use +the real CPU, the unused "slack" can be dispatched to other vCPU +with medium or low entitlement.
docs/system/s390x/cpu-topology.rst line 160
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+ +The host indicates to the guest how the real CPU resources are +provided to the vCPUs through the SYSIB with two polarity bits +inside the CPU TLE. + +Bits d - Polarization +0 0 Horizontal +0 1 Vertical low entitlement +1 0 Vertical medium entitlement +1 1 Vertical high entitlement
That SYSIB stuff looks like details for developers again ... I think you should either add more explanations here (I assume the average user does not know the term SYSIB), move it to a separate developers file or drop it.
docs/system/s390x/cpu-topology.rst line 173
Quoted 12 lines
docs/system/s390x/cpu-topology.rst new file +12
-0+A subsystem reset puts all vCPU of the configuration into the +horizontal polarization. + +The admin specifies the dedicated bit when the vCPU is dedicated +to a single real CPU. + +As for the Linux admin, the dedicated bit is an indication on the +affinity of a vCPU for a real CPU while the entitlement indicates the +sharing or exclusivity of use. + +QAPI interface for topology +---------------------------
A "grep -r QAPI docs/system/" shows hardly any entries there. I think QAPI documentation should go into docs/devel instead.
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+Let's start QEMU with the following command: + +.. code-block:: bash + + sudo /usr/local/bin/qemu-system-s390x \ + -enable-kvm \ + -cpu z14,ctop=on \ + -smp 1,drawers=3,books=3,sockets=2,cores=2,maxcpus=36 \ + \ + -device z14-s390x-cpu,core-id=19,polarity=3 \
docs/system/s390x/cpu-topology.rst line 194
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+ -device z14-s390x-cpu,core-id=11,polarity=1 \ + -device z14-s390x-cpu,core-id=12,polarity=3 \ + ... + +and see the result when using of the QAPI interface. + +query-topology ++++++++++++++++ + +The command cpu-topology allows the admin to query the topology
Not sure if the average admin runs QMP directly ... maybe rather talk about the "upper layers like libvirt" here or something similar.
Quoted 79 lines
docs/system/s390x/cpu-topology.rst new file +79
-0+tree and modifier for all configured vCPU. + +.. code-block:: QMP + + -> { "execute": "query-topology" } + {"return": + [ + { + "origin": 0, + "dedicated": false, + "book": 0, + "socket": 0, + "drawer": 0, + "polarity": 0, + "mask": "0x8000000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 2, + "socket": 1, + "drawer": 0, + "polarity": 1, + "mask": "0x0010000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 0, + "socket": 0, + "drawer": 1, + "polarity": 3, + "mask": "0x0008000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 1, + "socket": 1, + "drawer": 1, + "polarity": 3, + "mask": "0x0000100000000000" + } + ] + } + +change-topology ++++++++++++++++ + +The command change-topology allows the admin to modify the topology +tree or the topology modifiers of a vCPU in the configuration. + +.. code-block:: QMP + + -> { "execute": "change-topology", + "arguments": { + "core": 11, + "socket": 0, + "book": 0, + "drawer": 0, + "polarity": 0, + "dedicated": false + } + } + <- {"return": {}} + + +event POLARITY_CHANGE ++++++++++++++++++++++ + +When a guest is requesting a modification of the polarity, +QEMU sends a POLARITY_CHANGE event. + +When requesting the change, the guest only specifies horizontal or +vertical polarity. +The dedication and fine grain vertical entitlement depends on admin +to set according to its response to this event. + +Note that a vertical polarized dedicated vCPU can only have a high
docs/system/s390x/cpu-topology.rst line 283
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+entitlement, this gives 6 possibilities for a vCPU polarity: + +- Horizontal +- Horizontal dedicated +- Vertical low +- Vertical medium +- Vertical high +- Vertical high dedicated + +Example of the event received when the guest issues PTF(0) to request
Please mention that PTF is a CPU instruction (and provide the full name).
Thomas
Re: [PATCH v14 11/11] docs/s390x/cpu topology: document s390x cpu topology
Quoted 11 lines · Thomas Huth
Quoted 10 lines · Pierre Morel
Add some basic examples for the definition of cpu topology in s390x.
Signed-off-by Pierre Morel <[email protected]>---
docs/system/s390x/cpu-topology.rst| 292 +++++++++++++++++++++++++++++ docs/system/target-s390x.rst | 1 +2 files changed, 293 insertions(+)create mode 100644
docs/system/s390x/cpu-topology.rst
Quoted 12 lines
docs/system/s390x/cpu-topology.rst line 4
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +4
-0@@ -0,0 +1,292 @@ +CPU Topology on s390x +===================== + +CPU Topology on S390x provides up to 5 levels of topology containers:You sometimes write "Topology" with a capital T, sometimes lower case ... I'd suggest to write it lower case consistently everywhere.
OK
Quoted 4 lines
docs/system/s390x/cpu-topology.rst line 5
Quoted 2 lines
docs/system/s390x/cpu-topology.rst new file +1
-0+nodes, drawers, books, sockets and CPUs.Hmm, so here you mention that "nodes" are usable on s390x, too? ... in another spot below, you don't mention these anymore...
No, no nodes needed here, I remove that.
Quoted 16 lines
Quoted 12 lines
docs/system/s390x/cpu-topology.rst new file +3
-0+While the higher level containers, Containers Topology List Entries, +(Containers TLE) define a tree hierarchy, the lowest level of topology +definition, the CPU Topology List Entry (CPU TLE), provides theplacement
docs/system/s390x/cpu-topology.rst new file +3
-0+of the CPUs inside the parent container. + +Currently QEMU CPU topology uses a single level of container: thesockets.
docs/system/s390x/cpu-topology.rst new file +2
-0+ +For backward compatibility, threads can be declared on the ``-smp``command
docs/system/s390x/cpu-topology.rst line 15
Quoted 2 lines
docs/system/s390x/cpu-topology.rst new file +2
-0+line. They will be seen as CPUs by the guest as long as multithreading +is not really supported by QEMU for S390.Maybe mention that threads are not allowed with machine types >= 7.2 anymore?
yes
Quoted 12 lines
Quoted 12 lines
docs/system/s390x/cpu-topology.rst new file +9
-0+Beside the topological tree, S390x provides 3 CPU attributes: +- CPU type +- polarity entitlement +- dedication + +Prerequisites +------------- + +To use CPU Topology a Linux QEMU/KVM machine providing the CPUTopology facility
+(STFLE bit 11) is required.
Quoted 8 lines
Quoted 6 lines
docs/system/s390x/cpu-topology.rst new file +2
-0+ +However, since this facility has been enabled by default in an earlyversion
+of QEMU, we use a capability, ``KVM_CAP_S390_CPU_TOPOLOGY``, to notify KVM
+QEMU use of the CPU Topology.Has it? I thought bit 11 was not enabled by default in the past?
bit 11 enabled by default in QEMU, not in KVM.
However no code has been provided to support the STSI(15) and the PTF instruction which are enabled by facility 11.
So if we had enabled facility 11 in KVM without precaution a guest seeing facility 11 will use the PTF instruction and get a program interrupt.
Therefore we need a KVM capability to enable bit 11 in KVM
Quoted 7 lines
docs/system/s390x/cpu-topology.rst line 35
Quoted 5 lines
docs/system/s390x/cpu-topology.rst new file +4
-0+Enabling CPU topology +--------------------- + +Currently, CPU topology is only enabled in the host model.add a "by default if support is available in the host kernel" at the end of the sentence?
yes, thx
Quoted 14 lines
Quoted 14 lines
docs/system/s390x/cpu-topology.rst new file +13
-0+Enabling CPU topology in a CPU model is done by setting the CPU flag +``ctop`` to ``on`` like in: + +.. code-block:: bash + + -cpu gen16b,ctop=on + +Having the topology disabled by default allows migration between +old and new QEMU without adding new flags. + +Default topology usage +---------------------- +
Quoted 8 lines
docs/system/s390x/cpu-topology.rst line 55
Quoted 6 lines
docs/system/s390x/cpu-topology.rst new file +6
-0+The CPU Topology, can be specified on the QEMU command line +with the ``-smp`` or the ``-device`` QEMU command arguments +without using any new attributes. +In this case, the topology will be calculated by simply adding +to the topology the cores based on the core-id starting with +core-0 at position 0 of socket-0, book-0, drawer-0 with default... here you don't mention "nodes" anymore (which you still mentioned at the beginning of the doc).
I removed it
Quoted 7 lines
docs/system/s390x/cpu-topology.rst line 59
Quoted 5 lines
docs/system/s390x/cpu-topology.rst new file +4
-0+modifier attributes: horizontal polarity and no dedication. + +In the following machine we define 8 sockets with 4 cores each. +Note that S390 QEMU machines do not implement multithreading.I'd use s390x instead of S390 to avoid confusion with 31-bit machines.
OK
Quoted 32 lines
Quoted 32 lines
+.. code-block:: bash
docs/system/s390x/cpu-topology.rst new file +30
-0+ + $ qemu-system-s390x -m 2G \ + -cpu gen16b,ctop=on \ + -smp cpus=5,sockets=8,cores=4,maxcpus=32 \ + -device host-s390x-cpu,core-id=14 \ + +New CPUs can be plugged using the device_add hmp command like in: + +.. code-block:: bash + + (qemu) device_add gen16b-s390x-cpu,core-id=9 + +The core-id defines the placement of the core in the topology by +starting with core 0 in socket 0 up to maxcpus. + +In the example above: + +* There are 5 CPUs provided to the guest with the ``-smp`` command line + They will take the core-ids 0,1,2,3,4 + As we have 4 cores in a socket, we have 4 CPUs provided + to the guest in socket 0, with core-ids 0,1,2,3. + The last cpu, with core-id 4, will be on socket 1. + +* the core with ID 14 provided by the ``-device`` command line will + be placed in socket 3, with core-id 14 + +* the core with ID 9 provided by the ``device_add`` qmp command will + be placed in socket 2, with core-id 9 + +Note that the core ID is machine wide and the CPU TLE masks provided
Quoted 8 lines
docs/system/s390x/cpu-topology.rst line 97
Quoted 6 lines
docs/system/s390x/cpu-topology.rst new file +6
-0+by the STSI instruction will be written in a big endian mask: + +* in socket 0: 0xf000000000000000 (core id 0,1,2,3) +* in socket 1: 0x0800000000000000 (core id 4) +* in socket 2: 0x0040000000000000 (core id 9) +* in socket 3: 0x0002000000000000 (core id 14)Hmm, who's supposed to be the audience of this documentation? Users? Developers? For a doc in docs/system/ I'd expect this to be a documentation for users, so this seems to be way too much of implementation detail here already. If this is supposed to be a doc for developers instead, the file should likely rather go into doc/devel/ instead. Or maybe you want both? ... then you should split the information in here in two files, I think, one in docs/system/ and one in docs/devel/ .
I am not sure in devel there is all doc on QAPI interface not on commands. On the other hand the QAPI seems to have its own way to document the commands.
So what I write here is more detailed than in the QAPI documentation. May be I better write these details there and suppress them here, just naming the command, info and event without details.
Quoted 31 lines
Quoted 31 lines
docs/system/s390x/cpu-topology.rst new file +21
-0+Defining the topology on command line +------------------------------------- + +The topology can be defined entirely during the CPU definition, +with the exception of CPU 0 which must be defined with the -smp +argument. + +For example, here we set the position of the cores 1,2,3 on +drawer 1, book 1, socket 2 and cores 0,9 and 14 on drawer 0, +book 0, socket 0 with all horizontal polarity and not dedicated. +The core 4, will be set on its default position on socket 1 +(since we have 4 core per socket) and we define it with dedication and +vertical high entitlement. + +.. code-block:: bash + + $ qemu-system-s390x -m 2G \ + -cpu gen16b,ctop=on \ + -smp cpus=1,sockets=8,cores=4,maxcpus=32 \ + \ + -devicegen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=1 \
+ -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=2 \
+ -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=3 \
+ \
+ -device gen16b-s390x-cpu,drawer-id=0,book-id=0,socket-id=0,core-id=9 \
+ -device
Quoted 8 lines
docs/system/s390x/cpu-topology.rst line 129
Quoted 6 lines
gen16b-s390x-cpu,drawer-id=0,book-id=0,socket-id=0,core-id=14 \
+ \
+ -device gen16b-s390x-cpu,core-id=4,dedicated=on,polarity=3 \docs/system/s390x/cpu-topology.rst new file +3
-0+ +Polarity and dedication +-----------------------Since you are using the terms "polarity" and "dedication" in the previous paragraphs already, it might make sense to move this section here earlier in the document to teach the users about this first, before using the terms in the other paragraphs?
yes
Quoted 10 lines
docs/system/s390x/cpu-topology.rst line 137
Quoted 8 lines
docs/system/s390x/cpu-topology.rst new file +7
-0+Polarity can be of two types: horizontal or vertical. + +The horizontal polarization specifies that all guest's vCPUs get +almost the same amount of provisioning of real CPU by the host. + +The vertical polarization specifies that guest's vCPU can get +different real CPU provisions:Please remove one space between "different" and "real".
OK
Quoted 8 lines
Quoted 6 lines
+- a vCPU with Vertical high entitlement specifies that this + vCPU gets 100% of the real CPU provisioning.
+
+- a vCPU with Vertical medium entitlement specifies that this + vCPU shares the real CPU with other vCPU."with *one* other vCPU" or rather "with other vCPU*s*" ?
thx, vCPUs
Quoted 12 lines
Quoted 12 lines
docs/system/s390x/cpu-topology.rst new file +11
-0+ +- a vCPU with Vertical low entitlement specifies that this + vCPU only get real CPU provisioning when no other vCPU need it. + +In the case a vCPU with vertical high entitlement does not use +the real CPU, the unused "slack" can be dispatched to other vCPU +with medium or low entitlement. + +The host indicates to the guest how the real CPU resources are +provided to the vCPUs through the SYSIB with two polarity bits +inside the CPU TLE.
Quoted 9 lines
docs/system/s390x/cpu-topology.rst line 160
Quoted 6 lines
docs/system/s390x/cpu-topology.rst new file +6
-0+ +Bits d - Polarization +0 0 Horizontal +0 1 Vertical low entitlement +1 0 Vertical medium entitlement +1 1 Vertical high entitlementThat SYSIB stuff looks like details for developers again ... I think you should either add more explanations here (I assume the average user does not know the term SYSIB), move it to a separate developers file or drop it.
OK, I drop it
Quoted 6 lines
Quoted 6 lines
docs/system/s390x/cpu-topology.rst new file +6
-0+A subsystem reset puts all vCPU of the configuration into the +horizontal polarization. + +The admin specifies the dedicated bit when the vCPU is dedicated +to a single real CPU. +
Quoted 8 lines
docs/system/s390x/cpu-topology.rst line 173
Quoted 6 lines
docs/system/s390x/cpu-topology.rst new file +6
-0+As for the Linux admin, the dedicated bit is an indication on the +affinity of a vCPU for a real CPU while the entitlement indicates the +sharing or exclusivity of use. + +QAPI interface for topology +---------------------------A "grep -r QAPI docs/system/" shows hardly any entries there. I think QAPI documentation should go into docs/devel instead.
discussion above.
I enhance the QAPI internal doc or I move it into devel.
Quoted 107 lines
Quoted 11 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+Let's start QEMU with the following command: + +.. code-block:: bash + + sudo /usr/local/bin/qemu-system-s390x \ + -enable-kvm \ + -cpu z14,ctop=on \ + -smp 1,drawers=3,books=3,sockets=2,cores=2,maxcpus=36 \ + \ + -device z14-s390x-cpu,core-id=19,polarity=3 \docs/system/s390x/cpu-topology.rst line 194
Quoted 10 lines
docs/system/s390x/cpu-topology.rst new file +10
-0+ -device z14-s390x-cpu,core-id=11,polarity=1 \ + -device z14-s390x-cpu,core-id=12,polarity=3 \ + ... + +and see the result when using of the QAPI interface. + +query-topology ++++++++++++++++ + +The command cpu-topology allows the admin to query the topologyNot sure if the average admin runs QMP directly ... maybe rather talk about the "upper layers like libvirt" here or something similar.
Quoted 83 lines
docs/system/s390x/cpu-topology.rst new file +83
-0+tree and modifier for all configured vCPU. + +.. code-block:: QMP + + -> { "execute": "query-topology" } + {"return": + [ + { + "origin": 0, + "dedicated": false, + "book": 0, + "socket": 0, + "drawer": 0, + "polarity": 0, + "mask": "0x8000000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 2, + "socket": 1, + "drawer": 0, + "polarity": 1, + "mask": "0x0010000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 0, + "socket": 0, + "drawer": 1, + "polarity": 3, + "mask": "0x0008000000000000" + }, + { + "origin": 0, + "dedicated": false, + "book": 1, + "socket": 1, + "drawer": 1, + "polarity": 3, + "mask": "0x0000100000000000" + } + ] + } + +change-topology ++++++++++++++++ + +The command change-topology allows the admin to modify the topology +tree or the topology modifiers of a vCPU in the configuration. + +.. code-block:: QMP + + -> { "execute": "change-topology", + "arguments": { + "core": 11, + "socket": 0, + "book": 0, + "drawer": 0, + "polarity": 0, + "dedicated": false + } + } + <- {"return": {}} + + +event POLARITY_CHANGE ++++++++++++++++++++++ + +When a guest is requesting a modification of the polarity, +QEMU sends a POLARITY_CHANGE event. + +When requesting the change, the guest only specifies horizontal or +vertical polarity. +The dedication and fine grain vertical entitlement depends on admin +to set according to its response to this event. + +Note that a vertical polarized dedicated vCPU can only have a high +entitlement, this gives 6 possibilities for a vCPU polarity: + +- Horizontal +- Horizontal dedicated
Quoted 8 lines
docs/system/s390x/cpu-topology.rst line 283
Quoted 6 lines
+- Vertical low +- Vertical medium +- Vertical high +- Vertical high dedicateddocs/system/s390x/cpu-topology.rst new file +2
-0+ +Example of the event received when the guest issues PTF(0) to requestPlease mention that PTF is a CPU instruction (and provide the full name).
Yes, thanks.
regards,
Pierre
Quoted 3 lines
Thomas
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen
Re: [PATCH v14 11/11] docs/s390x/cpu topology: document s390x cpu topology
In reply to Pierre MorelQuoted 16 lines · Pierre Morel
Add some basic examples for the definition of cpu topology in s390x.
Signed-off-by Pierre Morel <[email protected]>--- docs/system/s390x/cpu-topology.rst | 292 +++++++++++++++++++++++++++++ docs/system/target-s390x.rst | 1 + 2 files changed, 293 insertions(+) create mode 100644 docs/system/s390x/cpu-topology.rstdocs/system/s390x/cpu-topology.rst new file +0
-0
docs/system/s390x/cpu-topology.rst line 5
Quoted 5 lines
docs/system/s390x/cpu-topology.rst new file +5
-0@@ -0,0 +1,292 @@ +CPU Topology on s390x +===================== + +CPU Topology on S390x provides up to 5 levels of topology containers: +nodes, drawers, books, sockets and CPUs.
The last level should be 'cores' not CPUs for QEMU terminology.
docs/system/s390x/cpu-topology.rst line 9
Quoted 4 lines
docs/system/s390x/cpu-topology.rst new file +4
-0+While the higher level containers, Containers Topology List Entries, +(Containers TLE) define a tree hierarchy, the lowest level of topology +definition, the CPU Topology List Entry (CPU TLE), provides the placement +of the CPUs inside the parent container.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v14 11/11] docs/s390x/cpu topology: document s390x cpu topology
Quoted 11 lines · Daniel P. Berrangé
Quoted 10 lines · Pierre Morel
Add some basic examples for the definition of cpu topology in s390x.
Signed-off-by Pierre Morel <[email protected]>--- docs/system/s390x/cpu-topology.rst | 292 +++++++++++++++++++++++++++++ docs/system/target-s390x.rst | 1 + 2 files changed, 293 insertions(+)create mode 100644
docs/system/s390x/cpu-topology.rst
Quoted 13 lines
docs/system/s390x/cpu-topology.rst line 5
Quoted 11 lines
docs/system/s390x/cpu-topology.rst new file +5
-0@@ -0,0 +1,292 @@ +CPU Topology on s390x +===================== + +CPU Topology on S390x provides up to 5 levels of topology containers: +nodes, drawers, books, sockets and CPUs.The last level should be 'cores' not CPUs for QEMU terminology.
Yes, thanks.
Regards,
Pierre
Signature · 2 lines
Pierre Morel IBM Lab Boeblingen