From: Pierre Morel <pmorel@linux.ibm.com>
To: linux-s390@vger.kernel.org
Cc: frankja@linux.ibm.com, thuth@redhat.com, kvm@vger.kernel.org,
cohuck@redhat.com, imbrenda@linux.ibm.com, david@redhat.com
Subject: [kvm-unit-tests PATCH v2 4/4] s390x: topology: Checking Configuration Topology Information
Date: Tue, 10 Aug 2021 18:22:24 +0200 [thread overview]
Message-ID: <1628612544-25130-5-git-send-email-pmorel@linux.ibm.com> (raw)
In-Reply-To: <1628612544-25130-1-git-send-email-pmorel@linux.ibm.com>
STSI with function code 15 is used to store the CPU configuration
topology.
We check if the topology stored is coherent with the QEMU -smp
parameters.
The current check is done on the number of CPUs, the maximum number
of CPUs, the number of sockets and the number of cores per sockets.
Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
---
s390x/topology.c | 208 ++++++++++++++++++++++++++++++++++++++++++++
s390x/unittests.cfg | 1 +
2 files changed, 209 insertions(+)
diff --git a/s390x/topology.c b/s390x/topology.c
index a0dc3b9e..be6f5abc 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -17,6 +17,53 @@
#include <sclp.h>
static int machine_level;
+static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2)));
+static int mnest;
+static long max_cpus;
+static long cores;
+static long sockets;
+static long books;
+static long drawers;
+static long nodes;
+static long ncpus;
+
+struct topology_core {
+ unsigned char nl;
+ unsigned char reserved0[3];
+ unsigned char :5;
+ unsigned char d:1;
+ unsigned char pp:2;
+ unsigned char type;
+ unsigned short origin;
+ unsigned long mask;
+};
+
+struct topology_container {
+ unsigned char nl;
+ unsigned char reserved[6];
+ unsigned char id;
+};
+
+union topology_entry {
+ unsigned char nl;
+ struct topology_core cpu;
+ struct topology_container container;
+};
+
+struct sysinfo_15_1_x {
+ unsigned char reserved0[2];
+ unsigned short length;
+ unsigned char mag6;
+ unsigned char mag5;
+ unsigned char mag4;
+ unsigned char mag3;
+ unsigned char mag2;
+ unsigned char mag1;
+ unsigned char reserved1;
+ unsigned char mnest;
+ unsigned char reserved2[4];
+ union topology_entry tle[0];
+};
#define PTF_REQ_HORIZONTAL 0
#define PTF_REQ_VERTICAL 1
@@ -79,10 +126,170 @@ end:
report_prefix_pop();
}
+static void check_sysinfo_15_1_x(struct sysinfo_15_1_x *info)
+{
+ struct topology_container *tc, *end;
+ struct topology_core *cpus;
+ int nb_nl0 = 0, nb_nl1 = 0, nb_nl2 = 0, nb_nl3 = 0;
+
+ if (mnest > 5)
+ report(info->mag6 == 0, "topology level 6");
+ if (mnest > 4)
+ report(info->mag5 == nodes, "Maximum number of nodes");
+ if (mnest > 3)
+ report(info->mag4 == drawers, "Maximum number of drawers");
+ if (mnest > 2)
+ report(info->mag3 == books, "Maximum number of books");
+
+ /* Both levels 2 and 1 are always valid */
+ report(info->mag2 == sockets, "Maximum number of sockets");
+ report(info->mag1 == cores, "Maximum number of cores");
+
+ tc = (void *)&info->tle[0];
+ end = (struct topology_container *)((unsigned long)info + info->length);
+
+ while (tc < end) {
+ switch (tc->nl) {
+ case 3:
+ report_info("drawer: %d %d", tc->nl, tc->id);
+ nb_nl3++;
+ break;
+ case 2:
+ report_info("book : %d %d", tc->nl, tc->id);
+ nb_nl2++;
+ break;
+ case 1:
+ report_info("socket: %d %d", tc->nl, tc->id);
+ nb_nl1++;
+ break;
+ case 0:
+ cpus = (struct topology_core *) tc;
+ report_info("cpu type %02x d: %d pp: %d", cpus->type, cpus->d, cpus->pp);
+ report_info("origin : %04x mask %016lx", cpus->origin, cpus->mask);
+ tc++;
+ nb_nl0++;
+ break;
+ default:
+ report_abort("Unexpected TL Entry: tle->nl: %d", tc->nl);
+ return;
+ }
+ tc++;
+ }
+ /*
+ * As we accept only 1 type of CPU, and only horizontal and dedicated CPUs
+ * We expect max_cpus / cores CPU entries
+ */
+ report(nb_nl0 == (1 + (ncpus - 1) / cores),
+ "Check count of cores: %d %ld", nb_nl0, ncpus / cores);
+ /* We expect the same count of sockets and CPU entries */
+ report(nb_nl1 == nb_nl0, "Check count of sockets");
+ if (mnest > 2)
+ report(nb_nl2 == nb_nl1 / sockets, "Checks count of books");
+ if (mnest > 3)
+ report(nb_nl3 == nb_nl2 / books, "Checks count of drawers");
+}
+
+static void test_stsi(void)
+{
+ int ret;
+
+ mnest = sclp_get_stsi_parm();
+ /* If the STSI parm is 0, the maximum MNEST for STSI is 2 */
+ if (!mnest)
+ mnest = 2;
+ report_info("SCLP MNEST : %d", mnest);
+
+ ret = sclp_get_cpu_num();
+ report_info("SCLP nb CPU: %d", ret);
+
+ ret = stsi(pagebuf, 15, 1, 2);
+ report(!ret, "valid stsi 15.1.2");
+ if (!ret)
+ check_sysinfo_15_1_x((struct sysinfo_15_1_x *)pagebuf);
+ else
+ report_info(" ret: %d", ret);
+
+ if (mnest < 3) {
+ report(stsi(pagebuf, 15, 1, 3) == 3, "invalid stsi 15.1.3");
+ } else {
+ report(stsi(pagebuf, 15, 1, 3) == 0, "valid stsi 15.1.3");
+ check_sysinfo_15_1_x((struct sysinfo_15_1_x *)pagebuf);
+ }
+
+ if (mnest < 4) {
+ report(stsi(pagebuf, 15, 1, 4) == 3, "invalid stsi 15.1.4");
+ } else {
+ report(stsi(pagebuf, 15, 1, 4) == 0, "valid stsi 15.1.4");
+ check_sysinfo_15_1_x((struct sysinfo_15_1_x *)pagebuf);
+ }
+
+ if (mnest < 5) {
+ report(stsi(pagebuf, 15, 1, 5) == 3, "invalid stsi 15.1.5");
+ } else {
+ report(stsi(pagebuf, 15, 1, 5) == 0, "valid stsi 15.1.5");
+ check_sysinfo_15_1_x((struct sysinfo_15_1_x *)pagebuf);
+ }
+
+ if (mnest < 6) {
+ report(stsi(pagebuf, 15, 1, 6) == 3, "invalid stsi 15.1.6");
+ } else {
+ report(stsi(pagebuf, 15, 1, 6) == 0, "valid stsi 15.1.6");
+ check_sysinfo_15_1_x((struct sysinfo_15_1_x *)pagebuf);
+ }
+}
+
+static void parse_topology_args(int argc, char **argv)
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (!strcmp("-c", argv[i])) {
+ i++;
+ if (i >= argc)
+ report_abort("-c (cores) needs a parameter");
+ cores = atol(argv[i]);
+ } else if (!strcmp("-s", argv[i])) {
+ i++;
+ if (i >= argc)
+ report_abort("-s (sockets) needs a parameter");
+ sockets = atol(argv[i]);
+ } else if (!strcmp("-b", argv[i])) {
+ i++;
+ if (i >= argc)
+ report_abort("-b (books) needs a parameter");
+ books = atol(argv[i]);
+ } else if (!strcmp("-d", argv[i])) {
+ i++;
+ if (i >= argc)
+ report_abort("-d (drawers) needs a parameter");
+ drawers = atol(argv[i]);
+ } else if (!strcmp("-n", argv[i])) {
+ i++;
+ if (i >= argc)
+ report_abort("-n (nodes) needs a parameter");
+ nodes = atol(argv[i]);
+ }
+ }
+ if (!cores)
+ cores = 1;
+ if (!sockets)
+ sockets = 1;
+ if (!books)
+ books = 1;
+ if (!drawers)
+ drawers = 1;
+ if (!nodes)
+ nodes = 1;
+ max_cpus = cores * sockets * books * drawers * nodes;
+ ncpus = smp_query_num_cpus();
+}
+
int main(int argc, char *argv[])
{
report_prefix_push("CPU Topology");
+ parse_topology_args(argc, argv);
+
if (!test_facility(11)) {
report_skip("Topology facility not present");
goto end;
@@ -92,6 +299,7 @@ int main(int argc, char *argv[])
report_info("Machine level %d", machine_level);
test_ptf();
+ test_stsi();
end:
report_prefix_pop();
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index 0f84d279..390e8398 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -112,3 +112,4 @@ file = mvpg-sie.elf
[topology]
file = topology.elf
+extra_params=-smp 5,sockets=4,cores=4,maxcpus=16 -append "-n 5 -s 4 -c 4 -m 16"
--
2.25.1
prev parent reply other threads:[~2021-08-10 16:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-10 16:22 [kvm-unit-tests PATCH v2 0/4] S390x: CPU Topology Information Pierre Morel
2021-08-10 16:22 ` [kvm-unit-tests PATCH v2 1/4] s390x: lib: Add SCLP toplogy nested level Pierre Morel
2021-08-11 14:59 ` Janosch Frank
2021-08-12 8:36 ` Pierre Morel
2021-08-12 12:56 ` Cornelia Huck
2021-08-12 15:05 ` Pierre Morel
2021-08-12 15:12 ` Cornelia Huck
2021-08-10 16:22 ` [kvm-unit-tests PATCH v2 2/4] s390x: lib: Simplify stsi_get_fc and move it to library Pierre Morel
2021-08-11 15:01 ` Janosch Frank
2021-08-12 8:38 ` Pierre Morel
2021-08-18 7:45 ` Thomas Huth
2021-08-23 9:17 ` Pierre Morel
2021-08-10 16:22 ` [kvm-unit-tests PATCH v2 3/4] s390x: topology: Check the Perform Topology Function Pierre Morel
2021-08-12 9:38 ` Janosch Frank
2021-08-12 11:40 ` Pierre Morel
2021-08-10 16:22 ` Pierre Morel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1628612544-25130-5-git-send-email-pmorel@linux.ibm.com \
--to=pmorel@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox