From nobody Tue Sep 9 07:02:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1640954944; cv=none; d=zohomail.com; s=zohoarc; b=AT47Qbarr64flWeqh7StyOlQN8IQZGyvQI3PQJlXbMEmC6HbtFznWSD/ec2Kam3lKmdF8arYZUsGtjyAsbv1XTiDZQ+oiH3YlS8PKNUXP3AEQDdMeWv8mRT5hiIxHD6Q1+T4J7JuOLzuaFO4ZVmG7LY836GTIKO0eXf4WQ6dNbo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640954944; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=XCjuVcTQ882USvAWxyDE+kQvzyHlN9CrhkHSlEa88PU=; b=nZPBXhzrPZAAictHUU985xWINS5NQr9KvyiUrCNzpcyZEDCUTZ+mA9jVCJr0XpcCKH0B4oUnB6VDTf906UOCaMMta3VbaclwuFQvP/pjFb5t33KtaNQcTQErXHnjD93ToCdgFjzZ6vbkxKAvZsFJQNiurIS9Vnx95bndkp4iBWk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1640954944472886.7590803717407; Fri, 31 Dec 2021 04:49:04 -0800 (PST) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-183-UuphCsIWOVi20h1M-ERgAg-1; Fri, 31 Dec 2021 07:49:02 -0500 Received: by mail-wr1-f69.google.com with SMTP id r7-20020adfbb07000000b001a254645f13so7578225wrg.7 for ; Fri, 31 Dec 2021 04:49:02 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (26.red-83-50-86.dynamicip.rima-tde.net. [83.50.86.26]) by smtp.gmail.com with ESMTPSA id m3sm26831117wrv.95.2021.12.31.04.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Dec 2021 04:49:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1640954943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XCjuVcTQ882USvAWxyDE+kQvzyHlN9CrhkHSlEa88PU=; b=d3ffUxkNdjzX4e+c7+oBjq1rc4g78T6BpaVR9IULYegM3quhGEOL082n9O5gU29VI9DRg5 X3mubTv1/snOZ03jSrYpZs7KHB0fDp2UY7lwoE2iluldf0lhBHD5/Zn2GpTUhV3Eqg9Cng lh15+sxcpzkxpL3NiUwa9+ET4uxJzoI= X-MC-Unique: UuphCsIWOVi20h1M-ERgAg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XCjuVcTQ882USvAWxyDE+kQvzyHlN9CrhkHSlEa88PU=; b=2Cvo1tNY9slRTQwWNSwkTKBSgCRlHMrtJhxClJHuKkbwb88BS4zpbu+kOoQ+x6Q6h/ kf5TBQNgcv/vAF0KSIjFt4y6+fuWEmDjO0aoFCGCIFGXM6sxFIA2HcB7BpmpoGf4ew2S HJOiCxzMgPg5Sft9n9c5dTj4p8ymGdWJnLsu5HEbAh2aMGlF4H1iMlt1qjVWNzm9CPPX aSIweGr0u6VmSBsSb96536Hv+FYDxigykThDs0yGI6Cd1wNU+/JPp8gisejrUPra6EVR b2Yu1NMlkCV2eIucH8WGCUiZ/6FmV4YwZkdOK+HulgbQFP607sKP7k71NpL9JimRWKds vE4A== X-Gm-Message-State: AOAM530GYaVbAgzLkscMiGqLzBicI2F33IipxYZEWSChgvDBopXOr7yX mDVuZQ0v8ImmD5kiTIB2On5G4J85pIgxGIbo4lXgLRV1WXnoh1FiIWCWYc1u3v1IKm6VJEegd3n 9MXl/9RO8JV9bDA== X-Received: by 2002:a5d:65d2:: with SMTP id e18mr6677507wrw.310.1640954941066; Fri, 31 Dec 2021 04:49:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMuznmFowzZ1h+S1ZeWEN3+iVQLWSKwyrbZ8HMnUgP/RVSfhjOhYbrTiwdRISEOt+j2Qn0OQ== X-Received: by 2002:a5d:65d2:: with SMTP id e18mr6677498wrw.310.1640954940877; Fri, 31 Dec 2021 04:49:00 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Yanan Wang , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 15/20] tests/unit/test-smp-parse: Add testcases for CPU clusters Date: Fri, 31 Dec 2021 13:47:49 +0100 Message-Id: <20211231124754.1005747-16-philmd@redhat.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211231124754.1005747-1-philmd@redhat.com> References: <20211231124754.1005747-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1640954946165000001 From: Yanan Wang 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 Message-Id: <20211228092221.21068-5-wangyanan55@huawei.com> Signed-off-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 b6df8137fcc..331719bbc4b 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.33.1