From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63F40C433F5 for ; Sun, 3 Oct 2021 07:49:04 +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 D54EB61B29 for ; Sun, 3 Oct 2021 07:49:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D54EB61B29 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWwF5-0003Q7-2s for qemu-devel@archiver.kernel.org; Sun, 03 Oct 2021 03:49:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWw9D-0003AA-Co for qemu-devel@nongnu.org; Sun, 03 Oct 2021 03:42:59 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:37828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mWw9B-0000lo-Nj for qemu-devel@nongnu.org; Sun, 03 Oct 2021 03:42:59 -0400 Received: by mail-ed1-x530.google.com with SMTP id ba1so51822799edb.4 for ; Sun, 03 Oct 2021 00:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SoQkCnkgqJjlJOEvR3S53h35evZiqhHpq/ld+Wj0kZs=; b=n7c0ym+gAWv3g6KOSCybw5kvoRMAtsuTs3x67qIHP3Rx77Jx9vzh8du7ndv0dJV/Gn vtUEnYpyV46TXd6hZpuRjNUjw6YXOwh7zb2g8T048uqW1+V0QmmMUnrBtyLGla+0np8d Cv5fHW66s6neGelxSq9lCwZJ8MTbrKB5VPXigfuDN0cAKiHMbR0Vd5cPMc2sX8e4bu9p Cs2xkM/eMOkh4xnLUU1J/jzfr51jct0SsiAE/A7nfVfbaVExUtd7olS2EtTVVpbILJxT BEfj1OBpN4fVpP0gCDgedfrusJFRzmlffaAxdj5SU/Wo18LlJupLAQ4ibe+ZVaXFvY+s 6btQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SoQkCnkgqJjlJOEvR3S53h35evZiqhHpq/ld+Wj0kZs=; b=MsKmRO1KN+3b/dQk5UyisVicy1KPzBKK5r2LW4m3h52cZYU/kdD1kyle/U9mnteo+f XB2YFlf3xcfcivHBeiO6R5vt+iB+VdYbmgY0YFpVsKLN4La1yTN1Az3wH0Sc8GapncAW ux0YXaMKtKPl5h5WK9W6zGhby26IgFCGccyGpVEYLj0gHq0XL/kZqe8xERaI9AuQKNc/ Jidpw3KkCzQs90gCEoWs6ZRs2dwmQx/Kg3Xu3gemR1pRDqN6v/QHy9mXTC8i8sFalvPJ Wd1WsADwaEmgwsiaHKNbbTLKrtCJGO95FY8/zgBrajIHkm5nQ0bH+yQXmW4yO7FRiuvU S8Pw== X-Gm-Message-State: AOAM5325w6McRJ8rouG20bKbMNu4rutbEF2uywolV6WVvVFIRwi83xgt RL4QcbCQa/jQQcFpiXkwOkbUU2a45vw= X-Google-Smtp-Source: ABdhPJwnIQYNxcLxnhJG4P9O4E1/ZFl3rruodI9dYaQnVxLjbhP8jJT+6sfPczehod0EKFX22sw26A== X-Received: by 2002:a17:906:39cd:: with SMTP id i13mr8664758eje.227.1633246976275; Sun, 03 Oct 2021 00:42:56 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id n6sm5560856eds.10.2021.10.03.00.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 00:42:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/30] machine: Set the value of cpus to match maxcpus if it's omitted Date: Sun, 3 Oct 2021 09:42:25 +0200 Message-Id: <20211003074250.60869-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211003074250.60869-1-pbonzini@redhat.com> References: <20211003074250.60869-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: Yanan Wang , Andrew Jones , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Yanan Wang 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 Reviewed-by: Daniel P. Berrangé Message-Id: <20210929025816.21076-6-wangyanan55@huawei.com> Signed-off-by: Paolo Bonzini --- 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, 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 e37e84cc7b..f24a1d72ad 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -727,25 +727,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 4a092a092a..2eac830fdb 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -220,9 +220,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. -- 2.31.1