Skip to contentSkip to conversation

s390x: CPU Topology

PATCH Superseded Nina Schoetterl-Glausch 2 participants 38 messages Sep 14, 2023 – Sep 25, 2023 Arm/Amlogic Meson SoC support

v23 of 26 Superseded Latest is v26 →

lore
Share & tools
lore
#0 lore raw

v23 cover s390x: CPU Topology

Changes since v22 (range-diff below):

* fix compile issues (thanks Thomas, Cédric)
* incorporate feedback (thanks Thomas!), most notably
* forbid books and drawers in older machine types
* changed implementation of TLE entry ordering
* also got rid of another ERRP_GUARD in s390_change_topology
* pick up R-b's (thanks Thomas)
* misc minor stuff

Changes since v21:

* fix ordering of entries in topology list
* don't leak topology list on error condition in insert_stsi_15_1_x
* make entitlement, dedication optional in query-cpu-info-fast
* rename query-cpu-polarization to query-s390x-cpu-polarization
* documentation changes
* add tests of guest view to avocado tests
* require KVM in avocado tests
* increase timeout in tests
* bump version in comments documenting availability to 8.2
* rename some symbols
* picked up R-b's (thanks Thomas)
* minor stuff, typos

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, entitlement 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 entitlement is medium
Default dedication is not dedicated.

- Machine polarization default to horizontal

Dynamic topology modification
-----------------------------

QAPI interface is extended with:
- a command: 'set-cpu-topology'
- a query: 'query-cpu-polarization'
- a query: extension of qmp 'query-cpus-fast'
- a query: extension of hmp 'hotpluggable-cpus'
- an event: 'CPU_POLARITY_CHANGE'

New command and interface are specified as unstable.

The admin may use query-cpus-fast to verify the topology provided to the guest and set-cpu-topology to modify it.

The event CPU_POLARITY_CHANGE is sent when the guest successfuly uses the PTF(2) 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.

This series provide 12 avocado tests using Fedora-35 kernel and initrd image.

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.

Previous changes:
Since v20:

- changed name of target/s390/kvm/cpu_topology to
target/s390/kvm/stsi-topology
(Thomas, Cedric)

- moved the TLE list head from a global to a local in insert_stsi_15_1_x()
(Nina)

- cleaning and merging some of the avocado tests
(Nina)

- Several cleanings
(Cedric, Thomas, Nina)

- moved setting of entitlement and dedicated from disapeared cpustate_to_cpuinfo_s390() to new s390_query_cpu_fast()

- small changes to documentation to reflect last changes using enum instead of int for polarization.
0 -> horizontal and 1 -> vertical

Since v19:

- use enum to specify the entitlement
(Nina)

- Change default entitlement to "auto"

- suppress skip_basis in avocado tests
(after comment from Cedric)

- Correction of the documentation
(Cedric)

- better code organization for s390_topology_add_core_to_socket and s390_socket_nb
(Cedric)

- Changed Copyright to respect IBM policy
(Nina)

- set vertical_polarization back into s390_topology (Nina)

Since v18:

- Changed default entitlement to S390_CPU_ENTITLEMENT__MAX because no default can be correct.

- added polarization entry to the S390CcwMachineState which allow to suppress shadow entitlement

- Suppress shadow entitlement
(Nina)

- Added query-cpu-polarization

- Added more avocado tests

- modified cpu_hierarchy_to_string to look better
(Nina)

Since v17:

- bug correction in handling PTF

- added avocado tests
(Thomas)

- Change comments on QEMU machine to 8.1

Since v16:

- documentation, split, bug correction and rephrasing (Nina, Thomas)

- create machine-common.json

- use of entitlement_shadow to keep track of the entitlement

- adding drawers and books to query-hotpluggable-cpus

- keep hmp interface for set-cpu-topology for a future series

Since v15:

- Use Enum for polarity and entitlement
(Nina)

- move kvm_vm_enable_cap(KVM_CAP_S390_CPU_TOPOLOGY) to kvm_arch_init()
(Thomas)

- Make all CPU attributes optional for set-cpu-topology monitor command
(Thomas, Nina)

- Change use of the prefix "x-" to the use of feature unstable to declare set-cpu-topology as unstable.
(Nina)

- Make CPU_POLARITY_CHANGE even as unstable
(Nina)

- Documentation update
(Thomas, Nina)

Since v14:

- move the ordering of TLE to just before filling the SYSIB, optimize TLE ordering to be done on need only. (Cedric in previous series)

- remove 'query-topology' and instead extend 'query-cpus-fast' (Daniel)

- rename POLARITY_CHANGE to CPU_POLARITY_CHANGE
(Thomas)

- Divers bugs correction and doc changes
(Thomas, Nina)

- Separate topology and entitlement, simplify pft handling (Nina)

- add the resetting of all CPU to horizontal polarity once implementing PTF interpretation

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)

Pierre Morel (20):
CPU topology: extend with s390 specifics
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: activate CPU topology qapi/s390x/cpu topology: set-cpu-topology qmp command
machine: adding s390 topology to query-cpu-fast
machine: adding s390 topology to info hotpluggable-cpus qapi/s390x/cpu topology: CPU_POLARIZATION_CHANGE qapi event qapi/s390x/cpu topology: query-cpu-polarization qmp command docs/s390x/cpu topology: document s390x cpu topology tests/avocado: s390x cpu topology core tests/avocado: s390x cpu topology polarization tests/avocado: s390x cpu topology entitlement tests tests/avocado: s390x cpu topology test dedicated CPU tests/avocado: s390x cpu topology test socket full tests/avocado: s390x cpu topology dedicated errors tests/avocado: s390x cpu topology bad move

 MAINTAINERS                         |  10 +
 docs/devel/index-internals.rst      |   1 +
 docs/devel/s390-cpu-topology.rst    | 170 ++++++++++
 docs/system/s390x/cpu-topology.rst  | 242 ++++++++++++++
 docs/system/target-s390x.rst        |   1 +
 qapi/machine-common.json            |  21 ++
 qapi/machine-target.json            | 113 +++++++
 qapi/machine.json                   |  28 +-
 include/hw/boards.h                 |  10 +-
 include/hw/qdev-properties-system.h |   4 +
 include/hw/s390x/cpu-topology.h     |  78 +++++
 include/hw/s390x/s390-virtio-ccw.h  |   6 +
 include/hw/s390x/sclp.h             |   4 +-
 target/s390x/cpu.h                  |  82 +++++
 target/s390x/kvm/kvm_s390x.h        |   1 +
 hw/core/machine-hmp-cmds.c          |   6 +
 hw/core/machine-smp.c               |  48 ++-
 hw/core/machine.c                   |   4 +
 hw/core/qdev-properties-system.c    |  13 +
 hw/s390x/cpu-topology.c             | 469 ++++++++++++++++++++++++++++
 hw/s390x/s390-virtio-ccw.c          |  29 +-
 hw/s390x/sclp.c                     |   5 +
 softmmu/vl.c                        |   6 +
 target/s390x/cpu-sysemu.c           |  13 +
 target/s390x/cpu.c                  |  16 +
 target/s390x/cpu_models.c           |   1 +
 target/s390x/kvm/kvm.c              |  42 ++-
 target/s390x/kvm/stsi-topology.c    | 338 ++++++++++++++++++++
 hw/s390x/meson.build                |   1 +
 qapi/meson.build                    |   1 +
 qemu-options.hx                     |   7 +-
 target/s390x/kvm/meson.build        |   3 +-
 tests/avocado/s390_topology.py      | 439 ++++++++++++++++++++++++++
 33 files changed, 2193 insertions(+), 19 deletions(-)
 create mode 100644 docs/devel/s390-cpu-topology.rst
 create mode 100644 docs/system/s390x/cpu-topology.rst
 create mode 100644 qapi/machine-common.json
 create mode 100644 include/hw/s390x/cpu-topology.h
 create mode 100644 hw/s390x/cpu-topology.c
 create mode 100644 target/s390x/kvm/stsi-topology.c
 create mode 100644 tests/avocado/s390_topology.py

