From patchwork Mon Aug 23 12:27:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanan Wang X-Patchwork-Id: 12452703 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FB42C4338F for ; Mon, 23 Aug 2021 12:34:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29F8160FD9 for ; Mon, 23 Aug 2021 12:34:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 29F8160FD9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:41688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mI99q-0004vp-6w for qemu-devel@archiver.kernel.org; Mon, 23 Aug 2021 08:34:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mI93s-0004qf-75 for qemu-devel@nongnu.org; Mon, 23 Aug 2021 08:28:21 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mI93p-0004vK-HQ for qemu-devel@nongnu.org; Mon, 23 Aug 2021 08:28:19 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GtWd366tgz8tQh; Mon, 23 Aug 2021 20:24:07 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 23 Aug 2021 20:28:15 +0800 Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 23 Aug 2021 20:28:14 +0800 From: Yanan Wang To: Subject: [PATCH v7 04/15] machine: Set the value of cpus to match maxcpus if it's omitted Date: Mon, 23 Aug 2021 20:27:53 +0800 Message-ID: <20210823122804.7692-5-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210823122804.7692-1-wangyanan55@huawei.com> References: <20210823122804.7692-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.188; envelope-from=wangyanan55@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrew Jones , Cornelia Huck , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Eduardo Habkost , Pierre Morel , "Michael S . Tsirkin" , Pankaj Gupta , Richard Henderson , Greg Kurz , Halil Pasic , wanghaibin.wang@huawei.com, Thomas Huth , Paolo Bonzini , Yanan Wang , David Gibson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Currently we directly calculate the omitted cpus based on the given incomplete collection of parameters. This makes some cmdlines like: -smp maxcpus=16 -smp sockets=2,maxcpus=16 -smp sockets=2,dies=2,maxcpus=16 -smp sockets=2,cores=4,maxcpus=16 not work. We should probably set the value of cpus to match maxcpus if it's omitted, which will make above configs start to work. So the calculation logic of cpus/maxcpus after this patch will be: When both maxcpus and cpus are omitted, maxcpus will be calculated from the given parameters and cpus will be set equal to maxcpus. When only one of maxcpus and cpus is given then the omitted one will be set to its counterpart's value. Both maxcpus and cpus may be specified, but maxcpus must be equal to or greater than cpus. Note: change in this patch won't affect any existing working cmdlines but allows more incomplete configs to be valid. Signed-off-by: Yanan Wang Reviewed-by: Andrew Jones --- hw/core/machine.c | 29 ++++++++++++++++------------- hw/i386/pc.c | 29 ++++++++++++++++------------- qemu-options.hx | 11 ++++++++--- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index dc12b5ec4e..85908abc77 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -757,25 +757,28 @@ static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) } /* compute missing values, prefer sockets over cores over threads */ - maxcpus = maxcpus > 0 ? maxcpus : cpus; - - if (cpus == 0) { + if (cpus == 0 && maxcpus == 0) { sockets = sockets > 0 ? sockets : 1; cores = cores > 0 ? cores : 1; threads = threads > 0 ? threads : 1; - cpus = sockets * cores * threads; + } else { maxcpus = maxcpus > 0 ? maxcpus : cpus; - } else if (sockets == 0) { - cores = cores > 0 ? cores : 1; - threads = threads > 0 ? threads : 1; - sockets = maxcpus / (cores * threads); - } else if (cores == 0) { - threads = threads > 0 ? threads : 1; - cores = maxcpus / (sockets * threads); - } else if (threads == 0) { - threads = maxcpus / (sockets * cores); + + if (sockets == 0) { + cores = cores > 0 ? cores : 1; + threads = threads > 0 ? threads : 1; + sockets = maxcpus / (cores * threads); + } else if (cores == 0) { + threads = threads > 0 ? threads : 1; + cores = maxcpus / (sockets * threads); + } else if (threads == 0) { + threads = maxcpus / (sockets * cores); + } } + maxcpus = maxcpus > 0 ? maxcpus : sockets * cores * threads; + cpus = 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 a9ff9ef52c..9ad7ae5254 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -725,25 +725,28 @@ static void pc_smp_parse(MachineState *ms, SMPConfiguration *config, Error **err dies = dies > 0 ? dies : 1; /* compute missing values, prefer sockets over cores over threads */ - maxcpus = maxcpus > 0 ? maxcpus : cpus; - - if (cpus == 0) { + if (cpus == 0 && maxcpus == 0) { sockets = sockets > 0 ? sockets : 1; cores = cores > 0 ? cores : 1; threads = threads > 0 ? threads : 1; - cpus = sockets * dies * cores * threads; + } else { maxcpus = maxcpus > 0 ? maxcpus : cpus; - } else if (sockets == 0) { - cores = cores > 0 ? cores : 1; - threads = threads > 0 ? threads : 1; - sockets = maxcpus / (dies * cores * threads); - } else if (cores == 0) { - threads = threads > 0 ? threads : 1; - cores = maxcpus / (sockets * dies * threads); - } else if (threads == 0) { - threads = maxcpus / (sockets * dies * cores); + + if (sockets == 0) { + cores = cores > 0 ? cores : 1; + threads = threads > 0 ? threads : 1; + sockets = maxcpus / (dies * cores * threads); + } else if (cores == 0) { + threads = threads > 0 ? threads : 1; + cores = maxcpus / (sockets * dies * threads); + } else if (threads == 0) { + threads = maxcpus / (sockets * dies * cores); + } } + maxcpus = maxcpus > 0 ? maxcpus : sockets * dies * cores * threads; + cpus = cpus > 0 ? cpus : maxcpus; + if (sockets * dies * cores * threads < cpus) { error_setg(errp, "cpu topology: " "sockets (%u) * dies (%u) * cores (%u) * threads (%u) < " diff --git a/qemu-options.hx b/qemu-options.hx index aee622f577..06f819177e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -214,9 +214,14 @@ SRST Simulate a SMP system with '\ ``n``\ ' CPUs initially present on the machine type board. On boards supporting CPU hotplug, the optional '\ ``maxcpus``\ ' parameter can be set to enable further CPUs to be - added at runtime. If omitted the maximum number of CPUs will be - set to match the initial CPU count. Both parameters are subject to - an upper limit that is determined by the specific machine type chosen. + added at runtime. When both parameters are omitted, the maximum number + of CPUs will be calculated from the provided topology members and the + initial CPU count will match the maximum number. When only one of them + is given then the omitted one will be set to its counterpart's value. + Both parameters may be specified, but the maximum number of CPUs must + be equal to or greater than the initial CPU count. Both parameters are + subject to an upper limit that is determined by the specific machine + type chosen. To control reporting of CPU topology information, the number of sockets, dies per socket, cores per die, and threads per core can be specified.