qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@linux.intel.com>
To: "Michael S . Tsirkin" <mst@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	qemu-devel@nongnu.org
Cc: Michael Tokarev <mjt@tls.msk.ru>,
	Zhenyu Wang <zhenyu.z.wang@intel.com>,
	Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH 01/16] tests: test-smp-parse: Add the test for cores/threads per socket helpers
Date: Fri, 25 Aug 2023 11:36:04 +0800	[thread overview]
Message-ID: <20230825033619.2075837-2-zhao1.liu@linux.intel.com> (raw)
In-Reply-To: <20230825033619.2075837-1-zhao1.liu@linux.intel.com>

From: Zhao Liu <zhao1.liu@intel.com>

Use the different ways to calculate cores/threads per socket, so that
the new CPU topology levels won't be missed in these 2 helpes:

* machine_topo_get_cores_per_socket()
* machine_topo_get_threads_per_socket()

Test the commit a1d027be95bc3 ("machine: Add helpers to get cores/
threads per socket").

Suggested-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 tests/unit/test-smp-parse.c | 67 ++++++++++++++++++++++++++++++-------
 1 file changed, 54 insertions(+), 13 deletions(-)

diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c
index fdc39a846ca6..24972666a74d 100644
--- a/tests/unit/test-smp-parse.c
+++ b/tests/unit/test-smp-parse.c
@@ -394,20 +394,47 @@ static char *smp_config_to_string(const SMPConfiguration *config)
         config->has_maxcpus ? "true" : "false", config->maxcpus);
 }
 
