From nobody Sat May 11 16:49:20 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 1632884508181802.7133860267442; Tue, 28 Sep 2021 20:01:48 -0700 (PDT) Received: from localhost ([::1]:48392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPqs-00080q-In for importer@patchew.org; Tue, 28 Sep 2021 23:01:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPnu-0004yM-MQ; Tue, 28 Sep 2021 22:58:42 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPns-0005m7-9s; Tue, 28 Sep 2021 22:58:42 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HK1JK4LjKz8tS5; Wed, 29 Sep 2021 10:57:37 +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.2308.8; Wed, 29 Sep 2021 10:58:29 +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; Wed, 29 Sep 2021 10:58:28 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 01/16] qapi/machine: Fix an incorrect comment of SMPConfiguration Date: Wed, 29 Sep 2021 10:58:01 +0800 Message-ID: <20210929025816.21076-2-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884510262100001 The explanation of @cores should be "number of cores per die" but not "number of cores per thread". Let's fix it. Fixes: 1e63fe685804 ("machine: pass QAPI struct to mc->smp_parse") Signed-off-by: Yanan Wang Reviewed-by: Daniel P. Berrang=C3=A9 --- qapi/machine.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qapi/machine.json b/qapi/machine.json index 32d47f4e35..227e75d8af 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -1331,7 +1331,7 @@ # # @dies: number of dies per socket in the CPU topology # -# @cores: number of cores per thread in the CPU topology +# @cores: number of cores per die in the CPU topology # # @threads: number of threads per core in the CPU topology # --=20 2.19.1 From nobody Sat May 11 16:49:20 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 1632884538068554.388916433642; Tue, 28 Sep 2021 20:02:18 -0700 (PDT) Received: from localhost ([::1]:50612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPrN-00019j-3s for importer@patchew.org; Tue, 28 Sep 2021 23:02:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPnw-0004z2-8D; Tue, 28 Sep 2021 22:58:44 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPns-0005mU-VS; Tue, 28 Sep 2021 22:58:44 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HK1DP459SzRbq6; Wed, 29 Sep 2021 10:54:13 +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.2308.8; Wed, 29 Sep 2021 10:58:30 +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; Wed, 29 Sep 2021 10:58:29 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 02/16] machine: Deprecate "parameter=0" SMP configurations Date: Wed, 29 Sep 2021 10:58:02 +0800 Message-ID: <20210929025816.21076-3-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884538562100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/about/deprecated.rst | 15 +++++++++++++++ hw/core/machine.c | 14 ++++++++++++++ qemu-options.hx | 12 +++++++----- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 3c2be84d80..97415dbecd 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -160,6 +160,21 @@ Use ``-display sdl`` instead. =20 Use ``-display curses`` 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 Plugin argument passing through ``arg=3D`` (since 6.1) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' diff --git a/hw/core/machine.c b/hw/core/machine.c index 067f42b528..4e409261c9 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("Deprecated CPU topology (considered invalid): " + "CPU topology parameters must be greater than zero"); + } + mc->smp_parse(ms, config, errp); if (*errp) { goto out_free; diff --git a/qemu-options.hx b/qemu-options.hx index 8f603cc7e6..91d859aa29 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 Sat May 11 16:49:20 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 1632884955648695.1993860148077; Tue, 28 Sep 2021 20:09:15 -0700 (PDT) Received: from localhost ([::1]:42928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPy6-00074L-JR for importer@patchew.org; Tue, 28 Sep 2021 23:09:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo5-0005SX-50; Tue, 28 Sep 2021 22:58:53 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3145) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo1-00061T-G7; Tue, 28 Sep 2021 22:58:52 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HK1DH6Wnxz8ygY; Wed, 29 Sep 2021 10:54: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.2308.8; Wed, 29 Sep 2021 10:58:31 +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; Wed, 29 Sep 2021 10:58:31 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 03/16] machine: Minor refactor/fix for the smp parsers Date: Wed, 29 Sep 2021 10:58:03 +0800 Message-ID: <20210929025816.21076-4-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884999629100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 4e409261c9..8e719e2932 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 557d49c9f8..93dc322a97 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.max_cpus =3D maxcpus; } =20 static --=20 2.19.1 From nobody Sat May 11 16:49:20 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 163288474590153.61654799019584; Tue, 28 Sep 2021 20:05:45 -0700 (PDT) Received: from localhost ([::1]:58582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPui-0006gc-Pr for importer@patchew.org; Tue, 28 Sep 2021 23:05:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPnw-0004zt-Si; Tue, 28 Sep 2021 22:58:44 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:3477) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPns-0005qC-LD; Tue, 28 Sep 2021 22:58:44 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HK1Ht2sX2zWZCx; Wed, 29 Sep 2021 10:57:14 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 29 Sep 2021 10:58:33 +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; Wed, 29 Sep 2021 10:58:32 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 04/16] machine: Uniformly use maxcpus to calculate the omitted parameters Date: Wed, 29 Sep 2021 10:58:04 +0800 Message-ID: <20210929025816.21076-5-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884746454100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 8e719e2932..596e758133 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 93dc322a97..87c06d3991 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 Sat May 11 16:49:20 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 1632884990979454.7987627740504; Tue, 28 Sep 2021 20:09:50 -0700 (PDT) Received: from localhost ([::1]:45730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPye-0000Wl-5w for importer@patchew.org; Tue, 28 Sep 2021 23:09:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo8-0005cX-1e; Tue, 28 Sep 2021 22:58:56 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3177) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo4-00063y-HA; Tue, 28 Sep 2021 22:58:55 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HK1Jg6Wk5z8tTv; Wed, 29 Sep 2021 10:57: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.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:33 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 05/16] machine: Set the value of cpus to match maxcpus if it's omitted Date: Wed, 29 Sep 2021 10:58:05 +0800 Message-ID: <20210929025816.21076-6-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632885009686100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 596e758133..d8f458db60 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 87c06d3991..d9382b7d57 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 91d859aa29..9d71a661bb 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 Sat May 11 16:49:20 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 1632884625277372.91493874714956; Tue, 28 Sep 2021 20:03:45 -0700 (PDT) Received: from localhost ([::1]:54476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPsm-0003qO-2k for importer@patchew.org; Tue, 28 Sep 2021 23:03:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo5-0005SL-2w; Tue, 28 Sep 2021 22:58:53 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo2-00061q-6H; Tue, 28 Sep 2021 22:58:52 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HK1DJ3y42z8ywc; Wed, 29 Sep 2021 10:54:08 +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.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:34 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 06/16] machine: Improve the error reporting of smp parsing Date: Wed, 29 Sep 2021 10:58:06 +0800 Message-ID: <20210929025816.21076-7-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884627389100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 d8f458db60..e38ab760e6 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 d9382b7d57..a37eef8057 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 Sat May 11 16:49:20 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 1632884518853945.0746127528836; Tue, 28 Sep 2021 20:01:58 -0700 (PDT) Received: from localhost ([::1]:49258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPr3-0000De-OV for importer@patchew.org; Tue, 28 Sep 2021 23:01:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPnw-0004z0-45; Tue, 28 Sep 2021 22:58:44 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPns-0005sG-UV; Tue, 28 Sep 2021 22:58:43 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HK1JS71zNz8tWW; Wed, 29 Sep 2021 10:57:44 +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.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:35 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 07/16] qtest/numa-test: Use detailed -smp CLIs in pc_dynamic_cpu_cfg Date: Wed, 29 Sep 2021 10:58:07 +0800 Message-ID: <20210929025816.21076-8-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884521165100001 Since commit 80d7835749 (qemu-options: rewrite help for -smp options), the preference of sockets/cores in -smp parsing is considered liable to change, and actually we are going to change it in a coming commit. So it'll be more stable to use detailed -smp CLIs in testing if we have strong dependency on the parsing results. pc_dynamic_cpu_cfg currently assumes/needs that there will be 2 CPU sockets with "-smp 2". To avoid breaking the test because of parsing logic change, now explicitly use "-smp 2,sockets=3D2". Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/qtest/numa-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qtest/numa-test.c b/tests/qtest/numa-test.c index c677cd63c4..fd7a2e80a0 100644 --- a/tests/qtest/numa-test.c +++ b/tests/qtest/numa-test.c @@ -265,7 +265,8 @@ static void pc_dynamic_cpu_cfg(const void *data) QTestState *qs; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-nodefaults --preconfig -machine smp.cpus=3D2"= ); + cli =3D make_cli(data, "-nodefaults --preconfig " + "-machine smp.cpus=3D2,smp.sockets=3D2"); qs =3D qtest_init(cli); =20 /* create 2 numa nodes */ --=20 2.19.1 From nobody Sat May 11 16:49:20 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 1632884844046752.9631981924803; Tue, 28 Sep 2021 20:07:24 -0700 (PDT) Received: from localhost ([::1]:35522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPwJ-0001yS-0Q for importer@patchew.org; Tue, 28 Sep 2021 23:07:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo7-0005b3-CZ; Tue, 28 Sep 2021 22:58:55 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3178) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo4-000644-RP; Tue, 28 Sep 2021 22:58:55 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4HK1Jh2px1z8tX9; Wed, 29 Sep 2021 10:57:56 +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.2308.8; Wed, 29 Sep 2021 10:58:37 +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; Wed, 29 Sep 2021 10:58:37 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 08/16] qtest/numa-test: Use detailed -smp CLIs in test_def_cpu_split Date: Wed, 29 Sep 2021 10:58:08 +0800 Message-ID: <20210929025816.21076-9-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884846653100001 Since commit 80d7835749 (qemu-options: rewrite help for -smp options), the preference of sockets/cores in -smp parsing is considered liable to change, and actually we are going to change it in a coming commit. So it'll be more stable to use detailed -smp CLIs in the testcases that have strong dependency on the parsing results. Currently, test_def_cpu_split use "-smp 8" and will get 8 CPU sockets based on current parsing rule. But if we change to prefer cores over sockets we will get one CPU socket with 8 cores, and this testcase will not get expected numa set by default on x86_64 (Ok on aarch64). So now explicitly use "-smp 8,sockets=3D8" to avoid affect from parsing logic change. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/qtest/numa-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qtest/numa-test.c b/tests/qtest/numa-test.c index fd7a2e80a0..90bf68a5b3 100644 --- a/tests/qtest/numa-test.c +++ b/tests/qtest/numa-test.c @@ -42,7 +42,8 @@ static void test_def_cpu_split(const void *data) g_autofree char *s =3D NULL; g_autofree char *cli =3D NULL; =20 - cli =3D make_cli(data, "-machine smp.cpus=3D8 -numa node,memdev=3Dram = -numa node"); + cli =3D make_cli(data, "-machine smp.cpus=3D8,smp.sockets=3D8 " + "-numa node,memdev=3Dram -numa node"); qts =3D qtest_init(cli); =20 s =3D qtest_hmp(qts, "info numa"); --=20 2.19.1 From nobody Sat May 11 16:49:20 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 1632884941842967.4313543874694; Tue, 28 Sep 2021 20:09:01 -0700 (PDT) Received: from localhost ([::1]:42452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPxr-0006lC-Ax for importer@patchew.org; Tue, 28 Sep 2021 23:09:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo5-0005U5-L8; Tue, 28 Sep 2021 22:58:53 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2933) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo2-00062U-IC; Tue, 28 Sep 2021 22:58:53 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HK1Dk09T9zbmxc; Wed, 29 Sep 2021 10:54:30 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:38 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 09/16] machine: Prefer cores over sockets in smp parsing since 6.2 Date: Wed, 29 Sep 2021 10:58:09 +0800 Message-ID: <20210929025816.21076-10-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884996959100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 1d59f0e59f..8c13deb5db 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2815,6 +2815,7 @@ static void virt_machine_6_1_options(MachineClass *mc) =20 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; =20 /* qemu ITS was introduced with 6.2 */ vmc->no_tcg_its =3D true; diff --git a/hw/core/machine.c b/hw/core/machine.c index e38ab760e6..f2a34d98c0 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 a37eef8057..447114e57a 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 46cd542d17..2d97c0ab3e 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 61aeccb163..5401c985cf 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -814,6 +814,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 9d71a661bb..5c1b0311c0 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 Sat May 11 16:49:20 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 1632884793263449.02682387968457; Tue, 28 Sep 2021 20:06:33 -0700 (PDT) Received: from localhost ([::1]:60794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPvU-0008H6-98 for importer@patchew.org; Tue, 28 Sep 2021 23:06:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPny-00053J-2n; Tue, 28 Sep 2021 22:58:46 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3144) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPnw-0005w2-0B; Tue, 28 Sep 2021 22:58:45 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HK1DB3MB3z8ywB; Wed, 29 Sep 2021 10:54:02 +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.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:39 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 10/16] machine: Use ms instead of global current_machine in sanity-check Date: Wed, 29 Sep 2021 10:58:10 +0800 Message-ID: <20210929025816.21076-11-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632884794557100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 f2a34d98c0..12d7416053 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 Sat May 11 16:49:20 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 1632885296047127.5067038203855; Tue, 28 Sep 2021 20:14:56 -0700 (PDT) Received: from localhost ([::1]:33034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVQ3b-00039D-2p for importer@patchew.org; Tue, 28 Sep 2021 23:14:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPoJ-0006M8-Q7; Tue, 28 Sep 2021 22:59:07 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPoH-0006Gu-Li; Tue, 28 Sep 2021 22:59:07 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HK1Db6YFSz900k; Wed, 29 Sep 2021 10:54: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.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:40 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 11/16] machine: Tweak the order of topology members in struct CpuTopology Date: Wed, 29 Sep 2021 10:58:11 +0800 Message-ID: <20210929025816.21076-12-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632885297390100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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 12d7416053..83cbdcce47 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 Sat May 11 16:49:20 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 163288528230138.66545604561031; Tue, 28 Sep 2021 20:14:42 -0700 (PDT) Received: from localhost ([::1]:60396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVQ3N-0002YG-B0 for importer@patchew.org; Tue, 28 Sep 2021 23:14:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo8-0005cx-6C; Tue, 28 Sep 2021 22:58:56 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo4-00063R-EY; Tue, 28 Sep 2021 22:58:55 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HK1Dk4H1tzbmxp; Wed, 29 Sep 2021 10:54:30 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 29 Sep 2021 10:58:46 +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; Wed, 29 Sep 2021 10:58:46 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 12/16] machine: Make smp_parse generic enough for all arches Date: Wed, 29 Sep 2021 10:58:12 +0800 Message-ID: <20210929025816.21076-13-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632885284430100001 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 Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Yanan Wang Reviewed-by: Daniel P. Berrang=C3=A9 --- hw/core/machine.c | 91 +++++++++++++++++++++++++++++++++++---------- hw/i386/pc.c | 84 +---------------------------------------- include/hw/boards.h | 9 +++++ 3 files changed, 81 insertions(+), 103 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 83cbdcce47..12872d7715 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -746,20 +746,69 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 +/* + * Report information of a machine's supported CPU topology hierarchy. + * Topology members will be ordered from the largest to the smallest + * in the string. + */ +static char *cpu_hierarchy_to_string(MachineState *ms) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + GString *s =3D g_string_new(NULL); + + g_string_append_printf(s, "sockets (%u)", ms->smp.sockets); + + if (mc->smp_props.dies_supported) { + g_string_append_printf(s, " * dies (%u)", ms->smp.dies); + } + + g_string_append_printf(s, " * cores (%u)", ms->smp.cores); + g_string_append_printf(s, " * threads (%u)", ms->smp.threads); + + return g_string_free(s, false); +} + +/* + * smp_parse - Generic function used to parse the given SMP configuration + * + * Any missing parameter in "cpus/maxcpus/sockets/cores/threads" will be + * automatically computed based on the provided ones. + * + * In the 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. + * + * In the calculation of cpus/maxcpus: When both maxcpus and cpus are omit= ted, + * 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 cpu= s. + * + * For compatibility, apart from the parameters that will be computed, new= ly + * introduced topology members which are likely to be target specific shou= ld + * be directly set as 1 if they are omitted (e.g. dies for PC since 4.1). + */ 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 + 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 +822,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_hierarchy_to_string(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_hierarchy_to_string(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 447114e57a..468fe8e0fb 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.max_cpus =3D maxcpus; -} - static void pc_machine_done(Notifier *notifier, void *data) { @@ -1742,7 +1660,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; @@ -1753,6 +1670,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 Sat May 11 16:49:20 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 1632885123445207.20061658697273; Tue, 28 Sep 2021 20:12:03 -0700 (PDT) Received: from localhost ([::1]:51306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVQ0n-0004Uc-Qw for importer@patchew.org; Tue, 28 Sep 2021 23:12:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo7-0005aM-9I; Tue, 28 Sep 2021 22:58:55 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo4-00064T-QV; Tue, 28 Sep 2021 22:58:54 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HK1Dm1PHgzbmxq; Wed, 29 Sep 2021 10:54:32 +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.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:48 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 13/16] machine: Remove smp_parse callback from MachineClass Date: Wed, 29 Sep 2021 10:58:13 +0800 Message-ID: <20210929025816.21076-14-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632885125106100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 12872d7715..8b0f1aed83 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -918,7 +918,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; } @@ -947,7 +947,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 Sat May 11 16:49:20 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 1632885455089564.6124470979123; Tue, 28 Sep 2021 20:17:35 -0700 (PDT) Received: from localhost ([::1]:37332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVQ6A-00067c-3A for importer@patchew.org; Tue, 28 Sep 2021 23:17:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPoK-0006Nc-5j; Tue, 28 Sep 2021 22:59:08 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2816) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPoH-0006HB-S4; Tue, 28 Sep 2021 22:59:07 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4HK1F10wNFzRfqC; Wed, 29 Sep 2021 10:54:45 +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.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:49 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 14/16] machine: Move smp_prefer_sockets to struct SMPCompatProps Date: Wed, 29 Sep 2021 10:58:14 +0800 Message-ID: <20210929025816.21076-15-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632885457425100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 8c13deb5db..7170aaacd5 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2815,7 +2815,7 @@ static void virt_machine_6_1_options(MachineClass *mc) =20 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; =20 /* qemu ITS was introduced with 6.2 */ vmc->no_tcg_its =3D true; diff --git a/hw/core/machine.c b/hw/core/machine.c index 8b0f1aed83..54f04a5ac6 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -817,7 +817,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 2d97c0ab3e..9eae40e32c 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 5401c985cf..653587ea62 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -814,7 +814,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 Sat May 11 16:49:20 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 1632884963188464.10548328315303; Tue, 28 Sep 2021 20:09:23 -0700 (PDT) Received: from localhost ([::1]:43656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVPyE-0007YG-6V for importer@patchew.org; Tue, 28 Sep 2021 23:09:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPoA-0005mm-I1; Tue, 28 Sep 2021 22:58:58 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:2872) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo8-00067X-1e; Tue, 28 Sep 2021 22:58:58 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HK1JF1YkBz1DHFx; Wed, 29 Sep 2021 10:57:33 +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.2308.8; Wed, 29 Sep 2021 10:58: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; Wed, 29 Sep 2021 10:58:50 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 15/16] machine: Put all sanity-check in the generic SMP parser Date: Wed, 29 Sep 2021 10:58:15 +0800 Message-ID: <20210929025816.21076-16-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632885002013100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 54f04a5ac6..4dc936732e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -798,6 +798,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("Deprecated CPU topology (considered invalid): " + "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. @@ -873,6 +887,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, @@ -895,7 +925,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(); @@ -904,40 +933,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("Deprecated CPU topology (considered invalid): " - "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 Sat May 11 16:49:20 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 1632885135496937.8785553342271; Tue, 28 Sep 2021 20:12:15 -0700 (PDT) Received: from localhost ([::1]:52538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVQ10-0005Qj-8U for importer@patchew.org; Tue, 28 Sep 2021 23:12:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPoB-0005oc-2B; Tue, 28 Sep 2021 22:58:59 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2936) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVPo8-00068L-O0; Tue, 28 Sep 2021 22:58:58 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HK1Dr1nV7zbmsX; Wed, 29 Sep 2021 10:54:36 +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.2308.8; Wed, 29 Sep 2021 10:58:53 +0800 Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 29 Sep 2021 10:58:52 +0800 From: Yanan Wang To: Eduardo Habkost , Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Andrew Jones , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Markus Armbruster" Subject: [PATCH v12 16/16] machine: Make smp_parse return a boolean Date: Wed, 29 Sep 2021 10:58:16 +0800 Message-ID: <20210929025816.21076-17-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210929025816.21076-1-wangyanan55@huawei.com> References: <20210929025816.21076-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 , Pierre Morel , Pankaj Gupta , Cornelia Huck , qemu-devel@nongnu.org, Yanan Wang , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1632885137147100001 Quoting one of the Rules described in include/qapi/error.h: " Whenever practical, also return a value that indicates success / failure. This can make the error checking more concise, and can avoid useless error object creation and destruction. Note that we still have many functions returning void. We recommend =E2=80=A2 bool-valued functions return true on success / false on failure, =E2=80=A2 pointer-valued functions return non-null / null pointer, and =E2=80=A2 integer-valued functions return non-negative / negative. " So make smp_parse() return true on success and false on failure, so that we can more laconically check whether the parsing has succeeded without touching the errp. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Yanan Wang Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/core/machine.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 4dc936732e..3e3a2707af 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -788,7 +788,7 @@ static char *cpu_hierarchy_to_string(MachineState *ms) * introduced topology members which are likely to be target specific shou= ld * be directly set as 1 if they are omitted (e.g. dies for PC since 4.1). */ -static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **= errp) +static bool smp_parse(MachineState *ms, SMPConfiguration *config, Error **= errp) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); unsigned cpus =3D config->has_cpus ? config->cpus : 0; @@ -818,7 +818,7 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) */ if (!mc->smp_props.dies_supported && dies > 1) { error_setg(errp, "dies not supported by this machine's CPU topolog= y"); - return; + return false; } =20 dies =3D dies > 0 ? dies : 1; @@ -876,7 +876,7 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) "product of the hierarchy must match maxcpus: " "%s !=3D maxcpus (%u)", topo_msg, maxcpus); - return; + return false; } =20 if (maxcpus < cpus) { @@ -885,7 +885,7 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) "maxcpus must be equal to or greater than smp: " "%s =3D=3D maxcpus (%u) < smp_cpus (%u)", topo_msg, maxcpus, cpus); - return; + return false; } =20 if (ms->smp.cpus < mc->min_cpus) { @@ -893,7 +893,7 @@ static void smp_parse(MachineState *ms, SMPConfiguratio= n *config, Error **errp) "supported by machine '%s' is %d", ms->smp.cpus, mc->name, mc->min_cpus); - return; + return false; } =20 if (ms->smp.max_cpus > mc->max_cpus) { @@ -901,8 +901,10 @@ static void smp_parse(MachineState *ms, SMPConfigurati= on *config, Error **errp) "supported by machine '%s' is %d", ms->smp.max_cpus, mc->name, mc->max_cpus); - return; + return false; } + + return true; } =20 static void machine_get_smp(Object *obj, Visitor *v, const char *name, @@ -933,8 +935,7 @@ static void machine_set_smp(Object *obj, Visitor *v, co= nst char *name, return; } =20 - smp_parse(ms, config, errp); - if (*errp) { + if (!smp_parse(ms, config, errp)) { qapi_free_SMPConfiguration(config); } } --=20 2.19.1