From nobody Mon Feb 9 20:31:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1640683480; cv=none; d=zohomail.com; s=zohoarc; b=AJa//XHmTYauuLY7Ruvuh1rku0xORlRvW8XOwoMx3RM7Lk6LlHnpWT9H+vdmdLxGyGzV/iQiIcA+0KHyHFbfCTCml1zawpuarmu2EP6v5Hl75pgDgsIVXws1bMbQvKzeq39Xyr4Q/E7u8fUFeU+1yWbCpSaub+wLUUEfnTGdH84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640683480; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xsCypEBaje894XuaU7ojE4aozVgPJrku/Coh/c6oMQI=; b=fgdLkxk9lTL67QWmcctmEL7xVUeISRC8OLOg7BoOL/PnRmUxQ3Z/76CqIpRPmHtAVfzMQrgoga0f5+HmdVJzmqe2qGdrodGuKVzBFd10axDAPwaQwHtUoD5IJHht4vtLJGaVPSrg+le2Hy+X4kNOdZ3Y3r9LKW9kjapb2d8hLtQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1640683480617240.0808318128462; Tue, 28 Dec 2021 01:24:40 -0800 (PST) Received: from localhost ([::1]:40570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n28il-00023N-Uk for importer@patchew.org; Tue, 28 Dec 2021 04:24:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n28h2-0007cG-DF; Tue, 28 Dec 2021 04:22:52 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]:4150) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n28gz-000794-Q3; Tue, 28 Dec 2021 04:22:52 -0500 Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JNTZ60H9Jz9rvl; Tue, 28 Dec 2021 17:21:50 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 28 Dec 2021 17:22:44 +0800 To: , CC: Peter Maydell , Andrew Jones , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Paolo Bonzini , "Michael S . Tsirkin" , Igor Mammedov , Shannon Zhao , Ani Sinha , Markus Armbruster , Eric Blake , , Yanan Wang Subject: [PATCH v5 04/14] tests/unit/test-smp-parse: Add testcases for CPU clusters Date: Tue, 28 Dec 2021 17:22:11 +0800 Message-ID: <20211228092221.21068-5-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20211228092221.21068-1-wangyanan55@huawei.com> References: <20211228092221.21068-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.188; envelope-from=wangyanan55@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Yanan Wang From: Yanan Wang via X-ZM-MESSAGEID: 1640683482551000003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add testcases for parsing of the four-level CPU topology hierarchy, ie sockets/clusters/cores/threads, which will be supported on ARM virt machines. Signed-off-by: Yanan Wang Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/unit/test-smp-parse.c | 130 ++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 7 deletions(-) diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c index b6df8137fc..331719bbc4 100644 --- a/tests/unit/test-smp-parse.c +++ b/tests/unit/test-smp-parse.c @@ -61,6 +61,20 @@ .has_maxcpus =3D hf, .maxcpus =3D f, \ } =20 +/* + * Currently a 4-level topology hierarchy is supported on ARM virt machines + * -sockets/clusters/cores/threads + */ +#define SMP_CONFIG_WITH_CLUSTERS(ha, a, hb, b, hc, c, hd, d, he, e, hf, f)= \ + { \ + .has_cpus =3D ha, .cpus =3D a, \ + .has_sockets =3D hb, .sockets =3D b, \ + .has_clusters =3D hc, .clusters =3D c, \ + .has_cores =3D hd, .cores =3D d, \ + .has_threads =3D he, .threads =3D e, \ + .has_maxcpus =3D hf, .maxcpus =3D f, \ + } + /** * @config - the given SMP configuration * @expect_prefer_sockets - the expected parsing result for the @@ -290,6 +304,10 @@ static const struct SMPTestData data_generic_invalid[]= =3D { /* config: -smp 2,dies=3D2 */ .config =3D SMP_CONFIG_WITH_DIES(T, 2, F, 0, T, 2, F, 0, F, 0, F, = 0), .expect_error =3D "dies not supported by this machine's CPU topolo= gy", + }, { + /* config: -smp 2,clusters=3D2 */ + .config =3D SMP_CONFIG_WITH_CLUSTERS(T, 2, F, 0, T, 2, F, 0, F, 0,= F, 0), + .expect_error =3D "clusters not supported by this machine's CPU to= pology", }, { /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D8 */ .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, T, 2, T, 8), @@ -337,20 +355,40 @@ static const struct SMPTestData data_with_dies_invali= d[] =3D { }, }; =20 +static const struct SMPTestData data_with_clusters_invalid[] =3D { + { + /* config: -smp 16,sockets=3D2,clusters=3D2,cores=3D4,threads=3D2,= maxcpus=3D16 */ + .config =3D SMP_CONFIG_WITH_CLUSTERS(T, 16, T, 2, T, 2, T, 4, T, 2= , T, 16), + .expect_error =3D "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "sockets (2) * clusters (2) * cores (4) * threads = (2) " + "!=3D maxcpus (16)", + }, { + /* config: -smp 34,sockets=3D2,clusters=3D2,cores=3D4,threads=3D2,= maxcpus=3D32 */ + .config =3D SMP_CONFIG_WITH_CLUSTERS(T, 34, T, 2, T, 2, T, 4, T, 2= , T, 32), + .expect_error =3D "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " + "sockets (2) * clusters (2) * cores (4) * threads = (2) " + "=3D=3D maxcpus (32) < smp_cpus (34)", + }, +}; + static char *smp_config_to_string(const SMPConfiguration *config) { return g_strdup_printf( "(SMPConfiguration) {\n" - " .has_cpus =3D %5s, cpus =3D %" PRId64 ",\n" - " .has_sockets =3D %5s, sockets =3D %" PRId64 ",\n" - " .has_dies =3D %5s, dies =3D %" PRId64 ",\n" - " .has_cores =3D %5s, cores =3D %" PRId64 ",\n" - " .has_threads =3D %5s, threads =3D %" PRId64 ",\n" - " .has_maxcpus =3D %5s, maxcpus =3D %" PRId64 ",\n" + " .has_cpus =3D %5s, cpus =3D %" PRId64 ",\n" + " .has_sockets =3D %5s, sockets =3D %" PRId64 ",\n" + " .has_dies =3D %5s, dies =3D %" PRId64 ",\n" + " .has_clusters =3D %5s, clusters =3D %" PRId64 ",\n" + " .has_cores =3D %5s, cores =3D %" PRId64 ",\n" + " .has_threads =3D %5s, threads =3D %" PRId64 ",\n" + " .has_maxcpus =3D %5s, maxcpus =3D %" PRId64 ",\n" "}", config->has_cpus ? "true" : "false", config->cpus, config->has_sockets ? "true" : "false", config->sockets, config->has_dies ? "true" : "false", config->dies, + config->has_clusters ? "true" : "false", config->clusters, config->has_cores ? "true" : "false", config->cores, config->has_threads ? "true" : "false", config->threads, config->has_maxcpus ? "true" : "false", config->maxcpus); @@ -363,11 +401,12 @@ static char *cpu_topology_to_string(const CpuTopology= *topo) " .cpus =3D %u,\n" " .sockets =3D %u,\n" " .dies =3D %u,\n" + " .clusters =3D %u,\n" " .cores =3D %u,\n" " .threads =3D %u,\n" " .max_cpus =3D %u,\n" "}", - topo->cpus, topo->sockets, topo->dies, + topo->cpus, topo->sockets, topo->dies, topo->clusters, topo->cores, topo->threads, topo->max_cpus); } =20 @@ -391,6 +430,7 @@ static void check_parse(MachineState *ms, const SMPConf= iguration *config, (ms->smp.cpus =3D=3D expect_topo->cpus) && (ms->smp.sockets =3D=3D expect_topo->sockets) && (ms->smp.dies =3D=3D expect_topo->dies) && + (ms->smp.clusters =3D=3D expect_topo->clusters) && (ms->smp.cores =3D=3D expect_topo->cores) && (ms->smp.threads =3D=3D expect_topo->threads) && (ms->smp.max_cpus =3D=3D expect_topo->max_cpus)) { @@ -472,6 +512,11 @@ static void unsupported_params_init(const MachineClass= *mc, SMPTestData *data) data->expect_prefer_sockets.dies =3D 1; data->expect_prefer_cores.dies =3D 1; } + + if (!mc->smp_props.clusters_supported) { + data->expect_prefer_sockets.clusters =3D 1; + data->expect_prefer_cores.clusters =3D 1; + } } =20 static void machine_base_class_init(ObjectClass *oc, void *data) @@ -491,6 +536,7 @@ static void machine_generic_valid_class_init(ObjectClas= s *oc, void *data) mc->max_cpus =3D MAX_CPUS; =20 mc->smp_props.dies_supported =3D false; + mc->smp_props.clusters_supported =3D false; } =20 static void machine_generic_invalid_class_init(ObjectClass *oc, void *data) @@ -502,6 +548,7 @@ static void machine_generic_invalid_class_init(ObjectCl= ass *oc, void *data) mc->max_cpus =3D 511; =20 mc->smp_props.dies_supported =3D false; + mc->smp_props.clusters_supported =3D false; } =20 static void machine_with_dies_class_init(ObjectClass *oc, void *data) @@ -512,6 +559,18 @@ static void machine_with_dies_class_init(ObjectClass *= oc, void *data) mc->max_cpus =3D MAX_CPUS; =20 mc->smp_props.dies_supported =3D true; + mc->smp_props.clusters_supported =3D false; +} + +static void machine_with_clusters_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->min_cpus =3D MIN_CPUS; + mc->max_cpus =3D MAX_CPUS; + + mc->smp_props.clusters_supported =3D true; + mc->smp_props.dies_supported =3D false; } =20 static void test_generic_valid(const void *opaque) @@ -607,6 +666,56 @@ static void test_with_dies(const void *opaque) object_unref(obj); } =20 +static void test_with_clusters(const void *opaque) +{ + const char *machine_type =3D opaque; + Object *obj =3D object_new(machine_type); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + SMPTestData data =3D {}; + unsigned int num_clusters =3D 2; + int i; + + for (i =3D 0; i < ARRAY_SIZE(data_generic_valid); i++) { + data =3D data_generic_valid[i]; + unsupported_params_init(mc, &data); + + /* when clusters parameter is omitted, it will be set as 1 */ + data.expect_prefer_sockets.clusters =3D 1; + data.expect_prefer_cores.clusters =3D 1; + + smp_parse_test(ms, &data, true); + + /* when clusters parameter is specified */ + data.config.has_clusters =3D true; + data.config.clusters =3D num_clusters; + if (data.config.has_cpus) { + data.config.cpus *=3D num_clusters; + } + if (data.config.has_maxcpus) { + data.config.maxcpus *=3D num_clusters; + } + + data.expect_prefer_sockets.clusters =3D num_clusters; + data.expect_prefer_sockets.cpus *=3D num_clusters; + data.expect_prefer_sockets.max_cpus *=3D num_clusters; + data.expect_prefer_cores.clusters =3D num_clusters; + data.expect_prefer_cores.cpus *=3D num_clusters; + data.expect_prefer_cores.max_cpus *=3D num_clusters; + + smp_parse_test(ms, &data, true); + } + + for (i =3D 0; i < ARRAY_SIZE(data_with_clusters_invalid); i++) { + data =3D data_with_clusters_invalid[i]; + unsupported_params_init(mc, &data); + + smp_parse_test(ms, &data, false); + } + + object_unref(obj); +} + /* Type info of the tested machine */ static const TypeInfo smp_machine_types[] =3D { { @@ -628,6 +737,10 @@ static const TypeInfo smp_machine_types[] =3D { .name =3D MACHINE_TYPE_NAME("smp-with-dies"), .parent =3D TYPE_MACHINE, .class_init =3D machine_with_dies_class_init, + }, { + .name =3D MACHINE_TYPE_NAME("smp-with-clusters"), + .parent =3D TYPE_MACHINE, + .class_init =3D machine_with_clusters_class_init, } }; =20 @@ -648,6 +761,9 @@ int main(int argc, char *argv[]) g_test_add_data_func("/test-smp-parse/with_dies", MACHINE_TYPE_NAME("smp-with-dies"), test_with_dies); + g_test_add_data_func("/test-smp-parse/with_clusters", + MACHINE_TYPE_NAME("smp-with-clusters"), + test_with_clusters); =20 g_test_run(); =20 --=20 2.27.0