Range-diff against v22:
1: c26d3df9f9 ! 1: f2219b7583 CPU topology: extend with s390 specifics
@@ qapi/machine.json
# @thread-id: ID of the underlying host thread
#
-# @props: properties describing to which node/socket/core/thread
--# virtual CPU belongs to, provided if supported by board
+# @props: properties describing to which node/drawer/book/socket/core/thread
-+# virtual CPU belongs to, provided if supported by board
+ # virtual CPU belongs to, provided if supported by board
#
# @target: the QEMU system emulation target, which determines which
- # additional fields will be listed (since 3.0)
@@
#
# @node-id: NUMA node ID the CPU belongs to
@@ hw/s390x/s390-virtio-ccw.c: static void ccw_machine_class_init(ObjectClass *oc,
assert(!mc->get_hotplug_handler);
mc->get_hotplug_handler = s390_get_hotplug_handler; mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
+@@ hw/s390x/s390-virtio-ccw.c: static void ccw_machine_8_1_class_options(MachineClass *mc)
+ {
+ ccw_machine_8_2_class_options(mc);
+ compat_props_add(mc->compat_props, hw_compat_8_1, hw_compat_8_1_len);
++ mc->smp_props.drawers_supported = false;
++ mc->smp_props.books_supported = false;
+ }
+ DEFINE_CCW_MACHINE(8_1, "8.1", false);
+

## softmmu/vl.c ##
@@ softmmu/vl.c: static QemuOptsList qemu_smp_opts = {
2: 6d32f1e3d4 ! 2: 5fae55e5a1 s390x/cpu topology: add topology entries on CPU hotplug
@@ Commit message

+ Reviewed-by: Thomas Huth <[email protected]>

## MAINTAINERS ##
@@ hw/s390x/cpu-topology.c (new)
+ return false;
+ }
+
-+ /* Check if one of the geometry topology is unset */
++ /* If one value is unset all are unset -> calculate defaults */
+ if (env->socket_id < 0) {
-+ /* Calculate default geometry topology attributes */
+ env->socket_id = s390_std_socket(env->core_id, smp);
+ env->book_id = s390_std_book(env->core_id, smp);
+ env->drawer_id = s390_std_drawer(env->core_id, smp);
@@ hw/s390x/cpu-topology.c (new)
+ bool dedicated, Error **errp)
+{
+ CpuTopology *smp = &current_machine->smp;
-+ ERRP_GUARD();
+
+ if (socket_id >= smp->sockets) {
+ error_setg(errp, "Unavailable socket: %d", socket_id);
@@ hw/s390x/cpu-topology.c (new)
+ */
+void s390_topology_setup_cpu(MachineState *ms, S390CPU *cpu, Error **errp) +{
-+ ERRP_GUARD();
+ int entry;
+
+ /*
3: ab54bb7881 ! 3: c775d90904 target/s390x/cpu topology: handle STSI(15) and build the SYSIB

    @@ Commit message
         (SYSIB) is built from the list of pre-ordered topology entries.
     
         Signed-off-by: Pierre Morel <[email protected]>
    +    Reviewed-by: Nina Schoetterl-Glausch <[email protected]>
         Co-developed-by: Nina Schoetterl-Glausch <[email protected]>
         Signed-off-by: Nina Schoetterl-Glausch <[email protected]>
     
    @@ qapi/machine-target.json
     +{ 'enum': 'CpuS390Polarization',
     +  'prefix': 'S390_CPU_POLARIZATION',
     +  'data': [ 'horizontal', 'vertical' ],
    -+    'if': { 'all': [ 'TARGET_S390X' , 'CONFIG_KVM' ] }
    ++    'if': 'TARGET_S390X'
     +}
     
      ## include/hw/s390x/cpu-topology.h ##
    @@ include/hw/s390x/cpu-topology.h
      
     +#define S390_TOPOLOGY_CPU_IFL   0x03
     +
    -+typedef union s390_topology_id {
    -+    uint64_t id;
    -+    struct {
    -+        uint8_t _reserved0;
    -+        uint8_t drawer;
    -+        uint8_t book;
    -+        uint8_t socket;
    -+        uint8_t type;
    -+        uint8_t inv_polarization;
    -+        uint8_t not_dedicated;
    -+        uint8_t origin;
    -+    };
    ++typedef struct s390_topology_id {
    ++    uint8_t sentinel;
    ++    uint8_t drawer;
    ++    uint8_t book;
    ++    uint8_t socket;
    ++    uint8_t type;
    ++    uint8_t vertical:1;
    ++    uint8_t entitlement:2;
    ++    uint8_t dedicated;
    ++    uint8_t origin;
     +} s390_topology_id;
     +
     +typedef struct S390TopologyEntry {
    @@ target/s390x/cpu.h: typedef union SysIB {
     + *
     + * 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:
    ++ * the CPU address origin field of the CPU TLE like in:
     + * CPU address = origin * 64 + bit position within the mask
    -+ *
     + */
     +/* Container type Topology List Entry */
     +typedef struct SYSIBContainerListEntry {
    @@ target/s390x/kvm/stsi-topology.c (new)
     +    s390_topology_id topology_id = entry->id;
     +
     +    tle->nl = 0;
    -+    tle->flags = 3 - topology_id.inv_polarization;
    -+    if (!topology_id.not_dedicated) {
    ++    tle->flags = 0;
    ++    if (topology_id.vertical) {
    ++        tle->flags |= topology_id.entitlement;
    ++    }
    ++    if (topology_id.dedicated) {
     +        tle->flags |= SYSIB_TLE_DEDICATED;
     +    }
     +    tle->type = topology_id.type;
    @@ target/s390x/kvm/stsi-topology.c (new)
     +
     +/**
     + * setup_stsi:
    -+ * sysib: pointer to a SysIB to be filled with SysIB_151x data
    -+ * level: Nested level specified by the guest
    ++ * @topology_list: ordered list of groups of CPUs with same properties
    ++ * @sysib: pointer to a SysIB to be filled with SysIB_151x data
    ++ * @level: Nested level specified by the guest
     + *
     + * Setup the SYSIB for STSI 15.1, the header as well as the description
     + * of the topology.
    @@ target/s390x/kvm/stsi-topology.c (new)
     + */
     +static s390_topology_id s390_topology_from_cpu(S390CPU *cpu)
     +{
    -+    s390_topology_id topology_id = {0};
    ++    s390_topology_id topology_id = {
    ++        .drawer = cpu->env.drawer_id,
    ++        .book = cpu->env.book_id,
    ++        .socket = cpu->env.socket_id,
    ++        .type = S390_TOPOLOGY_CPU_IFL,
    ++        .vertical = s390_topology.polarization == S390_CPU_POLARIZATION_VERTICAL,
    ++        .entitlement = cpu->env.entitlement,
    ++        .dedicated = cpu->env.dedicated,
    ++        .origin = cpu->env.core_id / 64,
    ++    };
     +
    -+    topology_id.drawer = cpu->env.drawer_id;
    -+    topology_id.book = cpu->env.book_id;
    -+    topology_id.socket = cpu->env.socket_id;
    -+    topology_id.type = S390_TOPOLOGY_CPU_IFL;
    -+    topology_id.not_dedicated = !cpu->env.dedicated;
    ++    return topology_id;
    ++}
     +
    -+    topology_id.inv_polarization = 3;
    -+    if (s390_topology.polarization == S390_CPU_POLARIZATION_VERTICAL) {
    -+        topology_id.inv_polarization -= cpu->env.entitlement;
    -+    }
    ++/**
    ++ * s390_topology_id_cmp:
    ++ * @l: first s390_topology_id
    ++ * @r: second s390_topology_id
    ++ *
    ++ * Compare two topology ids according to the sorting order specified by the PoP.
    ++ *
    ++ * Returns a negative number if the first id is less than, 0 if it is equal to
    ++ *     and positive if it is larger than the second id.
    ++ */
    ++static int s390_topology_id_cmp(const s390_topology_id *l,
    ++                                const s390_topology_id *r)
    ++{
    ++    /*
    ++     * lexical order, compare less significant values only if more significant
    ++     * ones are equal
    ++     */
    ++    return l->sentinel - r->sentinel ?:
    ++           l->drawer - r->drawer ?:
    ++           l->book - r->book ?:
    ++           l->socket - r->socket ?:
    ++           l->type - r->type ?:
    ++           -1 * (l->vertical - r->vertical) ?:
    ++           -1 * (l->entitlement - r->entitlement) ?:
    ++           -1 * (l->dedicated - r->dedicated) ?:
    ++           l->origin - r->origin;
    ++}
     +
    -+    topology_id.origin = cpu->env.core_id / 64;
    ++static bool s390_topology_id_eq(const s390_topology_id *l,
    ++                               const s390_topology_id *r)
    ++{
    ++    return !s390_topology_id_cmp(l, r);
    ++}
     +
    -+    return topology_id;
    ++static bool s390_topology_id_lt(const s390_topology_id *l,
    ++                                const s390_topology_id *r)
    ++{
    ++    return s390_topology_id_cmp(l, r) < 0;
     +}
     +
     +/**
     + * s390_topology_fill_list_sorted:
    ++ * @topology_list: list to fill
     + *
     + * Loop over all CPU and insert it at the right place
     + * inside the TLE entry list.
    @@ target/s390x/kvm/stsi-topology.c (new)
     +static void s390_topology_fill_list_sorted(S390TopologyList *topology_list)
     +{
     +    CPUState *cs;
    -+    S390TopologyEntry sentinel;
    ++    S390TopologyEntry sentinel = { .id.sentinel = 1 };
     +
     +    QTAILQ_INIT(topology_list);
     +
    -+    sentinel.id.id = cpu_to_be64(UINT64_MAX);
     +    QTAILQ_INSERT_HEAD(topology_list, &sentinel, next);
     +
     +    CPU_FOREACH(cs) {
     +        s390_topology_id id = s390_topology_from_cpu(S390_CPU(cs));
    -+        S390TopologyEntry *entry, *tmp;
    ++        S390TopologyEntry *entry = NULL, *tmp;
     +
     +        QTAILQ_FOREACH(tmp, topology_list, next) {
    -+            if (id.id == tmp->id.id) {
    ++            if (s390_topology_id_eq(&id, &tmp->id)) {
     +                entry = tmp;
     +                break;
    -+            } else if (be64_to_cpu(id.id) < be64_to_cpu(tmp->id.id)) {
    ++            } else if (s390_topology_id_lt(&id, &tmp->id)) {
     +                entry = g_malloc0(sizeof(*entry));
    -+                entry->id.id = id.id;
    ++                entry->id = id;
     +                QTAILQ_INSERT_BEFORE(tmp, entry, next);
     +                break;
     +            }
     +        }
    ++        assert(entry);
     +        s390_topology_add_cpu_to_entry(entry, S390_CPU(cs));
     +    }
     +
    @@ target/s390x/kvm/stsi-topology.c (new)
     +
     +/**
     + * insert_stsi_15_1_x:
    -+ * cpu: the CPU doing the call for which we set CC
    -+ * sel2: the selector 2, containing the nested level
    -+ * addr: Guest logical address of the guest SysIB
    -+ * ar: the access register number
    ++ * @cpu: the CPU doing the call for which we set CC
    ++ * @sel2: the selector 2, containing the nested level
    ++ * @addr: Guest logical address of the guest SysIB
    ++ * @ar: the access register number
    ++ * @ra: the return address
     + *
     + * Emulate STSI 15.1.x, that is, perform all necessary checks and
     + * fill the SYSIB.
 4:  67278aa3a0 =  4:  7c68edeb44 s390x/sclp: reporting the maximum nested topology entries
 5:  ce87494fd1 =  5:  78d0a953c9 s390x/cpu topology: resetting the Topology-Change-Report
 6:  c56178005a =  6:  f15c30a1b9 s390x/cpu topology: interception of PTF instruction
 7:  e56149e34f =  7:  837eb0924f target/s390x/cpu topology: activate CPU topology
 8:  c94943deef !  8:  394e0ae6c0 qapi/s390x/cpu topology: set-cpu-topology qmp command

@@ qapi/machine-target.json
#
@@
'data': [ 'horizontal', 'vertical' ],
- 'if': { 'all': [ 'TARGET_S390X' , 'CONFIG_KVM' ] }
+ 'if': 'TARGET_S390X'
}
+
+##
@@ hw/s390x/cpu-topology.c: static bool s390_topology_check(uint16_t socket_id, uin
+ * tree or the topology attributes change.
+ */
+static bool s390_topology_need_report(S390CPU *cpu, int drawer_id,
-+ int book_id, int socket_id,
-+ uint16_t entitlement, bool dedicated)
++ int book_id, int socket_id,
++ uint16_t entitlement, bool dedicated)
+{
+ return cpu->env.drawer_id != drawer_id ||
+ cpu->env.book_id != book_id ||
@@ hw/s390x/cpu-topology.c: void s390_topology_setup_cpu(MachineState *ms, S390CPU
+ int new_socket_entry;
+ bool report_needed;
+ S390CPU *cpu;
-+ ERRP_GUARD();
+
+ cpu = s390_cpu_addr2state(core_id);
+ if (!cpu) {
@@ hw/s390x/cpu-topology.c: void s390_topology_setup_cpu(MachineState *ms, S390CPU
+
+ /*
+ * When the user specifies the entitlement as 'auto' on the command line,
-+ * qemu will set the entitlement as:
++ * QEMU will set the entitlement as:
+ * Medium when the CPU is not dedicated.
+ * High when dedicated is true.
+ */
-+ if (!has_entitlement || (entitlement == S390_CPU_ENTITLEMENT_AUTO)) {
++ if (!has_entitlement || entitlement == S390_CPU_ENTITLEMENT_AUTO) {
+ if (dedicated) {
+ entitlement = S390_CPU_ENTITLEMENT_HIGH;
+ } else {
@@ hw/s390x/cpu-topology.c: void s390_topology_setup_cpu(MachineState *ms, S390CPU
+ bool has_dedicated, bool dedicated,
+ Error **errp)
+{
-+ ERRP_GUARD();
-+
+ if (!s390_has_topology()) {
+ error_setg(errp, "This machine doesn't support topology");
+ return;
9: 516a727ef5 ! 9: a4b6738536 machine: adding s390 topology to query-cpu-fast
@@ Commit message

+ Reviewed-by: Thomas Huth <[email protected]>

## qapi/machine.json ##
10: 4b8bfddea9 ! 10: c74f719b43 machine: adding s390 topology to info hotpluggable-cpus
@@ Commit message

+ Reviewed-by: Thomas Huth <[email protected]>

## hw/core/machine-hmp-cmds.c ##
@@ hw/core/machine-hmp-cmds.c: void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)

11:  6584a655e9 = 11:  a2bf4b54b3 qapi/s390x/cpu topology: CPU_POLARIZATION_CHANGE qapi event
12:  7e18ccdbcc ! 12:  6a9e834176 qapi/s390x/cpu topology: query-cpu-polarization qmp command

@@ Commit message

+ Reviewed-by: Nina Schoetterl-Glausch <[email protected]>

13: 810118478c ! 13: 24d2a3507b docs/s390x/cpu topology: document s390x cpu topology
@@ Commit message

+ Reviewed-by: Thomas Huth <[email protected]>

## MAINTAINERS ##
@@ docs/devel/s390-cpu-topology.rst (new)
+ -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,entitlement=high \
+ -device z14-s390x-cpu,core-id=11,entitlement=low \
+ -device z14-s390x-cpu,core-id=112,entitlement=high \
@@ docs/system/s390x/cpu-topology.rst (new)
+ 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 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
14: 717f901bb0 ! 14: bc1adfbdb7 tests/avocado: s390x cpu topology core
@@ Commit message
the QMP results in query-cpus-fast for various CPU topology.

+ Reviewed-by: Nina Schoetterl-Glausch <[email protected]>
+ Co-developed-by: Nina Schoetterl-Glausch <[email protected]>
+ Signed-off-by: Nina Schoetterl-Glausch <[email protected]>

## MAINTAINERS ##
@@ MAINTAINERS: F: hw/s390x/cpu-topology.c
@@ tests/avocado/s390_topology.py (new)
+ self.assertEqual(res['return'], {})
+ self.check_topology(0, 2, 0, 0, 'low', False)
+
-+ def test_hotplug_full(self):
++ def test_dash_device(self):
+ """
-+ This test verifies that a hotplugged defined with '-device'
-+ command line argument finds its right place inside the topology.
++ This test verifies that a CPU defined with the '-device'
++ command line option finds its right place inside the topology.
+
+ :avocado: tags=arch:s390x
+ :avocado: tags=machine:s390-ccw-virtio
15: 7c5793cf9b ! 15: d2be50e3a7 tests/avocado: s390x cpu topology polarization
@@ Commit message

+ Reviewed-by: Thomas Huth <[email protected]>
+ Reviewed-by: Nina Schoetterl-Glausch <[email protected]>

## tests/avocado/s390_topology.py ##
@@ tests/avocado/s390_topology.py: def kernel_init(self):
+ exec_command_and_wait_for_pattern(self,
+ """ mount proc -t proc /proc;
+ mount sys -t sysfs /sys;
-+ /bin/cat /sys/devices/system/cpu/dispatching """,
++ cat /sys/devices/system/cpu/dispatching """,
+ '0')
+
def test_single(self):
"""
This test checks the simplest topology with a single CPU.
-@@ tests/avocado/s390_topology.py: def test_hotplug_full(self):
+@@ tests/avocado/s390_topology.py: def test_dash_device(self):
self.check_topology(3, 1, 1, 1, 'high', False) self.check_topology(4, 1, 1, 1, 'medium', False) self.check_topology(5, 2, 1, 1, 'high', True)
@@ tests/avocado/s390_topology.py: def test_hotplug_full(self):
+ f'echo {dispatching} > /sys/devices/system/cpu/dispatching')
+ self.vm.event_wait('CPU_POLARIZATION_CHANGE', self.event_timeout)
+ exec_command_and_wait_for_pattern(self,
-+ '/bin/cat /sys/devices/system/cpu/dispatching', dispatching)
++ 'cat /sys/devices/system/cpu/dispatching', dispatching)
+
+
+ def test_polarization(self):
16: f1aa5e3d91 ! 16: 4ba53284b1 tests/avocado: s390x cpu topology entitlement tests
@@ Commit message
view, depending on the polarization.

+ Reviewed-by: Nina Schoetterl-Glausch <[email protected]>

@@ tests/avocado/s390_topology.py: def test_polarization(self):
+
+
+ def check_polarization(self, polarization):
-+ """
-+ We need the polarization change to get stabilized in kernel
-+ before we check it through the sysfs.
-+ """
++ #We need to wait for the change to have been propagated to the kernel
+ exec_command_and_wait_for_pattern(self,
-+ """ sleep 1 ;
-+ /bin/cat /sys/devices/system/cpu/cpu0/polarization """,
-+ polarization)
++ "\n".join([
++ "timeout 1 sh -c 'while true",
++ 'do',
++ ' syspath="/sys/devices/system/cpu/cpu0/polarization"',
++ ' polarization="$(cat "$syspath")" || exit',
++ f' if [ "$polarization" = "{polarization}" ]; then',
++ ' exit 0',
++ ' fi',
++ ' sleep 0.01',
++ #searched for strings mustn't show up in command, '' to obfuscate
++ "done' && echo succ''ess || echo fail''ure",
++ ]),
++ "success", "failure")
+
+
+ def test_entitlement(self):
17: 820481f18c ! 17: bfabe0aaf1 tests/avocado: s390x cpu topology test dedicated CPU
@@ Commit message

+ Reviewed-by: Thomas Huth <[email protected]>
+ Reviewed-by: Nina Schoetterl-Glausch <[email protected]>

## tests/avocado/s390_topology.py ##

18:  d1efe180f3 = 18:  32009fe084 tests/avocado: s390x cpu topology test socket full
19:  568de9fef9 = 19:  e607efc139 tests/avocado: s390x cpu topology dedicated errors
20:  9f9672adc2 = 20:  e600011277 tests/avocado: s390x cpu topology bad move

base-commit: 9ef497755afc252fb8e060c9ea6b0987abfd20b6

Signature · 1 line
2.39.2
#1 lore raw

PATCH v23 1/20 CPU topology: extend with s390 specifics

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

---
 qapi/machine-common.json            | 21 +++++++++++++
 qapi/machine.json                   | 19 ++++++++++--
 include/hw/boards.h                 | 10 +++++-
 include/hw/qdev-properties-system.h |  4 +++
 target/s390x/cpu.h                  |  6 ++++
 hw/core/machine-smp.c               | 48 ++++++++++++++++++++++++-----
 hw/core/machine.c                   |  4 +++
 hw/core/qdev-properties-system.c    | 13 ++++++++
 hw/s390x/s390-virtio-ccw.c          |  4 +++
 softmmu/vl.c                        |  6 ++++
 target/s390x/cpu.c                  |  7 +++++
 qapi/meson.build                    |  1 +
 qemu-options.hx                     |  7 +++--
 13 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 qapi/machine-common.json
qapi/machine-common.json new file +21 -0
new file mode 100644
index 0000000000..e40421bb37
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }
qapi/machine.json +16 -3
index a08b6576ca..a63cb951d2 100644
@@ -9,6 +9,7 @@
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'machine-common.json' }
 
 ##
 # @SysEmuTarget:
@@ -71,7 +72,7 @@
 #
 # @thread-id: ID of the underlying host thread
 #
-# @props: properties describing to which node/socket/core/thread
+# @props: properties describing to which node/drawer/book/socket/core/thread
 #     virtual CPU belongs to, provided if supported by board
 #
 # @target: the QEMU system emulation target, which determines which
@@ -901,7 +902,11 @@
 #
 # @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 (since 8.2)
+#
+# @book-id: book number within drawer/node/board the CPU belongs to (since 8.2)
+#
+# @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)
 #
@@ -912,7 +917,7 @@
 #
 # @thread-id: thread number within core the CPU belongs to
 #
-# Note: currently there are 6 properties that could be present but
+# 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 sync with the
@@ -922,6 +927,8 @@
 ##
 { 'struct': 'CpuInstanceProperties',
   'data': { '*node-id': 'int',
+            '*drawer-id': 'int',
+            '*book-id': 'int',
             '*socket-id': 'int',
             '*die-id': 'int',
             '*cluster-id': 'int',
@@ -1480,6 +1487,10 @@
 #
 # @cpus: number of virtual CPUs in the virtual machine
 #
+# @drawers: number of drawers in the CPU topology (since 8.2)
+#
+# @books: number of books in the CPU topology (since 8.2)
+#
 # @sockets: number of sockets in the CPU topology
 #
 # @dies: number of dies per socket in the CPU topology
@@ -1498,6 +1509,8 @@
 ##
 { 'struct': 'SMPConfiguration', 'data': {
      '*cpus': 'int',
+     '*drawers': 'int',
+     '*books': 'int',
      '*sockets': 'int',
      '*dies': 'int',
      '*clusters': 'int',
include/hw/boards.h +9 -1
index 6c67af196a..6dcfc879eb 100644
@@ -134,12 +134,16 @@ typedef struct {
  * @clusters_supported - whether clusters are supported by the machine
  * @has_clusters - whether clusters are explicitly specified in the user
  *                 provided SMP configuration
+ * @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 has_clusters;
+    bool books_supported;
+    bool drawers_supported;
 } SMPCompatProps;
 
 /**
@@ -310,7 +314,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
@@ -319,6 +325,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/qdev-properties-system.h +4 -0
index 0ac327ae60..e4f8a13afc 100644
@@ -22,6 +22,7 @@ extern const PropertyInfo qdev_prop_audiodev;
 extern const PropertyInfo qdev_prop_off_auto_pcibar;
 extern const PropertyInfo qdev_prop_pcie_link_speed;
 extern const PropertyInfo qdev_prop_pcie_link_width;
+extern const PropertyInfo qdev_prop_cpus390entitlement;
 
 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d)                   \
     DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
@@ -73,5 +74,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
 #define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) \
     DEFINE_PROP(_name, _state, _field, qdev_prop_uuid, QemuUUID)
 
+#define DEFINE_PROP_CPUS390ENTITLEMENT(_n, _s, _f, _d) \
+    DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_cpus390entitlement, \
+                       CpuS390Entitlement)
 
 #endif
target/s390x/cpu.h +6 -0
index 304029e57c..dfcc1aa1fc 100644
@@ -30,6 +30,7 @@
 #include "exec/cpu-defs.h"
 #include "qemu/cpu-float.h"
 #include "tcg/tcg_s390x.h"
+#include "qapi/qapi-types-machine-common.h"
 
 #define ELF_MACHINE_UNAME "S390X"
 
@@ -132,6 +133,11 @@ 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;
+    bool dedicated;
+    CpuS390Entitlement entitlement; /* Used only for vertical polarization */
     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
index da699cf4e1..363ddafc89 100644
@@ -843,6 +843,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,
@@ -1108,6 +1110,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/core/qdev-properties-system.c +13 -0
index 6d5d43eda2..7f50ce9746 100644
@@ -1147,3 +1147,16 @@ const PropertyInfo qdev_prop_uuid = {
     .set   = set_uuid,
     .set_default_value = set_default_uuid_auto,
 };
+
+/* --- s390 cpu entitlement policy --- */
+
+QEMU_BUILD_BUG_ON(sizeof(CpuS390Entitlement) != sizeof(int));
+
+const PropertyInfo qdev_prop_cpus390entitlement = {
+    .name  = "CpuS390Entitlement",
+    .description = "low/medium (default)/high",
+    .enum_table  = &CpuS390Entitlement_lookup,
+    .get   = qdev_propinfo_get_enum,
+    .set   = qdev_propinfo_set_enum,
+    .set_default_value = qdev_propinfo_set_default_value_enum,
+};
hw/s390x/s390-virtio-ccw.c +4 -0
index bfcf64d007..bbb001cb9e 100644
@@ -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;
@@ -842,6 +844,8 @@ static void ccw_machine_8_1_class_options(MachineClass *mc)
 {
     ccw_machine_8_2_class_options(mc);
     compat_props_add(mc->compat_props, hw_compat_8_1, hw_compat_8_1_len);
+    mc->smp_props.drawers_supported = false;
+    mc->smp_props.books_supported = false;
 }
 DEFINE_CCW_MACHINE(8_1, "8.1", false);
 
softmmu/vl.c +6 -0
index 3db4fd2680..eb2450ac24 100644
@@ -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 +7 -0
index df167493c3..74405beb51 100644
@@ -31,6 +31,7 @@
 #include "qapi/qapi-types-machine.h"
 #include "sysemu/hw_accel.h"
 #include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
 #include "fpu/softfloat-helpers.h"
 #include "disas/capstone.h"
 #include "sysemu/tcg.h"
@@ -292,6 +293,12 @@ 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_BOOL("dedicated", S390CPU, env.dedicated, false),
+    DEFINE_PROP_CPUS390ENTITLEMENT("entitlement", S390CPU, env.entitlement,
+                                   S390_CPU_ENTITLEMENT_AUTO),
 #endif
     DEFINE_PROP_END_OF_LIST()
 };
qapi/meson.build +1 -0
index 60a668b343..f81a37565c 100644
@@ -36,6 +36,7 @@ qapi_all_modules = [
   'error',
   'introspect',
   'job',
+  'machine-common',
   'machine',
   'machine-target',
   'migration',
qemu-options.hx +5 -2
index 6be621c232..09889913c3 100644
@@ -272,11 +272,14 @@ 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]\n"
+    "               [,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.39.2
#2 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

qapi/machine-common.json

Quoted 37 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

---
 qapi/machine-common.json            | 21 +++++++++++++
 qapi/machine.json                   | 19 ++++++++++--
 include/hw/boards.h                 | 10 +++++-
 include/hw/qdev-properties-system.h |  4 +++
 target/s390x/cpu.h                  |  6 ++++
 hw/core/machine-smp.c               | 48 ++++++++++++++++++++++++-----
 hw/core/machine.c                   |  4 +++
 hw/core/qdev-properties-system.c    | 13 ++++++++
 hw/s390x/s390-virtio-ccw.c          |  4 +++
 softmmu/vl.c                        |  6 ++++
 target/s390x/cpu.c                  |  7 +++++
 qapi/meson.build                    |  1 +
 qemu-options.hx                     |  7 +++--
 13 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 qapi/machine-common.json
qapi/machine-common.json new file +0 -0
new file mode 100644
index 0000000000..e40421bb37

Why do you need a separate QAPI sub-module?

qapi/machine.json

Quoted 27 lines
qapi/machine-common.json new file +21 -0
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }
qapi/machine.json +0 -0
index a08b6576ca..a63cb951d2 100644
@@ -9,6 +9,7 @@

##
# = Machines

qapi/machine.json line 12

Quoted 4 lines
qapi/machine.json +1 -0
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'machine-common.json' }

Section structure is borked :)

Existing section "Machine" now ends at the new "Machines S390 data types" you pull in here. The contents of below moves from "Machines" to "Machines S390 data types".

Before I explain how to avoid this, I'd like to understand why we need a new sub-module.

qapi/machine.json

Quoted 4 lines
qapi/machine.json +0 -0
 ##
 # @SysEmuTarget:
@@ -71,7 +72,7 @@

##
# @CpuInfoFast:
#
# Information about a virtual CPU
#
# @cpu-index: index of the virtual CPU
#
# @qom-path: path to the CPU object in the QOM tree

qapi/machine.json line 76

Quoted 6 lines
qapi/machine.json +1 -1
 #
 # @thread-id: ID of the underlying host thread
 #
-# @props: properties describing to which node/socket/core/thread
+# @props: properties describing to which node/drawer/book/socket/core/thread
 #     virtual CPU belongs to, provided if supported by board

Is this description accurate?

@props is of type CpuInstanceProperties, shown below. Its documentation describes it as "properties to be used for hotplugging a CPU instance, it should be passed by management with device_add command when a CPU is being hotplugged." Hmm.

I figure details ("node/drawer/book/socket/core/thread") are better left to CpuInstanceProperties.

The "provided if supported by board" part makes no sense to me. If @props is there, it lists the properties we need to provide with device_add. What if it's not there? Same as empty list, i.e. we don't need to provide properties with device_add?

Not your patch's fault, but let's get this in shape if we can.

qapi/machine.json line 907

Quoted 10 lines
qapi/machine.json +3 -1
 #
 # @target: the QEMU system emulation target, which determines which
@@ -901,7 +902,11 @@
 #
 # @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 (since 8.2)
+#
+# @book-id: book number within drawer/node/board the CPU belongs to (since 8.2)

Long lines, please wrap:

# @drawer-id: drawer number within node/board the CPU belongs to
# (since 8.2)
#
# @book-id: book number within drawer/node/board the CPU belongs to
# (since 8.2)

qapi/machine.json

Quoted 6 lines
qapi/machine.json +2 -0
+#
+# @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)
 #
@@ -912,7 +917,7 @@

##
# @CpuInstanceProperties:
#
# List of properties to be used for hotplugging a CPU instance, it

   # should be passed by management with device_add command when 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
   #
   # @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

qapi/machine.json line 923

Quoted 8 lines
qapi/machine.json +1 -1
 #
 # @thread-id: thread number within core the CPU belongs to
 #
-# Note: currently there are 6 properties that could be present but
+# 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 sync with the

# properties passed to -device/device_add.

The last sentence is for developers, not for users, which means it doesn't belong here. Suggest to move it to a non-doc comment, and rephrase the note like

# Note: management should be prepared to pass through additional

   # properties with device_add.

qapi/machine.json line 928

Quoted 3 lines
qapi/machine.json +0 -0
@@ -922,6 +927,8 @@
 ##
 { 'struct': 'CpuInstanceProperties',

Non-doc comment could go here:

# Keep these in sync with the properties device_add accepts

Again, not your patch's fault, but your help improving this stuff would be appreciated.

qapi/machine.json line 934

Quoted 6 lines
qapi/machine.json +2 -0
   'data': { '*node-id': 'int',
+            '*drawer-id': 'int',
+            '*book-id': 'int',
             '*socket-id': 'int',
             '*die-id': 'int',
             '*cluster-id': 'int',
               '*core-id': 'int',
               '*thread-id': 'int'
     }

}

Quoted 61 lines
qapi/machine.json +6 -0
@@ -1480,6 +1487,10 @@
 #
 # @cpus: number of virtual CPUs in the virtual machine
 #
+# @drawers: number of drawers in the CPU topology (since 8.2)
+#
+# @books: number of books in the CPU topology (since 8.2)
+#
 # @sockets: number of sockets in the CPU topology
 #
 # @dies: number of dies per socket in the CPU topology
@@ -1498,6 +1509,8 @@
 ##
 { 'struct': 'SMPConfiguration', 'data': {
      '*cpus': 'int',
+     '*drawers': 'int',
+     '*books': 'int',
      '*sockets': 'int',
      '*dies': 'int',
      '*clusters': 'int',
include/hw/boards.h +9 -1
index 6c67af196a..6dcfc879eb 100644
@@ -134,12 +134,16 @@ typedef struct {
  * @clusters_supported - whether clusters are supported by the machine
  * @has_clusters - whether clusters are explicitly specified in the user
  *                 provided SMP configuration
+ * @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 has_clusters;
+    bool books_supported;
+    bool drawers_supported;
 } SMPCompatProps;
 
 /**
@@ -310,7 +314,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
@@ -319,6 +325,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;

[...]

Quoted 12 lines
qapi/meson.build +1 -0
index 60a668b343..f81a37565c 100644
@@ -36,6 +36,7 @@ qapi_all_modules = [
   'error',
   'introspect',
   'job',
+  'machine-common',
   'machine',
   'machine-target',
   'migration',

[...]

#3 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

Quoted 34 lines · Markus Armbruster
Quoted 32 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

---
 qapi/machine-common.json            | 21 +++++++++++++
 qapi/machine.json                   | 19 ++++++++++--
 include/hw/boards.h                 | 10 +++++-
 include/hw/qdev-properties-system.h |  4 +++
 target/s390x/cpu.h                  |  6 ++++
 hw/core/machine-smp.c               | 48 ++++++++++++++++++++++++-----
 hw/core/machine.c                   |  4 +++
 hw/core/qdev-properties-system.c    | 13 ++++++++
 hw/s390x/s390-virtio-ccw.c          |  4 +++
 softmmu/vl.c                        |  6 ++++
 target/s390x/cpu.c                  |  7 +++++
 qapi/meson.build                    |  1 +
 qemu-options.hx                     |  7 +++--
 13 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 qapi/machine-common.json
Quoted 7 lines

qapi/machine-common.json

Quoted 5 lines
qapi/machine-common.json new file +0 -0
new file mode 100644
index 0000000000..e40421bb37

Why do you need a separate QAPI sub-module?

See here https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 56 lines

qapi/machine.json

Quoted 28 lines
qapi/machine-common.json new file +21 -0
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }
qapi/machine.json +0 -0
index a08b6576ca..a63cb951d2 100644
@@ -9,6 +9,7 @@

##
# = Machines

qapi/machine.json line 12

Quoted 4 lines
qapi/machine.json +1 -0
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'machine-common.json' }

Section structure is borked :)

Existing section "Machine" now ends at the new "Machines S390 data types" you pull in here. The contents of below moves from "Machines" to "Machines S390 data types".

Before I explain how to avoid this, I'd like to understand why we need a new sub-module.

qapi/machine.json

Quoted 4 lines
qapi/machine.json +0 -0
 ##
 # @SysEmuTarget:
@@ -71,7 +72,7 @@

##
# @CpuInfoFast:
#
# Information about a virtual CPU
#
# @cpu-index: index of the virtual CPU
#
# @qom-path: path to the CPU object in the QOM tree

Quoted 8 lines

qapi/machine.json line 76

Quoted 6 lines
qapi/machine.json +1 -1
 #
 # @thread-id: ID of the underlying host thread
 #
-# @props: properties describing to which node/socket/core/thread
+# @props: properties describing to which node/drawer/book/socket/core/thread
 #     virtual CPU belongs to, provided if supported by board

Is this description accurate?

Kinda, although the wording might not be the best.
All the CpuInstanceProperties fields are optional, it's like a superset of possible properties across architectures.
Only a subset might be returned by query-cpus-fast.
Also die and cluster are missing.

Quoted 6 lines

@props is of type CpuInstanceProperties, shown below. Its documentation describes it as "properties to be used for hotplugging a CPU instance, it should be passed by management with device_add command when a CPU is being hotplugged." Hmm.

Quoted 7 lines

I figure details ("node/drawer/book/socket/core/thread") are better left to CpuInstanceProperties.

The "provided if supported by board" part makes no sense to me. If @props is there, it lists the properties we need to provide with device_add. What if it's not there? Same as empty list, i.e. we don't need to provide properties with device_add?

There are default values/default logic.
For s390x, socket, book, drawer are calculated from the core id if not provided with device_add.
Partial specifications are rejected.

Quoted 16 lines

Not your patch's fault, but let's get this in shape if we can.

qapi/machine.json line 907

Quoted 10 lines
qapi/machine.json +3 -1
 #
 # @target: the QEMU system emulation target, which determines which
@@ -901,7 +902,11 @@
 #
 # @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 (since 8.2)
+#
+# @book-id: book number within drawer/node/board the CPU belongs to (since 8.2)

Long lines, please wrap:

Quoted 5 lines
   # @drawer-id: drawer number within node/board the CPU belongs to
   #     (since 8.2)
   #
   # @book-id: book number within drawer/node/board the CPU belongs to
   #     (since 8.2)

Ok.

Quoted 63 lines

qapi/machine.json

Quoted 7 lines
qapi/machine.json +2 -0
+#
+# @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)
 #
@@ -912,7 +917,7 @@

##
# @CpuInstanceProperties:
#
# List of properties to be used for hotplugging a CPU instance, it

   # should be passed by management with device_add command when 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
   #
   # @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

qapi/machine.json line 923

Quoted 8 lines
qapi/machine.json +1 -1
 #
 # @thread-id: thread number within core the CPU belongs to
 #
-# Note: currently there are 6 properties that could be present but
+# 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 sync with the

# properties passed to -device/device_add.

The last sentence is for developers, not for users, which means it doesn't belong here. Suggest to move it to a non-doc comment, and rephrase the note like

# Note: management should be prepared to pass through additional

   # properties with device_add.

qapi/machine.json line 928

Quoted 3 lines
qapi/machine.json +0 -0
@@ -922,6 +927,8 @@
 ##
 { 'struct': 'CpuInstanceProperties',

Non-doc comment could go here:

# Keep these in sync with the properties device_add accepts

Again, not your patch's fault, but your help improving this stuff would be appreciated.

qapi/machine.json line 934

Quoted 6 lines
qapi/machine.json +2 -0
   'data': { '*node-id': 'int',
+            '*drawer-id': 'int',
+            '*book-id': 'int',
             '*socket-id': 'int',
             '*die-id': 'int',
             '*cluster-id': 'int',
               '*core-id': 'int',
               '*thread-id': 'int'
     }

}

[...]

#4 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

Quoted 43 lines · Nina Schoetterl-Glausch
Quoted 34 lines · Markus Armbruster
Quoted 32 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

---
 qapi/machine-common.json            | 21 +++++++++++++
 qapi/machine.json                   | 19 ++++++++++--
 include/hw/boards.h                 | 10 +++++-
 include/hw/qdev-properties-system.h |  4 +++
 target/s390x/cpu.h                  |  6 ++++
 hw/core/machine-smp.c               | 48 ++++++++++++++++++++++++-----
 hw/core/machine.c                   |  4 +++
 hw/core/qdev-properties-system.c    | 13 ++++++++
 hw/s390x/s390-virtio-ccw.c          |  4 +++
 softmmu/vl.c                        |  6 ++++
 target/s390x/cpu.c                  |  7 +++++
 qapi/meson.build                    |  1 +
 qemu-options.hx                     |  7 +++--
 13 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 qapi/machine-common.json
Quoted 7 lines

qapi/machine-common.json

Quoted 5 lines
qapi/machine-common.json new file +0 -0
new file mode 100644
index 0000000000..e40421bb37

Why do you need a separate QAPI sub-module?

Quoted 1 line

See here https://lore.kernel.org/qemu-devel/[email protected]/

Quote:

CpuS390Entitlement would be useful in both machine.json and machine-target.json

This is not obvious from this patch. I figure this patch could add it to machine.json just fine. The use in machine-target.json in appears only in PATCH 08.

because query-cpu-fast is defined in machine.json and set-cpu-topology is defined in machine-target.json.

So then the question is where best to define CpuS390Entitlement. In machine.json and include machine.json in machine-target.json? Or define it in another file and include it from both?

You do the latter in this patch.

I figure the former would be tolerable, too.

That said, having target-specific stuff in machine.json feels... odd. Before this series, we have CpuInfoS390 and CpuS390State there, for query-cpus-fast. That command returns a list of objects where common members are target-independent, and the variant members are target-dependent. qmp_query_cpus_fast() uses a CPU method to populate the target-dependent members.

I'm not sure splitting query-cpus-fast into a target-dependent and a target-independent part is worth the bother.

In this patch, you work with the structure you found. Can't fault you for that :)

Quoted 64 lines
Quoted 55 lines

qapi/machine.json

Quoted 27 lines
qapi/machine-common.json new file +21 -0
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }
qapi/machine.json +0 -0
index a08b6576ca..a63cb951d2 100644
@@ -9,6 +9,7 @@

##
# = Machines

qapi/machine.json line 12

Quoted 4 lines
qapi/machine.json +1 -0
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'machine-common.json' }

Section structure is borked :)

Existing section "Machine" now ends at the new "Machines S390 data types" you pull in here. The contents of below moves from "Machines" to "Machines S390 data types".

Before I explain how to avoid this, I'd like to understand why we need a new sub-module.

qapi/machine.json

Quoted 4 lines
qapi/machine.json +0 -0
 ##
 # @SysEmuTarget:
@@ -71,7 +72,7 @@

##
# @CpuInfoFast:
#
# Information about a virtual CPU
#
# @cpu-index: index of the virtual CPU
#
# @qom-path: path to the CPU object in the QOM tree

Quoted 8 lines

qapi/machine.json line 76

Quoted 6 lines
qapi/machine.json +1 -1
 #
 # @thread-id: ID of the underlying host thread
 #
-# @props: properties describing to which node/socket/core/thread
+# @props: properties describing to which node/drawer/book/socket/core/thread
 #     virtual CPU belongs to, provided if supported by board

Is this description accurate?

Quoted 4 lines

Kinda, although the wording might not be the best.
All the CpuInstanceProperties fields are optional, it's like a superset of possible properties across architectures.
Only a subset might be returned by query-cpus-fast.

Let's see whether I got this right...

The members of CpuInstanceProperties are properties you can pass to device_add for some targets.

The members present in a response from query-cpus-fast are properties you must pass to device_add in this VM. Or is that a "may pass"?

On what exactly does the set of present members depend? Just the target? The machine type? The CPU? Anything else?

Quoted 1 line

Also die and cluster are missing.

Does this need fixing?

Quoted 13 lines
Quoted 5 lines

@props is of type CpuInstanceProperties, shown below. Its documentation describes it as "properties to be used for hotplugging a CPU instance, it should be passed by management with device_add command when a CPU is being hotplugged." Hmm.

Quoted 7 lines

I figure details ("node/drawer/book/socket/core/thread") are better left to CpuInstanceProperties.

The "provided if supported by board" part makes no sense to me. If @props is there, it lists the properties we need to provide with device_add. What if it's not there? Same as empty list, i.e. we don't need to provide properties with device_add?

Quoted 4 lines

There are default values/default logic.
For s390x, socket, book, drawer are calculated from the core id if not provided with device_add.
Partial specifications are rejected.

Undocumented magic?

Quoted 1 line
Quoted 1 line

Not your patch's fault, but let's get this in shape if we can.

[...]

#5 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

Quoted 47 lines · Markus Armbruster
Quoted 43 lines · Nina Schoetterl-Glausch
Quoted 34 lines · Markus Armbruster
Quoted 32 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

---
 qapi/machine-common.json            | 21 +++++++++++++
 qapi/machine.json                   | 19 ++++++++++--
 include/hw/boards.h                 | 10 +++++-
 include/hw/qdev-properties-system.h |  4 +++
 target/s390x/cpu.h                  |  6 ++++
 hw/core/machine-smp.c               | 48 ++++++++++++++++++++++++-----
 hw/core/machine.c                   |  4 +++
 hw/core/qdev-properties-system.c    | 13 ++++++++
 hw/s390x/s390-virtio-ccw.c          |  4 +++
 softmmu/vl.c                        |  6 ++++
 target/s390x/cpu.c                  |  7 +++++
 qapi/meson.build                    |  1 +
 qemu-options.hx                     |  7 +++--
 13 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 qapi/machine-common.json
Quoted 7 lines

qapi/machine-common.json

Quoted 5 lines
qapi/machine-common.json new file +0 -0
new file mode 100644
index 0000000000..e40421bb37

Why do you need a separate QAPI sub-module?

Quoted 1 line

See here https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 7 lines

Quote:

CpuS390Entitlement would be useful in both machine.json and machine-target.json

This is not obvious from this patch. I figure this patch could add it to machine.json just fine. The use in machine-target.json in appears only in PATCH 08.

Want me to add the rational to the commit message?

Quoted 94 lines

because query-cpu-fast is defined in machine.json and set-cpu-topology is defined in machine-target.json.

So then the question is where best to define CpuS390Entitlement. In machine.json and include machine.json in machine-target.json? Or define it in another file and include it from both?

You do the latter in this patch.

I figure the former would be tolerable, too.

That said, having target-specific stuff in machine.json feels... odd. Before this series, we have CpuInfoS390 and CpuS390State there, for query-cpus-fast. That command returns a list of objects where common members are target-independent, and the variant members are target-dependent. qmp_query_cpus_fast() uses a CPU method to populate the target-dependent members.

I'm not sure splitting query-cpus-fast into a target-dependent and a target-independent part is worth the bother.

In this patch, you work with the structure you found. Can't fault you for that :)

Quoted 64 lines
Quoted 55 lines

qapi/machine.json

Quoted 27 lines
qapi/machine-common.json new file +21 -0
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }
qapi/machine.json +0 -0
index a08b6576ca..a63cb951d2 100644
@@ -9,6 +9,7 @@

##
# = Machines

qapi/machine.json line 12

Quoted 4 lines
qapi/machine.json +1 -0
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'machine-common.json' }

Section structure is borked :)

Existing section "Machine" now ends at the new "Machines S390 data types" you pull in here. The contents of below moves from "Machines" to "Machines S390 data types".

Before I explain how to avoid this, I'd like to understand why we need a new sub-module.

qapi/machine.json

Quoted 4 lines
qapi/machine.json +0 -0
 ##
 # @SysEmuTarget:
@@ -71,7 +72,7 @@

##
# @CpuInfoFast:
#
# Information about a virtual CPU
#
# @cpu-index: index of the virtual CPU
#
# @qom-path: path to the CPU object in the QOM tree

Quoted 8 lines

qapi/machine.json line 76

Quoted 6 lines
qapi/machine.json +1 -1
 #
 # @thread-id: ID of the underlying host thread
 #
-# @props: properties describing to which node/socket/core/thread
+# @props: properties describing to which node/drawer/book/socket/core/thread
 #     virtual CPU belongs to, provided if supported by board

Is this description accurate?

Quoted 4 lines

Kinda, although the wording might not be the best.
All the CpuInstanceProperties fields are optional, it's like a superset of possible properties across architectures.
Only a subset might be returned by query-cpus-fast.

Quoted 4 lines

Let's see whether I got this right...

The members of CpuInstanceProperties are properties you can pass to device_add for some targets.

Yes.

Quoted 3 lines

The members present in a response from query-cpus-fast are properties you must pass to device_add in this VM. Or is that a "may pass"?

On x86 must pass, s390x may pass, I haven't checked other architectures. s390x shows the defaults calculated.

Quoted 3 lines

On what exactly does the set of present members depend? Just the target? The machine type? The CPU? Anything else?

The target and the machine I'd say.
On x86 if you have one die per socket you don't need to provide a die_id on device_add.

Quoted 4 lines
Quoted 2 lines

Also die and cluster are missing.

Does this need fixing?

Only if we keep the list of properties here.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

@props is of type CpuInstanceProperties, shown below. Its documentation describes it as "properties to be used for hotplugging a CPU instance, it should be passed by management with device_add command when a CPU is being hotplugged." Hmm.

I figure details ("node/drawer/book/socket/core/thread") are better left to CpuInstanceProperties.

The "provided if supported by board" part makes no sense to me. If @props is there, it lists the properties we need to provide with device_add. What if it's not there? Same as empty list, i.e. we don't need to provide properties with device_add?

Quoted 6 lines
Quoted 4 lines

There are default values/default logic.
For s390x, socket, book, drawer are calculated from the core id if not provided with device_add.
Partial specifications are rejected.

Undocumented magic?

Patch 13 documents it:

Default topology usage
----------------------

[...]

When a CPU is defined by the ``-device`` command argument, the tree topology attributes must all be defined or all not defined.

.. code-block:: bash

    -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=1

or

.. code-block:: bash

    -device gen16b-s390x-cpu,core-id=1,dedicated=true

If none of the tree attributes (drawer, book, sockets), are specified for the ``-device`` argument, like for all CPUs defined with the ``-smp`` command argument the topology tree attributes will be set by simply adding the CPUs to the topology based on the core-id.

QEMU will not try to resolve collisions and will report an error if the CPU topology defined explicitly or implicitly on a ``-device`` argument collides with the definition of a CPU implicitly defined on the ``-smp`` argument.

When the topology modifier attributes are not defined for the ``-device`` command argument they takes following default values:

- dedicated: ``false``
- entitlement: ``medium``

Hot plug
++++++++

New CPUs can be plugged using the device_add hmp command as in:

.. code-block:: bash

(qemu) device_add gen16b-s390x-cpu,core-id=9

The placement of the CPU is derived from the core-id as described above.

The topology can of course also be fully defined:

.. code-block:: bash

    (qemu) device_add gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=1
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

Not your patch's fault, but let's get this in shape if we can.

[...]

#6 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

Quoted 50 lines · Nina Schoetterl-Glausch
Quoted 49 lines · Markus Armbruster
Quoted 43 lines · Nina Schoetterl-Glausch
Quoted 34 lines · Markus Armbruster
Quoted 32 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

---
 qapi/machine-common.json            | 21 +++++++++++++
 qapi/machine.json                   | 19 ++++++++++--
 include/hw/boards.h                 | 10 +++++-
 include/hw/qdev-properties-system.h |  4 +++
 target/s390x/cpu.h                  |  6 ++++
 hw/core/machine-smp.c               | 48 ++++++++++++++++++++++++-----
 hw/core/machine.c                   |  4 +++
 hw/core/qdev-properties-system.c    | 13 ++++++++
 hw/s390x/s390-virtio-ccw.c          |  4 +++
 softmmu/vl.c                        |  6 ++++
 target/s390x/cpu.c                  |  7 +++++
 qapi/meson.build                    |  1 +
 qemu-options.hx                     |  7 +++--
 13 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 qapi/machine-common.json
Quoted 7 lines

qapi/machine-common.json

Quoted 5 lines
qapi/machine-common.json new file +0 -0
new file mode 100644
index 0000000000..e40421bb37

Why do you need a separate QAPI sub-module?

Quoted 1 line

See here https://lore.kernel.org/qemu-devel/[email protected]/

Quote:

Quoted 7 lines
Quoted 5 lines

CpuS390Entitlement would be useful in both machine.json and machine-target.json

This is not obvious from this patch. I figure this patch could add it to machine.json just fine. The use in machine-target.json in appears only in PATCH 08.

Want me to add the rational to the commit message?

Would work for me.

If the target-specific stuff in machine.json (discussed below) bothers us, we can clean up on top.

Quoted 98 lines
Quoted 93 lines

because query-cpu-fast is defined in machine.json and set-cpu-topology is defined in machine-target.json.

So then the question is where best to define CpuS390Entitlement. In machine.json and include machine.json in machine-target.json? Or define it in another file and include it from both?

You do the latter in this patch.

I figure the former would be tolerable, too.

That said, having target-specific stuff in machine.json feels... odd. Before this series, we have CpuInfoS390 and CpuS390State there, for query-cpus-fast. That command returns a list of objects where common members are target-independent, and the variant members are target-dependent. qmp_query_cpus_fast() uses a CPU method to populate the target-dependent members.

I'm not sure splitting query-cpus-fast into a target-dependent and a target-independent part is worth the bother.

In this patch, you work with the structure you found. Can't fault you for that :)

Quoted 64 lines
Quoted 55 lines

qapi/machine.json

Quoted 27 lines
qapi/machine-common.json new file +21 -0
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }
qapi/machine.json +0 -0
index a08b6576ca..a63cb951d2 100644
@@ -9,6 +9,7 @@

##
# = Machines

qapi/machine.json line 12

Quoted 4 lines
qapi/machine.json +1 -0
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'machine-common.json' }

Section structure is borked :)

Existing section "Machine" now ends at the new "Machines S390 data types" you pull in here. The contents of below moves from "Machines" to "Machines S390 data types".

Before I explain how to avoid this, I'd like to understand why we need a new sub-module.

qapi/machine.json

Quoted 4 lines
qapi/machine.json +0 -0
 ##
 # @SysEmuTarget:
@@ -71,7 +72,7 @@

##
# @CpuInfoFast:
#
# Information about a virtual CPU
#
# @cpu-index: index of the virtual CPU
#
# @qom-path: path to the CPU object in the QOM tree

Quoted 8 lines

qapi/machine.json line 76

Quoted 6 lines
qapi/machine.json +1 -1
 #
 # @thread-id: ID of the underlying host thread
 #
-# @props: properties describing to which node/socket/core/thread
+# @props: properties describing to which node/drawer/book/socket/core/thread
 #     virtual CPU belongs to, provided if supported by board

Is this description accurate?

Quoted 4 lines

Kinda, although the wording might not be the best.
All the CpuInstanceProperties fields are optional, it's like a superset of possible properties across architectures.
Only a subset might be returned by query-cpus-fast.

Quoted 4 lines

Let's see whether I got this right...

The members of CpuInstanceProperties are properties you can pass to device_add for some targets.

Quoted 8 lines

Yes.

Quoted 3 lines

The members present in a response from query-cpus-fast are properties you must pass to device_add in this VM. Or is that a "may pass"?

On x86 must pass, s390x may pass, I haven't checked other architectures. s390x shows the defaults calculated.

Asking you to figure this out for all the targets wouldn't be fair, so I won't.

Perhaps the documentation should state explicitly that properties may or may not be optional, and ideally point to documentation that tells you more, like the stuff you show below. This might also address my "undocumented magic" remark below.

Again, I'm not asking you to create documentation for the other targets.

Quoted 11 lines
Quoted 2 lines

On what exactly does the set of present members depend? Just the target? The machine type? The CPU? Anything else?

The target and the machine I'd say.
On x86 if you have one die per socket you don't need to provide a die_id on device_add.

Quoted 4 lines
Quoted 2 lines

Also die and cluster are missing.

Does this need fixing?

Only if we keep the list of properties here.

Makes sense. Let's replace it.

Quoted 78 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

@props is of type CpuInstanceProperties, shown below. Its documentation describes it as "properties to be used for hotplugging a CPU instance, it should be passed by management with device_add command when a CPU is being hotplugged." Hmm.

I figure details ("node/drawer/book/socket/core/thread") are better left to CpuInstanceProperties.

The "provided if supported by board" part makes no sense to me. If @props is there, it lists the properties we need to provide with device_add. What if it's not there? Same as empty list, i.e. we don't need to provide properties with device_add?

Quoted 6 lines
Quoted 4 lines

There are default values/default logic.
For s390x, socket, book, drawer are calculated from the core id if not provided with device_add.
Partial specifications are rejected.

Undocumented magic?

Patch 13 documents it:

Default topology usage
----------------------

[...]

When a CPU is defined by the ``-device`` command argument, the tree topology attributes must all be defined or all not defined.

.. code-block:: bash

    -device gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=1

or

.. code-block:: bash

    -device gen16b-s390x-cpu,core-id=1,dedicated=true

If none of the tree attributes (drawer, book, sockets), are specified for the ``-device`` argument, like for all CPUs defined with the ``-smp`` command argument the topology tree attributes will be set by simply adding the CPUs to the topology based on the core-id.

QEMU will not try to resolve collisions and will report an error if the CPU topology defined explicitly or implicitly on a ``-device`` argument collides with the definition of a CPU implicitly defined on the ``-smp`` argument.

When the topology modifier attributes are not defined for the ``-device`` command argument they takes following default values:

- dedicated: ``false``
- entitlement: ``medium``

Hot plug
++++++++

New CPUs can be plugged using the device_add hmp command as in:

.. code-block:: bash

(qemu) device_add gen16b-s390x-cpu,core-id=9

The placement of the CPU is derived from the core-id as described above.

The topology can of course also be fully defined:

.. code-block:: bash

    (qemu) device_add gen16b-s390x-cpu,drawer-id=1,book-id=1,socket-id=2,core-id=1
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

Not your patch's fault, but let's get this in shape if we can.

[...]

#7 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

In reply to Markus Armbruster
Quoted 76 lines · Markus Armbruster

qapi/machine-common.json

Quoted 37 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

---
 qapi/machine-common.json            | 21 +++++++++++++
 qapi/machine.json                   | 19 ++++++++++--
 include/hw/boards.h                 | 10 +++++-
 include/hw/qdev-properties-system.h |  4 +++
 target/s390x/cpu.h                  |  6 ++++
 hw/core/machine-smp.c               | 48 ++++++++++++++++++++++++-----
 hw/core/machine.c                   |  4 +++
 hw/core/qdev-properties-system.c    | 13 ++++++++
 hw/s390x/s390-virtio-ccw.c          |  4 +++
 softmmu/vl.c                        |  6 ++++
 target/s390x/cpu.c                  |  7 +++++
 qapi/meson.build                    |  1 +
 qemu-options.hx                     |  7 +++--
 13 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 qapi/machine-common.json
qapi/machine-common.json new file +0 -0
new file mode 100644
index 0000000000..e40421bb37

Why do you need a separate QAPI sub-module?

qapi/machine.json

Quoted 27 lines
qapi/machine-common.json new file +21 -0
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }
qapi/machine.json +0 -0
index a08b6576ca..a63cb951d2 100644
@@ -9,6 +9,7 @@

##
# = Machines

qapi/machine.json line 12

Quoted 4 lines
qapi/machine.json +1 -0
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'machine-common.json' }
Quoted 8 lines

Section structure is borked :)

Existing section "Machine" now ends at the new "Machines S390 data types" you pull in here. The contents of below moves from "Machines" to "Machines S390 data types".

Before I explain how to avoid this, I'd like to understand why we need a new sub-module.

Should I just move the include statements above the section header? I assume I could also include it in qapi-schema.json before the machine.json include and that that is the reason we don't have
the same problem with e.g. migration.json.
But just moving the includes seems cleaner.

[...]

#8 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

Quoted 83 lines · Nina Schoetterl-Glausch
Quoted 82 lines · Markus Armbruster

qapi/machine-common.json

Quoted 37 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

---
 qapi/machine-common.json            | 21 +++++++++++++
 qapi/machine.json                   | 19 ++++++++++--
 include/hw/boards.h                 | 10 +++++-
 include/hw/qdev-properties-system.h |  4 +++
 target/s390x/cpu.h                  |  6 ++++
 hw/core/machine-smp.c               | 48 ++++++++++++++++++++++++-----
 hw/core/machine.c                   |  4 +++
 hw/core/qdev-properties-system.c    | 13 ++++++++
 hw/s390x/s390-virtio-ccw.c          |  4 +++
 softmmu/vl.c                        |  6 ++++
 target/s390x/cpu.c                  |  7 +++++
 qapi/meson.build                    |  1 +
 qemu-options.hx                     |  7 +++--
 13 files changed, 137 insertions(+), 13 deletions(-)
 create mode 100644 qapi/machine-common.json
qapi/machine-common.json new file +0 -0
new file mode 100644
index 0000000000..e40421bb37

Why do you need a separate QAPI sub-module?

qapi/machine.json

Quoted 27 lines
qapi/machine-common.json new file +21 -0
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }
qapi/machine.json +0 -0
index a08b6576ca..a63cb951d2 100644
@@ -9,6 +9,7 @@

##
# = Machines

qapi/machine.json line 12

Quoted 4 lines
qapi/machine.json +1 -0
 ##
 
 { 'include': 'common.json' }
+{ 'include': 'machine-common.json' }

Section structure is borked :)

Existing section "Machine" now ends at the new "Machines S390 data types" you pull in here. The contents of below moves from "Machines" to "Machines S390 data types".

Quoted 8 lines
Quoted 2 lines

Before I explain how to avoid this, I'd like to understand why we need a new sub-module.

Should I just move the include statements above the section header? I assume I could also include it in qapi-schema.json before the machine.json include and that that is the reason we don't have
the same problem with e.g. migration.json.
But just moving the includes seems cleaner.

qapi-schema.json should include all sub-modules in the order desired for the manual.

Do double-check the generated manual's section structure when adding sections or moving include directives.

#9 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

In reply to Nina Schoetterl-Glausch
Quoted 26 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

qapi/machine-common.json new file +5 -0
new file mode 100644
index 0000000000..e40421bb37
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.

qapi/machine-common.json line 15

Quoted 10 lines
qapi/machine-common.json new file +10 -0
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU

CPU entitlements

Would someone reasonably familiar with S390 understand this? Because I'm not and I don't; I wonder what "a virtual CPU assuming an entitlement" means.

Quoted 6 lines
qapi/machine-common.json new file +6 -0
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }

[...]

#10 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

Quoted 41 lines · Markus Armbruster
Quoted 26 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

qapi/machine-common.json new file +5 -0
new file mode 100644
index 0000000000..e40421bb37
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.

qapi/machine-common.json line 15

Quoted 10 lines
qapi/machine-common.json new file +10 -0
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU

CPU entitlements

Quoted 1 line

Would someone reasonably familiar with S390 understand this? Because

Well, someone familiar with s390 topology would, otherwise probably not tbh.

Quoted 2 lines

I'm not and I don't; I wonder what "a virtual CPU assuming an entitlement" means.

Basically, on s390x the OS is always running on some hypervisor. Even without KVM or z/VM you can slice up the machine, namely into logical partitions (LPARs). Therefore, there is a scheduling of virtual CPUs to the actual physical ones. "Entitlement" is a statement about how that scheduling works for a virtual CPU. The same concepts can then also be applied to KVM.

Quoted 10 lines
Quoted 7 lines
qapi/machine-common.json new file +6 -0
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Entitlement',
+  'prefix': 'S390_CPU_ENTITLEMENT',
+  'data': [ 'auto', 'low', 'medium', 'high' ] }

[...]

#11 lore raw

Re: [PATCH v23 01/20] CPU topology: extend with s390 specifics

Quoted 42 lines · Nina Schoetterl-Glausch
Quoted 41 lines · Markus Armbruster
Quoted 26 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 adds two new SMP levels, drawers and books to the CPU topology.
S390 CPUs have specific topology features like dedication and entitlement. These indicate to the guest information on host vCPU scheduling and help the guest make better scheduling decisions.

Let us provide the SMP properties with books and drawers levels and S390 CPU with dedication and entitlement,

qapi/machine-common.json new file +5 -0
new file mode 100644
index 0000000000..e40421bb37
@@ -0,0 +1,21 @@
+# -*- Mode: Python -*-
+# vim: filetype=python
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.

qapi/machine-common.json line 15

Quoted 10 lines
qapi/machine-common.json new file +10 -0
+
+##
+# = Machines S390 data types
+##
+
+##
+# @CpuS390Entitlement:
+#
+# An enumeration of cpu entitlements that can be assumed by a virtual
+# S390 CPU

CPU entitlements

Quoted 3 lines
Quoted 1 line

Would someone reasonably familiar with S390 understand this? Because

Well, someone familiar with s390 topology would, otherwise probably not tbh.

Good enough, I guess.

Quoted 8 lines
Quoted 2 lines

I'm not and I don't; I wonder what "a virtual CPU assuming an entitlement" means.

Basically, on s390x the OS is always running on some hypervisor. Even without KVM or z/VM you can slice up the machine, namely into logical partitions (LPARs). Therefore, there is a scheduling of virtual CPUs to the actual physical ones. "Entitlement" is a statement about how that scheduling works for a virtual CPU. The same concepts can then also be applied to KVM.

Thanks!

[...]

#12 lore raw

PATCH v23 2/20 s390x/cpu topology: add topology entries on CPU hotplug

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

The topology information are attributes of the CPU and are specified during the CPU device creation.

On hot plug we:
- calculate the default values for the topology for drawers, books and sockets in the case they are not specified.
- verify the CPU attributes
- check that we have still room on the desired socket

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 advantage of the CPU topology.

---
 MAINTAINERS                     |   6 +
 include/hw/s390x/cpu-topology.h |  54 +++++++
 hw/s390x/cpu-topology.c         | 259 ++++++++++++++++++++++++++++++++
 hw/s390x/s390-virtio-ccw.c      |  22 ++-
 hw/s390x/meson.build            |   1 +
 5 files changed, 340 insertions(+), 2 deletions(-)
 create mode 100644 include/hw/s390x/cpu-topology.h
 create mode 100644 hw/s390x/cpu-topology.c
MAINTAINERS +6 -0
index 00562f924f..9c6599a55b 100644
@@ -1697,6 +1697,12 @@ F: hw/s390x/event-facility.c
 F: hw/s390x/sclp*.c
 L: [email protected]
 
+S390 CPU topology
+M: Nina Schoetterl-Glausch <[email protected]>
+S: Supported
+F: include/hw/s390x/cpu-topology.h
+F: hw/s390x/cpu-topology.c
+
 X86 Machines
 ------------
 PC
include/hw/s390x/cpu-topology.h new file +54 -0

54 lines not on this page · raw message

hw/s390x/cpu-topology.c new file +259 -0

259 lines not on this page · raw message

hw/s390x/s390-virtio-ccw.c +20 -2
index bbb001cb9e..4e05a00de8 100644
@@ -45,6 +45,7 @@
 #include "target/s390x/kvm/pv.h"
 #include "migration/blocker.h"
 #include "qapi/visitor.h"
+#include "hw/s390x/cpu-topology.h"
 
 static Error *pv_mig_blocker;
 
@@ -308,10 +309,18 @@ static void s390_cpu_plug(HotplugHandler *hotplug_dev,
 {
     MachineState *ms = MACHINE(hotplug_dev);
     S390CPU *cpu = S390_CPU(dev);
+    ERRP_GUARD();
 
     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_setup_cpu(ms, cpu, errp);
+        if (*errp) {
+            return;
+        }
+    }
+
     if (dev->hotplugged) {
         raise_irq_cpu_hotplug();
     }
@@ -551,11 +560,20 @@ static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
                                   sizeof(CPUArchId) * max_cpus);
     ms->possible_cpus->len = max_cpus;
     for (i = 0; i < ms->possible_cpus->len; i++) {
+        CpuInstanceProperties *props = &ms->possible_cpus->cpus[i].props;
+
         ms->possible_cpus->cpus[i].type = ms->cpu_type;
         ms->possible_cpus->cpus[i].vcpus_count = 1;
         ms->possible_cpus->cpus[i].arch_id = i;
-        ms->possible_cpus->cpus[i].props.has_core_id = true;
-        ms->possible_cpus->cpus[i].props.core_id = i;
+
+        props->has_core_id = true;
+        props->core_id = i;
+        props->has_socket_id = true;
+        props->socket_id = s390_std_socket(i, &ms->smp);
+        props->has_book_id = true;
+        props->book_id = s390_std_book(i, &ms->smp);
+        props->has_drawer_id = true;
+        props->drawer_id = s390_std_drawer(i, &ms->smp);
     }
 
     return ms->possible_cpus;
hw/s390x/meson.build +1 -0
index 6fd096813a..482fd13420 100644
@@ -23,6 +23,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files(
   's390-skeys-kvm.c',
   's390-stattrib-kvm.c',
   's390-pci-kvm.c',
+  'cpu-topology.c',
 ))
 s390x_ss.add(when: 'CONFIG_TCG', if_true: files(
   'tod-tcg.c',
Signature · 1 line
2.39.2
#13 lore raw

PATCH v23 3/20 target/s390x/cpu topology: handle STSI(15) and build the SYSIB

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.

---
 MAINTAINERS                      |   1 +
 qapi/machine-target.json         |  14 ++
 include/hw/s390x/cpu-topology.h  |  23 +++
 include/hw/s390x/sclp.h          |   1 +
 target/s390x/cpu.h               |  75 +++++++
 hw/s390x/cpu-topology.c          |   2 +
 target/s390x/kvm/kvm.c           |   5 +-
 target/s390x/kvm/stsi-topology.c | 338 +++++++++++++++++++++++++++++++
 target/s390x/kvm/meson.build     |   3 +-
 9 files changed, 460 insertions(+), 2 deletions(-)
 create mode 100644 target/s390x/kvm/stsi-topology.c
MAINTAINERS +1 -0
index 9c6599a55b..17b92fe3ce 100644
@@ -1702,6 +1702,7 @@ M: Nina Schoetterl-Glausch <[email protected]>
 S: Supported
 F: include/hw/s390x/cpu-topology.h
 F: hw/s390x/cpu-topology.c
+F: target/s390x/kvm/stsi-topology.c
 
 X86 Machines
 ------------
qapi/machine-target.json +14 -0
index f0a6b72414..0d45a590ce 100644
@@ -361,3 +361,17 @@
                    'TARGET_MIPS',
                    'TARGET_LOONGARCH64',
                    'TARGET_RISCV' ] } }
+
+##
+# @CpuS390Polarization:
+#
+# An enumeration of cpu polarization that can be assumed by a virtual
+# S390 CPU
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Polarization',
+  'prefix': 'S390_CPU_POLARIZATION',
+  'data': [ 'horizontal', 'vertical' ],
+    'if': 'TARGET_S390X'
+}
include/hw/s390x/cpu-topology.h +23 -0
index 97b0af2795..350c7ea8aa 100644
@@ -15,10 +15,33 @@
 #include "hw/boards.h"
 #include "qapi/qapi-types-machine-target.h"
 
+#define S390_TOPOLOGY_CPU_IFL   0x03
+
+typedef struct s390_topology_id {
+    uint8_t sentinel;
+    uint8_t drawer;
+    uint8_t book;
+    uint8_t socket;
+    uint8_t type;
+    uint8_t vertical:1;
+    uint8_t entitlement:2;
+    uint8_t dedicated;
+    uint8_t origin;
+} s390_topology_id;
+
+typedef struct S390TopologyEntry {
+    QTAILQ_ENTRY(S390TopologyEntry) next;
+    s390_topology_id id;
+    uint64_t mask;
+} S390TopologyEntry;
+
 typedef struct S390Topology {
     uint8_t *cores_per_socket;
+    CpuS390Polarization polarization;
 } S390Topology;
 
+typedef QTAILQ_HEAD(, S390TopologyEntry) S390TopologyList;
+
 #ifdef CONFIG_KVM
 bool s390_has_topology(void);
 void s390_topology_setup_cpu(MachineState *ms, S390CPU *cpu, Error **errp);
include/hw/s390x/sclp.h +1 -0
index cf1f2efae2..c49051e17e 100644
@@ -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 +75 -0

90 lines not on this page · raw message

hw/s390x/cpu-topology.c +2 -0
index 189fcc5334..9bf13a6ebf 100644
@@ -28,10 +28,12 @@
  * s390_topology is used to keep the topology information.
  * .cores_per_socket: tracks information on the count of cores
  *                    per socket.
+ * .polarization: tracks machine polarization.
  */
 S390Topology s390_topology = {
     /* will be initialized after the CPU model is realized */
     .cores_per_socket = NULL,
+    .polarization = S390_CPU_POLARIZATION_HORIZONTAL,
 };
 
 /**
target/s390x/kvm/kvm.c +4 -1
index 852fbd0df7..56b31b8aae 100644
@@ -1911,9 +1911,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, RA_IGNORED);
+        return 0;
     default:
         return 0;
     }
target/s390x/kvm/stsi-topology.c new file +338 -0

338 lines not on this page · raw message

target/s390x/kvm/meson.build +2 -1
index d6aca590ae..588a9aa737 100644
@@ -1,7 +1,8 @@
 
 s390x_ss.add(when: 'CONFIG_KVM', if_true: files(
   'pv.c',
-  'kvm.c'
+  'kvm.c',
+  'stsi-topology.c'
 ), if_false: files(
   'stubs.c'
 ))
Signature · 1 line
2.39.2
#14 lore raw

Re: [PATCH v23 03/20] target/s390x/cpu topology: handle STSI(15) and build the SYSIB

Quoted 21 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.

---
 MAINTAINERS                      |   1 +
 qapi/machine-target.json         |  14 ++
 include/hw/s390x/cpu-topology.h  |  23 +++
 include/hw/s390x/sclp.h          |   1 +
 target/s390x/cpu.h               |  75 +++++++
 hw/s390x/cpu-topology.c          |   2 +
 target/s390x/kvm/kvm.c           |   5 +-
 target/s390x/kvm/stsi-topology.c | 338 +++++++++++++++++++++++++++++++
 target/s390x/kvm/meson.build     |   3 +-
 9 files changed, 460 insertions(+), 2 deletions(-)
 create mode 100644 target/s390x/kvm/stsi-topology.c

[...]

Quoted 5 lines
target/s390x/kvm/stsi-topology.c new file +0 -0
new file mode 100644
index 0000000000..22bac2b834

[...]

Quoted 15 lines
target/s390x/kvm/stsi-topology.c new file +15 -0
+/**
+ * s390_topology_id_cmp:
+ * @l: first s390_topology_id
+ * @r: second s390_topology_id
+ *
+ * Compare two topology ids according to the sorting order specified by the PoP.
+ *
+ * Returns a negative number if the first id is less than, 0 if it is equal to
+ *     and positive if it is larger than the second id.
+ */
+static int s390_topology_id_cmp(const s390_topology_id *l,
+                                const s390_topology_id *r)
+{
+    /*
+     * lexical order, compare less significant values only if more significant

target/s390x/kvm/stsi-topology.c line 224

Quoted 10 lines
target/s390x/kvm/stsi-topology.c new file +10 -0
+     * ones are equal
+     */
+    return l->sentinel - r->sentinel ?:
+           l->drawer - r->drawer ?:
+           l->book - r->book ?:
+           l->socket - r->socket ?:
+           l->type - r->type ?:
+           -1 * (l->vertical - r->vertical) ?:
+           -1 * (l->entitlement - r->entitlement) ?:
+           -1 * (l->dedicated - r->dedicated) ?:

I'll switch around those expressions manually, since gcc complains:

error: ‘*’ in boolean context, suggest ‘&&’ instead [-Werror=int-in-bool-context]

  222 |            -1 * (l->vertical - r->vertical) ?:
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'll add a comment also, since the inverted logic is not as obvious as before.

Quoted 2 lines
target/s390x/kvm/stsi-topology.c new file +2 -0
+           l->origin - r->origin;
+}

[...]

#15 lore raw

Re: [PATCH v23 03/20] target/s390x/cpu topology: handle STSI(15) and build the SYSIB

In reply to Nina Schoetterl-Glausch
Quoted 39 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

On interception of STSI(15.1.x) the System Information Block (SYSIB) is built from the list of pre-ordered topology entries.

---
 MAINTAINERS                      |   1 +
 qapi/machine-target.json         |  14 ++
 include/hw/s390x/cpu-topology.h  |  23 +++
 include/hw/s390x/sclp.h          |   1 +
 target/s390x/cpu.h               |  75 +++++++
 hw/s390x/cpu-topology.c          |   2 +
 target/s390x/kvm/kvm.c           |   5 +-
 target/s390x/kvm/stsi-topology.c | 338 +++++++++++++++++++++++++++++++
 target/s390x/kvm/meson.build     |   3 +-
 9 files changed, 460 insertions(+), 2 deletions(-)
 create mode 100644 target/s390x/kvm/stsi-topology.c
MAINTAINERS +1 -0
index 9c6599a55b..17b92fe3ce 100644
@@ -1702,6 +1702,7 @@ M: Nina Schoetterl-Glausch <[email protected]>
 S: Supported
 F: include/hw/s390x/cpu-topology.h
 F: hw/s390x/cpu-topology.c
+F: target/s390x/kvm/stsi-topology.c
 
 X86 Machines
 ------------
qapi/machine-target.json +0 -0
index f0a6b72414..0d45a590ce 100644

qapi/machine-target.json line 369

Quoted 9 lines
qapi/machine-target.json +6 -0
@@ -361,3 +361,17 @@
                    'TARGET_MIPS',
                    'TARGET_LOONGARCH64',
                    'TARGET_RISCV' ] } }
+
+##
+# @CpuS390Polarization:
+#
+# An enumeration of cpu polarization that can be assumed by a virtual
+# S390 CPU

CPU polarization

Would someone reasonably familiar with S390 understand this? Because I'm not and I don't; I wonder what "a virtual CPU assuming a polarization" means.

qapi/machine-target.json line 376

Quoted 7 lines
qapi/machine-target.json +7 -0
+#
+# Since: 8.2
+##
+{ 'enum': 'CpuS390Polarization',
+  'prefix': 'S390_CPU_POLARIZATION',
+  'data': [ 'horizontal', 'vertical' ],
+    'if': 'TARGET_S390X'

Indentation is off.

Quoted 1 line
qapi/machine-target.json +1 -0
+}
#16 lore raw

PATCH v23 4/20 s390x/sclp: reporting the maximum nested topology entries

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

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.

---
 include/hw/s390x/sclp.h | 5 +++--
 hw/s390x/sclp.c         | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)
include/hw/s390x/sclp.h +3 -2
index c49051e17e..9aef6d9370 100644
@@ -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-15 */
     uint16_t entries_cpu;               /* 16-17 */
     uint16_t offset_cpu;                /* 18-19 */
     uint8_t  _reserved2[24 - 20];       /* 20-23 */
hw/s390x/sclp.c +5 -0
index eff74479f4..d339cbb7e4 100644
@@ -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)
 {
@@ -123,6 +124,10 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
         return;
     }
 
+    if (s390_has_topology()) {
+        read_info->stsi_parm = SCLP_READ_SCP_INFO_MNEST;
+    }
+
     /* CPU information */
     prepare_cpu_entries(machine, entries_start, &cpu_count);
     read_info->entries_cpu = cpu_to_be16(cpu_count);
Signature · 1 line
2.39.2
#17 lore raw

PATCH v23 5/20 s390x/cpu topology: resetting the Topology-Change-Report

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

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.

---
 include/hw/s390x/cpu-topology.h |  1 +
 target/s390x/cpu.h              |  1 +
 target/s390x/kvm/kvm_s390x.h    |  1 +
 hw/s390x/cpu-topology.c         | 11 +++++++++++
 hw/s390x/s390-virtio-ccw.c      |  3 +++
 target/s390x/cpu-sysemu.c       | 13 +++++++++++++
 target/s390x/kvm/kvm.c          | 17 +++++++++++++++++
 7 files changed, 47 insertions(+)
include/hw/s390x/cpu-topology.h +1 -0
index 350c7ea8aa..196c9afb3f 100644
@@ -56,6 +56,7 @@ static inline void s390_topology_setup_cpu(MachineState *ms,
 #endif
 
 extern S390Topology s390_topology;
+void s390_topology_reset(void);
 
 static inline int s390_std_socket(int n, CpuTopology *smp)
 {
target/s390x/cpu.h +1 -0
index c1ba5c46d6..2722e7c450 100644
@@ -655,6 +655,7 @@ typedef struct SysIBCPUListEntry {
 QEMU_BUILD_BUG_ON(sizeof(SysIBCPUListEntry) != 16);
 
 void insert_stsi_15_1_x(S390CPU *cpu, int sel2, uint64_t addr, uint8_t ar, uintptr_t ra);
+void s390_cpu_topology_set_changed(bool changed);
 
 /* MMU defines */
 #define ASCE_ORIGIN           (~0xfffULL) /* segment table origin             */
target/s390x/kvm/kvm_s390x.h +1 -0
index f9785564d0..649dae5948 100644
@@ -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/cpu-topology.c +11 -0
index 9bf13a6ebf..03de3d3d10 100644
@@ -90,6 +90,17 @@ static void s390_topology_init(MachineState *ms)
                                             smp->books * smp->drawers);
 }
 
+/**
+ * s390_topology_reset:
+ *
+ * Generic reset for CPU topology, calls s390_topology_reset()
+ * to reset the kernel Modified Topology Change Record.
+ */
+void s390_topology_reset(void)
+{
+    s390_cpu_topology_set_changed(false);
+}
+
 /**
  * s390_topology_cpu_default:
  * @cpu: pointer to a S390CPU
hw/s390x/s390-virtio-ccw.c +3 -0
index 4e05a00de8..6c63636eee 100644
@@ -123,6 +123,9 @@ static void subsystem_reset(void)
             device_cold_reset(dev);
         }
     }
+    if (s390_has_topology()) {
+        s390_topology_reset();
+    }
 }
 
 static int virtio_ccw_hcall_notify(const uint64_t *args)
target/s390x/cpu-sysemu.c +13 -0
index 8112561e5e..1cd30c1d84 100644
@@ -307,3 +307,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_set_changed(bool changed)
+{
+    int ret;
+
+    if (kvm_enabled()) {
+        ret = kvm_s390_topology_set_mtcr(changed);
+        if (ret) {
+            error_report("Failed to set Modified Topology Change Report: %s",
+                         strerror(-ret));
+        }
+    }
+}
target/s390x/kvm/kvm.c +17 -0
index 56b31b8aae..ee6345ba27 100644
@@ -2584,6 +2584,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.39.2
#18 lore raw

PATCH v23 6/20 s390x/cpu topology: interception of PTF instruction

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

When the host supports the CPU topology facility, the PTF instruction with function code 2 is interpreted by the SIE, provided that the userland hypervisor 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 hypervisor.

During RESET all CPU of the configuration are placed in horizontal polarity.

---
 include/hw/s390x/s390-virtio-ccw.h |  6 ++++
 hw/s390x/cpu-topology.c            | 55 ++++++++++++++++++++++++++++++
 target/s390x/kvm/kvm.c             | 11 ++++++
 3 files changed, 72 insertions(+)
include/hw/s390x/s390-virtio-ccw.h +6 -0
index 9bba21a916..c1d46e78af 100644
@@ -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;
hw/s390x/cpu-topology.c +55 -0

67 lines not on this page · raw message

target/s390x/kvm/kvm.c +11 -0
index ee6345ba27..10d66c2b65 100644
@@ -86,6 +86,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
@@ -1457,6 +1458,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;
@@ -1474,6 +1482,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.39.2
#19 lore raw

PATCH v23 7/20 target/s390x/cpu topology: activate CPU topology

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

The KVM capability KVM_CAP_S390_CPU_TOPOLOGY is used to activate the S390_FEAT_CONFIGURATION_TOPOLOGY feature and the topology facility in the host CPU model 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    | 9 +++++++++
 3 files changed, 11 insertions(+), 1 deletion(-)
hw/s390x/cpu-topology.c +1 -1
index c34581964f..13f404a0d7 100644
@@ -69,7 +69,7 @@ static int s390_socket_nb(S390CPU *cpu)
  */
 bool s390_has_topology(void)
 {
-    return false;
+    return s390_has_feat(S390_FEAT_CONFIGURATION_TOPOLOGY);
 }
 
 /**
target/s390x/cpu_models.c +1 -0
index 91ce896491..c67b7eeb84 100644
@@ -255,6 +255,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 +9 -0
index 10d66c2b65..42795d3027 100644
@@ -366,6 +366,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
     kvm_vm_enable_cap(s, KVM_CAP_S390_USER_SIGP, 0);
     kvm_vm_enable_cap(s, KVM_CAP_S390_VECTOR_REGISTERS, 0);
     kvm_vm_enable_cap(s, KVM_CAP_S390_USER_STSI, 0);
+    kvm_vm_enable_cap(s, KVM_CAP_S390_CPU_TOPOLOGY, 0);
     if (ri_allowed()) {
         if (kvm_vm_enable_cap(s, KVM_CAP_S390_RI, 0) == 0) {
             cap_ri = 1;
@@ -2462,6 +2463,14 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
         set_bit(S390_FEAT_UNPACK, model->features);
     }
 
+    /*
+     * If we have kernel support for CPU Topology indicate the
+     * configuration-topology facility.
+     */
+    if (kvm_check_extension(kvm_state, KVM_CAP_S390_CPU_TOPOLOGY)) {
+        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.39.2
#20 lore raw

PATCH v23 8/20 qapi/s390x/cpu topology: set-cpu-topology qmp command

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

The modification of the CPU attributes are done through a monitor command.

It allows to move the core inside the topology tree to optimize the cache usage in the case the host's hypervisor previously moved the CPU.

The same command allows to modify 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.

The command has a feature unstable for the moment.

---
 qapi/machine-target.json |  37 +++++++++++
 hw/s390x/cpu-topology.c  | 132 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 169 insertions(+)
qapi/machine-target.json +37 -0
index 0d45a590ce..e47a252bd9 100644
@@ -4,6 +4,8 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
 # See the COPYING file in the top-level directory.
 
+{ 'include': 'machine-common.json' }
+
 ##
 # @CpuModelInfo:
 #
@@ -375,3 +377,38 @@
   'data': [ 'horizontal', 'vertical' ],
     'if': 'TARGET_S390X'
 }
+
+##
+# @set-cpu-topology:
+#
+# @core-id: the vCPU ID to be moved
+# @socket-id: optional destination socket where to move the vCPU
+# @book-id: optional destination book where to move the vCPU
+# @drawer-id: optional destination drawer where to move the vCPU
+# @entitlement: optional entitlement
+# @dedicated: optional, if the vCPU is dedicated to a real CPU
+#
+# Features:
+# @unstable: This command may still be modified.
+#
+# Modifies the topology by moving the CPU inside the topology
+# tree or by changing a modifier attribute of a CPU.
+# Default value for optional parameter is the current value
+# used by the CPU.
+#
+# Returns: Nothing on success, the reason on failure.
+#
+# Since: 8.2
+##
+{ 'command': 'set-cpu-topology',
+  'data': {
+      'core-id': 'uint16',
+      '*socket-id': 'uint16',
+      '*book-id': 'uint16',
+      '*drawer-id': 'uint16',
+      '*entitlement': 'CpuS390Entitlement',
+      '*dedicated': 'bool'
+  },
+  'features': [ 'unstable' ],
+  'if': { 'all': [ 'TARGET_S390X' , 'CONFIG_KVM' ] }
+}
hw/s390x/cpu-topology.c +132 -0

147 lines not on this page · raw message

Signature · 1 line
2.39.2
#21 lore raw

Re: [PATCH v23 08/20] qapi/s390x/cpu topology: set-cpu-topology qmp command

Quoted 41 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

The modification of the CPU attributes are done through a monitor command.

It allows to move the core inside the topology tree to optimize the cache usage in the case the host's hypervisor previously moved the CPU.

The same command allows to modify 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.

The command has a feature unstable for the moment.

---
 qapi/machine-target.json |  37 +++++++++++
 hw/s390x/cpu-topology.c  | 132 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 169 insertions(+)
qapi/machine-target.json +2 -0
index 0d45a590ce..e47a252bd9 100644
@@ -4,6 +4,8 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
 # See the COPYING file in the top-level directory.
 
+{ 'include': 'machine-common.json' }
+
 ##
 # @CpuModelInfo:
 #

qapi/machine-target.json line 382

Quoted 6 lines
qapi/machine-target.json +3 -0
@@ -375,3 +377,38 @@
   'data': [ 'horizontal', 'vertical' ],
     'if': 'TARGET_S390X'
 }
+
+##
+# @set-cpu-topology:

Move the overview here from [*] below.

qapi/machine-target.json line 389

Quoted 7 lines
qapi/machine-target.json +7 -0
+#
+# @core-id: the vCPU ID to be moved
+# @socket-id: optional destination socket where to move the vCPU
+# @book-id: optional destination book where to move the vCPU
+# @drawer-id: optional destination drawer where to move the vCPU
+# @entitlement: optional entitlement
+# @dedicated: optional, if the vCPU is dedicated to a real CPU

Separate the members with blank lines, please.

The doc generator adds optional automatically, so this will come out like

"socket-id": "int" (optional)
optional destination socket where to move the vCPU

"book-id": "int" (optional)
optional destination book where to move the vCPU

"drawer-id": "int" (optional)
optional destination drawer where to move the vCPU

"entitlement": "CpuS390Entitlement" (optional)
optional entitlement

"dedicated": "boolean" (optional)
optional, if the vCPU is dedicated to a real CPU

Drop the optional from the text.

Suggest

# @dedicated: whether the vCPU is dedicated to a real CPU

(whatever that may mean; I'm an S390 noob)

qapi/machine-target.json line 391

Quoted 2 lines
qapi/machine-target.json +2 -0
+#
+# Features:

Another blank line, please.

qapi/machine-target.json line 393

Quoted 2 lines
qapi/machine-target.json +2 -0
+# @unstable: This command may still be modified.
+#

[*] The overview:

qapi/machine-target.json line 397

Quoted 4 lines
qapi/machine-target.json +4 -0
+# Modifies the topology by moving the CPU inside the topology
+# tree or by changing a modifier attribute of a CPU.
+# Default value for optional parameter is the current value
+# used by the CPU.

So, anything absent will not be changed. Maybe that's a clearer way to put it. What do you think?

qapi/machine-target.json line 408

Quoted 11 lines
qapi/machine-target.json +11 -0
+#
+# Returns: Nothing on success, the reason on failure.
+#
+# Since: 8.2
+##
+{ 'command': 'set-cpu-topology',
+  'data': {
+      'core-id': 'uint16',
+      '*socket-id': 'uint16',
+      '*book-id': 'uint16',
+      '*drawer-id': 'uint16',

CpuInstanceProperties uses 'int' for these. Any particular reason for the difference?

Quoted 6 lines
qapi/machine-target.json +6 -0
+      '*entitlement': 'CpuS390Entitlement',
+      '*dedicated': 'bool'
+  },
+  'features': [ 'unstable' ],
+  'if': { 'all': [ 'TARGET_S390X' , 'CONFIG_KVM' ] }
+}

[...]

#22 lore raw

Re: [PATCH v23 08/20] qapi/s390x/cpu topology: set-cpu-topology qmp command

Quoted 33 lines · Markus Armbruster
Quoted 31 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

The modification of the CPU attributes are done through a monitor command.

It allows to move the core inside the topology tree to optimize the cache usage in the case the host's hypervisor previously moved the CPU.

The same command allows to modify 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.

The command has a feature unstable for the moment.

---
 qapi/machine-target.json |  37 +++++++++++
 hw/s390x/cpu-topology.c  | 132 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 169 insertions(+)
qapi/machine-target.json +0 -0
index 0d45a590ce..e47a252bd9 100644

[...]

Quoted 7 lines

qapi/machine-target.json line 397

Quoted 4 lines
qapi/machine-target.json +4 -0
+# Modifies the topology by moving the CPU inside the topology
+# tree or by changing a modifier attribute of a CPU.
+# Default value for optional parameter is the current value
+# used by the CPU.

So, anything absent will not be changed. Maybe that's a clearer way to put it. What do you think?

Yes.

Quoted 15 lines

qapi/machine-target.json line 408

Quoted 12 lines
qapi/machine-target.json +11 -0
+#
+# Returns: Nothing on success, the reason on failure.
+#
+# Since: 8.2
+##
+{ 'command': 'set-cpu-topology',
+  'data': {
+      'core-id': 'uint16',
+      '*socket-id': 'uint16',
+      '*book-id': 'uint16',
+      '*drawer-id': 'uint16',

CpuInstanceProperties uses 'int' for these. Any particular reason for the difference?

unsigned -> no need to check if >0
16bit is also the width the hardware uses for these values on s390.

Quoted 9 lines
Quoted 6 lines
qapi/machine-target.json +6 -0
+      '*entitlement': 'CpuS390Entitlement',
+      '*dedicated': 'bool'
+  },
+  'features': [ 'unstable' ],
+  'if': { 'all': [ 'TARGET_S390X' , 'CONFIG_KVM' ] }
+}

[...]

#23 lore raw

PATCH v23 9/20 machine: adding s390 topology to query-cpu-fast

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390x provides two more topology attributes, entitlement and dedication.

Let's add these CPU attributes to the QAPI command query-cpu-fast.

---
 qapi/machine.json  | 9 ++++++++-
 target/s390x/cpu.c | 9 +++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
qapi/machine.json +8 -1
index a63cb951d2..be1d70d8cd 100644
@@ -56,10 +56,17 @@
 # Additional information about a virtual S390 CPU
 #
 # @cpu-state: the virtual CPU's state
+# @dedicated: the virtual CPU's dedication (since 8.2)
+# @entitlement: the virtual CPU's entitlement (since 8.2)
 #
 # Since: 2.12
 ##
-{ 'struct': 'CpuInfoS390', 'data': { 'cpu-state': 'CpuS390State' } }
+{ 'struct': 'CpuInfoS390',
+  'data': { 'cpu-state': 'CpuS390State',
+            '*dedicated': 'bool',
+            '*entitlement': 'CpuS390Entitlement'
+  }
+}
 
 ##
 # @CpuInfoFast:
target/s390x/cpu.c +9 -0
index 74405beb51..5967e34a85 100644
@@ -38,6 +38,7 @@
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/reset.h"
 #endif
+#include "hw/s390x/cpu-topology.h"
 
 #define CR0_RESET       0xE0UL
 #define CR14_RESET      0xC2000000UL;
@@ -146,6 +147,14 @@ static void s390_query_cpu_fast(CPUState *cpu, CpuInfoFast *value)
     S390CPU *s390_cpu = S390_CPU(cpu);
 
     value->u.s390x.cpu_state = s390_cpu->env.cpu_state;
+#if !defined(CONFIG_USER_ONLY)
+    if (s390_has_topology()) {
+        value->u.s390x.has_dedicated = true;
+        value->u.s390x.dedicated = s390_cpu->env.dedicated;
+        value->u.s390x.has_entitlement = true;
+        value->u.s390x.entitlement = s390_cpu->env.entitlement;
+    }
+#endif
 }
 
 /* S390CPUClass::reset() */
Signature · 1 line
2.39.2
#24 lore raw

Re: [PATCH v23 09/20] machine: adding s390 topology to query-cpu-fast

Quoted 21 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390x provides two more topology attributes, entitlement and dedication.

Let's add these CPU attributes to the QAPI command query-cpu-fast.

---
 qapi/machine.json  | 9 ++++++++-
 target/s390x/cpu.c | 9 +++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
qapi/machine.json +0 -0
index a63cb951d2..be1d70d8cd 100644

qapi/machine.json line 60

Quoted 5 lines
qapi/machine.json +2 -0
@@ -56,10 +56,17 @@
 # Additional information about a virtual S390 CPU
 #
 # @cpu-state: the virtual CPU's state
+# @dedicated: the virtual CPU's dedication (since 8.2)
+# @entitlement: the virtual CPU's entitlement (since 8.2)

Blank lines between members, please.

Quoted 13 lines
qapi/machine.json +6 -1
 #
 # Since: 2.12
 ##
-{ 'struct': 'CpuInfoS390', 'data': { 'cpu-state': 'CpuS390State' } }
+{ 'struct': 'CpuInfoS390',
+  'data': { 'cpu-state': 'CpuS390State',
+            '*dedicated': 'bool',
+            '*entitlement': 'CpuS390Entitlement'
+  }
+}
 
 ##
 # @CpuInfoFast:

[...]

#25 lore raw

PATCH v23 10/20 machine: adding s390 topology to info hotpluggable-cpus

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

S390 topology adds books and drawers topology containers. Let's add these to the HMP information for hotpluggable cpus.

---
 hw/core/machine-hmp-cmds.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/core/machine-hmp-cmds.c +6 -0
index c3e55ef9e9..9a4b59c6f2 100644
@@ -71,6 +71,12 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
         if (c->has_node_id) {
             monitor_printf(mon, "    node-id: \"%" PRIu64 "\"\n", c->node_id);
         }
+        if (c->has_drawer_id) {
+            monitor_printf(mon, "    drawer-id: \"%" PRIu64 "\"\n", c->drawer_id);
+        }
+        if (c->has_book_id) {
+            monitor_printf(mon, "    book-id: \"%" PRIu64 "\"\n", c->book_id);
+        }
         if (c->has_socket_id) {
             monitor_printf(mon, "    socket-id: \"%" PRIu64 "\"\n", c->socket_id);
         }
Signature · 1 line
2.39.2
#26 lore raw

PATCH v23 11/20 qapi/s390x/cpu topology: CPU_POLARIZATION_CHANGE qapi event

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

When the guest asks to change the polarization this change is forwarded to the upper layer using QAPI.
The upper layer is supposed to take according decisions concerning CPU provisioning.

---
 qapi/machine-target.json | 33 +++++++++++++++++++++++++++++++++
 hw/s390x/cpu-topology.c  |  2 ++
 2 files changed, 35 insertions(+)
qapi/machine-target.json +33 -0
index e47a252bd9..276c3bf9d1 100644
@@ -412,3 +412,36 @@
   'features': [ 'unstable' ],
   'if': { 'all': [ 'TARGET_S390X' , 'CONFIG_KVM' ] }
 }
+
+##
+# @CPU_POLARIZATION_CHANGE:
+#
+# Emitted when the guest asks to change the polarization.
+#
+# @polarization: polarization specified by the guest
+#
+# Features:
+# @unstable: This command may still be modified.
+#
+# The guest can tell the host (via the PTF instruction) whether the
+# CPUs should be provisioned using horizontal or vertical polarization.
+#
+# On horizontal polarization the host is expected to provision all vCPUs
+# equally.
+# On vertical polarization the host can provision each vCPU differently.
+# The guest will get information on the details of the provisioning
+# the next time it uses the STSI(15) instruction.
+#
+# Since: 8.2
+#
+# Example:
+#
+# <- { "event": "CPU_POLARIZATION_CHANGE",
+#      "data": { "polarization": "horizontal" },
+#      "timestamp": { "seconds": 1401385907, "microseconds": 422329 } }
+##
+{ 'event': 'CPU_POLARIZATION_CHANGE',
+  'data': { 'polarization': 'CpuS390Polarization' },
+  'features': [ 'unstable' ],
+  'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] }
+}
hw/s390x/cpu-topology.c +2 -0
index 28adfb3f84..18274db74c 100644
@@ -24,6 +24,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"
 
 /*
  * s390_topology is used to keep the topology information.
@@ -136,6 +137,7 @@ void s390_handle_ptf(S390CPU *cpu, uint8_t r1, uintptr_t ra)
         } else {
             s390_topology.polarization = polarization;
             s390_cpu_topology_set_changed(true);
+            qapi_event_send_cpu_polarization_change(polarization);
             setcc(cpu, 0);
         }
         break;
Signature · 1 line
2.39.2
#27 lore raw

Re: [PATCH v23 11/20] qapi/s390x/cpu topology: CPU_POLARIZATION_CHANGE qapi event

Quoted 24 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

When the guest asks to change the polarization this change is forwarded to the upper layer using QAPI.
The upper layer is supposed to take according decisions concerning CPU provisioning.

---
 qapi/machine-target.json | 33 +++++++++++++++++++++++++++++++++
 hw/s390x/cpu-topology.c  |  2 ++
 2 files changed, 35 insertions(+)
qapi/machine-target.json +0 -0
index e47a252bd9..276c3bf9d1 100644
@@ -412,3 +412,36 @@
   'features': [ 'unstable' ],
   'if': { 'all': [ 'TARGET_S390X' , 'CONFIG_KVM' ] }

qapi/machine-target.json line 423

Quoted 10 lines
qapi/machine-target.json +9 -0
 }
+
+##
+# @CPU_POLARIZATION_CHANGE:
+#
+# Emitted when the guest asks to change the polarization.
+#
+# @polarization: polarization specified by the guest
+#
+# Features:

Blank line, please.

qapi/machine-target.json line 424

Quoted 1 line
qapi/machine-target.json +1 -0
+# @unstable: This command may still be modified.

Event, not command. Suggest

# @unstable: This event is experimental.

qapi/machine-target.json line 433

Quoted 9 lines
qapi/machine-target.json +9 -0
+#
+# The guest can tell the host (via the PTF instruction) whether the
+# CPUs should be provisioned using horizontal or vertical polarization.
+#
+# On horizontal polarization the host is expected to provision all vCPUs
+# equally.
+# On vertical polarization the host can provision each vCPU differently.
+# The guest will get information on the details of the provisioning
+# the next time it uses the STSI(15) instruction.

Move this up before @polarization for consistency with other event documentation.

Quoted 14 lines
qapi/machine-target.json +14 -0
+#
+# Since: 8.2
+#
+# Example:
+#
+# <- { "event": "CPU_POLARIZATION_CHANGE",
+#      "data": { "polarization": "horizontal" },
+#      "timestamp": { "seconds": 1401385907, "microseconds": 422329 } }
+##
+{ 'event': 'CPU_POLARIZATION_CHANGE',
+  'data': { 'polarization': 'CpuS390Polarization' },
+  'features': [ 'unstable' ],
+  'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] }
+}

[...]

#28 lore raw

PATCH v23 12/20 qapi/s390x/cpu topology: query-cpu-polarization qmp command

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

The query-cpu-polarization qmp command returns the current CPU polarization of the machine.

---
 qapi/machine-target.json | 29 +++++++++++++++++++++++++++++
 hw/s390x/cpu-topology.c  |  8 ++++++++
 2 files changed, 37 insertions(+)
qapi/machine-target.json +29 -0
index 276c3bf9d1..58ba28a868 100644
@@ -445,3 +445,32 @@
   'features': [ 'unstable' ],
   'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] }
 }
+
+##
+# @CpuPolarizationInfo:
+#
+# The result of a cpu polarization
+#
+# @polarization: the CPU polarization
+#
+# Since: 8.2
+##
+{ 'struct': 'CpuPolarizationInfo',
+  'data': { 'polarization': 'CpuS390Polarization' },
+  'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] }
+}
+
+##
+# @query-s390x-cpu-polarization:
+#
+# Features:
+# @unstable: This command may still be modified.
+#
+# Returns: the machine polarization
+#
+# Since: 8.2
+##
+{ 'command': 'query-s390x-cpu-polarization', 'returns': 'CpuPolarizationInfo',
+  'features': [ 'unstable' ],
+  'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] }
+}
hw/s390x/cpu-topology.c +8 -0
index 18274db74c..1561a8ab44 100644
@@ -459,3 +459,11 @@ void qmp_set_cpu_topology(uint16_t core,
                          has_drawer, drawer, has_entitlement, entitlement,
                          has_dedicated, dedicated, errp);
 }
+
+CpuPolarizationInfo *qmp_query_s390x_cpu_polarization(Error **errp)
+{
+    CpuPolarizationInfo *info = g_new0(CpuPolarizationInfo, 1);
+
+    info->polarization = s390_topology.polarization;
+    return info;
+}
Signature · 1 line
2.39.2
#29 lore raw

Re: [PATCH v23 12/20] qapi/s390x/cpu topology: query-cpu-polarization qmp command

Quoted 20 lines · Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

The query-cpu-polarization qmp command returns the current CPU polarization of the machine.

---
 qapi/machine-target.json | 29 +++++++++++++++++++++++++++++
 hw/s390x/cpu-topology.c  |  8 ++++++++
 2 files changed, 37 insertions(+)
qapi/machine-target.json +0 -0
index 276c3bf9d1..58ba28a868 100644

qapi/machine-target.json line 452

Quoted 8 lines
qapi/machine-target.json +5 -0
@@ -445,3 +445,32 @@
   'features': [ 'unstable' ],
   'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] }
 }
+
+##
+# @CpuPolarizationInfo:
+#
+# The result of a cpu polarization

CPU polarization

End the sentence with a period, please.

Quoted 4 lines
qapi/machine-target.json +4 -0
+#
+# @polarization: the CPU polarization
+#
+# Since: 8.2

qapi/machine-target.json line 466

Quoted 10 lines
qapi/machine-target.json +10 -0
+##
+{ 'struct': 'CpuPolarizationInfo',
+  'data': { 'polarization': 'CpuS390Polarization' },
+  'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] }
+}
+
+##
+# @query-s390x-cpu-polarization:
+#
+# Features:

Blank line, please.

qapi/machine-target.json line 467

Quoted 1 line
qapi/machine-target.json +1 -0
+# @unstable: This command may still be modified.

Make this

# @unstable: This command is experimental.

qapi/machine-target.json line 469

Quoted 2 lines
qapi/machine-target.json +2 -0
+#
+# Returns: the machine polarization

The CPU polarization, I presume?

Quoted 7 lines
qapi/machine-target.json +7 -0
+#
+# Since: 8.2
+##
+{ 'command': 'query-s390x-cpu-polarization', 'returns': 'CpuPolarizationInfo',
+  'features': [ 'unstable' ],
+  'if': { 'all': [ 'TARGET_S390X', 'CONFIG_KVM' ] }
+}

[...]

#30 lore raw

PATCH v23 13/20 docs/s390x/cpu topology: document s390x cpu topology

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

Add some basic examples for the definition of cpu topology in s390x.

---
 MAINTAINERS                        |   2 +
 docs/devel/index-internals.rst     |   1 +
 docs/devel/s390-cpu-topology.rst   | 170 ++++++++++++++++++++
 docs/system/s390x/cpu-topology.rst | 242 +++++++++++++++++++++++++++++
 docs/system/target-s390x.rst       |   1 +
 5 files changed, 416 insertions(+)
 create mode 100644 docs/devel/s390-cpu-topology.rst
 create mode 100644 docs/system/s390x/cpu-topology.rst
MAINTAINERS +2 -0
index 17b92fe3ce..0cba0cb2d1 100644
@@ -1703,6 +1703,8 @@ S: Supported
 F: include/hw/s390x/cpu-topology.h
 F: hw/s390x/cpu-topology.c
 F: target/s390x/kvm/stsi-topology.c
+F: docs/devel/s390-cpu-topology.rst
+F: docs/system/s390x/cpu-topology.rst
 
 X86 Machines
 ------------
docs/devel/index-internals.rst +1 -0
index e1a93df263..6f81df92bc 100644
@@ -14,6 +14,7 @@ Details about QEMU's various subsystems including how to add features to them.
    migration
    multi-process
    reset
+   s390-cpu-topology
    s390-dasd-ipl
    tracing
    vfio-migration
docs/devel/s390-cpu-topology.rst new file +170 -0

170 lines not on this page · raw message

docs/system/s390x/cpu-topology.rst new file +242 -0

242 lines not on this page · raw message

docs/system/target-s390x.rst +1 -0
index f6f11433c7..94c981e732 100644
@@ -34,3 +34,4 @@ Architectural features
 .. toctree::
    s390x/bootdevices
    s390x/protvirt
+   s390x/cpu-topology
Signature · 1 line
2.39.2
#31 lore raw

PATCH v23 14/20 tests/avocado: s390x cpu topology core

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

Introduction of the s390x cpu topology core functions and basic tests.

We test the correlation between the command line and the QMP results in query-cpus-fast for various CPU topology.

---
 MAINTAINERS                    |   1 +
 tests/avocado/s390_topology.py | 200 +++++++++++++++++++++++++++++++++
 2 files changed, 201 insertions(+)
 create mode 100644 tests/avocado/s390_topology.py
MAINTAINERS +1 -0
index 0cba0cb2d1..405800ac15 100644
@@ -1705,6 +1705,7 @@ F: hw/s390x/cpu-topology.c
 F: target/s390x/kvm/stsi-topology.c
 F: docs/devel/s390-cpu-topology.rst
 F: docs/system/s390x/cpu-topology.rst
+F: tests/avocado/s390_topology.py
 
 X86 Machines
 ------------
tests/avocado/s390_topology.py new file +200 -0

200 lines not on this page · raw message

Signature · 1 line
2.39.2
#32 lore raw

PATCH v23 15/20 tests/avocado: s390x cpu topology polarization

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

Polarization is changed on a request from the guest. Let's verify the polarization is accordingly set by QEMU.

---
 tests/avocado/s390_topology.py | 45 ++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
tests/avocado/s390_topology.py +45 -0
index 9078b45281..8166cee134 100644
@@ -41,6 +41,7 @@ class S390CPUTopology(QemuSystemTest):
     The polarization is changed on a request from the guest.
     """
     timeout = 90
+    event_timeout = 10
 
     KERNEL_COMMON_COMMAND_LINE = ('printk.time=0 '
                                   'root=/dev/ram '
@@ -103,6 +104,14 @@ def kernel_init(self):
                          '-initrd', initrd_path,
                          '-append', kernel_command_line)
 
+    def system_init(self):
+        self.log.info("System init")
+        exec_command_and_wait_for_pattern(self,
+                """ mount proc -t proc /proc;
+                    mount sys -t sysfs /sys;
+                    cat /sys/devices/system/cpu/dispatching """,
+                    '0')
+
     def test_single(self):
         """
         This test checks the simplest topology with a single CPU.
@@ -198,3 +207,39 @@ def test_dash_device(self):
         self.check_topology(3, 1, 1, 1, 'high', False)
         self.check_topology(4, 1, 1, 1, 'medium', False)
         self.check_topology(5, 2, 1, 1, 'high', True)
+
+
+    def guest_set_dispatching(self, dispatching):
+        exec_command(self,
+                f'echo {dispatching} > /sys/devices/system/cpu/dispatching')
+        self.vm.event_wait('CPU_POLARIZATION_CHANGE', self.event_timeout)
+        exec_command_and_wait_for_pattern(self,
+                'cat /sys/devices/system/cpu/dispatching', dispatching)
+
+
+    def test_polarization(self):
+        """
+        This test verifies that QEMU modifies the entitlement change after
+        several guest polarization change requests.
+
+        :avocado: tags=arch:s390x
+        :avocado: tags=machine:s390-ccw-virtio
+        """
+        self.kernel_init()
+        self.vm.launch()
+        self.wait_until_booted()
+
+        self.system_init()
+        res = self.vm.qmp('query-s390x-cpu-polarization')
+        self.assertEqual(res['return']['polarization'], 'horizontal')
+        self.check_topology(0, 0, 0, 0, 'medium', False)
+
+        self.guest_set_dispatching('1');
+        res = self.vm.qmp('query-s390x-cpu-polarization')
+        self.assertEqual(res['return']['polarization'], 'vertical')
+        self.check_topology(0, 0, 0, 0, 'medium', False)
+
+        self.guest_set_dispatching('0');
+        res = self.vm.qmp('query-s390x-cpu-polarization')
+        self.assertEqual(res['return']['polarization'], 'horizontal')
+        self.check_topology(0, 0, 0, 0, 'medium', False)
Signature · 1 line
2.39.2
#33 lore raw

PATCH v23 16/20 tests/avocado: s390x cpu topology entitlement tests

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

Test changes in the entitlement from both a guest and a host point of view, depending on the polarization.

---
 tests/avocado/s390_topology.py | 62 ++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
tests/avocado/s390_topology.py +62 -0
index 8166cee134..24fac9a54d 100644
@@ -243,3 +243,65 @@ def test_polarization(self):
         res = self.vm.qmp('query-s390x-cpu-polarization')
         self.assertEqual(res['return']['polarization'], 'horizontal')
         self.check_topology(0, 0, 0, 0, 'medium', False)
+
+
+    def check_polarization(self, polarization):
+        #We need to wait for the change to have been propagated to the kernel
+        exec_command_and_wait_for_pattern(self,
+            "\n".join([
+                "timeout 1 sh -c 'while true",
+                'do',
+                '    syspath="/sys/devices/system/cpu/cpu0/polarization"',
+                '    polarization="$(cat "$syspath")" || exit',
+               f'    if [ "$polarization" = "{polarization}" ]; then',
+                '        exit 0',
+                '    fi',
+                '    sleep 0.01',
+                #searched for strings mustn't show up in command, '' to obfuscate
+                "done' && echo succ''ess || echo fail''ure",
+            ]),
+            "success", "failure")
+
+
+    def test_entitlement(self):
+        """
+        This test verifies that QEMU modifies the entitlement
+        after a guest request and that the guest sees the change.
+
+        :avocado: tags=arch:s390x
+        :avocado: tags=machine:s390-ccw-virtio
+        """
+        self.kernel_init()
+        self.vm.launch()
+        self.wait_until_booted()
+
+        self.system_init()
+
+        self.check_polarization('horizontal')
+        self.check_topology(0, 0, 0, 0, 'medium', False)
+
+        self.guest_set_dispatching('1')
+        self.check_polarization('vertical:medium')
+        self.check_topology(0, 0, 0, 0, 'medium', False)
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'low'})
+        self.assertEqual(res['return'], {})
+        self.check_polarization('vertical:low')
+        self.check_topology(0, 0, 0, 0, 'low', False)
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'medium'})
+        self.assertEqual(res['return'], {})
+        self.check_polarization('vertical:medium')
+        self.check_topology(0, 0, 0, 0, 'medium', False)
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'high'})
+        self.assertEqual(res['return'], {})
+        self.check_polarization('vertical:high')
+        self.check_topology(0, 0, 0, 0, 'high', False)
+
+        self.guest_set_dispatching('0');
+        self.check_polarization("horizontal")
+        self.check_topology(0, 0, 0, 0, 'high', False)
Signature · 1 line
2.39.2
#34 lore raw

PATCH v23 17/20 tests/avocado: s390x cpu topology test dedicated CPU

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

A dedicated CPU in vertical polarization can only have a high entitlement.
Let's check this from both host and guest point of view.

---
 tests/avocado/s390_topology.py | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
tests/avocado/s390_topology.py +33 -0
index 24fac9a54d..3661048f4c 100644
@@ -305,3 +305,36 @@ def test_entitlement(self):
         self.guest_set_dispatching('0');
         self.check_polarization("horizontal")
         self.check_topology(0, 0, 0, 0, 'high', False)
+
+
+    def test_dedicated(self):
+        """
+        This test verifies that QEMU adjusts the entitlement correctly when a
+        CPU is made dedicated.
+        QEMU retains the entitlement value when horizontal polarization is in effect.
+        For the guest, the field shows the effective value of the entitlement.
+
+        :avocado: tags=arch:s390x
+        :avocado: tags=machine:s390-ccw-virtio
+        """
+        self.kernel_init()
+        self.vm.launch()
+        self.wait_until_booted()
+
+        self.system_init()
+
+        self.check_polarization("horizontal")
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'dedicated': True})
+        self.assertEqual(res['return'], {})
+        self.check_topology(0, 0, 0, 0, 'high', True)
+        self.check_polarization("horizontal")
+
+        self.guest_set_dispatching('1');
+        self.check_topology(0, 0, 0, 0, 'high', True)
+        self.check_polarization("vertical:high")
+
+        self.guest_set_dispatching('0');
+        self.check_topology(0, 0, 0, 0, 'high', True)
+        self.check_polarization("horizontal")
Signature · 1 line
2.39.2
#35 lore raw

PATCH v23 18/20 tests/avocado: s390x cpu topology test socket full

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

This test verifies that QMP set-cpu-topology does not accept to overload a socket.

---
 tests/avocado/s390_topology.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
tests/avocado/s390_topology.py +26 -0
index 3661048f4c..a63c2b2923 100644
@@ -338,3 +338,29 @@ def test_dedicated(self):
         self.guest_set_dispatching('0');
         self.check_topology(0, 0, 0, 0, 'high', True)
         self.check_polarization("horizontal")
+
+
+    def test_socket_full(self):
+        """
+        This test verifies that QEMU does not accept to overload a socket.
+        The socket-id 0 on book-id 0 already contains CPUs 0 and 1 and can
+        not accept any new CPU while socket-id 0 on book-id 1 is free.
+
+        :avocado: tags=arch:s390x
+        :avocado: tags=machine:s390-ccw-virtio
+        """
+        self.kernel_init()
+        self.vm.add_args('-smp',
+                         '3,drawers=2,books=2,sockets=3,cores=2,maxcpus=24')
+        self.vm.launch()
+        self.wait_until_booted()
+
+        self.system_init()
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 2, 'socket-id': 0, 'book-id': 0})
+        self.assertEqual(res['error']['class'], 'GenericError')
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 2, 'socket-id': 0, 'book-id': 1})
+        self.assertEqual(res['return'], {})
Signature · 1 line
2.39.2
#36 lore raw

PATCH v23 19/20 tests/avocado: s390x cpu topology dedicated errors

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

Let's test that QEMU refuses to setup a dedicated CPU with low or medium entitlement.

---
 tests/avocado/s390_topology.py | 48 ++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
tests/avocado/s390_topology.py +48 -0
index a63c2b2923..d3e6556c0f 100644
@@ -364,3 +364,51 @@ def test_socket_full(self):
         res = self.vm.qmp('set-cpu-topology',
                           {'core-id': 2, 'socket-id': 0, 'book-id': 1})
         self.assertEqual(res['return'], {})
+
+    def test_dedicated_error(self):
+        """
+        This test verifies that QEMU refuses to lower the entitlement
+        of a dedicated CPU
+
+        :avocado: tags=arch:s390x
+        :avocado: tags=machine:s390-ccw-virtio
+        """
+        self.kernel_init()
+        self.vm.launch()
+        self.wait_until_booted()
+
+        self.system_init()
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'dedicated': True})
+        self.assertEqual(res['return'], {})
+
+        self.check_topology(0, 0, 0, 0, 'high', True)
+
+        self.guest_set_dispatching('1');
+
+        self.check_topology(0, 0, 0, 0, 'high', True)
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'low', 'dedicated': True})
+        self.assertEqual(res['error']['class'], 'GenericError')
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'low'})
+        self.assertEqual(res['error']['class'], 'GenericError')
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'medium', 'dedicated': True})
+        self.assertEqual(res['error']['class'], 'GenericError')
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'medium'})
+        self.assertEqual(res['error']['class'], 'GenericError')
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'low', 'dedicated': False})
+        self.assertEqual(res['return'], {})
+
+        res = self.vm.qmp('set-cpu-topology',
+                          {'core-id': 0, 'entitlement': 'medium', 'dedicated': False})
+        self.assertEqual(res['return'], {})
Signature · 1 line
2.39.2
#37 lore raw

PATCH v23 20/20 tests/avocado: s390x cpu topology bad move

In reply to Nina Schoetterl-Glausch

From: Pierre Morel <[email protected]>

This test verifies that QEMU refuses to move a CPU to an nonexistent location.

---
 tests/avocado/s390_topology.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
tests/avocado/s390_topology.py +25 -0
index d3e6556c0f..9154ac8776 100644
@@ -412,3 +412,28 @@ def test_dedicated_error(self):
         res = self.vm.qmp('set-cpu-topology',
                           {'core-id': 0, 'entitlement': 'medium', 'dedicated': False})
         self.assertEqual(res['return'], {})
+
+    def test_move_error(self):
+        """
+        This test verifies that QEMU refuses to move a CPU to an
+        nonexistent location
+
+        :avocado: tags=arch:s390x
+        :avocado: tags=machine:s390-ccw-virtio
+        """
+        self.kernel_init()
+        self.vm.launch()
+        self.wait_until_booted()
+
+        self.system_init()
+
+        res = self.vm.qmp('set-cpu-topology', {'core-id': 0, 'drawer-id': 1})
+        self.assertEqual(res['error']['class'], 'GenericError')
+
+        res = self.vm.qmp('set-cpu-topology', {'core-id': 0, 'book-id': 1})
+        self.assertEqual(res['error']['class'], 'GenericError')
+
+        res = self.vm.qmp('set-cpu-topology', {'core-id': 0, 'socket-id': 1})
+        self.assertEqual(res['error']['class'], 'GenericError')
+
+        self.check_topology(0, 0, 0, 0, 'medium', False)
Signature · 1 line
2.39.2