-static char *cpu_topology_to_string(const CpuTopology *topo)
+/* Use the different calculation than machine_topo_get_threads_per_socket(). */
+static unsigned int cpu_topology_get_threads_per_socket(const CpuTopology *topo)
+{
+    /* Check the divisor to avoid invalid topology examples causing SIGFPE. */
+    if (!topo->sockets) {
+        return 0;
+    } else {
+        return topo->max_cpus / topo->sockets;
+    }
+}
+
+/* Use the different calculation than machine_topo_get_cores_per_socket(). */
+static unsigned int cpu_topology_get_cores_per_socket(const CpuTopology *topo)
+{
+    /* Check the divisor to avoid invalid topology examples causing SIGFPE. */
+    if (!topo->threads) {
+        return 0;
+    } else {
+        return cpu_topology_get_threads_per_socket(topo) / topo->threads;
+    }
+}
+
+static char *cpu_topology_to_string(const CpuTopology *topo,
+                                    unsigned int threads_per_socket,
+                                    unsigned int cores_per_socket)
 {
     return g_strdup_printf(
         "(CpuTopology) {\n"
-        "    .cpus     = %u,\n"
-        "    .sockets  = %u,\n"
-        "    .dies     = %u,\n"
-        "    .clusters = %u,\n"
-        "    .cores    = %u,\n"
-        "    .threads  = %u,\n"
-        "    .max_cpus = %u,\n"
+        "    .cpus               = %u,\n"
+        "    .sockets            = %u,\n"
+        "    .dies               = %u,\n"
+        "    .clusters           = %u,\n"
+        "    .cores              = %u,\n"
+        "    .threads            = %u,\n"
+        "    .max_cpus           = %u,\n"
+        "    .threads_per_socket = %u,\n"
+        "    .cores_per_socket   = %u,\n"
         "}",
         topo->cpus, topo->sockets, topo->dies, topo->clusters,
-        topo->cores, topo->threads, topo->max_cpus);
+        topo->cores, topo->threads, topo->max_cpus,
+        threads_per_socket, cores_per_socket);
 }
 
 static void check_parse(MachineState *ms, const SMPConfiguration *config,
@@ -415,14 +442,26 @@ static void check_parse(MachineState *ms, const SMPConfiguration *config,
                         bool is_valid)
 {
     g_autofree char *config_str = smp_config_to_string(config);
-    g_autofree char *expect_topo_str = cpu_topology_to_string(expect_topo);
-    g_autofree char *output_topo_str = NULL;
+    g_autofree char *expect_topo_str = NULL, *output_topo_str = NULL;
+    unsigned int expect_threads_per_socket, expect_cores_per_socket;
+    unsigned int ms_threads_per_socket, ms_cores_per_socket;
     Error *err = NULL;
 
+    expect_threads_per_socket =
+                        cpu_topology_get_threads_per_socket(expect_topo);
+    expect_cores_per_socket =
+                        cpu_topology_get_cores_per_socket(expect_topo);
+    expect_topo_str = cpu_topology_to_string(expect_topo,
+                                             expect_threads_per_socket,
+                                             expect_cores_per_socket);
+
     /* call the generic parser */
     machine_parse_smp_config(ms, config, &err);
 
-    output_topo_str = cpu_topology_to_string(&ms->smp);
+    ms_threads_per_socket = machine_topo_get_threads_per_socket(ms);
+    ms_cores_per_socket = machine_topo_get_cores_per_socket(ms);
+    output_topo_str = cpu_topology_to_string(&ms->smp, ms_threads_per_socket,
+                                             ms_cores_per_socket);
 
     /* when the configuration is supposed to be valid */
     if (is_valid) {
@@ -433,7 +472,9 @@ static void check_parse(MachineState *ms, const SMPConfiguration *config,
             (ms->smp.clusters == expect_topo->clusters) &&
             (ms->smp.cores == expect_topo->cores) &&
             (ms->smp.threads == expect_topo->threads) &&
-            (ms->smp.max_cpus == expect_topo->max_cpus)) {
+            (ms->smp.max_cpus == expect_topo->max_cpus) &&
+            (ms_threads_per_socket == expect_threads_per_socket) &&
+            (ms_cores_per_socket == expect_cores_per_socket)) {
             return;
         }
 
-- 
2.34.1



  reply	other threads:[~2023-08-25  3:27 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25  3:36 [PATCH 00/16] tests: Add CPU topology related smbios test cases Zhao Liu
2023-08-25  3:36 ` Zhao Liu [this message]
2023-09-15 12:31   ` [PATCH 01/16] tests: test-smp-parse: Add the test for cores/threads per socket helpers Igor Mammedov
2023-09-19  7:18     ` Zhao Liu
2023-08-25  3:36 ` [PATCH 02/16] tests: bios-tables-test: Prepare the ACPI table change for type4 count test Zhao Liu
2023-08-25  3:36 ` [PATCH 03/16] tests: bios-tables-test: Add test for smbios type4 count Zhao Liu
2023-09-15 12:54   ` Igor Mammedov
2023-09-19  7:20     ` Zhao Liu
2023-08-25  3:36 ` [PATCH 04/16] tests: bios-tables-test: Add ACPI table binaries for type4 count test Zhao Liu
2023-09-15 13:05   ` Igor Mammedov
2023-09-19  7:26     ` Zhao Liu
2023-08-25  3:36 ` [PATCH 05/16] tests: bios-tables-test: Prepare the ACPI table change for type4 core " Zhao Liu
2023-08-25  3:36 ` [PATCH 06/16] tests: bios-tables-test: Add test for smbios type4 core count Zhao Liu
2023-09-15 13:03   ` Igor Mammedov
2023-09-19  7:21     ` Zhao Liu
2023-08-25  3:36 ` [PATCH 07/16] tests: bios-tables-test: Add ACPI table binaries for type4 core count test Zhao Liu
2023-08-25  3:36 ` [PATCH 08/16] tests: bios-tables-test: Prepare the ACPI table change for type4 core count2 test Zhao Liu
2023-08-25  3:36 ` [PATCH 09/16] tests: bios-tables-test: Extend core count2 test to cover general topology Zhao Liu
2023-09-15 13:11   ` Igor Mammedov
2023-09-19  7:14     ` Zhao Liu
2023-08-25  3:36 ` [PATCH 10/16] tests: bios-tables-test: Update ACPI table binaries for core count2 test Zhao Liu
2023-08-25  3:36 ` [PATCH 11/16] tests: bios-tables-test: Prepare the ACPI table change for type4 thread count test Zhao Liu
2023-08-25  3:36 ` [PATCH 12/16] tests: bios-tables-test: Add test for smbios type4 thread count Zhao Liu
2023-09-15 13:19   ` Igor Mammedov
2023-09-19  7:13     ` Zhao Liu
2023-08-25  3:36 ` [PATCH 13/16] tests: bios-tables-test: Add ACPI table binaries for type4 thread count test Zhao Liu
2023-08-25  3:36 ` [PATCH 14/16] tests: bios-tables-test: Prepare the ACPI table change for type4 thread count2 test Zhao Liu
2023-08-25  3:36 ` [PATCH 15/16] tests: bios-tables-test: Add test for smbios type4 thread count2 Zhao Liu
2023-09-15 13:29   ` Igor Mammedov
2023-09-19  7:12     ` Zhao Liu
2023-09-19  8:01       ` Igor Mammedov
2023-08-25  3:36 ` [PATCH 16/16] tests: bios-tables-test: Add ACPI table binaries for type4 thread count2 test Zhao Liu
2023-09-01  9:55 ` [PATCH 00/16] tests: Add CPU topology related smbios test cases Michael Tokarev
2023-09-05  6:56   ` Zhao Liu
2023-09-15 13:48     ` Michael S. Tsirkin
2023-09-15 14:30       ` Igor Mammedov
2023-09-19  6:46         ` Zhao Liu
2023-09-06 14:40   ` Philippe Mathieu-Daudé

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=20230825033619.2075837-2-zhao1.liu@linux.intel.com \
    --to=zhao1.liu@linux.intel.com \
    --cc=anisinha@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=imammedo@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mjt@tls.msk.ru \
    --cc=mst@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wangyanan55@huawei.com \
    --cc=zhao1.liu@intel.com \
    --cc=zhenyu.z.wang@intel.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;
as well as URLs for NNTP newsgroup(s).