From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626664938118924.4358492227939; Sun, 18 Jul 2021 20:22:18 -0700 (PDT) Received: from localhost ([::1]:43802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5JrF-0000Qg-3h for importer@patchew.org; Sun, 18 Jul 2021 23:22:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq2-00067H-Cf for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:02 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jpz-0005ve-AW for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:01 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GSn5h4QYpzYd6J; Mon, 19 Jul 2021 11:15:04 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:48 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:47 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 01/11] machine: Disallow specifying topology parameters as zero Date: Mon, 19 Jul 2021 11:20:33 +0800 Message-ID: <20210719032043.25416-2-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.187; envelope-from=wangyanan55@huawei.com; helo=szxga01-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626664938778100004 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the SMP configuration, we should either specify a topology parameter with a reasonable value (equal to or greater than 1) or just leave it omitted and QEMU will calculate its value. Configurations which explicitly specify the topology parameters as zero like "sockets=3D0" are meaningless, so disallow them. Suggested-by: Andrew Jones Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- hw/core/machine.c | 31 +++++++++++++++++++++++-------- hw/i386/pc.c | 29 +++++++++++++++++++++-------- qapi/machine.json | 4 ++-- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 775add0795..d73daa10f4 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -745,11 +745,25 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) { unsigned cpus =3D config->has_cpus ? config->cpus : 0; unsigned sockets =3D config->has_sockets ? config->sockets : 0; + unsigned dies =3D config->has_dies ? config->dies : 1; unsigned cores =3D config->has_cores ? config->cores : 0; unsigned threads =3D config->has_threads ? config->threads : 0; + unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; + + if ((config->has_cpus && config->cpus =3D=3D 0) || + (config->has_sockets && config->sockets =3D=3D 0) || + (config->has_dies && config->dies =3D=3D 0) || + (config->has_cores && config->cores =3D=3D 0) || + (config->has_threads && config->threads =3D=3D 0) || + (config->has_maxcpus && config->maxcpus =3D=3D 0)) { + error_setg(errp, "parameters must be equal to or greater than one" + "if provided"); + return; + } =20 - if (config->has_dies && config->dies !=3D 0 && config->dies !=3D 1) { + if (dies > 1) { error_setg(errp, "dies not supported by this machine's CPU topolog= y"); + return; } =20 /* compute missing values, prefer sockets over cores over threads */ @@ -760,8 +774,8 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) sockets =3D sockets > 0 ? sockets : 1; cpus =3D cores * threads * sockets; } else { - ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : c= pus; - sockets =3D ms->smp.max_cpus / (cores * threads); + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + sockets =3D maxcpus / (cores * threads); } } else if (cores =3D=3D 0) { threads =3D threads > 0 ? threads : 1; @@ -778,26 +792,27 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) return; } =20 - ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : cpus; + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; =20 - if (ms->smp.max_cpus < cpus) { + if (maxcpus < cpus) { error_setg(errp, "maxcpus must be equal to or greater than smp"); return; } =20 - if (sockets * cores * threads !=3D ms->smp.max_cpus) { + if (sockets * cores * threads !=3D maxcpus) { error_setg(errp, "Invalid CPU topology: " "sockets (%u) * cores (%u) * threads (%u) " "!=3D maxcpus (%u)", sockets, cores, threads, - ms->smp.max_cpus); + maxcpus); return; } =20 ms->smp.cpus =3D cpus; + ms->smp.sockets =3D sockets; ms->smp.cores =3D cores; ms->smp.threads =3D threads; - ms->smp.sockets =3D sockets; + ms->smp.max_cpus =3D maxcpus; } =20 static void machine_get_smp(Object *obj, Visitor *v, const char *name, diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c2b9d62a35..c6b63c00a5 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -719,6 +719,18 @@ static void pc_smp_parse(MachineState *ms, SMPConfigur= ation *config, Error **err unsigned dies =3D config->has_dies ? config->dies : 1; unsigned cores =3D config->has_cores ? config->cores : 0; unsigned threads =3D config->has_threads ? config->threads : 0; + unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; + + if ((config->has_cpus && config->cpus =3D=3D 0) || + (config->has_sockets && config->sockets =3D=3D 0) || + (config->has_dies && config->dies =3D=3D 0) || + (config->has_cores && config->cores =3D=3D 0) || + (config->has_threads && config->threads =3D=3D 0) || + (config->has_maxcpus && config->maxcpus =3D=3D 0)) { + error_setg(errp, "parameters must be equal to or greater than one" + "if provided"); + return; + } =20 /* compute missing values, prefer sockets over cores over threads */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { @@ -728,8 +740,8 @@ static void pc_smp_parse(MachineState *ms, SMPConfigura= tion *config, Error **err sockets =3D sockets > 0 ? sockets : 1; cpus =3D cores * threads * dies * sockets; } else { - ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : c= pus; - sockets =3D ms->smp.max_cpus / (cores * threads * dies); + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + sockets =3D maxcpus / (cores * threads * dies); } } else if (cores =3D=3D 0) { threads =3D threads > 0 ? threads : 1; @@ -746,27 +758,28 @@ static void pc_smp_parse(MachineState *ms, SMPConfigu= ration *config, Error **err return; } =20 - ms->smp.max_cpus =3D config->has_maxcpus ? config->maxcpus : cpus; + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; =20 - if (ms->smp.max_cpus < cpus) { + if (maxcpus < cpus) { error_setg(errp, "maxcpus must be equal to or greater than smp"); return; } =20 - if (sockets * dies * cores * threads !=3D ms->smp.max_cpus) { + if (sockets * dies * cores * threads !=3D maxcpus) { error_setg(errp, "Invalid CPU topology deprecated: " "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " "!=3D maxcpus (%u)", sockets, dies, cores, threads, - ms->smp.max_cpus); + maxcpus); return; } =20 ms->smp.cpus =3D cpus; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; ms->smp.sockets =3D sockets; ms->smp.dies =3D dies; + ms->smp.cores =3D cores; + ms->smp.threads =3D threads; + ms->smp.max_cpus =3D maxcpus; } =20 static diff --git a/qapi/machine.json b/qapi/machine.json index c3210ee1fb..c11b2e6f73 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1288,8 +1288,8 @@ ## # @SMPConfiguration: # -# Schema for CPU topology configuration. "0" or a missing value lets -# QEMU figure out a suitable value based on the ones that are provided. +# Schema for CPU topology configuration. A missing value lets QEMU +# figure out a suitable value based on the ones that are provided. # # @cpus: number of virtual CPUs in the virtual machine # --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626665035390803.58552524315; Sun, 18 Jul 2021 20:23:55 -0700 (PDT) Received: from localhost ([::1]:52214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5Jso-0005yD-B3 for importer@patchew.org; Sun, 18 Jul 2021 23:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq4-00068n-Te for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:04 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2434) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jpz-0005x6-He for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:04 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GSn8V3Lx4zZqmj; Mon, 19 Jul 2021 11:17:30 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:50 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:49 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 02/11] machine: Make smp_parse generic enough for all arches Date: Mon, 19 Jul 2021 11:20:34 +0800 Message-ID: <20210719032043.25416-3-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.187; envelope-from=wangyanan55@huawei.com; helo=szxga01-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665036339100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the only difference between smp_parse and pc_smp_parse is the support of multi-dies and the related error reporting code. With an arch compat variable "bool smp_dies_supported", we can easily make smp_parse generic enough for all arches and the PC specific one can be removed. Making smp_parse() generic enough can reduce code duplication and ease the code maintenance, and also allows extending the topology with more arch specific members (e.g., clusters) in the future. No functional change intended. Suggested-by: Andrew Jones Signed-off-by: Yanan Wang --- hw/core/machine.c | 28 ++++++++++------- hw/i386/pc.c | 76 +-------------------------------------------- include/hw/boards.h | 1 + 3 files changed, 19 insertions(+), 86 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index d73daa10f4..ed6712e964 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -743,6 +743,7 @@ void machine_set_cpu_numa_node(MachineState *machine, =20 static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **= errp) { + MachineClass *mc =3D MACHINE_GET_CLASS(ms); unsigned cpus =3D config->has_cpus ? config->cpus : 0; unsigned sockets =3D config->has_sockets ? config->sockets : 0; unsigned dies =3D config->has_dies ? config->dies : 1; @@ -761,7 +762,7 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) return; } =20 - if (dies > 1) { + if (!mc->smp_dies_supported && dies > 1) { error_setg(errp, "dies not supported by this machine's CPU topolog= y"); return; } @@ -772,23 +773,25 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) threads =3D threads > 0 ? threads : 1; if (cpus =3D=3D 0) { sockets =3D sockets > 0 ? sockets : 1; - cpus =3D cores * threads * sockets; + cpus =3D sockets * dies * cores * threads; } else { maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - sockets =3D maxcpus / (cores * threads); + sockets =3D maxcpus / (dies * cores * threads); } } else if (cores =3D=3D 0) { threads =3D threads > 0 ? threads : 1; - cores =3D cpus / (sockets * threads); + cores =3D cpus / (sockets * dies * threads); cores =3D cores > 0 ? cores : 1; } else if (threads =3D=3D 0) { - threads =3D cpus / (cores * sockets); + threads =3D cpus / (sockets * dies * cores); threads =3D threads > 0 ? threads : 1; - } else if (sockets * cores * threads < cpus) { + } else if (sockets * dies * cores * threads < cpus) { + g_autofree char *dies_msg =3D g_strdup_printf( + mc->smp_dies_supported ? " * dies (%u)" : "", dies); error_setg(errp, "cpu topology: " - "sockets (%u) * cores (%u) * threads (%u) < " + "sockets (%u)%s * cores (%u) * threads (%u) < " "smp_cpus (%u)", - sockets, cores, threads, cpus); + sockets, dies_msg, cores, threads, cpus); return; } =20 @@ -799,17 +802,20 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) return; } =20 - if (sockets * cores * threads !=3D maxcpus) { + if (sockets * dies * cores * threads !=3D maxcpus) { + g_autofree char *dies_msg =3D g_strdup_printf( + mc->smp_dies_supported ? " * dies (%u)" : "", dies); error_setg(errp, "Invalid CPU topology: " - "sockets (%u) * cores (%u) * threads (%u) " + "sockets (%u)%s * cores (%u) * threads (%u) " "!=3D maxcpus (%u)", - sockets, cores, threads, + sockets, dies_msg, cores, threads, maxcpus); return; } =20 ms->smp.cpus =3D cpus; ms->smp.sockets =3D sockets; + ms->smp.dies =3D dies; ms->smp.cores =3D cores; ms->smp.threads =3D threads; ms->smp.max_cpus =3D maxcpus; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c6b63c00a5..d94ef582b5 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -708,80 +708,6 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int = level) } } =20 -/* - * This function is very similar to smp_parse() - * in hw/core/machine.c but includes CPU die support. - */ -static void pc_smp_parse(MachineState *ms, SMPConfiguration *config, Error= **errp) -{ - unsigned cpus =3D config->has_cpus ? config->cpus : 0; - unsigned sockets =3D config->has_sockets ? config->sockets : 0; - unsigned dies =3D config->has_dies ? config->dies : 1; - unsigned cores =3D config->has_cores ? config->cores : 0; - unsigned threads =3D config->has_threads ? config->threads : 0; - unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; - - if ((config->has_cpus && config->cpus =3D=3D 0) || - (config->has_sockets && config->sockets =3D=3D 0) || - (config->has_dies && config->dies =3D=3D 0) || - (config->has_cores && config->cores =3D=3D 0) || - (config->has_threads && config->threads =3D=3D 0) || - (config->has_maxcpus && config->maxcpus =3D=3D 0)) { - error_setg(errp, "parameters must be equal to or greater than one" - "if provided"); - return; - } - - /* compute missing values, prefer sockets over cores over threads */ - if (cpus =3D=3D 0 || sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - if (cpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cpus =3D cores * threads * dies * sockets; - } else { - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - sockets =3D maxcpus / (cores * threads * dies); - } - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D cpus / (sockets * dies * threads); - cores =3D cores > 0 ? cores : 1; - } else if (threads =3D=3D 0) { - threads =3D cpus / (cores * dies * sockets); - threads =3D threads > 0 ? threads : 1; - } else if (sockets * dies * cores * threads < cpus) { - error_setg(errp, "cpu topology: " - "sockets (%u) * dies (%u) * cores (%u) * threads (%u) <= " - "smp_cpus (%u)", - sockets, dies, cores, threads, cpus); - return; - } - - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - - if (maxcpus < cpus) { - error_setg(errp, "maxcpus must be equal to or greater than smp"); - return; - } - - if (sockets * dies * cores * threads !=3D maxcpus) { - error_setg(errp, "Invalid CPU topology deprecated: " - "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, dies, cores, threads, - maxcpus); - return; - } - - ms->smp.cpus =3D cpus; - ms->smp.sockets =3D sockets; - ms->smp.dies =3D dies; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; - ms->smp.max_cpus =3D maxcpus; -} - static void pc_machine_done(Notifier *notifier, void *data) { @@ -1735,7 +1661,6 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) mc->auto_enable_numa_with_memdev =3D true; mc->has_hotpluggable_cpus =3D true; mc->default_boot_order =3D "cad"; - mc->smp_parse =3D pc_smp_parse; mc->block_default_type =3D IF_IDE; mc->max_cpus =3D 255; mc->reset =3D pc_machine_reset; @@ -1746,6 +1671,7 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) hc->unplug =3D pc_machine_device_unplug_cb; mc->default_cpu_type =3D TARGET_DEFAULT_CPU_TYPE; mc->nvdimm_supported =3D true; + mc->smp_dies_supported =3D true; mc->default_ram_id =3D "pc.ram"; =20 object_class_property_add(oc, PC_MACHINE_MAX_RAM_BELOW_4G, "size", diff --git a/include/hw/boards.h b/include/hw/boards.h index accd6eff35..b6161cee88 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -246,6 +246,7 @@ struct MachineClass { bool smbus_no_migration_support; bool nvdimm_supported; bool numa_mem_supported; + bool smp_dies_supported; bool auto_enable_numa; const char *default_ram_id; =20 --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626665035029498.9365563661671; Sun, 18 Jul 2021 20:23:55 -0700 (PDT) Received: from localhost ([::1]:52248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5Jsn-0005zM-UJ for importer@patchew.org; Sun, 18 Jul 2021 23:23:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq5-00068v-0t for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:05 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq0-0005wq-23 for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:04 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GSn8B0Q6tz7tBl; Mon, 19 Jul 2021 11:17:14 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:51 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:50 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 03/11] machine: Uniformly use maxcpus to calculate the omitted parameters Date: Mon, 19 Jul 2021 11:20:35 +0800 Message-ID: <20210719032043.25416-4-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665036328100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We are currently using maxcpus to calculate the omitted sockets but using cpus to calculate the omitted cores/threads. This makes cmdlines like: -smp cpus=3D8,maxcpus=3D16 -smp cpus=3D8,cores=3D4,maxcpus=3D16 -smp cpus=3D8,threads=3D2,maxcpus=3D16 work fine but the ones like: -smp cpus=3D8,sockets=3D2,maxcpus=3D16 -smp cpus=3D8,sockets=3D2,cores=3D4,maxcpus=3D16 -smp cpus=3D8,sockets=3D2,threads=3D2,maxcpus=3D16 break the invalid cpu topology check. Since we require for the valid config that the sum of "sockets * cores * dies * threads" should equal to the maxcpus, we should uniformly use maxcpus to calculate their omitted values. Also the if-branch of "cpus =3D=3D 0 || sockets =3D=3D 0" was splited into = two branches of "cpus =3D=3D 0" and "sockets =3D=3D 0" so that we can clearly r= ead that we are parsing -smp cmdlines with a preference of cpus over sockets over cores over threads. Note: change in this patch won't affect any existing working cmdlines but improves consistency and allow more incomplete configs to be valid. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- hw/core/machine.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index ed6712e964..c9f15b15a5 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -768,24 +768,26 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) } =20 /* compute missing values, prefer sockets over cores over threads */ - if (cpus =3D=3D 0 || sockets =3D=3D 0) { + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + + if (cpus =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; cores =3D cores > 0 ? cores : 1; threads =3D threads > 0 ? threads : 1; - if (cpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cpus =3D sockets * dies * cores * threads; - } else { - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - sockets =3D maxcpus / (dies * cores * threads); - } + cpus =3D sockets * dies * cores * threads; + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + } else if (sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); } else if (cores =3D=3D 0) { threads =3D threads > 0 ? threads : 1; - cores =3D cpus / (sockets * dies * threads); - cores =3D cores > 0 ? cores : 1; + cores =3D maxcpus / (sockets * dies * threads); } else if (threads =3D=3D 0) { - threads =3D cpus / (sockets * dies * cores); - threads =3D threads > 0 ? threads : 1; - } else if (sockets * dies * cores * threads < cpus) { + threads =3D maxcpus / (sockets * dies * cores); + } + + if (sockets * dies * cores * threads < cpus) { g_autofree char *dies_msg =3D g_strdup_printf( mc->smp_dies_supported ? " * dies (%u)" : "", dies); error_setg(errp, "cpu topology: " @@ -795,8 +797,6 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) return; } =20 - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - if (maxcpus < cpus) { error_setg(errp, "maxcpus must be equal to or greater than smp"); return; --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162666493775082.5921260967175; Sun, 18 Jul 2021 20:22:17 -0700 (PDT) Received: from localhost ([::1]:43768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5JrE-0000P5-DF for importer@patchew.org; Sun, 18 Jul 2021 23:22:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq3-00067m-W0 for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:04 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq1-0005xk-BP for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:03 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GSn8C1X1Hz7wFP; Mon, 19 Jul 2021 11:17:15 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:52 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:51 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 04/11] machine: Use the computed parameters to calculate omitted cpus Date: Mon, 19 Jul 2021 11:20:36 +0800 Message-ID: <20210719032043.25416-5-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626664938704100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently we directly calculate the omitted cpus based on the already provided parameters. This makes some cmdlines like: -smp maxcpus=3D16 -smp sockets=3D2,maxcpus=3D16 -smp sockets=3D2,dies=3D2,maxcpus=3D16 -smp sockets=3D2,cores=3D4,maxcpus=3D16 not work. We should probably use the computed paramters to calculate cpus when maxcpus is provided while cpus is omitted, which will make above configs start to work. Note: change in this patch won't affect any existing working cmdlines but allows more incomplete configs to be valid. Signed-off-by: Yanan Wang --- hw/core/machine.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index c9f15b15a5..668f0a1553 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -767,26 +767,27 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) return; } =20 - /* compute missing values, prefer sockets over cores over threads */ maxcpus =3D maxcpus > 0 ? maxcpus : cpus; =20 - if (cpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - cpus =3D sockets * dies * cores * threads; - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - } else if (sockets =3D=3D 0) { + /* compute missing values, prefer sockets over cores over threads */ + if (sockets =3D=3D 0) { cores =3D cores > 0 ? cores : 1; threads =3D threads > 0 ? threads : 1; sockets =3D maxcpus / (dies * cores * threads); + sockets =3D sockets > 0 ? sockets : 1; } else if (cores =3D=3D 0) { threads =3D threads > 0 ? threads : 1; cores =3D maxcpus / (sockets * dies * threads); + cores =3D cores > 0 ? cores : 1; } else if (threads =3D=3D 0) { threads =3D maxcpus / (sockets * dies * cores); + threads =3D threads > 0 ? threads : 1; } =20 + /* use the computed parameters to calculate the omitted cpus */ + cpus =3D cpus > 0 ? cpus : sockets * dies * cores * threads; + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + if (sockets * dies * cores * threads < cpus) { g_autofree char *dies_msg =3D g_strdup_printf( mc->smp_dies_supported ? " * dies (%u)" : "", dies); --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162666512843486.49595529334454; Sun, 18 Jul 2021 20:25:28 -0700 (PDT) Received: from localhost ([::1]:59738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5JuJ-0002Tk-DQ for importer@patchew.org; Sun, 18 Jul 2021 23:25:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5JqN-0007MM-TR for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:23 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5JqL-0006L5-RK for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:23 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GSn923jLwzZqm5; Mon, 19 Jul 2021 11:17:58 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:53 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:52 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 05/11] machine: Improve the error reporting of smp parsing Date: Mon, 19 Jul 2021 11:20:37 +0800 Message-ID: <20210719032043.25416-6-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.187; envelope-from=wangyanan55@huawei.com; helo=szxga01-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665129091100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We totally have two requirements for a valid SMP configuration: the sum of "sockets * dies * cores * threads" must represent all the possible cpus, i.e., max_cpus, and must include the initial present cpus, i.e., smp_cpus. We only need to ensure "sockets * dies * cores * threads =3D=3D maxcpus" at first and then ensure "sockets * dies * cores * threads >=3D cpus". With a reasonable order of the sanity-check, we can simplify the error reporting code. Signed-off-by: Yanan Wang --- hw/core/machine.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 668f0a1553..8b4d07d3fc 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -788,21 +788,6 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) cpus =3D cpus > 0 ? cpus : sockets * dies * cores * threads; maxcpus =3D maxcpus > 0 ? maxcpus : cpus; =20 - if (sockets * dies * cores * threads < cpus) { - g_autofree char *dies_msg =3D g_strdup_printf( - mc->smp_dies_supported ? " * dies (%u)" : "", dies); - error_setg(errp, "cpu topology: " - "sockets (%u)%s * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, dies_msg, cores, threads, cpus); - return; - } - - if (maxcpus < cpus) { - error_setg(errp, "maxcpus must be equal to or greater than smp"); - return; - } - if (sockets * dies * cores * threads !=3D maxcpus) { g_autofree char *dies_msg =3D g_strdup_printf( mc->smp_dies_supported ? " * dies (%u)" : "", dies); @@ -814,6 +799,16 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) return; } =20 + if (sockets * dies * cores * threads < cpus) { + g_autofree char *dies_msg =3D g_strdup_printf( + mc->smp_dies_supported ? " * dies (%u)" : "", dies); + error_setg(errp, "Invalid CPU topology: " + "sockets (%u)%s * cores (%u) * threads (%u) < " + "smp_cpus (%u)", + sockets, dies_msg, cores, threads, cpus); + return; + } + ms->smp.cpus =3D cpus; ms->smp.sockets =3D sockets; ms->smp.dies =3D dies; --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626665064857233.34821501906197; Sun, 18 Jul 2021 20:24:24 -0700 (PDT) Received: from localhost ([::1]:55316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5JtH-0007zb-S5 for importer@patchew.org; Sun, 18 Jul 2021 23:24:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq5-0006Ag-PL for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:05 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2191) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq1-00060B-0w for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:05 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GSn7930RRz7vcG; Mon, 19 Jul 2021 11:16:21 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:55 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:54 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 06/11] hw: Add compat machines for 6.2 Date: Mon, 19 Jul 2021 11:20:38 +0800 Message-ID: <20210719032043.25416-7-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.189; envelope-from=wangyanan55@huawei.com; helo=szxga03-in.huawei.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665067056100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add 6.2 machine types for arm/i440fx/q35/s390x/spapr. Signed-off-by: Yanan Wang Acked-by: David Gibson Reviewed-by: Andrew Jones Reviewed-by: Cornelia Huck Reviewed-by: Pankaj Gupta --- hw/arm/virt.c | 9 ++++++++- hw/core/machine.c | 3 +++ hw/i386/pc.c | 3 +++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- hw/ppc/spapr.c | 15 +++++++++++++-- hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ 9 files changed, 71 insertions(+), 6 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 81eda46b0b..01165f7f53 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2788,10 +2788,17 @@ static void machvirt_machine_init(void) } type_init(machvirt_machine_init); =20 +static void virt_machine_6_2_options(MachineClass *mc) +{ +} +DEFINE_VIRT_MACHINE_AS_LATEST(6, 2) + static void virt_machine_6_1_options(MachineClass *mc) { + virt_machine_6_2_options(mc); + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); } -DEFINE_VIRT_MACHINE_AS_LATEST(6, 1) +DEFINE_VIRT_MACHINE(6, 1) =20 static void virt_machine_6_0_options(MachineClass *mc) { diff --git a/hw/core/machine.c b/hw/core/machine.c index 8b4d07d3fc..63439c4a6d 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -37,6 +37,9 @@ #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-pci.h" =20 +GlobalProperty hw_compat_6_1[] =3D {}; +const size_t hw_compat_6_1_len =3D G_N_ELEMENTS(hw_compat_6_1); + GlobalProperty hw_compat_6_0[] =3D { { "gpex-pcihost", "allow-unmapped-accesses", "false" }, { "i8042", "extended-state", "false"}, diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d94ef582b5..c6768c6ce7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -94,6 +94,9 @@ #include "trace.h" #include CONFIG_DEVICES =20 +GlobalProperty pc_compat_6_1[] =3D {}; +const size_t pc_compat_6_1_len =3D G_N_ELEMENTS(pc_compat_6_1); + GlobalProperty pc_compat_6_0[] =3D { { "qemu64" "-" TYPE_X86_CPU, "family", "6" }, { "qemu64" "-" TYPE_X86_CPU, "model", "6" }, diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 30b8bd6ea9..fd5c2277f2 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -413,7 +413,7 @@ static void pc_i440fx_machine_options(MachineClass *m) machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE); } =20 -static void pc_i440fx_6_1_machine_options(MachineClass *m) +static void pc_i440fx_6_2_machine_options(MachineClass *m) { PCMachineClass *pcmc =3D PC_MACHINE_CLASS(m); pc_i440fx_machine_options(m); @@ -422,6 +422,18 @@ static void pc_i440fx_6_1_machine_options(MachineClass= *m) pcmc->default_cpu_version =3D 1; } =20 +DEFINE_I440FX_MACHINE(v6_2, "pc-i440fx-6.2", NULL, + pc_i440fx_6_2_machine_options); + +static void pc_i440fx_6_1_machine_options(MachineClass *m) +{ + pc_i440fx_6_2_machine_options(m); + m->alias =3D NULL; + m->is_default =3D false; + compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len); + compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len); +} + DEFINE_I440FX_MACHINE(v6_1, "pc-i440fx-6.1", NULL, pc_i440fx_6_1_machine_options); =20 diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 04b4a4788d..b45903b15e 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -355,7 +355,7 @@ static void pc_q35_machine_options(MachineClass *m) m->max_cpus =3D 288; } =20 -static void pc_q35_6_1_machine_options(MachineClass *m) +static void pc_q35_6_2_machine_options(MachineClass *m) { PCMachineClass *pcmc =3D PC_MACHINE_CLASS(m); pc_q35_machine_options(m); @@ -363,6 +363,17 @@ static void pc_q35_6_1_machine_options(MachineClass *m) pcmc->default_cpu_version =3D 1; } =20 +DEFINE_Q35_MACHINE(v6_2, "pc-q35-6.2", NULL, + pc_q35_6_2_machine_options); + +static void pc_q35_6_1_machine_options(MachineClass *m) +{ + pc_q35_6_2_machine_options(m); + m->alias =3D NULL; + compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len); + compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len); +} + DEFINE_Q35_MACHINE(v6_1, "pc-q35-6.1", NULL, pc_q35_6_1_machine_options); =20 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 81699d4f8b..d39fd4e644 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4685,15 +4685,26 @@ static void spapr_machine_latest_class_options(Mach= ineClass *mc) } \ type_init(spapr_machine_register_##suffix) =20 +/* + * pseries-6.2 + */ +static void spapr_machine_6_2_class_options(MachineClass *mc) +{ + /* Defaults for the latest behaviour inherited from the base class */ +} + +DEFINE_SPAPR_MACHINE(6_2, "6.2", true); + /* * pseries-6.1 */ static void spapr_machine_6_1_class_options(MachineClass *mc) { - /* Defaults for the latest behaviour inherited from the base class */ + spapr_machine_6_2_class_options(mc); + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); } =20 -DEFINE_SPAPR_MACHINE(6_1, "6.1", true); +DEFINE_SPAPR_MACHINE(6_1, "6.1", false); =20 /* * pseries-6.0 diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index e4b18aef49..4d25278cf2 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -791,14 +791,26 @@ bool css_migration_enabled(void) } = \ type_init(ccw_machine_register_##suffix) =20 +static void ccw_machine_6_2_instance_options(MachineState *machine) +{ +} + +static void ccw_machine_6_2_class_options(MachineClass *mc) +{ +} +DEFINE_CCW_MACHINE(6_2, "6.2", true); + static void ccw_machine_6_1_instance_options(MachineState *machine) { + ccw_machine_6_2_instance_options(machine); } =20 static void ccw_machine_6_1_class_options(MachineClass *mc) { + ccw_machine_6_2_class_options(mc); + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); } -DEFINE_CCW_MACHINE(6_1, "6.1", true); +DEFINE_CCW_MACHINE(6_1, "6.1", false); =20 static void ccw_machine_6_0_instance_options(MachineState *machine) { diff --git a/include/hw/boards.h b/include/hw/boards.h index b6161cee88..2832f0f8aa 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -354,6 +354,9 @@ struct MachineState { } \ type_init(machine_initfn##_register_types) =20 +extern GlobalProperty hw_compat_6_1[]; +extern const size_t hw_compat_6_1_len; + extern GlobalProperty hw_compat_6_0[]; extern const size_t hw_compat_6_0_len; =20 diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 88dffe7517..97b4ab79b5 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -196,6 +196,9 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, siz= e_t flash_size); void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, const CPUArchIdList *apic_ids, GArray *entry); =20 +extern GlobalProperty pc_compat_6_1[]; +extern const size_t pc_compat_6_1_len; + extern GlobalProperty pc_compat_6_0[]; extern const size_t pc_compat_6_0_len; =20 --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626664938187997.5777429825018; Sun, 18 Jul 2021 20:22:18 -0700 (PDT) Received: from localhost ([::1]:43804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5JrE-0000Qh-VI for importer@patchew.org; Sun, 18 Jul 2021 23:22:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq4-00067r-6U for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:04 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2192) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq0-00062F-4k for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:03 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GSn7C6FjPz7vcr; Mon, 19 Jul 2021 11:16:23 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:56 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:55 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 07/11] machine: Prefer cores over sockets in smp parsing since 6.2 Date: Mon, 19 Jul 2021 11:20:39 +0800 Message-ID: <20210719032043.25416-8-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.189; envelope-from=wangyanan55@huawei.com; helo=szxga03-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665841213100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the real SMP hardware topology world, it's much more likely that we have high cores-per-socket counts and few sockets totally. While the current preference of sockets over cores in smp parsing results in a virtual cpu topology with low cores-per-sockets counts and a large number of sockets, which is just contrary to the real world. Given that it is better to make the virtual cpu topology be more reflective of the real world and also for the sake of compatibility, we start to prefer cores over sockets over threads in smp parsing since machine type 6.2 for different arches. In this patch, a boolean "smp_prefer_sockets" is added, and we only enable the old preference on older machines and enable the new one since type 6.2 for all arches by using the machine compat mechanism. Suggested-by: Daniel P. Berrange Signed-off-by: Yanan Wang Acked-by: David Gibson --- hw/arm/virt.c | 1 + hw/core/machine.c | 59 +++++++++++++++++++++++++++++--------- hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + hw/ppc/spapr.c | 1 + hw/s390x/s390-virtio-ccw.c | 1 + include/hw/boards.h | 1 + qemu-options.hx | 4 ++- 8 files changed, 55 insertions(+), 14 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 01165f7f53..7babea40dc 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2797,6 +2797,7 @@ static void virt_machine_6_1_options(MachineClass *mc) { virt_machine_6_2_options(mc); compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); + mc->smp_prefer_sockets =3D true; } DEFINE_VIRT_MACHINE(6, 1) =20 diff --git a/hw/core/machine.c b/hw/core/machine.c index 63439c4a6d..c074425015 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -744,6 +744,22 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 +/* + * smp_parse - Generic function used to parse the given SMP configuration + * + * The topology parameters must be specified equal to or great than one + * or just omitted, explicit configuration like "cpus=3D0" is not allowed. + * The omitted parameters will be calculated based on the provided ones. + * + * maxcpus will default to the value of cpus if omitted and will be used + * to compute the missing sockets/cores/threads. cpus will be calculated + * from the computed parametrs if omitted. + * + * In calculation of omitted arch-netural sockets/cores/threads, we prefer + * sockets over cores over threads before 6.2, while prefer cores over + * sockets over threads since 6.2 on. The arch-specific dies will directly + * default to 1 if omitted. + */ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **= errp) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); @@ -772,19 +788,36 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) =20 maxcpus =3D maxcpus > 0 ? maxcpus : cpus; =20 - /* compute missing values, prefer sockets over cores over threads */ - if (sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (dies * cores * threads); - sockets =3D sockets > 0 ? sockets : 1; - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * dies * threads); - cores =3D cores > 0 ? cores : 1; - } else if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * dies * cores); - threads =3D threads > 0 ? threads : 1; + /* prefer sockets over cores over threads before 6.2 */ + if (mc->smp_prefer_sockets) { + if (sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); + sockets =3D sockets > 0 ? sockets : 1; + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * dies * threads); + cores =3D cores > 0 ? cores : 1; + } else if (threads =3D=3D 0) { + threads =3D maxcpus / (sockets * dies * cores); + threads =3D threads > 0 ? threads : 1; + } + /* prefer cores over sockets over threads since 6.2 */ + } else { + if (cores =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * dies * threads); + cores =3D cores > 0 ? cores : 1; + } else if (sockets =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); + sockets =3D sockets > 0 ? sockets : 1; + } else if (threads =3D=3D 0) { + threads =3D maxcpus / (sockets * dies * cores); + threads =3D threads > 0 ? threads : 1; + } } =20 /* use the computed parameters to calculate the omitted cpus */ diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index fd5c2277f2..9b811fc6ca 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -432,6 +432,7 @@ static void pc_i440fx_6_1_machine_options(MachineClass = *m) m->is_default =3D false; compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len); compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len); + m->smp_prefer_sockets =3D true; } =20 DEFINE_I440FX_MACHINE(v6_1, "pc-i440fx-6.1", NULL, diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index b45903b15e..88efb7fde4 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -372,6 +372,7 @@ static void pc_q35_6_1_machine_options(MachineClass *m) m->alias =3D NULL; compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len); compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len); + m->smp_prefer_sockets =3D true; } =20 DEFINE_Q35_MACHINE(v6_1, "pc-q35-6.1", NULL, diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index d39fd4e644..a481fade51 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4702,6 +4702,7 @@ static void spapr_machine_6_1_class_options(MachineCl= ass *mc) { spapr_machine_6_2_class_options(mc); compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); + mc->smp_prefer_sockets =3D true; } =20 DEFINE_SPAPR_MACHINE(6_1, "6.1", false); diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 4d25278cf2..b40e647883 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -809,6 +809,7 @@ static void ccw_machine_6_1_class_options(MachineClass = *mc) { ccw_machine_6_2_class_options(mc); compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); + mc->smp_prefer_sockets =3D true; } DEFINE_CCW_MACHINE(6_1, "6.1", false); =20 diff --git a/include/hw/boards.h b/include/hw/boards.h index 2832f0f8aa..8df885c9d2 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -247,6 +247,7 @@ struct MachineClass { bool nvdimm_supported; bool numa_mem_supported; bool smp_dies_supported; + bool smp_prefer_sockets; bool auto_enable_numa; const char *default_ram_id; =20 diff --git a/qemu-options.hx b/qemu-options.hx index 0c9ddc0274..6ef57e838c 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -227,7 +227,9 @@ SRST from those which are given. Historically preference was given to the coarsest topology parameters when computing missing values (ie sockets preferred over cores, which were preferred over threads), however, this - behaviour is considered liable to change. + behaviour is considered liable to change. The historical preference of + sockets over cores over threads works before 6.2, and a new preference + of cores over sockets over threads starts to work since 6.2 on. ERST =20 DEF("numa", HAS_ARG, QEMU_OPTION_numa, --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626665211607687.8090492642858; Sun, 18 Jul 2021 20:26:51 -0700 (PDT) Received: from localhost ([::1]:36650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5Jve-0005xx-KO for importer@patchew.org; Sun, 18 Jul 2021 23:26:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5JqN-0007Ku-I7 for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:23 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2436) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5JqL-0006LA-SF for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:23 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GSn924JvKzZqmS; Mon, 19 Jul 2021 11:17:58 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:57 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:56 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 08/11] machine: Use ms instead of global current_machine in sanity-check Date: Mon, 19 Jul 2021 11:20:40 +0800 Message-ID: <20210719032043.25416-9-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.187; envelope-from=wangyanan55@huawei.com; helo=szxga01-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665212421100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the sanity-check of smp_cpus and max_cpus against mc in function machine_set_smp(), we are now using ms->smp.max_cpus for the check but using current_machine->smp.max_cpus in the error message. Tweak this by uniformly using the local ms. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- hw/core/machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index c074425015..f5620c4d34 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -896,7 +896,7 @@ static void machine_set_smp(Object *obj, Visitor *v, co= nst char *name, } else if (ms->smp.max_cpus > mc->max_cpus) { error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " "supported by machine '%s' is %d", - current_machine->smp.max_cpus, + ms->smp.max_cpus, mc->name, mc->max_cpus); } =20 --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626665128148138.24182686649488; Sun, 18 Jul 2021 20:25:28 -0700 (PDT) Received: from localhost ([::1]:59766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5JuJ-0002Uv-5f for importer@patchew.org; Sun, 18 Jul 2021 23:25:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq5-00069U-8y for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:05 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2193) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5Jq1-000638-IY for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:05 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GSn7F2GyGz7vbp; Mon, 19 Jul 2021 11:16:25 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:20:59 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:58 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 09/11] machine: Tweak the order of topology members in struct CpuTopology Date: Mon, 19 Jul 2021 11:20:41 +0800 Message-ID: <20210719032043.25416-10-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.189; envelope-from=wangyanan55@huawei.com; helo=szxga03-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665129100100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that all the possible topology parameters are integrated in struct CpuTopology, tweak the order of topology members to be "cpus/sockets/ dies/cores/threads/maxcpus" for readability and consistency. We also tweak the comment by adding explanation of dies parameter. Furthermore, a comment of struct SMPConfiguration is fixed. Reviewed-by: Pankaj Gupta Reviewed-by: Andrew Jones Signed-off-by: Yanan Wang --- hw/core/machine.c | 4 ++-- include/hw/boards.h | 7 ++++--- qapi/machine.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index f5620c4d34..9d24b67ef3 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1075,10 +1075,10 @@ static void machine_initfn(Object *obj) /* default to mc->default_cpus */ ms->smp.cpus =3D mc->default_cpus; ms->smp.max_cpus =3D mc->default_cpus; - ms->smp.cores =3D 1; + ms->smp.sockets =3D 1; ms->smp.dies =3D 1; + ms->smp.cores =3D 1; ms->smp.threads =3D 1; - ms->smp.sockets =3D 1; } =20 static void machine_finalize(Object *obj) diff --git a/include/hw/boards.h b/include/hw/boards.h index 8df885c9d2..12ab0f5968 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -276,17 +276,18 @@ typedef struct DeviceMemoryState { /** * CpuTopology: * @cpus: the number of present logical processors on the machine - * @cores: the number of cores in one package - * @threads: the number of threads in one core * @sockets: the number of sockets on the machine + * @dies: the number of dies in one socket + * @cores: the number of cores in one die + * @threads: the number of threads in one core * @max_cpus: the maximum number of logical processors on the machine */ typedef struct CpuTopology { unsigned int cpus; + unsigned int sockets; unsigned int dies; unsigned int cores; unsigned int threads; - unsigned int sockets; unsigned int max_cpus; } CpuTopology; =20 diff --git a/qapi/machine.json b/qapi/machine.json index c11b2e6f73..9272cb3cf8 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1297,7 +1297,7 @@ # # @dies: number of dies per socket in the CPU topology # -# @cores: number of cores per thread in the CPU topology +# @cores: number of cores per die in the CPU topology # # @threads: number of threads per core in the CPU topology # --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1626665035680622.8573857215945; Sun, 18 Jul 2021 20:23:55 -0700 (PDT) Received: from localhost ([::1]:52278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5Jso-00060a-M5 for importer@patchew.org; Sun, 18 Jul 2021 23:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5JqJ-00076M-So for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:19 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2194) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5JqH-0006Dp-34 for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:19 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GSn7W3LSWz7vd7; Mon, 19 Jul 2021 11:16:39 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:21:00 +0800 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.2176.2; Mon, 19 Jul 2021 11:20:59 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 10/11] machine: Split out the smp parsing code Date: Mon, 19 Jul 2021 11:20:42 +0800 Message-ID: <20210719032043.25416-11-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.189; envelope-from=wangyanan55@huawei.com; helo=szxga03-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665036352100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We are going to introduce an unit test for the parser smp_parse() in hw/core/machine.c, but now machine.c is only built in softmmu. In order to solve the build dependency on the smp parsing code and avoid building unrelated stuff for the unit tests, move the related code from machine.c into a new common file, i.e., machine-smp.c. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- MAINTAINERS | 1 + hw/core/machine-smp.c | 124 ++++++++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 109 ------------------------------------- hw/core/meson.build | 1 + include/hw/boards.h | 1 + 5 files changed, 127 insertions(+), 109 deletions(-) create mode 100644 hw/core/machine-smp.c diff --git a/MAINTAINERS b/MAINTAINERS index 9100f9a043..70633e3bf4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1626,6 +1626,7 @@ F: cpu.c F: hw/core/cpu.c F: hw/core/machine-qmp-cmds.c F: hw/core/machine.c +F: hw/core/machine-smp.c F: hw/core/null-machine.c F: hw/core/numa.c F: hw/cpu/cluster.c diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c new file mode 100644 index 0000000000..6a00cfe44a --- /dev/null +++ b/hw/core/machine-smp.c @@ -0,0 +1,124 @@ +/* + * QEMU Machine (related to SMP configuration) + * + * Copyright (C) 2014 Red Hat Inc + * + * Authors: + * Marcel Apfelbaum + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/boards.h" +#include "qapi/error.h" + +/* + * smp_parse - Generic function used to parse the given SMP configuration + * + * The topology parameters must be specified equal to or great than one + * or just omitted, explicit configuration like "cpus=3D0" is not allowed. + * The omitted parameters will be calculated based on the provided ones. + * + * maxcpus will default to the value of cpus if omitted and will be used + * to compute the missing sockets/cores/threads. cpus will be calculated + * from the computed parametrs if omitted. + * + * In calculation of omitted arch-netural sockets/cores/threads, we prefer + * sockets over cores over threads before 6.2, while prefer cores over + * sockets over threads since 6.2 on. The arch-specific dies will directly + * default to 1 if omitted. + */ +void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + unsigned cpus =3D config->has_cpus ? config->cpus : 0; + unsigned sockets =3D config->has_sockets ? config->sockets : 0; + unsigned dies =3D config->has_dies ? config->dies : 1; + unsigned cores =3D config->has_cores ? config->cores : 0; + unsigned threads =3D config->has_threads ? config->threads : 0; + unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; + + if ((config->has_cpus && config->cpus =3D=3D 0) || + (config->has_sockets && config->sockets =3D=3D 0) || + (config->has_dies && config->dies =3D=3D 0) || + (config->has_cores && config->cores =3D=3D 0) || + (config->has_threads && config->threads =3D=3D 0) || + (config->has_maxcpus && config->maxcpus =3D=3D 0)) { + error_setg(errp, "parameters must be equal to or greater than one" + "if provided"); + return; + } + + if (!mc->smp_dies_supported && dies > 1) { + error_setg(errp, "dies not supported by this machine's CPU topolog= y"); + return; + } + + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + + /* prefer sockets over cores over threads before 6.2 */ + if (mc->smp_prefer_sockets) { + if (sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); + sockets =3D sockets > 0 ? sockets : 1; + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * dies * threads); + cores =3D cores > 0 ? cores : 1; + } else if (threads =3D=3D 0) { + threads =3D maxcpus / (sockets * dies * cores); + threads =3D threads > 0 ? threads : 1; + } + /* prefer cores over sockets over threads since 6.2 */ + } else { + if (cores =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * dies * threads); + cores =3D cores > 0 ? cores : 1; + } else if (sockets =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); + sockets =3D sockets > 0 ? sockets : 1; + } else if (threads =3D=3D 0) { + threads =3D maxcpus / (sockets * dies * cores); + threads =3D threads > 0 ? threads : 1; + } + } + + /* use the computed parameters to calculate the omitted cpus */ + cpus =3D cpus > 0 ? cpus : sockets * dies * cores * threads; + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + + if (sockets * dies * cores * threads !=3D maxcpus) { + g_autofree char *dies_msg =3D g_strdup_printf( + mc->smp_dies_supported ? " * dies (%u)" : "", dies); + error_setg(errp, "Invalid CPU topology: " + "sockets (%u)%s * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, dies_msg, cores, threads, + maxcpus); + return; + } + + if (sockets * dies * cores * threads < cpus) { + g_autofree char *dies_msg =3D g_strdup_printf( + mc->smp_dies_supported ? " * dies (%u)" : "", dies); + error_setg(errp, "Invalid CPU topology: " + "sockets (%u)%s * cores (%u) * threads (%u) < " + "smp_cpus (%u)", + sockets, dies_msg, cores, threads, cpus); + return; + } + + ms->smp.cpus =3D cpus; + ms->smp.sockets =3D sockets; + ms->smp.dies =3D dies; + ms->smp.cores =3D cores; + ms->smp.threads =3D threads; + ms->smp.max_cpus =3D maxcpus; +} diff --git a/hw/core/machine.c b/hw/core/machine.c index 9d24b67ef3..61be266b6c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -744,115 +744,6 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 -/* - * smp_parse - Generic function used to parse the given SMP configuration - * - * The topology parameters must be specified equal to or great than one - * or just omitted, explicit configuration like "cpus=3D0" is not allowed. - * The omitted parameters will be calculated based on the provided ones. - * - * maxcpus will default to the value of cpus if omitted and will be used - * to compute the missing sockets/cores/threads. cpus will be calculated - * from the computed parametrs if omitted. - * - * In calculation of omitted arch-netural sockets/cores/threads, we prefer - * sockets over cores over threads before 6.2, while prefer cores over - * sockets over threads since 6.2 on. The arch-specific dies will directly - * default to 1 if omitted. - */ -static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **= errp) -{ - MachineClass *mc =3D MACHINE_GET_CLASS(ms); - unsigned cpus =3D config->has_cpus ? config->cpus : 0; - unsigned sockets =3D config->has_sockets ? config->sockets : 0; - unsigned dies =3D config->has_dies ? config->dies : 1; - unsigned cores =3D config->has_cores ? config->cores : 0; - unsigned threads =3D config->has_threads ? config->threads : 0; - unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; - - if ((config->has_cpus && config->cpus =3D=3D 0) || - (config->has_sockets && config->sockets =3D=3D 0) || - (config->has_dies && config->dies =3D=3D 0) || - (config->has_cores && config->cores =3D=3D 0) || - (config->has_threads && config->threads =3D=3D 0) || - (config->has_maxcpus && config->maxcpus =3D=3D 0)) { - error_setg(errp, "parameters must be equal to or greater than one" - "if provided"); - return; - } - - if (!mc->smp_dies_supported && dies > 1) { - error_setg(errp, "dies not supported by this machine's CPU topolog= y"); - return; - } - - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - - /* prefer sockets over cores over threads before 6.2 */ - if (mc->smp_prefer_sockets) { - if (sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (dies * cores * threads); - sockets =3D sockets > 0 ? sockets : 1; - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * dies * threads); - cores =3D cores > 0 ? cores : 1; - } else if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * dies * cores); - threads =3D threads > 0 ? threads : 1; - } - /* prefer cores over sockets over threads since 6.2 */ - } else { - if (cores =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * dies * threads); - cores =3D cores > 0 ? cores : 1; - } else if (sockets =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (dies * cores * threads); - sockets =3D sockets > 0 ? sockets : 1; - } else if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * dies * cores); - threads =3D threads > 0 ? threads : 1; - } - } - - /* use the computed parameters to calculate the omitted cpus */ - cpus =3D cpus > 0 ? cpus : sockets * dies * cores * threads; - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - - if (sockets * dies * cores * threads !=3D maxcpus) { - g_autofree char *dies_msg =3D g_strdup_printf( - mc->smp_dies_supported ? " * dies (%u)" : "", dies); - error_setg(errp, "Invalid CPU topology: " - "sockets (%u)%s * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, dies_msg, cores, threads, - maxcpus); - return; - } - - if (sockets * dies * cores * threads < cpus) { - g_autofree char *dies_msg =3D g_strdup_printf( - mc->smp_dies_supported ? " * dies (%u)" : "", dies); - error_setg(errp, "Invalid CPU topology: " - "sockets (%u)%s * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, dies_msg, cores, threads, cpus); - return; - } - - ms->smp.cpus =3D cpus; - ms->smp.sockets =3D sockets; - ms->smp.dies =3D dies; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; - ms->smp.max_cpus =3D maxcpus; -} - static void machine_get_smp(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { diff --git a/hw/core/meson.build b/hw/core/meson.build index 18f44fb7c2..6d727c7742 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -14,6 +14,7 @@ hwcore_files =3D files( ) =20 common_ss.add(files('cpu-common.c')) +common_ss.add(files('machine-smp.c')) common_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c')) common_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loade= r.c')) common_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: files('guest-lo= ader.c')) diff --git a/include/hw/boards.h b/include/hw/boards.h index 12ab0f5968..071eec1e74 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -34,6 +34,7 @@ HotpluggableCPUList *machine_query_hotpluggable_cpus(Mach= ineState *machine); void machine_set_cpu_numa_node(MachineState *machine, const CpuInstanceProperties *props, Error **errp); +void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp); =20 /** * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devic= es --=20 2.19.1 From nobody Fri May 10 17:34:35 2024 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=fail(p=none dis=none) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162666525999087.18313806578408; Sun, 18 Jul 2021 20:27:39 -0700 (PDT) Received: from localhost ([::1]:38958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5JwQ-0007Vz-TE for importer@patchew.org; Sun, 18 Jul 2021 23:27:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5JqS-0007jn-ST for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:28 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2437) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5JqN-0006NF-1e for qemu-devel@nongnu.org; Sun, 18 Jul 2021 23:21:28 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GSn930SYRzZqmW; Mon, 19 Jul 2021 11:17:59 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 11:21:01 +0800 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.2176.2; Mon, 19 Jul 2021 11:21:00 +0800 From: Yanan Wang To: Subject: [PATCH for-6.2 v2 11/11] tests/unit: Add a unit test for smp parsing Date: Mon, 19 Jul 2021 11:20:43 +0800 Message-ID: <20210719032043.25416-12-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210719032043.25416-1-wangyanan55@huawei.com> References: <20210719032043.25416-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.187; envelope-from=wangyanan55@huawei.com; helo=szxga01-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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, Richard Henderson , Greg Kurz , Halil Pasic , yuzenghui@huawei.com, Igor Mammedov , Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1626665261868100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a QEMU unit test for the parsing of given SMP configuration. Since all the parsing logic is in generic function smp_parse(), this test passes diffenent SMP configurations to the function and compare the parsing result with what is expected. In the test, all possible collections of the topology parameters and the corressponding expected results are listed, including the valid and invalid ones. The preference of sockets over cores and the preference of cores over sockets, and the support of multi-dies are also considered. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- MAINTAINERS | 1 + tests/unit/meson.build | 1 + tests/unit/test-smp-parse.c | 1117 +++++++++++++++++++++++++++++++++++ 3 files changed, 1119 insertions(+) create mode 100644 tests/unit/test-smp-parse.c diff --git a/MAINTAINERS b/MAINTAINERS index 70633e3bf4..160dba2e57 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1636,6 +1636,7 @@ F: include/hw/boards.h F: include/hw/core/cpu.h F: include/hw/cpu/cluster.h F: include/sysemu/numa.h +F: tests/unit/test-smp-parse.c T: git https://gitlab.com/ehabkost/qemu.git machine-next =20 Xtensa Machines diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 3e0504dd21..694a924627 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -44,6 +44,7 @@ tests =3D { 'test-uuid': [], 'ptimer-test': ['ptimer-test-stubs.c', meson.source_root() / 'hw/core/pt= imer.c'], 'test-qapi-util': [], + 'test-smp-parse': [qom, meson.source_root() / 'hw/core/machine-smp.c'], } =20 if have_system or have_tools diff --git a/tests/unit/test-smp-parse.c b/tests/unit/test-smp-parse.c new file mode 100644 index 0000000000..bc1d324c3d --- /dev/null +++ b/tests/unit/test-smp-parse.c @@ -0,0 +1,1117 @@ +/* + * SMP parsing unit-tests + * + * Copyright (C) 2021, Huawei, Inc. + * + * Authors: + * Yanan Wang + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. + * See the COPYING.LIB file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "qemu/module.h" +#include "qapi/error.h" + +#include "hw/boards.h" + +#define T true +#define F false + +/** + * SMPTestData: + * @config - the given SMP configuration for parsing + * @should_be_valid - whether the given configuration is supposed to be va= lid + * @expect - the CPU topology info expected to be parsed out + */ +typedef struct SMPTestData { + SMPConfiguration config; + bool should_be_valid; + CpuTopology expect; +} SMPTestData; + +/* the specific machine type info for this test */ +static const TypeInfo smp_machine_info =3D { + .name =3D TYPE_MACHINE, + .parent =3D TYPE_OBJECT, + .class_size =3D sizeof(MachineClass), + .instance_size =3D sizeof(MachineState), +}; + +/* + * prefer sockets over cores over threads before 6.2. + * all possible SMP configurations and the corressponding expected outputs + * are listed for testing, including the valid and invalid ones. + */ +static struct SMPTestData prefer_sockets[] =3D { + { + /* config: no smp configuration provided + * expect: cpus=3D1,sockets=3D1,dies=3D1,cores=3D1,threads=3D1,max= cpus=3D1 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 1, 1, 1, 1, 1, 1 }, + }, { + /* config: -smp 8 + * expect: cpus=3D8,sockets=3D8,dies=3D1,cores=3D1,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 8, 1, 1, 1, 8 }, + }, { + /* config: -smp sockets=3D2 + * expect: cpus=3D2,sockets=3D2,dies=3D1,cores=3D1,threads=3D1,max= cpus=3D2 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 2, 2, 1, 1, 1, 2 }, + }, { + /* config: -smp cores=3D4 + * expect: cpus=3D4,sockets=3D1,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D4 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 4, 1, 1, 4, 1, 4 }, + }, { + /* config: -smp threads=3D2 + * expect: cpus=3D2,sockets=3D1,dies=3D1,cores=3D1,threads=3D2,max= cpus=3D2 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 2, 1, 1, 1, 2, 2 }, + }, { + /* config: -smp maxcpus=3D16 + * expect: cpus=3D16,sockets=3D16,dies=3D1,cores=3D1,threads=3D1,m= axcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, F, 0, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 16, 1, 1, 1, 16 }, + }, { + /* config: -smp 8,sockets=3D2 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp 8,cores=3D4 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp 8,threads=3D2 + * expect: cpus=3D8,sockets=3D4,dies=3D1,cores=3D1,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 4, 1, 1, 2, 8 }, + }, { + /* config: -smp 8,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D16,dies=3D1,cores=3D1,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, F, 0, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 16, 1, 1, 1, 16 }, + }, { + /* config: -smp sockets=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp sockets=3D2,threads=3D2 + * expect: cpus=3D4,sockets=3D2,dies=3D1,cores=3D1,threads=3D2,max= cpus=3D4 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 4, 2, 1, 1, 2, 4 }, + }, { + /* config: -smp sockets=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D8,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, F, 0, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 8, 1, 16 }, + }, { + /* config: -smp cores=3D4,threads=3D2 + * expect: cpus=3D8,sockets=3D1,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 1, 4, 2, 8 }, + }, { + /* config: -smp cores=3D4,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D4,dies=3D1,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, T, 4, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 4, 1, 4, 1, 16 }, + }, { + /* config: -smp threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D8,dies=3D1,cores=3D1,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, F, 0, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 8, 1, 1, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp 8,sockets=3D2,threads=3D2 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D2,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 2, 2, 8 }, + }, { + /* config: -smp 8,sockets=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D8,threads=3D1,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, F, 0, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 8, 1, 16 }, + }, { + /* config: -smp 8,cores=3D4,threads=3D2 + * expect: cpus=3D8,sockets=3D1,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 1, 4, 2, 8 }, + }, { + /* config: -smp 8,cores=3D4,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D4,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, T, 4, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 4, 1, 4, 1, 16 }, + }, { + /* config: -smp 8,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D8,dies=3D1,cores=3D1,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, F, 0, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 8, 1, 1, 2, 16 }, + }, { + /* config: -smp sockets=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp sockets=3D2,cores=3D4,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, T, 4, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp sockets=3D2,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, F, 0, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D1 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, T, 1, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, F, 0, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: -smp 16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,maxc= pus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,maxcp= us=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, T, 1, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 0, F, 0, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 8, T, 0, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,dies=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 0, T, 2, T, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,dies=3D1,cores=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 8, T, 2, T, 1, T, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,dies=3D1,cores=3D4,threads=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 8, T, 2, T, 1, T, 4, T, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,maxcp= us=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 8, T, 2, T, 1, T, 4, T, 2, T, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,dies=3D2 + * expect: error, multi-dies not supported */ + .config =3D (SMPConfiguration) { T, 8, F, 0, T, 2, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,cores=3D8 + * expect: error, sum (16) !=3D max_cpus (8) */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,cores=3D5,threads=3D2,maxcpus=3D16 + * expect: error, sum (20) !=3D max_cpus (16) */ + .config =3D (SMPConfiguration) { F, 0, T, 3, F, 0, T, 5, T, 1, T, = 16 }, + .should_be_valid =3D false, + }, { + /* config: -smp 16,maxcpus=3D12 + * expect: error, sum (12) < smp_cpus (16) */ + .config =3D (SMPConfiguration) { T, 16, F, 0, F, 0, F, 0, F, 0, T,= 12 }, + .should_be_valid =3D false, + }, +}; + +static struct SMPTestData prefer_sockets_support_dies[] =3D { + { + /* config: -smp dies=3D2 + * expect: cpus=3D2,sockets=3D1,dies=3D2,cores=3D1,threads=3D1,max= cpus=3D2 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 2, 1, 2, 1, 1, 2 }, + }, { + /* config: -smp 16,dies=3D2 + * expect: cpus=3D16,sockets=3D8,dies=3D2,cores=3D1,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, F, 0, F, 0, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 8, 2, 1, 1, 16 }, + }, { + /* config: -smp sockets=3D2,dies=3D2 + * expect: cpus=3D4,sockets=3D2,dies=3D2,cores=3D1,threads=3D1,max= cpus=3D4 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 4, 2, 2, 1, 1, 4 }, + }, { + /* config: -smp dies=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D1,dies=3D2,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 2, 4, 1, 8 }, + }, { + /* config: -smp dies=3D2,threads=3D2 + * expect: cpus=3D4,sockets=3D1,dies=3D2,cores=3D1,threads=3D2,max= cpus=3D4 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 4, 1, 2, 1, 2, 4 }, + }, { + /* config: -smp dies=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D16,dies=3D2,cores=3D1,threads=3D1,m= axcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, F, 0, F, 0, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 16, 2, 1, 1, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, F, 0, F, 0, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp 16,dies=3D2,cores=3D4 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, T, 4, F, 0, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp 16,dies=3D2,threads=3D2 + * expect: cpus=3D16,sockets=3D4,dies=3D2,cores=3D1,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, F, 0, T, 2, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 4, 2, 1, 2, 16 }, + }, { + /* config: -smp 16,dies=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D16,dies=3D2,cores=3D1,threads=3D1,m= axcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, F, 0, F, 0, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 16, 2, 1, 1, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,threads=3D2 + * expect: cpus=3D8,sockets=3D2,dies=3D2,cores=3D1,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 2, 1, 2, 8 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D8,threads=3D1,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, F, 0, F, 0, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 8, 1, 32 }, + }, { + /* config: -smp dies=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D16,sockets=3D1,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 2, 4, 2, 16 }, + }, { + /* config: -smp dies=3D2,cores=3D4,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D4,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, T, 4, F, 0, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 4, 2, 4, 1, 32 }, + }, { + /* config: -smp dies=3D2,threads=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D8,dies=3D2,cores=3D1,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, F, 0, T, 2, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 8, 2, 1, 2, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, T, 4, F, 0, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,threads=3D2 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D2,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, F, 0, T, 2, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 2, 2, 16 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D8,threads=3D1,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, F, 0, F, 0, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 8, 1, 32 }, + }, { + /* config: -smp 16,dies=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D16,sockets=3D1,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, T, 4, T, 2, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 2, 4, 2, 16 }, + }, { + /* config: -smp 16,dies=3D2,cores=3D4,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D4,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, T, 4, F, 0, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 4, 2, 4, 1, 32 }, + }, { + /* config: -smp 16,dies=3D2,threads=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D8,dies=3D2,cores=3D1,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, F, 0, T, 2, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 8, 2, 1, 2, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, T, 4, F, 0, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,threads=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, F, 0, T, 2, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp dies=3D2,cores=3D4,threads=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, T, 4, T, 2, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, T, 4, T, 1, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, T, 4, F, 0, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,threads=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, F, 0, T, 2, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp 16,dies=3D2,cores=3D4,threads=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, T, 4, T, 2, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxcpus= =3D32 + * expect: -smp 32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxc= pus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, T, 4, T, 2, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxc= pus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, T, 4, T, 2, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 2, 32 }, + }, +}; + +/* + * prefer cores over sockets over threads since 6.2. + * all possible SMP configurations and the corressponding expected outputs + * are listed for testing, including the valid and invalid ones. + */ +static struct SMPTestData prefer_cores[] =3D { + { + /* config: no smp configuration + * expect: cpus=3D1,sockets=3D1,dies=3D1,cores=3D1,threads=3D1,max= cpus=3D1 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 1, 1, 1, 1, 1, 1 }, + }, { + /* config: -smp 8 + * expect: cpus=3D8,sockets=3D1,dies=3D1,cores=3D8,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 1, 8, 1, 8 }, + }, { + /* config: -smp sockets=3D2 + * expect: cpus=3D2,sockets=3D2,dies=3D1,cores=3D1,threads=3D1,max= cpus=3D2 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 2, 2, 1, 1, 1, 2 }, + }, { + /* config: -smp cores=3D4 + * expect: cpus=3D4,sockets=3D1,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D4 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 4, 1, 1, 4, 1, 4 }, + }, { + /* config: -smp threads=3D2 + * expect: cpus=3D2,sockets=3D1,dies=3D1,cores=3D1,threads=3D2,max= cpus=3D2 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 2, 1, 1, 1, 2, 2 }, + }, { + /* config: -smp maxcpus=3D16 + * expect: cpus=3D16,sockets=3D1,dies=3D1,cores=3D16,threads=3D1,m= axcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, F, 0, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 1, 16, 1, 16 }, + }, { + /* config: -smp 8,sockets=3D2 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp 8,cores=3D4 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp 8,threads=3D2 + * expect: cpus=3D8,sockets=3D1,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 1, 4, 2, 8 }, + }, { + /* config: -smp 8,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D1,dies=3D1,cores=3D16,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, F, 0, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 1, 16, 1, 16 }, + }, { + /* config: -smp sockets=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp sockets=3D2,threads=3D2 + * expect: cpus=3D4,sockets=3D2,dies=3D1,cores=3D1,threads=3D2,max= cpus=3D4 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 4, 2, 1, 1, 2, 4 }, + }, { + /* config: -smp sockets=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D8,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, F, 0, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 8, 1, 16 }, + }, { + /* config: -smp cores=3D4,threads=3D2 + * expect: cpus=3D8,sockets=3D1,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 1, 4, 2, 8 }, + }, { + /* config: -smp cores=3D4,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D4,dies=3D1,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, T, 4, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 4, 1, 4, 1, 16 }, + }, { + /* config: -smp threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D1,dies=3D1,cores=3D8,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, F, 0, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 1, 8, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp 8,sockets=3D2,threads=3D2 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D2,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 2, 2, 8 }, + }, { + /* config: -smp 8,sockets=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D8,threads=3D1,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, F, 0, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 8, 1, 16 }, + }, { + /* config: -smp 8,cores=3D4,threads=3D2 + * expect: cpus=3D8,sockets=3D1,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 1, 4, 2, 8 }, + }, { + /* config: -smp 8,cores=3D4,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D4,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, T, 4, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 4, 1, 4, 1, 16 }, + }, { + /* config: -smp 8,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D1,dies=3D1,cores=3D8,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, F, 0, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 1, 8, 2, 16 }, + }, { + /* config: -smp sockets=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp sockets=3D2,cores=3D4,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, T, 4, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp sockets=3D2,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, F, 0, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, F, 0, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D1 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, T, 1, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 1, 8 }, + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, F, 0, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, F, 0, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, F, 0, F, 0, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: -smp 16,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,maxc= pus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, F, 0, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,maxcp= us=3D16 + * expect: cpus=3D8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,max= cpus=3D16 */ + .config =3D (SMPConfiguration) { T, 8, T, 2, T, 1, T, 4, T, 2, T, = 16 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 1, 4, 2, 16 }, + }, { + /* config: -smp 0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 0, F, 0, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 8, T, 0, F, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,dies=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 0, T, 2, T, 0, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,dies=3D1,cores=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 8, T, 2, T, 1, T, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,dies=3D1,cores=3D4,threads=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 8, T, 2, T, 1, T, 4, T, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,dies=3D1,cores=3D4,threads=3D2,maxcp= us=3D0 + * expect: error, "anything=3D0" is not allowed */ + .config =3D (SMPConfiguration) { T, 8, T, 2, T, 1, T, 4, T, 2, T, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,dies=3D2 + * expect: error, multi-dies not supported */ + .config =3D (SMPConfiguration) { T, 8, F, 0, T, 2, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,cores=3D8 + * expect: error, sum (16) !=3D max_cpus (8) */ + .config =3D (SMPConfiguration) { T, 8, T, 2, F, 0, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D false, + }, { + /* config: -smp 8,sockets=3D2,cores=3D5,threads=3D2,maxcpus=3D16 + * expect: error, sum (20) !=3D max_cpus (16) */ + .config =3D (SMPConfiguration) { F, 0, T, 3, F, 0, T, 5, T, 1, T, = 16 }, + .should_be_valid =3D false, + }, { + /* config: -smp 16,maxcpus=3D12 + * expect: error, sum (12) < smp_cpus (16) */ + .config =3D (SMPConfiguration) { T, 16, F, 0, F, 0, F, 0, F, 0, T,= 12 }, + .should_be_valid =3D false, + }, +}; + +static struct SMPTestData prefer_cores_support_dies[] =3D { + { + /* config: -smp dies=3D2 + * expect: cpus=3D2,sockets=3D1,dies=3D2,cores=3D1,threads=3D1,max= cpus=3D2 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 2, 1, 2, 1, 1, 2 }, + }, { + /* config: -smp 16,dies=3D2 + * expect: cpus=3D16,sockets=3D1,dies=3D2,cores=3D8,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, F, 0, F, 0, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 2, 8, 1, 16 }, + }, { + /* config: -smp sockets=3D2,dies=3D2 + * expect: cpus=3D4,sockets=3D2,dies=3D2,cores=3D1,threads=3D1,max= cpus=3D4 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, F, 0, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 4, 2, 2, 1, 1, 4 }, + }, { + /* config: -smp dies=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D1,dies=3D2,cores=3D4,threads=3D1,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 1, 2, 4, 1, 8 }, + }, { + /* config: -smp dies=3D2,threads=3D2 + * expect: cpus=3D4,sockets=3D1,dies=3D2,cores=3D1,threads=3D2,max= cpus=3D4 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 4, 1, 2, 1, 2, 4 }, + }, { + /* config: -smp dies=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D1,dies=3D2,cores=3D16,threads=3D1,m= axcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, F, 0, F, 0, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 1, 2, 16, 1, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, F, 0, F, 0, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp 16,dies=3D2,cores=3D4 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, T, 4, F, 0, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp 16,dies=3D2,threads=3D2 + * expect: cpus=3D16,sockets=3D1,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, F, 0, T, 2, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 2, 4, 2, 16 }, + }, { + /* config: -smp 16,dies=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D1,dies=3D2,cores=3D16,threads=3D1,m= axcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, F, 0, F, 0, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 2, 16, 1, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, T, 4, F, 0, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,threads=3D2 + * expect: cpus=3D8,sockets=3D2,dies=3D2,cores=3D1,threads=3D2,max= cpus=3D8 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, F, 0, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 8, 2, 2, 1, 2, 8 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D8,threads=3D1,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, F, 0, F, 0, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 8, 1, 32 }, + }, { + /* config: -smp dies=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D16,sockets=3D1,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 2, 4, 2, 16 }, + }, { + /* config: -smp dies=3D2,cores=3D4,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D4,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, T, 4, F, 0, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 4, 2, 4, 1, 32 }, + }, { + /* config: -smp dies=3D2,threads=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D1,dies=3D2,cores=3D8,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, F, 0, T, 2, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 1, 2, 8, 2, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, T, 4, F, 0, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,threads=3D2 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D2,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, F, 0, T, 2, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 2, 2, 16 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D8,threads=3D1,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, F, 0, F, 0, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 8, 1, 32 }, + }, { + /* config: -smp 16,dies=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D16,sockets=3D1,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, T, 4, T, 2, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 2, 4, 2, 16 }, + }, { + /* config: -smp 16,dies=3D2,cores=3D4,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D4,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, T, 4, F, 0, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 4, 2, 4, 1, 32 }, + }, { + /* config: -smp 16,dies=3D2,threads=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D1,dies=3D2,cores=3D8,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, F, 0, T, 2, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 1, 2, 8, 2, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, T, 4, T, 2, F, = 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, T, 4, F, 0, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,threads=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, F, 0, T, 2, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp dies=3D2,cores=3D4,threads=3D2,maxcpus=3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, F, 0, T, 2, T, 4, T, 2, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D1,ma= xcpus=3D16 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, T, 4, T, 1, F,= 0 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 1, 16 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, T, 4, F, 0, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,threads=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, F, 0, T, 2, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp 16,dies=3D2,cores=3D4,threads=3D2,maxcpus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, F, 0, T, 2, T, 4, T, 2, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxcpus= =3D32 + * expect: -smp 32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxc= pus=3D32 */ + .config =3D (SMPConfiguration) { F, 0, T, 2, T, 2, T, 4, T, 2, T, = 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 32, 2, 2, 4, 2, 32 }, + }, { + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxc= pus=3D32 + * expect: cpus=3D16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D (SMPConfiguration) { T, 16, T, 2, T, 2, T, 4, T, 2, T,= 32 }, + .should_be_valid =3D true, + .expect =3D (CpuTopology) { 16, 2, 2, 4, 2, 32 }, + }, +}; + +static char *get_config_info(SMPConfiguration *config) +{ + return g_strdup_printf( + "(SMPConfiguration) {\n" + " .has_cpus =3D %5s, cpus =3D %ld,\n" + " .has_sockets =3D %5s, sockets =3D %ld,\n" + " .has_dies =3D %5s, dies =3D %ld,\n" + " .has_cores =3D %5s, cores =3D %ld,\n" + " .has_threads =3D %5s, threads =3D %ld,\n" + " .has_maxcpus =3D %5s, maxcpus =3D %ld,\n" + "}", + config->has_cpus ? "true" : "false", config->cpus, + config->has_sockets ? "true" : "false", config->sockets, + config->has_dies ? "true" : "false", config->dies, + config->has_cores ? "true" : "false", config->cores, + config->has_threads ? "true" : "false", config->threads, + config->has_maxcpus ? "true" : "false", config->maxcpus); +} + +static char *get_topo_info(CpuTopology *topo) +{ + return g_strdup_printf( + "(CpuTopology) {\n" + " .cpus =3D %u,\n" + " .sockets =3D %u,\n" + " .dies =3D %u,\n" + " .cores =3D %u,\n" + " .threads =3D %u,\n" + " .max_cpus =3D %u,\n" + "}", + topo->cpus, topo->sockets, topo->dies, + topo->cores, topo->threads, topo->max_cpus); +} + +static void check_smp_parse(MachineState *ms, SMPTestData *data) +{ + SMPConfiguration *config =3D &data->config; + CpuTopology *expect =3D &data->expect; + g_autofree char *config_info =3D NULL; + g_autofree char *expect_info =3D NULL; + g_autofree char *result_info =3D NULL; + Error *err =3D NULL; + + /* call the generic parser smp_parse() in hw/core/machine-smp.c */ + smp_parse(ms, config, &err); + + if (data->should_be_valid) { + if ((err =3D=3D NULL) && + (ms->smp.cpus =3D=3D expect->cpus) && + (ms->smp.sockets =3D=3D expect->sockets) && + (ms->smp.dies =3D=3D expect->dies) && + (ms->smp.cores =3D=3D expect->cores) && + (ms->smp.threads =3D=3D expect->threads) && + (ms->smp.max_cpus =3D=3D expect->max_cpus)) { + return; + } + + config_info =3D get_config_info(config); + expect_info =3D get_topo_info(expect); + + if (err !=3D NULL) { + g_printerr("Check smp_parse failed:\n" + "config: %s\n" + "expect: %s\n" + "should_be_valid: yes\n\n" + "result_is_valid: no\n" + "error_msg: %s\n", + config_info, expect_info, error_get_pretty(err)); + error_free(err); + } else { + result_info =3D get_topo_info(&ms->smp); + g_printerr("Check smp_parse failed:\n" + "config: %s\n" + "expect: %s\n" + "should_be_valid: yes\n\n" + "result_is_valid: yes\n" + "result: %s\n", + config_info, expect_info, result_info); + } + } else { + if (err !=3D NULL) { + error_free(err); + return; + } + + config_info =3D get_config_info(config); + result_info =3D get_topo_info(&ms->smp); + + g_printerr("Check smp_parse failed:\n" + "config: %s\n" + "should_be_valid: no\n\n" + "result_is_valid: yes\n" + "result: %s\n", + config_info, result_info); + } + + abort(); +} + +static void smp_prefer_sockets_test(void) +{ + Object *obj =3D object_new(TYPE_MACHINE); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + int i; + + /* make sure that we have created the object */ + g_assert_nonnull(ms); + g_assert_nonnull(mc); + + mc->smp_prefer_sockets =3D true; + + /* test cases when multi-dies are not supported */ + mc->smp_dies_supported =3D false; + for (i =3D 0; i < ARRAY_SIZE(prefer_sockets); i++) { + check_smp_parse(ms, &prefer_sockets[i]); + } + + /* test cases when multi-dies are supported */ + mc->smp_dies_supported =3D true; + for (i =3D 0; i < ARRAY_SIZE(prefer_sockets_support_dies); i++) { + check_smp_parse(ms, &prefer_sockets_support_dies[i]); + } + + object_unref(obj); +} + +static void smp_prefer_cores_test(void) +{ + Object *obj =3D object_new(TYPE_MACHINE); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + int i; + + /* make sure that we have created the object */ + g_assert_nonnull(ms); + g_assert_nonnull(mc); + + mc->smp_prefer_sockets =3D false; + + /* test cases when multi-dies are not supported */ + mc->smp_dies_supported =3D false; + for (i =3D 0; i < ARRAY_SIZE(prefer_cores); i++) { + check_smp_parse(ms, &prefer_cores[i]); + } + + /* test cases when multi-dies are supported */ + mc->smp_dies_supported =3D true; + for (i =3D 0; i < ARRAY_SIZE(prefer_cores_support_dies); i++) { + check_smp_parse(ms, &prefer_cores_support_dies[i]); + } + + object_unref(obj); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + module_call_init(MODULE_INIT_QOM); + type_register_static(&smp_machine_info); + + g_test_add_func("/test-smp-parse/prefer_sockets", smp_prefer_sockets_t= est); + g_test_add_func("/test-smp-parse/prefer_cores", smp_prefer_cores_test); + + g_test_run(); + + return 0; +} --=20 2.19.1