From nobody Mon May 6 19:11:37 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 1630580797287202.7448557884361; Thu, 2 Sep 2021 04:06:37 -0700 (PDT) Received: from localhost ([::1]:55764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkYF-0001ug-1o for importer@patchew.org; Thu, 02 Sep 2021 07:06:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVX-0006tq-4J; Thu, 02 Sep 2021 07:03:47 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3124) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVT-0003WZ-I2; Thu, 02 Sep 2021 07:03:46 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H0dGZ5yV0z8xd7; Thu, 2 Sep 2021 18:59:18 +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; Thu, 2 Sep 2021 19:03:34 +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.2308.8; Thu, 2 Sep 2021 19:03:33 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 01/14] machine: Deprecate "parameter=0" SMP configurations Date: Thu, 2 Sep 2021 19:03:17 +0800 Message-ID: <20210902110330.18036-2-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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: -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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630580800167100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the SMP configuration, we should either provide a topology parameter with a reasonable value (greater than zero) or just omit it and QEMU will compute the missing value. The users shouldn't provide a configuration with any parameter of it specified as zero (e.g. -smp 8,sockets=3D0) which could possibly cause unexpected results in the -smp parsing. So we deprecate this kind of configurations since 6.2 by adding the explicit sanity check. Signed-off-by: Yanan Wang Reviewed-by: Cornelia Huck --- docs/about/deprecated.rst | 15 +++++++++++++++ hw/core/machine.c | 14 ++++++++++++++ qapi/machine.json | 2 +- qemu-options.hx | 12 +++++++----- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 1e1a5e96ad..3e9e655129 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -138,6 +138,21 @@ an underscore between "window" and "close"). The ``-no-quit`` is a synonym for ``-display ...,window-close=3Doff`` which should be used instead. =20 +``-smp`` ("parameter=3D0" SMP configurations) (since 6.2) +''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +Specified CPU topology parameters must be greater than zero. + +In the SMP configuration, users should either provide a CPU topology +parameter with a reasonable value (greater than zero) or just omit it +and QEMU will compute the missing value. + +However, historically it was implicitly allowed for users to provide +a parameter with zero value, which is meaningless and could also possibly +cause unexpected results in the -smp parsing. So support for this kind of +configurations (e.g. -smp 8,sockets=3D0) is deprecated since 6.2 and will +be removed in the near future, users have to ensure that all the topology +members described with -smp are greater than zero. =20 QEMU Machine Protocol (QMP) commands ------------------------------------ diff --git a/hw/core/machine.c b/hw/core/machine.c index 067f42b528..711e83db54 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -835,6 +835,20 @@ static void machine_set_smp(Object *obj, Visitor *v, c= onst char *name, return; } =20 + /* + * Specified CPU topology parameters must be greater than zero, + * explicit configuration like "cpus=3D0" is not allowed. + */ + 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)) { + warn_report("Invalid CPU topology deprecated: " + "CPU topology parameters must be greater than zero"); + } + mc->smp_parse(ms, config, errp); if (*errp) { goto out_free; diff --git a/qapi/machine.json b/qapi/machine.json index 157712f006..10a97837d3 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 # diff --git a/qemu-options.hx b/qemu-options.hx index 83aa59a920..aee622f577 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -227,11 +227,13 @@ SRST of computing the CPU maximum count. =20 Either the initial CPU count, or at least one of the topology paramete= rs - must be specified. Values for any omitted parameters will be computed - 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. + must be specified. The specified parameters must be greater than zero, + explicit configuration like "cpus=3D0" is not allowed. Values for any + omitted parameters will be computed 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. ERST =20 DEF("numa", HAS_ARG, QEMU_OPTION_numa, --=20 2.19.1 From nobody Mon May 6 19:11:37 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 1630581048494882.4526688753601; Thu, 2 Sep 2021 04:10:48 -0700 (PDT) Received: from localhost ([::1]:37632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkcJ-0001Ho-Dy for importer@patchew.org; Thu, 02 Sep 2021 07:10:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVY-0006uZ-Qm; Thu, 02 Sep 2021 07:03:48 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2526) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVU-0003XM-Er; Thu, 02 Sep 2021 07:03:48 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H0dLg5ZzTzYrkJ; Thu, 2 Sep 2021 19:02:51 +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; Thu, 2 Sep 2021 19:03:35 +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.2308.8; Thu, 2 Sep 2021 19:03:34 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 02/14] machine: Minor refactor/fix for the smp parsers Date: Thu, 2 Sep 2021 19:03:18 +0800 Message-ID: <20210902110330.18036-3-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581049053100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To pave the way for the functional improvement in later patches, make some refactor/cleanup for the smp parsers, including using local maxcpus instead of ms->smp.max_cpus in the calculation, defaulting dies to 0 initially like other members, cleanup the sanity check for dies. We actually also fix a hidden defect by avoiding directly using the provided *zero value* in the calculation, which could cause a segment fault (e.g. using dies=3D0 in the calculation). Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- hw/core/machine.c | 18 ++++++++++-------- hw/i386/pc.c | 23 ++++++++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 711e83db54..cf9cf53911 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -752,8 +752,9 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) unsigned sockets =3D config->has_sockets ? config->sockets : 0; 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; =20 - if (config->has_dies && config->dies !=3D 0 && config->dies !=3D 1) { + if (config->has_dies && config->dies > 1) { error_setg(errp, "dies not supported by this machine's CPU topolog= y"); return; } @@ -766,8 +767,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; @@ -784,26 +785,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 1276bfeee4..8733c2882f 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -718,9 +718,13 @@ static void pc_smp_parse(MachineState *ms, SMPConfigur= ation *config, Error **err { 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 dies =3D config->has_dies ? config->dies : 0; 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; + + /* directly default dies to 1 if it's omitted */ + dies =3D dies > 0 ? dies : 1; =20 /* compute missing values, prefer sockets over cores over threads */ if (cpus =3D=3D 0 || sockets =3D=3D 0) { @@ -730,8 +734,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 / (dies * cores * threads); } } else if (cores =3D=3D 0) { threads =3D threads > 0 ? threads : 1; @@ -748,27 +752,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.maxcpus =3D maxcpus; } =20 static --=20 2.19.1 From nobody Mon May 6 19:11:37 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 163058081471827.63187280343061; Thu, 2 Sep 2021 04:06:54 -0700 (PDT) Received: from localhost ([::1]:56998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkYX-0002kp-Kz for importer@patchew.org; Thu, 02 Sep 2021 07:06:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVZ-0006vm-H2; Thu, 02 Sep 2021 07:03:49 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVU-0003YQ-8l; Thu, 02 Sep 2021 07:03:49 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4H0dM53F8cz8DBN; Thu, 2 Sep 2021 19:03:13 +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; Thu, 2 Sep 2021 19:03:36 +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.2308.8; Thu, 2 Sep 2021 19:03:35 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 03/14] machine: Uniformly use maxcpus to calculate the omitted parameters Date: Thu, 2 Sep 2021 19:03:19 +0800 Message-ID: <20210902110330.18036-4-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630580815376100001 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 sanity check. Since we require for a valid config that the product of "sockets * cores * 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 split into two branches of "cpus =3D=3D 0" and "sockets =3D=3D 0" so that we can clearly r= ead that we are parsing the configuration with a preference on cpus over sockets over cores over threads. Note: change in this patch won't affect any existing working cmdlines but improves consistency and allows more incomplete configs to be valid. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Pankaj Gupta --- hw/core/machine.c | 30 +++++++++++++++--------------- hw/i386/pc.c | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index cf9cf53911..56bd3033a5 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -760,24 +760,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 cores * threads * sockets; - } else { - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - sockets =3D maxcpus / (cores * threads); - } + cpus =3D sockets * 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 / (cores * threads); } else if (cores =3D=3D 0) { threads =3D threads > 0 ? threads : 1; - cores =3D cpus / (sockets * threads); - cores =3D cores > 0 ? cores : 1; + cores =3D maxcpus / (sockets * threads); } else if (threads =3D=3D 0) { - threads =3D cpus / (cores * sockets); - threads =3D threads > 0 ? threads : 1; - } else if (sockets * cores * threads < cpus) { + threads =3D maxcpus / (sockets * cores); + } + + if (sockets * cores * threads < cpus) { error_setg(errp, "cpu topology: " "sockets (%u) * cores (%u) * threads (%u) < " "smp_cpus (%u)", @@ -785,8 +787,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; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8733c2882f..4b67c49f38 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -727,24 +727,26 @@ static void pc_smp_parse(MachineState *ms, SMPConfigu= ration *config, Error **err dies =3D dies > 0 ? dies : 1; =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 cores * threads * dies * sockets; - } 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 / (cores * dies * sockets); - 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) { error_setg(errp, "cpu topology: " "sockets (%u) * dies (%u) * cores (%u) * threads (%u) <= " "smp_cpus (%u)", @@ -752,8 +754,6 @@ static void pc_smp_parse(MachineState *ms, SMPConfigura= tion *config, Error **err 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 Mon May 6 19:11:37 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 1630581284617505.17665298724364; Thu, 2 Sep 2021 04:14:44 -0700 (PDT) Received: from localhost ([::1]:48070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkg7-0000Ga-Ht for importer@patchew.org; Thu, 02 Sep 2021 07:14:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVd-00076t-Gq; Thu, 02 Sep 2021 07:03:53 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3126) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVW-0003dw-D6; Thu, 02 Sep 2021 07:03:52 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H0dGk51d6z8xf7; Thu, 2 Sep 2021 18:59:26 +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; Thu, 2 Sep 2021 19:03:38 +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.2308.8; Thu, 2 Sep 2021 19:03:37 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 04/14] machine: Set the value of cpus to match maxcpus if it's omitted Date: Thu, 2 Sep 2021 19:03:20 +0800 Message-ID: <20210902110330.18036-5-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581285370100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently we directly calculate the omitted cpus based on the given incomplete collection of 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 set the value of cpus to match maxcpus if it's omitted, which will make above configs start to work. So the calculation logic of cpus/maxcpus after this patch will be: When both maxcpus and cpus are omitted, maxcpus will be calculated from the given parameters and cpus will be set equal to maxcpus. When only one of maxcpus and cpus is given then the omitted one will be set to its counterpart's value. Both maxcpus and cpus may be specified, but maxcpus must be equal to or greater than cpus. 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 Reviewed-by: Andrew Jones --- hw/core/machine.c | 29 ++++++++++++++++------------- hw/i386/pc.c | 29 ++++++++++++++++------------- qemu-options.hx | 11 ++++++++--- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 56bd3033a5..fe935cb4a3 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -760,25 +760,28 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) } =20 /* compute missing values, prefer sockets over cores over threads */ - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - - if (cpus =3D=3D 0) { + if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { sockets =3D sockets > 0 ? sockets : 1; cores =3D cores > 0 ? cores : 1; threads =3D threads > 0 ? threads : 1; - cpus =3D sockets * cores * threads; + } else { 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 / (cores * threads); - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * threads); - } else if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * cores); + + if (sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (cores * threads); + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * threads); + } else if (threads =3D=3D 0) { + threads =3D maxcpus / (sockets * cores); + } } =20 + maxcpus =3D maxcpus > 0 ? maxcpus : sockets * cores * threads; + cpus =3D cpus > 0 ? cpus : maxcpus; + if (sockets * cores * threads < cpus) { error_setg(errp, "cpu topology: " "sockets (%u) * cores (%u) * threads (%u) < " diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4b67c49f38..cf75fa5c7a 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -727,25 +727,28 @@ static void pc_smp_parse(MachineState *ms, SMPConfigu= ration *config, Error **err dies =3D dies > 0 ? dies : 1; =20 /* compute missing values, prefer sockets over cores over threads */ - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - - if (cpus =3D=3D 0) { + if (cpus =3D=3D 0 && maxcpus =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; + } else { 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 maxcpus / (sockets * dies * threads); - } else if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * dies * cores); + + 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 maxcpus / (sockets * dies * threads); + } else if (threads =3D=3D 0) { + threads =3D maxcpus / (sockets * dies * cores); + } } =20 + maxcpus =3D maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; + cpus =3D cpus > 0 ? cpus : maxcpus; + if (sockets * dies * cores * threads < cpus) { error_setg(errp, "cpu topology: " "sockets (%u) * dies (%u) * cores (%u) * threads (%u) <= " diff --git a/qemu-options.hx b/qemu-options.hx index aee622f577..06f819177e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -214,9 +214,14 @@ SRST Simulate a SMP system with '\ ``n``\ ' CPUs initially present on the machine type board. On boards supporting CPU hotplug, the optional '\ ``maxcpus``\ ' parameter can be set to enable further CPUs to be - added at runtime. If omitted the maximum number of CPUs will be - set to match the initial CPU count. Both parameters are subject to - an upper limit that is determined by the specific machine type chosen. + added at runtime. When both parameters are omitted, the maximum number + of CPUs will be calculated from the provided topology members and the + initial CPU count will match the maximum number. When only one of them + is given then the omitted one will be set to its counterpart's value. + Both parameters may be specified, but the maximum number of CPUs must + be equal to or greater than the initial CPU count. Both parameters are + subject to an upper limit that is determined by the specific machine + type chosen. =20 To control reporting of CPU topology information, the number of socket= s, dies per socket, cores per die, and threads per core can be specified. --=20 2.19.1 From nobody Mon May 6 19:11:37 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 163058109757884.99473942468603; Thu, 2 Sep 2021 04:11:37 -0700 (PDT) Received: from localhost ([::1]:38696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkd6-000202-GU for importer@patchew.org; Thu, 02 Sep 2021 07:11:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVa-0006yc-8p; Thu, 02 Sep 2021 07:03:50 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVV-0003bL-5y; Thu, 02 Sep 2021 07:03:49 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H0dGg5NWcz8xdm; Thu, 2 Sep 2021 18:59: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; Thu, 2 Sep 2021 19:03:39 +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.2308.8; Thu, 2 Sep 2021 19:03:38 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 05/14] machine: Improve the error reporting of smp parsing Date: Thu, 2 Sep 2021 19:03:21 +0800 Message-ID: <20210902110330.18036-6-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581098250100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We have two requirements for a valid SMP configuration: the product of "sockets * cores * threads" must represent all the possible cpus, i.e., max_cpus, and then must include the initially present cpus, i.e., smp_cpus. So we only need to ensure 1) "sockets * cores * threads =3D=3D maxcpus" at first and then ensure 2) "maxcpus >=3D cpus". With a reasonable order of the sanity check, we can simplify the error reporting code. When reporting an error message we also report the exact value of each topology member to make users easily see what's going on. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Pankaj Gupta --- hw/core/machine.c | 22 +++++++++------------- hw/i386/pc.c | 24 ++++++++++-------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index fe935cb4a3..f1b30b3101 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -782,25 +782,21 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) maxcpus =3D maxcpus > 0 ? maxcpus : sockets * cores * threads; cpus =3D cpus > 0 ? cpus : maxcpus; =20 - if (sockets * cores * threads < cpus) { - error_setg(errp, "cpu topology: " - "sockets (%u) * cores (%u) * threads (%u) < " - "smp_cpus (%u)", - sockets, cores, threads, cpus); + if (sockets * cores * threads !=3D maxcpus) { + error_setg(errp, "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "sockets (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, cores, threads, maxcpus); return; } =20 if (maxcpus < cpus) { - error_setg(errp, "maxcpus must be equal to or greater than smp"); - return; - } - - if (sockets * cores * threads !=3D maxcpus) { error_setg(errp, "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " "sockets (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, cores, threads, - maxcpus); + "=3D=3D maxcpus (%u) < smp_cpus (%u)", + sockets, cores, threads, maxcpus, cpus); return; } =20 diff --git a/hw/i386/pc.c b/hw/i386/pc.c index cf75fa5c7a..19dbe28d12 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -749,25 +749,21 @@ static void pc_smp_parse(MachineState *ms, SMPConfigu= ration *config, Error **err maxcpus =3D maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; cpus =3D cpus > 0 ? cpus : maxcpus; =20 - 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); + if (sockets * dies * cores * threads !=3D maxcpus) { + error_setg(errp, "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " + "!=3D maxcpus (%u)", + sockets, dies, cores, threads, maxcpus); return; } =20 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: " + error_setg(errp, "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, dies, cores, threads, - maxcpus); + "=3D=3D maxcpus (%u) < smp_cpus (%u)", + sockets, dies, cores, threads, maxcpus, cpus); return; } =20 --=20 2.19.1 From nobody Mon May 6 19:11:37 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 1630580805761765.4514501840429; Thu, 2 Sep 2021 04:06:45 -0700 (PDT) Received: from localhost ([::1]:56464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkYO-0002PV-Ed for importer@patchew.org; Thu, 02 Sep 2021 07:06:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVY-0006uA-0O; Thu, 02 Sep 2021 07:03:48 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2478) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVU-0003c6-76; Thu, 02 Sep 2021 07:03:47 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H0dH43Wdpzbl83; Thu, 2 Sep 2021 18:59:44 +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; Thu, 2 Sep 2021 19:03:40 +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.2308.8; Thu, 2 Sep 2021 19:03:39 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 06/14] machine: Prefer cores over sockets in smp parsing since 6.2 Date: Thu, 2 Sep 2021 19:03:22 +0800 Message-ID: <20210902110330.18036-7-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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: -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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630580806884100001 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 Acked-by: Cornelia Huck Reviewed-by: Andrew Jones Reviewed-by: Pankaj Gupta --- hw/arm/virt.c | 1 + hw/core/machine.c | 35 ++++++++++++++++++++++++++--------- hw/i386/pc.c | 35 ++++++++++++++++++++++++++--------- 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 | 3 ++- 9 files changed, 60 insertions(+), 19 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 73e9c6bb7c..ad244f0ff1 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2793,6 +2793,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 f1b30b3101..0df597f99c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -748,6 +748,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 cores =3D config->has_cores ? config->cores : 0; @@ -759,7 +760,7 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) return; } =20 - /* compute missing values, prefer sockets over cores over threads */ + /* compute missing values based on the provided ones */ if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { sockets =3D sockets > 0 ? sockets : 1; cores =3D cores > 0 ? cores : 1; @@ -767,14 +768,30 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) } else { maxcpus =3D maxcpus > 0 ? maxcpus : cpus; =20 - if (sockets =3D=3D 0) { - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (cores * threads); - } else if (cores =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * threads); - } else if (threads =3D=3D 0) { + if (mc->smp_prefer_sockets) { + /* prefer sockets over cores before 6.2 */ + if (sockets =3D=3D 0) { + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (cores * threads); + } else if (cores =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * threads); + } + } else { + /* prefer cores over sockets since 6.2 */ + if (cores =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * threads); + } else if (sockets =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (cores * threads); + } + } + + /* try to calculate omitted threads at last */ + if (threads =3D=3D 0) { threads =3D maxcpus / (sockets * cores); } } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 19dbe28d12..c79d9b87c1 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -716,6 +716,7 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int l= evel) */ static void pc_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 : 0; @@ -726,7 +727,7 @@ static void pc_smp_parse(MachineState *ms, SMPConfigura= tion *config, Error **err /* directly default dies to 1 if it's omitted */ dies =3D dies > 0 ? dies : 1; =20 - /* compute missing values, prefer sockets over cores over threads */ + /* compute missing values based on the provided ones */ if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { sockets =3D sockets > 0 ? sockets : 1; cores =3D cores > 0 ? cores : 1; @@ -734,14 +735,30 @@ static void pc_smp_parse(MachineState *ms, SMPConfigu= ration *config, Error **err } else { maxcpus =3D maxcpus > 0 ? maxcpus : cpus; =20 - 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 maxcpus / (sockets * dies * threads); - } else if (threads =3D=3D 0) { + if (mc->smp_prefer_sockets) { + /* prefer sockets over cores before 6.2 */ + 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 maxcpus / (sockets * dies * threads); + } + } else { + /* prefer cores over sockets since 6.2 */ + if (cores =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * dies * threads); + } else if (sockets =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); + } + } + + /* try to calculate omitted threads at last */ + if (threads =3D=3D 0) { threads =3D maxcpus / (sockets * dies * cores); } } diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index c5da7739ce..077644ee9c 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -431,6 +431,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 565fadce54..c762df5818 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -371,6 +371,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 463a5514f9..2ae039b74f 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 auto_enable_numa; + bool smp_prefer_sockets; const char *default_ram_id; =20 HotplugHandler *(*get_hotplug_handler)(MachineState *machine, diff --git a/qemu-options.hx b/qemu-options.hx index 06f819177e..451d2cd817 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -238,7 +238,8 @@ SRST 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. + liable to change. Prior to 6.2 the preference was sockets over cores + over threads. Since 6.2 the preference is cores over sockets over thre= ads. ERST =20 DEF("numa", HAS_ARG, QEMU_OPTION_numa, --=20 2.19.1 From nobody Mon May 6 19:11:37 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 163058128695091.21617248118798; Thu, 2 Sep 2021 04:14:46 -0700 (PDT) Received: from localhost ([::1]:48202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkg9-0000Mr-Um for importer@patchew.org; Thu, 02 Sep 2021 07:14:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVa-0006zA-G1; Thu, 02 Sep 2021 07:03:50 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3127) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVV-0003e1-Pb; Thu, 02 Sep 2021 07:03:50 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H0dGk6GHsz8xfN; Thu, 2 Sep 2021 18:59:26 +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; Thu, 2 Sep 2021 19:03:41 +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.2308.8; Thu, 2 Sep 2021 19:03:40 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 07/14] machine: Use ms instead of global current_machine in sanity-check Date: Thu, 2 Sep 2021 19:03:23 +0800 Message-ID: <20210902110330.18036-8-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581287656100001 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 Reviewed-by: Pankaj Gupta Reviewed-by: Cornelia Huck --- 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 0df597f99c..1ad5dac3e8 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -881,7 +881,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 Mon May 6 19:11:37 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 1630581098067832.4842411704552; Thu, 2 Sep 2021 04:11:38 -0700 (PDT) Received: from localhost ([::1]:38746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkd6-00021a-Vr for importer@patchew.org; Thu, 02 Sep 2021 07:11:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVb-00073G-Pv; Thu, 02 Sep 2021 07:03:52 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVY-0003gV-0I; Thu, 02 Sep 2021 07:03:51 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H0dGn084Kz8xdN; Thu, 2 Sep 2021 18:59:29 +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; Thu, 2 Sep 2021 19:03:43 +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.2308.8; Thu, 2 Sep 2021 19:03:42 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 08/14] machine: Tweak the order of topology members in struct CpuTopology Date: Thu, 2 Sep 2021 19:03:24 +0800 Message-ID: <20210902110330.18036-9-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581100165100003 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. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Pankaj Gupta --- hw/core/machine.c | 8 ++++---- include/hw/boards.h | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 1ad5dac3e8..a21fcd7700 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -829,11 +829,11 @@ static void machine_get_smp(Object *obj, Visitor *v, = const char *name, { MachineState *ms =3D MACHINE(obj); SMPConfiguration *config =3D &(SMPConfiguration){ - .has_cores =3D true, .cores =3D ms->smp.cores, + .has_cpus =3D true, .cpus =3D ms->smp.cpus, .has_sockets =3D true, .sockets =3D ms->smp.sockets, .has_dies =3D true, .dies =3D ms->smp.dies, + .has_cores =3D true, .cores =3D ms->smp.cores, .has_threads =3D true, .threads =3D ms->smp.threads, - .has_cpus =3D true, .cpus =3D ms->smp.cpus, .has_maxcpus =3D true, .maxcpus =3D ms->smp.max_cpus, }; if (!visit_type_SMPConfiguration(v, name, &config, &error_abort)) { @@ -1060,10 +1060,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 2ae039b74f..2a1bba86c0 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -275,17 +275,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 --=20 2.19.1 From nobody Mon May 6 19:11:37 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 1630581639863923.2592260589894; Thu, 2 Sep 2021 04:20:39 -0700 (PDT) Received: from localhost ([::1]:33670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLklq-0001D6-Pj for importer@patchew.org; Thu, 02 Sep 2021 07:20:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVj-0007Qt-6C; Thu, 02 Sep 2021 07:03:59 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2527) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVe-0003mo-Lv; Thu, 02 Sep 2021 07:03:58 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H0dLz1HbtzYws9; Thu, 2 Sep 2021 19:03:07 +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; Thu, 2 Sep 2021 19:03:44 +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.2308.8; Thu, 2 Sep 2021 19:03:43 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 09/14] machine: Make smp_parse generic enough for all arches Date: Thu, 2 Sep 2021 19:03:25 +0800 Message-ID: <20210902110330.18036-10-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581640430100001 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 dies parameter and the related error reporting. With some arch compat variables like "bool dies_supported", we can 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. Suggested-by: Andrew Jones Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- hw/core/machine.c | 110 ++++++++++++++++++++++++++++++++++++-------- hw/i386/pc.c | 84 +-------------------------------- include/hw/boards.h | 9 ++++ 3 files changed, 100 insertions(+), 103 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index a21fcd7700..4b5c943f8e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -15,6 +15,7 @@ #include "qapi/qmp/qerror.h" #include "sysemu/replay.h" #include "qemu/units.h" +#include "qemu/cutils.h" #include "hw/boards.h" #include "hw/loader.h" #include "qapi/error.h" @@ -746,20 +747,87 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 +static char *cpu_topology_hierarchy(MachineState *ms) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + SMPCompatProps *smp_props =3D &mc->smp_props; + char topo_msg[256] =3D ""; + + /* + * Topology members should be ordered from the largest to the smallest. + * Concept of sockets/cores/threads is supported by default and will be + * reported in the hierarchy. Unsupported members will not be reported. + */ + g_autofree char *sockets_msg =3D g_strdup_printf( + " * sockets (%u)", ms->smp.sockets); + pstrcat(topo_msg, sizeof(topo_msg), sockets_msg); + + if (smp_props->dies_supported) { + g_autofree char *dies_msg =3D g_strdup_printf( + " * dies (%u)", ms->smp.dies); + pstrcat(topo_msg, sizeof(topo_msg), dies_msg); + } + + g_autofree char *cores_msg =3D g_strdup_printf( + " * cores (%u)", ms->smp.cores); + pstrcat(topo_msg, sizeof(topo_msg), cores_msg); + + g_autofree char *threads_msg =3D g_strdup_printf( + " * threads (%u)", ms->smp.threads); + pstrcat(topo_msg, sizeof(topo_msg), threads_msg); + + return g_strdup_printf("%s", topo_msg + 3); +} + +/* + * smp_parse - Generic function used to parse the given SMP configuration + * + * If not supported by the machine, a topology parameter must be omitted + * or specified equal to 1. Concept of sockets/cores/threads is supported + * by default. Unsupported members will not be reported in the topology + * hierarchy message. + * + * For compatibility, omitted arch-specific members (e.g. dies) will not + * be computed, but will directly default to 1 instead. This logic should + * also apply to future introduced ones. + * + * Omitted arch-neutral parameters (i.e. cpus/sockets/cores/threads/maxcpu= s) + * will be computed based on the provided ones. When both maxcpus and cpus + * are omitted, maxcpus will be computed from the given parameters and cpus + * will be set equal to maxcpus. When only one of maxcpus and cpus is given + * then the omitted one will be set to its given counterpart's value. + * Both maxcpus and cpus may be specified, but maxcpus must be equal to or + * greater than cpus. + * + * In calculation of omitted sockets/cores/threads, we prefer sockets over + * cores over threads before 6.2, while preferring cores over sockets over + * threads since 6.2. + */ 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 : 0; 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; =20 - if (config->has_dies && config->dies > 1) { + /* + * If not supported by the machine, a topology parameter must be + * omitted or specified equal to 1. + */ + if (!mc->smp_props.dies_supported && dies > 1) { error_setg(errp, "dies not supported by this machine's CPU topolog= y"); return; } =20 + /* + * Omitted arch-specific members will not be computed, but will + * directly default to 1 instead. + */ + dies =3D dies > 0 ? dies : 1; + /* compute missing values based on the provided ones */ if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { sockets =3D sockets > 0 ? sockets : 1; @@ -773,55 +841,57 @@ static void smp_parse(MachineState *ms, SMPConfigurat= ion *config, Error **errp) if (sockets =3D=3D 0) { cores =3D cores > 0 ? cores : 1; threads =3D threads > 0 ? threads : 1; - 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 maxcpus / (sockets * threads); + cores =3D maxcpus / (sockets * dies * threads); } } else { /* prefer cores over sockets since 6.2 */ if (cores =3D=3D 0) { sockets =3D sockets > 0 ? sockets : 1; threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * threads); + cores =3D maxcpus / (sockets * dies * threads); } else if (sockets =3D=3D 0) { threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (cores * threads); + sockets =3D maxcpus / (dies * cores * threads); } } =20 /* try to calculate omitted threads at last */ if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * cores); + threads =3D maxcpus / (sockets * dies * cores); } } =20 - maxcpus =3D maxcpus > 0 ? maxcpus : sockets * cores * threads; + maxcpus =3D maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; cpus =3D cpus > 0 ? cpus : maxcpus; =20 - if (sockets * cores * threads !=3D maxcpus) { + 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; + + /* sanity-check of the computed topology */ + if (sockets * dies * cores * threads !=3D maxcpus) { + g_autofree char *topo_msg =3D cpu_topology_hierarchy(ms); error_setg(errp, "Invalid CPU topology: " "product of the hierarchy must match maxcpus: " - "sockets (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, cores, threads, maxcpus); + "%s !=3D maxcpus (%u)", + topo_msg, maxcpus); return; } =20 if (maxcpus < cpus) { + g_autofree char *topo_msg =3D cpu_topology_hierarchy(ms); error_setg(errp, "Invalid CPU topology: " "maxcpus must be equal to or greater than smp: " - "sockets (%u) * cores (%u) * threads (%u) " - "=3D=3D maxcpus (%u) < smp_cpus (%u)", - sockets, cores, threads, maxcpus, cpus); + "%s =3D=3D maxcpus (%u) < smp_cpus (%u)", + topo_msg, maxcpus, cpus); return; } - - ms->smp.cpus =3D cpus; - ms->smp.sockets =3D sockets; - ms->smp.cores =3D cores; - ms->smp.threads =3D threads; - 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 c79d9b87c1..fe8864980e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -710,88 +710,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) -{ - 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 : 0; - 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; - - /* directly default dies to 1 if it's omitted */ - dies =3D dies > 0 ? dies : 1; - - /* compute missing values based on the provided ones */ - if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - } else { - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - - if (mc->smp_prefer_sockets) { - /* prefer sockets over cores before 6.2 */ - 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 maxcpus / (sockets * dies * threads); - } - } else { - /* prefer cores over sockets since 6.2 */ - if (cores =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * dies * threads); - } else if (sockets =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (dies * cores * threads); - } - } - - /* try to calculate omitted threads at last */ - if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * dies * cores); - } - } - - maxcpus =3D maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; - cpus =3D cpus > 0 ? cpus : maxcpus; - - if (sockets * dies * cores * threads !=3D maxcpus) { - error_setg(errp, "Invalid CPU topology: " - "product of the hierarchy must match maxcpus: " - "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " - "!=3D maxcpus (%u)", - sockets, dies, cores, threads, maxcpus); - return; - } - - if (maxcpus < cpus) { - error_setg(errp, "Invalid CPU topology: " - "maxcpus must be equal to or greater than smp: " - "sockets (%u) * dies (%u) * cores (%u) * threads (%u) " - "=3D=3D maxcpus (%u) < smp_cpus (%u)", - sockets, dies, cores, threads, maxcpus, 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.maxcpus =3D maxcpus; -} - static void pc_machine_done(Notifier *notifier, void *data) { @@ -1745,7 +1663,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; @@ -1756,6 +1673,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_props.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 2a1bba86c0..72a23e4e0f 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -108,6 +108,14 @@ typedef struct { CPUArchId cpus[]; } CPUArchIdList; =20 +/** + * SMPCompatProps: + * @dies_supported - whether dies are supported by the machine + */ +typedef struct { + bool dies_supported; +} SMPCompatProps; + /** * MachineClass: * @deprecation_reason: If set, the machine is marked as deprecated. The @@ -248,6 +256,7 @@ struct MachineClass { bool numa_mem_supported; bool auto_enable_numa; bool smp_prefer_sockets; + SMPCompatProps smp_props; const char *default_ram_id; =20 HotplugHandler *(*get_hotplug_handler)(MachineState *machine, --=20 2.19.1 From nobody Mon May 6 19:11:37 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 1630581150627825.0410858325852; Thu, 2 Sep 2021 04:12:30 -0700 (PDT) Received: from localhost ([::1]:41060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkdx-0003gq-Jd for importer@patchew.org; Thu, 02 Sep 2021 07:12:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVc-00073M-3h; Thu, 02 Sep 2021 07:03:52 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2229) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVZ-0003hH-BW; Thu, 02 Sep 2021 07:03:51 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4H0dMG3QQmz8DTS; Thu, 2 Sep 2021 19:03:22 +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; Thu, 2 Sep 2021 19:03:45 +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.2308.8; Thu, 2 Sep 2021 19:03:44 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 10/14] machine: Remove smp_parse callback from MachineClass Date: Thu, 2 Sep 2021 19:03:26 +0800 Message-ID: <20210902110330.18036-11-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581152399100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now we have a generic smp parser for all arches, and there will not be any other arch specific ones, so let's remove the callback from MachineClass and call the parser directly. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- hw/core/machine.c | 3 +-- include/hw/boards.h | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 4b5c943f8e..ca7ca68ae3 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -937,7 +937,7 @@ static void machine_set_smp(Object *obj, Visitor *v, co= nst char *name, "CPU topology parameters must be greater than zero"); } =20 - mc->smp_parse(ms, config, errp); + smp_parse(ms, config, errp); if (*errp) { goto out_free; } @@ -966,7 +966,6 @@ static void machine_class_init(ObjectClass *oc, void *d= ata) /* Default 128 MB as guest ram size */ mc->default_ram_size =3D 128 * MiB; mc->rom_file_has_mr =3D true; - mc->smp_parse =3D smp_parse; =20 /* numa node memory size aligned on 8MB by default. * On Linux, each node's border has to be 8MB aligned diff --git a/include/hw/boards.h b/include/hw/boards.h index 72a23e4e0f..fa284e01e9 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -177,10 +177,6 @@ typedef struct { * kvm-type may be NULL if it is not needed. * @numa_mem_supported: * true if '--numa node.mem' option is supported and false otherwise - * @smp_parse: - * The function pointer to hook different machine specific functions for - * parsing "smp-opts" from QemuOpts to MachineState::CpuTopology and mo= re - * machine specific topology fields, such as smp_dies for PCMachine. * @hotplug_allowed: * If the hook is provided, then it'll be called for each device * hotplug to check whether the device hotplug is allowed. Return @@ -217,7 +213,6 @@ struct MachineClass { void (*reset)(MachineState *state); void (*wakeup)(MachineState *state); int (*kvm_type)(MachineState *machine, const char *arg); - void (*smp_parse)(MachineState *ms, SMPConfiguration *config, Error **= errp); =20 BlockInterfaceType block_default_type; int units_per_default_bus; --=20 2.19.1 From nobody Mon May 6 19:11:37 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 1630581358689962.8804564615231; Thu, 2 Sep 2021 04:15:58 -0700 (PDT) Received: from localhost ([::1]:50428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkhJ-0001tx-Hb for importer@patchew.org; Thu, 02 Sep 2021 07:15:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVg-0007FU-7f; Thu, 02 Sep 2021 07:03:56 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:2855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVb-0003jM-V8; Thu, 02 Sep 2021 07:03:55 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H0dLv4fkkz1DFjS; Thu, 2 Sep 2021 19:03:03 +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; Thu, 2 Sep 2021 19:03:47 +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.2308.8; Thu, 2 Sep 2021 19:03:46 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 11/14] machine: Move smp_prefer_sockets to struct SMPCompatProps Date: Thu, 2 Sep 2021 19:03:27 +0800 Message-ID: <20210902110330.18036-12-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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.255; envelope-from=wangyanan55@huawei.com; helo=szxga08-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.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581360741100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now we have a common structure SMPCompatProps used to store information about SMP compatibility stuff, so we can also move smp_prefer_sockets there for cleaner code. No functional change intended. Signed-off-by: Yanan Wang Acked-by: David Gibson Reviewed-by: Andrew Jones --- hw/arm/virt.c | 2 +- hw/core/machine.c | 2 +- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/ppc/spapr.c | 2 +- hw/s390x/s390-virtio-ccw.c | 2 +- include/hw/boards.h | 3 ++- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ad244f0ff1..be2e5ff37c 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2793,7 +2793,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; + mc->smp_props.prefer_sockets =3D true; } DEFINE_VIRT_MACHINE(6, 1) =20 diff --git a/hw/core/machine.c b/hw/core/machine.c index ca7ca68ae3..1bdeff32b3 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -836,7 +836,7 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) } else { maxcpus =3D maxcpus > 0 ? maxcpus : cpus; =20 - if (mc->smp_prefer_sockets) { + if (mc->smp_props.prefer_sockets) { /* prefer sockets over cores before 6.2 */ if (sockets =3D=3D 0) { cores =3D cores > 0 ? cores : 1; diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 077644ee9c..5efb6f1949 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -431,7 +431,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; + m->smp_props.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 c762df5818..1ce653a21a 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -371,7 +371,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; + m->smp_props.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 a481fade51..efdea43c0d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4702,7 +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; + mc->smp_props.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 b40e647883..5bdef9b4d7 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -809,7 +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; + mc->smp_props.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 fa284e01e9..5adbcbb99b 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -110,9 +110,11 @@ typedef struct { =20 /** * SMPCompatProps: + * @prefer_sockets - whether sockets are preferred over cores in smp parsi= ng * @dies_supported - whether dies are supported by the machine */ typedef struct { + bool prefer_sockets; bool dies_supported; } SMPCompatProps; =20 @@ -250,7 +252,6 @@ struct MachineClass { bool nvdimm_supported; bool numa_mem_supported; bool auto_enable_numa; - bool smp_prefer_sockets; SMPCompatProps smp_props; const char *default_ram_id; =20 --=20 2.19.1 From nobody Mon May 6 19:11:37 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 1630581341173512.344404505078; Thu, 2 Sep 2021 04:15:41 -0700 (PDT) Received: from localhost ([::1]:49510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkh2-0001H9-3V for importer@patchew.org; Thu, 02 Sep 2021 07:15:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVi-0007Mw-4O; Thu, 02 Sep 2021 07:03:58 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVe-0003mt-Ox; Thu, 02 Sep 2021 07:03:57 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H0dLz22bPzYwwD; Thu, 2 Sep 2021 19:03:07 +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; Thu, 2 Sep 2021 19:03: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.2308.8; Thu, 2 Sep 2021 19:03:47 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 12/14] machine: Put all sanity-check in the generic SMP parser Date: Thu, 2 Sep 2021 19:03:28 +0800 Message-ID: <20210902110330.18036-13-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581342098100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Put both sanity-check of the input SMP configuration and sanity-check of the output SMP configuration uniformly in the generic parser. Then machine_set_smp() will become cleaner, also all the invalid scenarios can be tested only by calling the parser. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Pankaj Gupta --- hw/core/machine.c | 63 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 1bdeff32b3..5b62ba7e34 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -813,6 +813,20 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) unsigned threads =3D config->has_threads ? config->threads : 0; unsigned maxcpus =3D config->has_maxcpus ? config->maxcpus : 0; =20 + /* + * Specified CPU topology parameters must be greater than zero, + * explicit configuration like "cpus=3D0" is not allowed. + */ + 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)) { + warn_report("Invalid CPU topology deprecated: " + "CPU topology parameters must be greater than zero"); + } + /* * If not supported by the machine, a topology parameter must be * omitted or specified equal to 1. @@ -892,6 +906,22 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) topo_msg, maxcpus, cpus); return; } + + if (ms->smp.cpus < mc->min_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " + "supported by machine '%s' is %d", + ms->smp.cpus, + mc->name, mc->min_cpus); + return; + } + + if (ms->smp.max_cpus > mc->max_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " + "supported by machine '%s' is %d", + ms->smp.max_cpus, + mc->name, mc->max_cpus); + return; + } } =20 static void machine_get_smp(Object *obj, Visitor *v, const char *name, @@ -914,7 +944,6 @@ static void machine_get_smp(Object *obj, Visitor *v, co= nst char *name, static void machine_set_smp(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - MachineClass *mc =3D MACHINE_GET_CLASS(obj); MachineState *ms =3D MACHINE(obj); SMPConfiguration *config; ERRP_GUARD(); @@ -923,40 +952,10 @@ static void machine_set_smp(Object *obj, Visitor *v, = const char *name, return; } =20 - /* - * Specified CPU topology parameters must be greater than zero, - * explicit configuration like "cpus=3D0" is not allowed. - */ - 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)) { - warn_report("Invalid CPU topology deprecated: " - "CPU topology parameters must be greater than zero"); - } - smp_parse(ms, config, errp); if (*errp) { - goto out_free; - } - - /* sanity-check smp_cpus and max_cpus against mc */ - if (ms->smp.cpus < mc->min_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " - "supported by machine '%s' is %d", - ms->smp.cpus, - mc->name, mc->min_cpus); - } 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", - ms->smp.max_cpus, - mc->name, mc->max_cpus); + qapi_free_SMPConfiguration(config); } - -out_free: - qapi_free_SMPConfiguration(config); } =20 static void machine_class_init(ObjectClass *oc, void *data) --=20 2.19.1 From nobody Mon May 6 19:11:37 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 1630581558302349.46496509882604; Thu, 2 Sep 2021 04:19:18 -0700 (PDT) Received: from localhost ([::1]:58332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLkkX-0007Fc-3Q for importer@patchew.org; Thu, 02 Sep 2021 07:19:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVj-0007Ra-Id; Thu, 02 Sep 2021 07:04:00 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2479) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVe-0003mh-5o; Thu, 02 Sep 2021 07:03:58 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H0dHF6wjCzblCw; Thu, 2 Sep 2021 18:59:53 +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; Thu, 2 Sep 2021 19:03: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.2308.8; Thu, 2 Sep 2021 19:03:49 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 13/14] machine: Split out the smp parsing code Date: Thu, 2 Sep 2021 19:03:29 +0800 Message-ID: <20210902110330.18036-14-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581559781100001 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 | 200 ++++++++++++++++++++++++++++++++++++++++++ hw/core/machine.c | 178 ------------------------------------- hw/core/meson.build | 1 + include/hw/boards.h | 1 + 5 files changed, 203 insertions(+), 178 deletions(-) create mode 100644 hw/core/machine-smp.c diff --git a/MAINTAINERS b/MAINTAINERS index c8221650b8..fb0bd4c023 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1631,6 +1631,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..07604aef8d --- /dev/null +++ b/hw/core/machine-smp.c @@ -0,0 +1,200 @@ +/* + * QEMU Machine (related to SMP) + * + * Copyright (c) 2021 Huawei Technologies Co., Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/boards.h" +#include "qapi/error.h" +#include "qemu/cutils.h" + +static char *cpu_topology_hierarchy(MachineState *ms) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + SMPCompatProps *smp_props =3D &mc->smp_props; + char topo_msg[256] =3D ""; + + /* + * Topology members should be ordered from the largest to the smallest. + * Concept of sockets/cores/threads is supported by default and will be + * reported in the hierarchy. Unsupported members will not be reported. + */ + g_autofree char *sockets_msg =3D g_strdup_printf( + " * sockets (%u)", ms->smp.sockets); + pstrcat(topo_msg, sizeof(topo_msg), sockets_msg); + + if (smp_props->dies_supported) { + g_autofree char *dies_msg =3D g_strdup_printf( + " * dies (%u)", ms->smp.dies); + pstrcat(topo_msg, sizeof(topo_msg), dies_msg); + } + + g_autofree char *cores_msg =3D g_strdup_printf( + " * cores (%u)", ms->smp.cores); + pstrcat(topo_msg, sizeof(topo_msg), cores_msg); + + g_autofree char *threads_msg =3D g_strdup_printf( + " * threads (%u)", ms->smp.threads); + pstrcat(topo_msg, sizeof(topo_msg), threads_msg); + + return g_strdup_printf("%s", topo_msg + 3); +} + +/* + * smp_parse - Generic function used to parse the given SMP configuration + * + * If not supported by the machine, a topology parameter must be omitted + * or specified equal to 1. Concept of sockets/cores/threads is supported + * by default. Unsupported members will not be reported in the topology + * hierarchy message. + * + * For compatibility, omitted arch-specific members (e.g. dies) will not + * be computed, but will directly default to 1 instead. This logic should + * also apply to future introduced ones. + * + * Omitted arch-neutral parameters (i.e. cpus/sockets/cores/threads/maxcpu= s) + * will be computed based on the provided ones. When both maxcpus and cpus + * are omitted, maxcpus will be computed from the given parameters and cpus + * will be set equal to maxcpus. When only one of maxcpus and cpus is given + * then the omitted one will be set to its given counterpart's value. + * Both maxcpus and cpus may be specified, but maxcpus must be equal to or + * greater than cpus. + * + * In calculation of omitted sockets/cores/threads, we prefer sockets over + * cores over threads before 6.2, while preferring cores over sockets over + * threads since 6.2. + */ +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 : 0; + 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; + + /* + * Specified CPU topology parameters must be greater than zero, + * explicit configuration like "cpus=3D0" is not allowed. + */ + 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)) { + warn_report("Invalid CPU topology deprecated: " + "CPU topology parameters must be greater than zero"); + } + + /* + * If not supported by the machine, a topology parameter must be + * omitted or specified equal to 1. + */ + if (!mc->smp_props.dies_supported && dies > 1) { + error_setg(errp, "dies not supported by this machine's CPU topolog= y"); + return; + } + + /* + * Omitted arch-specific members will not be computed, but will + * directly default to 1 instead. + */ + dies =3D dies > 0 ? dies : 1; + + /* compute missing values based on the provided ones */ + if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + cores =3D cores > 0 ? cores : 1; + threads =3D threads > 0 ? threads : 1; + } else { + maxcpus =3D maxcpus > 0 ? maxcpus : cpus; + + if (mc->smp_props.prefer_sockets) { + /* prefer sockets over cores before 6.2 */ + 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 maxcpus / (sockets * dies * threads); + } + } else { + /* prefer cores over sockets since 6.2 */ + if (cores =3D=3D 0) { + sockets =3D sockets > 0 ? sockets : 1; + threads =3D threads > 0 ? threads : 1; + cores =3D maxcpus / (sockets * dies * threads); + } else if (sockets =3D=3D 0) { + threads =3D threads > 0 ? threads : 1; + sockets =3D maxcpus / (dies * cores * threads); + } + } + + /* try to calculate omitted threads at last */ + if (threads =3D=3D 0) { + threads =3D maxcpus / (sockets * dies * cores); + } + } + + maxcpus =3D maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; + cpus =3D cpus > 0 ? cpus : maxcpus; + + 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; + + /* sanity-check of the computed topology */ + if (sockets * dies * cores * threads !=3D maxcpus) { + g_autofree char *topo_msg =3D cpu_topology_hierarchy(ms); + error_setg(errp, "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "%s !=3D maxcpus (%u)", + topo_msg, maxcpus); + return; + } + + if (maxcpus < cpus) { + g_autofree char *topo_msg =3D cpu_topology_hierarchy(ms); + error_setg(errp, "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " + "%s =3D=3D maxcpus (%u) < smp_cpus (%u)", + topo_msg, maxcpus, cpus); + return; + } + + if (ms->smp.cpus < mc->min_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " + "supported by machine '%s' is %d", + ms->smp.cpus, + mc->name, mc->min_cpus); + return; + } + + if (ms->smp.max_cpus > mc->max_cpus) { + error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " + "supported by machine '%s' is %d", + ms->smp.max_cpus, + mc->name, mc->max_cpus); + return; + } +} diff --git a/hw/core/machine.c b/hw/core/machine.c index 5b62ba7e34..771c0be17d 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -15,7 +15,6 @@ #include "qapi/qmp/qerror.h" #include "sysemu/replay.h" #include "qemu/units.h" -#include "qemu/cutils.h" #include "hw/boards.h" #include "hw/loader.h" #include "qapi/error.h" @@ -747,183 +746,6 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 -static char *cpu_topology_hierarchy(MachineState *ms) -{ - MachineClass *mc =3D MACHINE_GET_CLASS(ms); - SMPCompatProps *smp_props =3D &mc->smp_props; - char topo_msg[256] =3D ""; - - /* - * Topology members should be ordered from the largest to the smallest. - * Concept of sockets/cores/threads is supported by default and will be - * reported in the hierarchy. Unsupported members will not be reported. - */ - g_autofree char *sockets_msg =3D g_strdup_printf( - " * sockets (%u)", ms->smp.sockets); - pstrcat(topo_msg, sizeof(topo_msg), sockets_msg); - - if (smp_props->dies_supported) { - g_autofree char *dies_msg =3D g_strdup_printf( - " * dies (%u)", ms->smp.dies); - pstrcat(topo_msg, sizeof(topo_msg), dies_msg); - } - - g_autofree char *cores_msg =3D g_strdup_printf( - " * cores (%u)", ms->smp.cores); - pstrcat(topo_msg, sizeof(topo_msg), cores_msg); - - g_autofree char *threads_msg =3D g_strdup_printf( - " * threads (%u)", ms->smp.threads); - pstrcat(topo_msg, sizeof(topo_msg), threads_msg); - - return g_strdup_printf("%s", topo_msg + 3); -} - -/* - * smp_parse - Generic function used to parse the given SMP configuration - * - * If not supported by the machine, a topology parameter must be omitted - * or specified equal to 1. Concept of sockets/cores/threads is supported - * by default. Unsupported members will not be reported in the topology - * hierarchy message. - * - * For compatibility, omitted arch-specific members (e.g. dies) will not - * be computed, but will directly default to 1 instead. This logic should - * also apply to future introduced ones. - * - * Omitted arch-neutral parameters (i.e. cpus/sockets/cores/threads/maxcpu= s) - * will be computed based on the provided ones. When both maxcpus and cpus - * are omitted, maxcpus will be computed from the given parameters and cpus - * will be set equal to maxcpus. When only one of maxcpus and cpus is given - * then the omitted one will be set to its given counterpart's value. - * Both maxcpus and cpus may be specified, but maxcpus must be equal to or - * greater than cpus. - * - * In calculation of omitted sockets/cores/threads, we prefer sockets over - * cores over threads before 6.2, while preferring cores over sockets over - * threads since 6.2. - */ -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 : 0; - 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; - - /* - * Specified CPU topology parameters must be greater than zero, - * explicit configuration like "cpus=3D0" is not allowed. - */ - 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)) { - warn_report("Invalid CPU topology deprecated: " - "CPU topology parameters must be greater than zero"); - } - - /* - * If not supported by the machine, a topology parameter must be - * omitted or specified equal to 1. - */ - if (!mc->smp_props.dies_supported && dies > 1) { - error_setg(errp, "dies not supported by this machine's CPU topolog= y"); - return; - } - - /* - * Omitted arch-specific members will not be computed, but will - * directly default to 1 instead. - */ - dies =3D dies > 0 ? dies : 1; - - /* compute missing values based on the provided ones */ - if (cpus =3D=3D 0 && maxcpus =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - cores =3D cores > 0 ? cores : 1; - threads =3D threads > 0 ? threads : 1; - } else { - maxcpus =3D maxcpus > 0 ? maxcpus : cpus; - - if (mc->smp_props.prefer_sockets) { - /* prefer sockets over cores before 6.2 */ - 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 maxcpus / (sockets * dies * threads); - } - } else { - /* prefer cores over sockets since 6.2 */ - if (cores =3D=3D 0) { - sockets =3D sockets > 0 ? sockets : 1; - threads =3D threads > 0 ? threads : 1; - cores =3D maxcpus / (sockets * dies * threads); - } else if (sockets =3D=3D 0) { - threads =3D threads > 0 ? threads : 1; - sockets =3D maxcpus / (dies * cores * threads); - } - } - - /* try to calculate omitted threads at last */ - if (threads =3D=3D 0) { - threads =3D maxcpus / (sockets * dies * cores); - } - } - - maxcpus =3D maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; - cpus =3D cpus > 0 ? cpus : maxcpus; - - 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; - - /* sanity-check of the computed topology */ - if (sockets * dies * cores * threads !=3D maxcpus) { - g_autofree char *topo_msg =3D cpu_topology_hierarchy(ms); - error_setg(errp, "Invalid CPU topology: " - "product of the hierarchy must match maxcpus: " - "%s !=3D maxcpus (%u)", - topo_msg, maxcpus); - return; - } - - if (maxcpus < cpus) { - g_autofree char *topo_msg =3D cpu_topology_hierarchy(ms); - error_setg(errp, "Invalid CPU topology: " - "maxcpus must be equal to or greater than smp: " - "%s =3D=3D maxcpus (%u) < smp_cpus (%u)", - topo_msg, maxcpus, cpus); - return; - } - - if (ms->smp.cpus < mc->min_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " - "supported by machine '%s' is %d", - ms->smp.cpus, - mc->name, mc->min_cpus); - return; - } - - if (ms->smp.max_cpus > mc->max_cpus) { - error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " - "supported by machine '%s' is %d", - ms->smp.max_cpus, - mc->name, mc->max_cpus); - return; - } -} - 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 5adbcbb99b..e36fc7d861 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 Mon May 6 19:11:37 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 1630581624166252.5905388494342; Thu, 2 Sep 2021 04:20:24 -0700 (PDT) Received: from localhost ([::1]:60930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLklZ-0000YO-B7 for importer@patchew.org; Thu, 02 Sep 2021 07:20:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVn-0007dC-DQ; Thu, 02 Sep 2021 07:04:03 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2105) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLkVf-0003np-PU; Thu, 02 Sep 2021 07:04:03 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H0dHH1qztzbfwC; Thu, 2 Sep 2021 18:59:55 +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; Thu, 2 Sep 2021 19:03: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.2308.8; Thu, 2 Sep 2021 19:03:50 +0800 From: Yanan Wang To: Eduardo Habkost , Marcel Apfelbaum , , , , Subject: [PATCH v8 14/14] tests/unit: Add a unit test for smp parsing Date: Thu, 2 Sep 2021 19:03:30 +0800 Message-ID: <20210902110330.18036-15-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210902110330.18036-1-wangyanan55@huawei.com> References: <20210902110330.18036-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Greg Kurz , Yanan Wang , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1630581625440100001 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 different 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 corresponding 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 | 866 ++++++++++++++++++++++++++++++++++++ 3 files changed, 868 insertions(+) create mode 100644 tests/unit/test-smp-parse.c diff --git a/MAINTAINERS b/MAINTAINERS index fb0bd4c023..1b4081a9c2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1641,6 +1641,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 5736d285b2..e208173970 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -45,6 +45,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..836dfd320f --- /dev/null +++ b/tests/unit/test-smp-parse.c @@ -0,0 +1,866 @@ +/* + * SMP parsing unit-tests + * + * Copyright (c) 2021 Huawei Technologies Co., Ltd + * + * 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 + +#define MIN_CPUS 1 +#define MAX_CPUS 512 + +/* define a CPU topology hierarchy of sockets/cores/threads */ +#define SMP_CONFIG_GENERIC(ha, a, hb, b, hc, c, hd, d, he, e) \ + { \ + .has_cpus =3D ha, .cpus =3D a, \ + .has_sockets =3D hb, .sockets =3D b, \ + .has_cores =3D hc, .cores =3D c, \ + .has_threads =3D hd, .threads =3D d, \ + .has_maxcpus =3D he, .maxcpus =3D e, \ + } + +#define CPU_TOPOLOGY_GENERIC(a, b, c, d, e) \ + { \ + .cpus =3D a, \ + .sockets =3D b, \ + .cores =3D c, \ + .threads =3D d, \ + .max_cpus =3D e, \ + } + +/* define a CPU topology hierarchy of sockets/dies/cores/threads */ +#define SMP_CONFIG_WITH_DIES(ha, a, hb, b, hc, c, hd, d, he, e, hf, f) \ + { \ + .has_cpus =3D ha, .cpus =3D a, \ + .has_sockets =3D hb, .sockets =3D b, \ + .has_dies =3D hc, .dies =3D c, \ + .has_cores =3D hd, .cores =3D d, \ + .has_threads =3D he, .threads =3D e, \ + .has_maxcpus =3D hf, .maxcpus =3D f, \ + } + +#define CPU_TOPOLOGY_WITH_DIES(a, b, c, d, e, f) \ + { \ + .cpus =3D a, \ + .sockets =3D b, \ + .dies =3D c, \ + .cores =3D d, \ + .threads =3D e, \ + .max_cpus =3D f, \ + } + +/** + * SMPTestData: + * @config - the given SMP configuration + * @expect_prefer_sockets - expected topology result for the valid + * configuration, when sockets are preferred over cores in parsing + * @expect_prefer_cores - expected topology result for the valid + * configuration, when cores are preferred over sockets in parsing + * @expect_error - expected error report for the invalid configuration + */ +typedef struct SMPTestData { + SMPConfiguration config; + CpuTopology expect_prefer_sockets; + CpuTopology expect_prefer_cores; + const char *expect_error; +} SMPTestData; + +/* specific machine type info for testing */ +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), +}; + +/* + * all possible valid collections of generic topology parameters + * and the corresponding expected outputs are listed. + */ +static struct SMPTestData data_generic[] =3D { + { + /* config: no configuration provided + * expect: cpus=3D1,sockets=3D1,cores=3D1,threads=3D1,maxcpus=3D1 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(1, 1, 1, 1, 1), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(1, 1, 1, 1, 1), + }, { + /* config: -smp 8 + * prefer_sockets: cpus=3D8,sockets=3D8,cores=3D1,threads=3D1,maxc= pus=3D8 + * prefer_cores: cpus=3D8,sockets=3D1,cores=3D8,threads=3D1,maxcpu= s=3D8 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, F, 0, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 8, 1, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 8, 1, 8), + }, { + /* config: -smp sockets=3D2 + * expect: cpus=3D2,sockets=3D2,cores=3D1,threads=3D1,maxcpus=3D2 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, F, 0, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(2, 2, 1, 1, 2), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(2, 2, 1, 1, 2), + }, { + /* config: -smp cores=3D4 + * expect: cpus=3D4,sockets=3D1,cores=3D4,threads=3D1,maxcpus=3D4 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, T, 4, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(4, 1, 4, 1, 4), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(4, 1, 4, 1, 4), + }, { + /* config: -smp threads=3D2 + * expect: cpus=3D2,sockets=3D1,cores=3D1,threads=3D2,maxcpus=3D2 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(2, 1, 1, 2, 2), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(2, 1, 1, 2, 2), + }, { + /* config: -smp maxcpus=3D16 + * prefer_sockets: cpus=3D16,sockets=3D16,cores=3D1,threads=3D1,ma= xcpus=3D16 + * prefer_cores: cpus=3D16,sockets=3D1,cores=3D16,threads=3D1,maxc= pus=3D16 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 16, 1, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 1, 16, 1, 16), + }, { + /* config: -smp 8,sockets=3D2 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, F, 0, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp 8,cores=3D4 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, T, 4, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp 8,threads=3D2 + * prefer_sockets: cpus=3D8,sockets=3D4,cores=3D1,threads=3D2,maxc= pus=3D8 + * prefer_cores: cpus=3D8,sockets=3D1,cores=3D4,threads=3D2,maxcpu= s=3D8 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, F, 0, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 4, 1, 2, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + }, { + /* config: -smp 8,maxcpus=3D16 + * prefer_sockets: cpus=3D8,sockets=3D16,cores=3D1,threads=3D1,max= cpus=3D16 + * prefer_cores: cpus=3D8,sockets=3D1,cores=3D16,threads=3D1,maxcp= us=3D16 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, F, 0, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 16, 1, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 16, 1, 16), + }, { + /* config: -smp sockets=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, T, 4, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp sockets=3D2,threads=3D2 + * expect: cpus=3D4,sockets=3D2,cores=3D1,threads=3D2,maxcpus=3D4 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, F, 0, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(4, 2, 1, 2, 4), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(4, 2, 1, 2, 4), + }, { + /* config: -smp sockets=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D8,threads=3D1,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, F, 0, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 8, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 8, 1, 16), + }, { + /* config: -smp cores=3D4,threads=3D2 + * expect: cpus=3D8,sockets=3D1,cores=3D4,threads=3D2,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, T, 4, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + }, { + /* config: -smp cores=3D4,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D4,cores=3D4,threads=3D1,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, T, 4, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 4, 4, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 4, 4, 1, 16), + }, { + /* config: -smp threads=3D2,maxcpus=3D16 + * prefer_sockets: cpus=3D16,sockets=3D8,cores=3D1,threads=3D2,max= cpus=3D16 + * prefer_cores: cpus=3D16,sockets=3D1,cores=3D8,threads=3D2,maxcp= us=3D16 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, F, 0, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 8, 1, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 1, 8, 2, 16), + }, { + /* config: -smp 8,sockets=3D2,cores=3D4 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, F, 0, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp 8,sockets=3D2,threads=3D2 + * expect: cpus=3D8,sockets=3D2,cores=3D2,threads=3D2,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, F, 0, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 2, 2, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 2, 2, 8), + }, { + /* config: -smp 8,sockets=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D8,threads=3D1,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, F, 0, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 8, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 8, 1, 16), + }, { + /* config: -smp 8,cores=3D4,threads=3D2 + * expect: cpus=3D8,sockets=3D1,cores=3D4,threads=3D2,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, T, 4, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 4, 2, 8), + }, { + /* config: -smp 8,cores=3D4,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D4,cores=3D4,threads=3D1,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, T, 4, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 4, 4, 1, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 4, 4, 1, 16), + }, { + /* config: -smp 8,threads=3D2,maxcpus=3D16 + * prefer_sockets: cpus=3D8,sockets=3D8,cores=3D1,threads=3D2,maxc= pus=3D16 + * prefer_cores: cpus=3D8,sockets=3D1,cores=3D8,threads=3D2,maxcpu= s=3D16 */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, F, 0, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 8, 1, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 1, 8, 2, 16), + }, { + /* config: -smp sockets=3D2,cores=3D4,threads=3D2 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, T, 4, T, 2, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp sockets=3D2,cores=3D4,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, T, 4, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp sockets=3D2,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, F, 0, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, F, 0, T, 4, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D1 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D1,maxcpus=3D8 = */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, T, 1, F, 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 1, 8), + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, F, 0, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + }, { + /* config: -smp 8,sockets=3D2,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, F, 0, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + }, { + /* config: -smp 8,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, F, 0, T, 4, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + }, { + /* config: -smp sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D16,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D1= 6 */ + .config =3D SMP_CONFIG_GENERIC(F, 0, T, 2, T, 4, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(16, 2, 4, 2, 16), + }, { + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 + * expect: cpus=3D8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16= */ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, T, 2, T, 16), + .expect_prefer_sockets =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_GENERIC(8, 2, 4, 2, 16), + }, +}; + +/* + * all possible valid collections of topology parameters (with dies) + * and the corresponding expected outputs are listed. + */ +static SMPTestData data_with_dies[] =3D { + { + /* config: -smp dies=3D2 + * expect: cpus=3D2,sockets=3D1,dies=3D2,cores=3D1,threads=3D1,max= cpus=3D2 */ + .config =3D SMP_CONFIG_WITH_DIES(F, 0, F, 0, T, 2, F, 0, F, 0, F, = 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(2, 1, 2, 1, 1, 2= ), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(2, 1, 2, 1, 1, 2= ), + }, { + /* config: -smp 16,dies=3D2 + * prefer_sockets: cpus=3D16,sockets=3D8,dies=3D2,cores=3D1,thread= s=3D1,maxcpus=3D16 + * prefer_cores: cpus=3D16,sockets=3D1,dies=3D2,cores=3D8,threads= =3D1,maxcpus=3D16 */ + .config =3D SMP_CONFIG_WITH_DIES(T, 16, F, 0, T, 2, F, 0, F, 0, F,= 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 8, 2, 1, 1, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, T, 2, T, 2, F, 0, F, 0, F, = 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(4, 2, 2, 1, 1, 4= ), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, F, 0, T, 2, T, 4, F, 0, F, = 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(8, 1, 2, 4, 1, 8= ), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, F, 0, T, 2, F, 0, T, 2, F, = 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(4, 1, 2, 1, 2, 4= ), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(4, 1, 2, 1, 2, 4= ), + }, { + /* config: -smp dies=3D2,maxcpus=3D32 + * prefer_sockets: cpus=3D32,sockets=3D16,dies=3D2,cores=3D1,threa= ds=3D1,maxcpus=3D32 + * prefer_cores: cpus=3D32,sockets=3D1,dies=3D2,cores=3D16,threads= =3D1,maxcpus=3D32 */ + .config =3D SMP_CONFIG_WITH_DIES(F, 0, F, 0, T, 2, F, 0, F, 0, T, = 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 16, 2, 1, 1,= 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, F, 0, F, 0, F,= 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 1, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, F, 0, T, 2, T, 4, F, 0, F,= 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 1, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 1, = 16), + }, { + /* config: -smp 16,dies=3D2,threads=3D2 + * prefer_sockets: cpus=3D16,sockets=3D4,dies=3D2,cores=3D1,thread= s=3D2,maxcpus=3D16 + * prefer_cores: cpus=3D16,sockets=3D1,dies=3D2,cores=3D4,threads= =3D2,maxcpus=3D16 */ + .config =3D SMP_CONFIG_WITH_DIES(T, 16, F, 0, T, 2, F, 0, T, 2, F,= 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 4, 2, 1, 2, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(16, 1, 2, 4, 2, = 16), + }, { + /* config: -smp 16,dies=3D2,maxcpus=3D32 + * prefer_sockets: cpus=3D16,sockets=3D16,dies=3D2,cores=3D1,threa= ds=3D1,maxcpus=3D32 + * prefer_cores: cpus=3D16,sockets=3D1,dies=3D2,cores=3D16,threads= =3D1,maxcpus=3D32 */ + .config =3D SMP_CONFIG_WITH_DIES(T, 16, F, 0, T, 2, F, 0, F, 0, T,= 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 16, 2, 1, 1,= 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, T, 2, T, 2, T, 4, F, 0, F, = 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 1, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, T, 2, T, 2, F, 0, T, 2, F, = 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(8, 2, 2, 1, 2, 8= ), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, T, 2, T, 2, F, 0, F, 0, T, = 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 2, 2, 8, 1, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, F, 0, T, 2, T, 4, T, 2, F, = 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 1, 2, 4, 2, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, F, 0, T, 2, T, 4, F, 0, T, = 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 4, 2, 4, 1, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(32, 4, 2, 4, 1, = 32), + }, { + /* config: -smp dies=3D2,threads=3D2,maxcpus=3D32 + * prefer_sockets: cpus=3D32,sockets=3D8,dies=3D2,cores=3D1,thread= s=3D2,maxcpus=3D32 + * prefer_cores: cpus=3D32,sockets=3D1,dies=3D2,cores=3D8,threads= =3D2,maxcpus=3D32 */ + .config =3D SMP_CONFIG_WITH_DIES(F, 0, F, 0, T, 2, F, 0, T, 2, T, = 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 8, 2, 1, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, T, 4, F, 0, F,= 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 1, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, F, 0, T, 2, F,= 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 2, 2, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, F, 0, F, 0, T,= 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 8, 1, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, F, 0, T, 2, T, 4, T, 2, F,= 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 1, 2, 4, 2, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, F, 0, T, 2, T, 4, F, 0, T,= 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 4, 2, 4, 1, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(16, 4, 2, 4, 1, = 32), + }, { + /* config: -smp 16,dies=3D2,threads=3D2,maxcpus=3D32 + * prefer_sockets: cpus=3D16,sockets=3D8,dies=3D2,cores=3D1,thread= s=3D2,maxcpus=3D32 + * prefer_cores: cpus=3D16,sockets=3D1,dies=3D2,cores=3D8,threads= =3D2,maxcpus=3D32 */ + .config =3D SMP_CONFIG_WITH_DIES(T, 16, F, 0, T, 2, F, 0, T, 2, T,= 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 8, 2, 1, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, T, 2, T, 2, T, 4, T, 2, F, = 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, T, 2, T, 2, T, 4, F, 0, T, = 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, T, 2, T, 2, F, 0, T, 2, T, = 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(F, 0, F, 0, T, 2, T, 4, T, 2, T, = 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, T, 4, T, 1, F,= 0), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 1, = 16), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, T, 4, F, 0, T,= 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, F, 0, T, 2, T,= 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, F, 0, T, 2, T, 4, T, 2, T,= 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 2, = 32), + }, { + /* config: -smp sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxcpus= =3D32 + * expect: cpus=3D32,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,ma= xcpus=3D32 */ + .config =3D SMP_CONFIG_WITH_DIES(F, 0, T, 2, T, 2, T, 4, T, 2, T, = 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(32, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(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 SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, T, 4, T, 2, T,= 32), + .expect_prefer_sockets =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 2, = 32), + .expect_prefer_cores =3D CPU_TOPOLOGY_WITH_DIES(16, 2, 2, 4, 2, = 32), + }, +}; + +/* + * generic invalid configurations + * specified smp CPUs can't be less than supported min CPUs. + * specified max CPUs can't be more than supported max CPUs. + */ + +static SMPTestData data_generic_invalid[] =3D { + { + /* config: -smp MIN_CPUS + * reset the machine supported min CPUs to "MIN_CPUS + 1" */ + .config =3D SMP_CONFIG_GENERIC(T, MIN_CPUS, F, 0, F, 0, F, 0, F, 0= ), + .expect_error =3D "Invalid SMP CPUs 1. The min CPUs supported " + "by machine '(null)' is 2", + }, { + /* config: -smp MAX_CPUS + * reset the machine supported max CPUs to "MAX_CPUS - 1" */ + .config =3D SMP_CONFIG_GENERIC(T, MAX_CPUS, F, 0, F, 0, F, 0, F, 0= ), + .expect_error =3D "Invalid SMP CPUs 512. The max CPUs supported " + "by machine '(null)' is 511", + }, +}; + +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, SMPConfiguration *config, + CpuTopology *expect_topo, const char *expect_e= rr, + bool valid) +{ + g_autofree char *config_info =3D NULL; + g_autofree char *expect_topo_info =3D NULL; + g_autofree char *result_topo_info =3D NULL; + const char *result_err; + Error *err =3D NULL; + + /* call the generic parser smp_parse() in hw/core/machine-smp.c */ + smp_parse(ms, config, &err); + + if (valid) { + if ((err =3D=3D NULL) && + (ms->smp.cpus =3D=3D expect_topo->cpus) && + (ms->smp.sockets =3D=3D expect_topo->sockets) && + (ms->smp.dies =3D=3D expect_topo->dies) && + (ms->smp.cores =3D=3D expect_topo->cores) && + (ms->smp.threads =3D=3D expect_topo->threads) && + (ms->smp.max_cpus =3D=3D expect_topo->max_cpus)) { + return; + } + + config_info =3D get_config_info(config); + expect_topo_info =3D get_topo_info(expect_topo); + + if (err !=3D NULL) { + g_printerr("Check smp_parse failed:\n" + "config: %s\n" + "expect_topo: %s\n" + "should_be_valid: yes\n\n" + "result_is_valid: no\n" + "result_error: %s\n", + config_info, expect_topo_info, + error_get_pretty(err)); + error_free(err); + } else { + result_topo_info =3D get_topo_info(&ms->smp); + g_printerr("Check smp_parse failed:\n" + "config: %s\n" + "expect_topo: %s\n" + "should_be_valid: yes\n\n" + "result_is_valid: yes\n" + "result_topo: %s\n", + config_info, expect_topo_info, + result_topo_info); + } + } else { + if (err !=3D NULL) { + result_err =3D error_get_pretty(err); + + if (expect_err =3D=3D NULL || (expect_err !=3D NULL && + g_str_equal(expect_err, result_err))) { + error_free(err); + return; + } + + config_info =3D get_config_info(config); + g_printerr("Check smp_parse failed:\n" + "config: %s\n" + "expect_error: %s\n" + "should_be_valid: no\n\n" + "result_is_valid: no\n" + "result_error: %s\n", + config_info, expect_err, result_err); + error_free(err); + } else { + config_info =3D get_config_info(config); + result_topo_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_topo: %s\n", + config_info, result_topo_info); + } + } + + abort(); +} + +static void smp_test_data_init(SMPTestData *targ, SMPTestData *src) +{ + targ->config =3D src->config; + targ->expect_prefer_sockets =3D src->expect_prefer_sockets; + targ->expect_prefer_cores =3D src->expect_prefer_cores; + targ->expect_error =3D src->expect_error; +} + +static void smp_machine_class_reinit(MachineClass *mc) +{ + mc->min_cpus =3D MIN_CPUS; + mc->max_cpus =3D MAX_CPUS; + + mc->smp_props.prefer_sockets =3D true; + mc->smp_props.dies_supported =3D false; +} + +static void smp_generic_test(void) +{ + Object *obj =3D object_new(TYPE_MACHINE); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + SMPTestData data; + int i; + + /* make sure that we have created the object */ + g_assert_nonnull(ms); + g_assert_nonnull(mc); + + /* reinitialize related machine properties before each subtest */ + smp_machine_class_reinit(mc); + + for (i =3D 0; i < ARRAY_SIZE(data_generic); i++) { + smp_test_data_init(&data, &data_generic[i]); + + /* parsed values of unsupported parameters should be 1 */ + data.expect_prefer_sockets.dies =3D 1; + data.expect_prefer_cores.dies =3D 1; + + mc->smp_props.prefer_sockets =3D true; + check_smp_parse(ms, &data.config, + &data.expect_prefer_sockets, NULL, true); + + mc->smp_props.prefer_sockets =3D false; + check_smp_parse(ms, &data.config, + &data.expect_prefer_cores, NULL, true); + + /* + * it's now allowed that unsupported dies can be set equal to 1 + * in the SMP configuration. + */ + data.config.has_dies =3D true; + data.config.dies =3D 1; + + mc->smp_props.prefer_sockets =3D true; + check_smp_parse(ms, &data.config, + &data.expect_prefer_sockets, NULL, true); + + mc->smp_props.prefer_sockets =3D false; + check_smp_parse(ms, &data.config, + &data.expect_prefer_cores, NULL, true); + } + + object_unref(obj); +} + +static void smp_with_dies_test(void) +{ + Object *obj =3D object_new(TYPE_MACHINE); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + SMPTestData data; + int i; + + /* make sure that we have created the object */ + g_assert_nonnull(ms); + g_assert_nonnull(mc); + + /* reinitialize related machine properties before each subtest */ + smp_machine_class_reinit(mc); + + mc->smp_props.dies_supported =3D true; + + for (i =3D 0; i < ARRAY_SIZE(data_generic); i++) { + smp_test_data_init(&data, &data_generic[i]); + + /* omitted arch-specific dies should directly default to 1 */ + data.expect_prefer_sockets.dies =3D 1; + data.expect_prefer_cores.dies =3D 1; + + mc->smp_props.prefer_sockets =3D true; + check_smp_parse(ms, &data.config, + &data.expect_prefer_sockets, NULL, true); + + mc->smp_props.prefer_sockets =3D false; + check_smp_parse(ms, &data.config, + &data.expect_prefer_cores, NULL, true); + } + + /* when dies is provided in the configuration */ + for (i =3D 0; i < ARRAY_SIZE(data_with_dies); i++) { + smp_test_data_init(&data, &data_with_dies[i]); + + mc->smp_props.prefer_sockets =3D true; + check_smp_parse(ms, &data.config, + &data.expect_prefer_sockets, NULL, true); + + mc->smp_props.prefer_sockets =3D false; + check_smp_parse(ms, &data.config, + &data.expect_prefer_cores, NULL, true); + } + + object_unref(obj); +} + +static void acceptance_generic_test(void) +{ + Object *obj =3D object_new(TYPE_MACHINE); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + SMPTestData *datap; + int i; + + /* make sure that we have created the object */ + g_assert_nonnull(ms); + g_assert_nonnull(mc); + + /* reinitialize related machine properties before each subtest */ + smp_machine_class_reinit(mc); + + /* reset the machine supported min CPUs and max CPUs */ + mc->min_cpus =3D MIN_CPUS + 1; + mc->max_cpus =3D MAX_CPUS - 1; + + for (i =3D 0; i < ARRAY_SIZE(data_generic_invalid); i++) { + datap =3D &data_generic_invalid[i]; + check_smp_parse(ms, &datap->config, NULL, datap->expect_error, fal= se); + } + + /* config: -smp 8,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D8 */ + datap =3D &(SMPTestData){ + .config =3D SMP_CONFIG_GENERIC(T, 8, T, 2, T, 4, T, 2, T, 8), + .expect_error =3D "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "sockets (2) * cores (4) * threads (2) " + "!=3D maxcpus (8)", + }; + check_smp_parse(ms, &datap->config, NULL, datap->expect_error, false); + + /* config: -smp 18,sockets=3D2,cores=3D4,threads=3D2,maxcpus=3D16 */ + datap =3D &(SMPTestData){ + .config =3D SMP_CONFIG_GENERIC(T, 18, T, 2, T, 4, T, 2, T, 16), + .expect_error =3D "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " + "sockets (2) * cores (4) * threads (2) " + "=3D=3D maxcpus (16) < smp_cpus (18)", + }; + check_smp_parse(ms, &datap->config, NULL, datap->expect_error, false); + + /* config: -smp 8,dies=3D2 */ + datap =3D &(SMPTestData){ + .config =3D SMP_CONFIG_WITH_DIES(T, 8, F, 0, T, 2, F, 0, F, 0, F, = 0), + .expect_error =3D "dies not supported by this machine's CPU topolo= gy", + }; + check_smp_parse(ms, &datap->config, NULL, datap->expect_error, false); + + object_unref(obj); +} + +static void acceptance_with_dies_test(void) +{ + Object *obj =3D object_new(TYPE_MACHINE); + MachineState *ms =3D MACHINE(obj); + MachineClass *mc =3D MACHINE_GET_CLASS(obj); + SMPTestData *datap; + + /* make sure that we have created the object */ + g_assert_nonnull(ms); + g_assert_nonnull(mc); + + /* reinitialize related machine properties before each subtest */ + smp_machine_class_reinit(mc); + + mc->smp_props.dies_supported =3D true; + + /* config: -smp 16,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxcpus= =3D16 */ + datap =3D &(SMPTestData){ + .config =3D SMP_CONFIG_WITH_DIES(T, 16, T, 2, T, 2, T, 4, T, 2, T,= 16), + .expect_error =3D "Invalid CPU topology: " + "product of the hierarchy must match maxcpus: " + "sockets (2) * dies (2) * cores (4) * threads (2) " + "!=3D maxcpus (16)", + }; + check_smp_parse(ms, &datap->config, NULL, datap->expect_error, false); + + /* config: -smp 34,sockets=3D2,dies=3D2,cores=3D4,threads=3D2,maxcpus= =3D32 */ + datap =3D &(SMPTestData){ + .config =3D SMP_CONFIG_WITH_DIES(T, 34, T, 2, T, 2, T, 4, T, 2, T,= 32), + .expect_error =3D "Invalid CPU topology: " + "maxcpus must be equal to or greater than smp: " + "sockets (2) * dies (2) * cores (4) * threads (2) " + "=3D=3D maxcpus (32) < smp_cpus (34)", + }; + check_smp_parse(ms, &datap->config, NULL, datap->expect_error, false); + + 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/smp-generic", smp_generic_test); + g_test_add_func("/test-smp-parse/smp-with-dies", smp_with_dies_test); + g_test_add_func("/test-smp-parse/acceptance-generic", + acceptance_generic_test); + g_test_add_func("/test-smp-parse/acceptance-with-dies", + acceptance_with_dies_test); + + g_test_run(); + + return 0; +} --=20 2.19.1