From nobody Tue Nov 26 06:31:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=pass(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1709718092; cv=none; d=zohomail.com; s=zohoarc; b=L6bQeP7q2Z9qRc8rQ839Ms2Y4FThKfQVKXsrUAz/lvRdp/Fr8vbzz7hna7hySM8RTI+YdSOwgAOUHrSe1FlaVl1vzKJ85WA4ijsjjjotzLZnBOsmfs5EtTvEGKd8Zdb2TwbOVRW7PEOkvrphon2yQbcnkWz4yZo+vl0GMOcTNY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709718092; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=F3mjyc8ZxfsHF2ZBSVTqjGOmSoGJuxcBXUVlTjlIPDA=; b=DEGN1pvT55rhuWELln7u+M9GJOI+sQ3HKbHwwXo5yZlRclcvqvyD7i4T9L1xRPC0JkOb05WCmBsKszxpXqyTjXwXCLptZF/SrPuD3TwkR4h4JxWlXZewapipou3nDTZXEWWDRI2Nt/i0Xl/i/Wsh2ol8aThjh6C3ReWK5hV4HZ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170971809205581.52753066854098; Wed, 6 Mar 2024 01:41:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhnlU-0007Qj-EM; Wed, 06 Mar 2024 04:40:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhnlT-0007QH-4w for qemu-devel@nongnu.org; Wed, 06 Mar 2024 04:40:43 -0500 Received: from mgamail.intel.com ([198.175.65.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhnlQ-0002EH-Df for qemu-devel@nongnu.org; Wed, 06 Mar 2024 04:40:41 -0500 Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 01:40:39 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by fmviesa002.fm.intel.com with ESMTP; 06 Mar 2024 01:40:36 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709718040; x=1741254040; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EwAYN36P3lzqN1glAqPGtpQAeH7zDs5xPFp9VL7Pp+Y=; b=GdQIK8mcrdr/Yx2yXM8xc2or3r1S/g+ksppSHr3GI/PfXlBF0rtzm7u1 H26wSMnuWjuzpiP0PhiBXW5Ut6yIPoe8BCs2pld9XzEXTp6MxvPXkvCBQ upL1FKkn1o5pypAtQXm0wR7gSohCAaPylErm/TDkFqeXc50dur6fNCdbO vGF2k4blKoR5uQeBGokWM0f/TQhPrV9BiWsReB1d3eQXa+6rN+fmbbYlr Yt9hDMjDnGurv6zTY82hranKq5XEZp6hJr9ciruHnuyXbAvBId3xFS5mN Eg6moHlL4QAQMgKB69UpT44e6MFZSUIxfr3MFCHm95lNnuRfUSNFYZ3d1 A==; X-IronPort-AV: E=McAfee;i="6600,9927,11004"; a="14897840" X-IronPort-AV: E=Sophos;i="6.06,207,1705392000"; d="scan'208";a="14897840" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,207,1705392000"; d="scan'208";a="32854140" From: Zhao Liu To: Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Thomas Huth , Igor Mammedov , Prasad Pandit , qemu-devel@nongnu.org Cc: Xiaoling Song , Zhao Liu Subject: [PATCH 04/14] hw/core/machine-smp: Calculate total CPUs once in machine_parse_smp_config() Date: Wed, 6 Mar 2024 17:53:57 +0800 Message-Id: <20240306095407.3058909-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240306095407.3058909-1-zhao1.liu@linux.intel.com> References: <20240306095407.3058909-1-zhao1.liu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: none client-ip=198.175.65.11; envelope-from=zhao1.liu@linux.intel.com; helo=mgamail.intel.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1709718092856100001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu In machine_parse_smp_config(), the number of total CPUs is calculated by: drawers * books * sockets * dies * clusters * cores * threads To avoid missing the future new topology level, use a local variable to cache the calculation result so that total CPUs are only calculated once. Signed-off-by: Zhao Liu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/core/machine-smp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index 3d9799aef039..0e398ef02666 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -91,6 +91,7 @@ void machine_parse_smp_config(MachineState *ms, unsigned cores =3D config->cores; unsigned threads =3D config->threads; unsigned maxcpus =3D config->maxcpus; + unsigned total_cpus; =20 /* * Specified CPU topology parameters must be greater than zero, @@ -211,8 +212,8 @@ void machine_parse_smp_config(MachineState *ms, } } =20 - maxcpus =3D maxcpus > 0 ? maxcpus : drawers * books * sockets * dies * - clusters * cores * threads; + total_cpus =3D drawers * books * sockets * dies * clusters * cores * t= hreads; + maxcpus =3D maxcpus > 0 ? maxcpus : total_cpus; cpus =3D cpus > 0 ? cpus : maxcpus; =20 ms->smp.cpus =3D cpus; @@ -228,8 +229,7 @@ void machine_parse_smp_config(MachineState *ms, mc->smp_props.has_clusters =3D config->has_clusters; =20 /* sanity-check of the computed topology */ - if (drawers * books * sockets * dies * clusters * cores * threads !=3D - maxcpus) { + if (total_cpus !=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: " --=20 2.34.1