From nobody Sun May 19 23:41:29 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=1687959947; cv=none; d=zohomail.com; s=zohoarc; b=cSOfpG+yij7moPAk8ko5AQJ6+UFIy5GLTqJVqHNAqavjbr+1b5u4qbUeQmL/26myW8cH4YwokvMi9w6WcdIWAsnbDSuIo2kQnshTRzAUNv4YpR+HAlyDHV7pNsV/ZLenuxRWgYPsktfqnqSDYAn3N9zMHeLd18YmJzXp1VrAFMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687959947; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G2lbmgFgGTR9ZU03KTdHM3RafEq5DaFnOSeCdMwI8z0=; b=GIHG5U6GBP0SB5v71bgwMAdtdoNo9QVf40qmMLaxvxSyDlaD0Ij3c8Lj6FqG6rVm2Bs4wXY3aYPOat2yCADjp67FDM5h6GgVJslhEgnMNoY20ErtTEr4MqgNXQTCRQLYOGKTprlGeZAElzgg6AF+MnjfSTsEaL3Gt1KQBpekwks= 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 1687959947654276.4678579841667; Wed, 28 Jun 2023 06:45:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEVTe-0005Bd-VU; Wed, 28 Jun 2023 09:44:59 -0400 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 1qEVTc-0005Av-Ui for qemu-devel@nongnu.org; Wed, 28 Jun 2023 09:44:57 -0400 Received: from mga07.intel.com ([134.134.136.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEVTb-00088Q-DC for qemu-devel@nongnu.org; Wed, 28 Jun 2023 09:44:56 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 06:44:51 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.28]) by FMSMGA003.fm.intel.com with ESMTP; 28 Jun 2023 06:44:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687959895; x=1719495895; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/p2yXUJZCsxnEMkGSLP23fJhX9cTP2S05PNdFSoPzpY=; b=Hn8PaDPFw6ao+L6y9ckHn7M6MJD4AQerq6M3HAkQCicY4m3w3Ezm1hv3 46Te8vsnZ17JzAX5q7OJqqxGRp04ECbZxdfE4GyUek8KZ9D7sBxvLRSgZ wqgFXfTTEU8ye71cmz84QVJyB1S3B088RXcqzk3cLK6AT4oMeS3seTHue /WL44jGKU1Cs6Wd2ERG9tKjKhAdNNrbZJT4feJOp8q9S85neNHc944+5T NJFiqLABiMO4NraE2GyClZ3J8BXLT1U8oYVTTyR3d14mUUTVH7nPyg4hf xkgc7rMj2ROgeeerd+TJfj0mioJHmWmGm1rzfK/Xr4KxPZBJ/1DYG+Dx6 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="427854116" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="427854116" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="806905470" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="806905470" From: Zhao Liu To: "Michael S . Tsirkin" , Igor Mammedov , Ani Sinha , Eduardo Habkost , Yanan Wang Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [PATCH v4 1/4] machine: Add helpers to get cores/threads per socket Date: Wed, 28 Jun 2023 21:54:34 +0800 Message-Id: <20230628135437.1145805-2-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628135437.1145805-1-zhao1.liu@linux.intel.com> References: <20230628135437.1145805-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=134.134.136.100; envelope-from=zhao1.liu@linux.intel.com; helo=mga07.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1687959948466100009 Content-Type: text/plain; charset="utf-8" From: Zhao Liu The number of cores/threads per socket are needed for smbios, and are also useful for other modules. Provide the helpers to wrap the calculation of cores/threads per socket so that we can avoid calculation errors caused by other modules miss topology changes. Suggested-by: Igor Mammedov Signed-off-by: Zhao Liu Acked-by: Igor Mammedov --- v4: * Put the declarations/definitions after machine_parse_smp_config() to avoid missing future topology related changes. (Igor) v3: * The new patch to wrap the calculation of cores/threads per socket. --- hw/core/machine-smp.c | 10 ++++++++++ include/hw/boards.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c index 89fe0cda4275..0f4d9b6f7a9f 100644 --- a/hw/core/machine-smp.c +++ b/hw/core/machine-smp.c @@ -197,3 +197,13 @@ void machine_parse_smp_config(MachineState *ms, return; } } + +unsigned int machine_topo_get_cores_per_socket(const MachineState *ms) +{ + return ms->smp.cores * ms->smp.clusters * ms->smp.dies; +} + +unsigned int machine_topo_get_threads_per_socket(const MachineState *ms) +{ + return ms->smp.threads * machine_topo_get_cores_per_socket(ms); +} diff --git a/include/hw/boards.h b/include/hw/boards.h index 6b267c21ce7d..12d9e9d17ce9 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -35,6 +35,8 @@ void machine_set_cpu_numa_node(MachineState *machine, Error **errp); void machine_parse_smp_config(MachineState *ms, const SMPConfiguration *config, Error **errp= ); +unsigned int machine_topo_get_cores_per_socket(const MachineState *ms); +unsigned int machine_topo_get_threads_per_socket(const MachineState *ms); =20 /** * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devic= es --=20 2.34.1 From nobody Sun May 19 23:41:29 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=1687959947; cv=none; d=zohomail.com; s=zohoarc; b=OzVBGIIUVQbvK1rZeAP0tCa1b4P8AnfbF0NEzLw19YO2EOleTTKyLoukkqmYnTtW5lGlsDjB8RHdoKYG7sL7e97sgSmwLE9ujWsUhMVM8xEbdANi/M7x7scDd9+HoEakhRpwbG6QnfoRLiXCxIfcNB5W6gx8MSQGotSft+n4uKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687959947; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NxkudkFss3H/BjWITRiXucCYQt3sLRvrnCshmNXIDQQ=; b=DkgjQNs61TmNF+k0TPhpsdTxBph8RU6+F5qfYTIRzTH8wYLTY85fJVc4YcnydlPjDivag6kRW//chX6ZqLELvKC3SoTF/BLTCAu2baVgwN6F14CHweg0obeZ2Tza9d8rn8QK0hcfb/LWvEBsAziupLWJYV90k6tsI+7cQL5R+Ls= 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 1687959947077923.8445096071523; Wed, 28 Jun 2023 06:45:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEVTn-0005CZ-64; Wed, 28 Jun 2023 09:45:07 -0400 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 1qEVTe-0005BR-7w for qemu-devel@nongnu.org; Wed, 28 Jun 2023 09:44:58 -0400 Received: from mga07.intel.com ([134.134.136.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEVTc-000885-Ne for qemu-devel@nongnu.org; Wed, 28 Jun 2023 09:44:57 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 06:44:54 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.28]) by FMSMGA003.fm.intel.com with ESMTP; 28 Jun 2023 06:44:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687959896; x=1719495896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZUSL+eca/5GsGL4WFLQFgSwu2Mpnrl1Ujo1b6PRxk54=; b=d7/jOO7o/NM3hD05f2dExV4ffvNYcKZtAdR2fuow54M5Xel0UrUul8qq ZU721vsZ/5FJlYOFZkPyB3uHFVoW5VGYM4B1ZI/DMbu0pk4A03By0U5pN 6eG0bmAnzxvN5LUYbHXKjWNs5HMM02k1W1XTRqagftBozHy7sxk8AqeD+ zwCrRcuFTx+05f8ZO4I9LPs/NXotMLHRMjNi7nMcQV/nGBd0pdywu1rTV fg0IPHkBum4IUzDzwDrOZBtyT6ujPQlWxnxnUJs3Q97YOSvK+mmHOuKdR 77aMlEDxKdYK/dXZ/sQd3yQUlNoad8GUdjL/SIVrfwbKlOnu0IeH91q2M Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="427854126" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="427854126" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="806905480" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="806905480" From: Zhao Liu To: "Michael S . Tsirkin" , Igor Mammedov , Ani Sinha , Eduardo Habkost , Yanan Wang Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [PATCH v4 2/4] hw/smbios: Fix smbios_smp_sockets caculation Date: Wed, 28 Jun 2023 21:54:35 +0800 Message-Id: <20230628135437.1145805-3-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628135437.1145805-1-zhao1.liu@linux.intel.com> References: <20230628135437.1145805-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=134.134.136.100; envelope-from=zhao1.liu@linux.intel.com; helo=mga07.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1687959948340100005 Content-Type: text/plain; charset="utf-8" From: Zhao Liu smp.sockets is the number of sockets which is configured by "-smp" ( otherwise, the default is 1). Trying to recalculate it here with another rules leads to errors, such as: 1. 003f230e37d7 ("machine: Tweak the order of topology members in struct CpuTopology") changes the meaning of smp.cores but doesn't fix original smp.cores uses. With the introduction of cluster, now smp.cores means the number of cores in one cluster. So smp.cores * smp.threads just means the threads in a cluster not in a socket. 2. On the other hand, we shouldn't use smp.cpus here because it indicates the initial number of online CPUs at the boot time, and is not mathematically related to smp.sockets. So stop reinventing the another wheel and use the topo values that has been calculated. Fixes: 003f230e37d7 ("machine: Tweak the order of topology members in struc= t CpuTopology") Signed-off-by: Zhao Liu Acked-by: Igor Mammedov --- v4: * None. v3: * Reorganized changlog. (Igor) v2: * None. --- hw/smbios/smbios.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index d2007e70fb05..d67415d44dd8 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -1088,8 +1088,7 @@ void smbios_get_tables(MachineState *ms, smbios_build_type_2_table(); smbios_build_type_3_table(); =20 - smbios_smp_sockets =3D DIV_ROUND_UP(ms->smp.cpus, - ms->smp.cores * ms->smp.threads); + smbios_smp_sockets =3D ms->smp.sockets; assert(smbios_smp_sockets >=3D 1); =20 for (i =3D 0; i < smbios_smp_sockets; i++) { --=20 2.34.1 From nobody Sun May 19 23:41:29 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=1687959955; cv=none; d=zohomail.com; s=zohoarc; b=JdaboVJ/BZBycpoPxxN+ZEW3lNuweyNYNPdFThBAPcXRgCClrMX5J+WPHNe+HI/heIGbFUfahvMs9FVYxqcgJDOU13Iby6HucoTScsJWBB+x7KTYDbqKwzeFHCLWsIPSr/M0WPITuLE4bDPqxcf2ZBbQPqUsoYLseaCjPf79PeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687959955; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=81ciGREfl5/jVNkL3vZjYRbBjAGFXBmKsKfxnk8jJLM=; b=B55aQ9ytudhDAY8jNdca4vDQ4+hCHfnnV7GZaRkyTp8b54f0QH6bINXcCyWZ0IJszIWd43U9DPYwnD2pPk0U9QqKDcjykahAHcFUsrrj0uhWEY/25gOsJKYwAoatfrEBbAYeXGRVGDYtd/fWZmngULn3B20ZQahzzKTOECPGwSA= 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 168795995561823.449694421196; Wed, 28 Jun 2023 06:45:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEVTn-0005Cp-71; Wed, 28 Jun 2023 09:45:08 -0400 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 1qEVTf-0005Bv-Hd for qemu-devel@nongnu.org; Wed, 28 Jun 2023 09:44:59 -0400 Received: from mga07.intel.com ([134.134.136.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEVTd-00088Q-OR for qemu-devel@nongnu.org; Wed, 28 Jun 2023 09:44:59 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 06:44:57 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.28]) by FMSMGA003.fm.intel.com with ESMTP; 28 Jun 2023 06:44:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687959897; x=1719495897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4DPJq8oj0vzSj8F4qI9x0FHKf1kKXEnnAnZ0dqAQZEw=; b=DRINkirMCYle6YsYVFI4QaB4Ovpvisr1kjbOF/CbGnaBIBh/G4hgUhlI 6VhOnsZ20RUQHh4RG1rb/vl4mCUm/pIB6NyrMIr+XoLRm3zcNFBlWPKeA 70gZtJgFdM6X9V78ooQyaJcCXd2cZGP3jut0JPUWHGyHErtq+Q5yKvwe6 NzQR20Rn2iXm+QFPyllqXb3s7M2UrfRH2OBtcZ6BvlnF/g06ig6nSfg9h 1BFACva6Bs9tdK6aFj7+T/uV149lJxkUWBN9HC7tmAL5Vx7v4R2JtQTMB 8FqOhmdR+I/VElSE7hdxZMD5bajfdDlnZpL53eSnpuagCRiu3m+Vdhy0h w==; X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="427854142" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="427854142" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="806905488" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="806905488" From: Zhao Liu To: "Michael S . Tsirkin" , Igor Mammedov , Ani Sinha , Eduardo Habkost , Yanan Wang Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [PATCH v4 3/4] hw/smbios: Fix thread count in type4 Date: Wed, 28 Jun 2023 21:54:36 +0800 Message-Id: <20230628135437.1145805-4-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628135437.1145805-1-zhao1.liu@linux.intel.com> References: <20230628135437.1145805-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=134.134.136.100; envelope-from=zhao1.liu@linux.intel.com; helo=mga07.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1687959956230100001 Content-Type: text/plain; charset="utf-8" From: Zhao Liu From SMBIOS 3.0 specification, thread count field means: Thread Count is the total number of threads detected by the BIOS for this processor socket. It is a processor-wide count, not a thread-per-core count. [1] So here we should use threads per socket other than threads per core. [1] SMBIOS 3.0.0, section 7.5.8, Processor Information - Thread Count Fixes: c97294ec1b9e ("SMBIOS: Build aggregate smbios tables and entry point= ") Signed-off-by: Zhao Liu Acked-by: Igor Mammedov --- v4: * None. v3: * Use the wrapped hepler to get threads per socket. v2: * Rename cpus_per_socket to threads_per_socket. * Add the comment about smp.max_cpus. Thread count and core count will be calculated in 2 ways and will add a sanity check to ensure we don't miss any topology level. --- hw/smbios/smbios.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index d67415d44dd8..3aae9328c014 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -713,6 +713,7 @@ static void smbios_build_type_4_table(MachineState *ms,= unsigned instance) { char sock_str[128]; size_t tbl_len =3D SMBIOS_TYPE_4_LEN_V28; + unsigned threads_per_socket; =20 if (smbios_ep_type =3D=3D SMBIOS_ENTRY_POINT_TYPE_64) { tbl_len =3D SMBIOS_TYPE_4_LEN_V30; @@ -747,17 +748,19 @@ static void smbios_build_type_4_table(MachineState *m= s, unsigned instance) SMBIOS_TABLE_SET_STR(4, asset_tag_number_str, type4.asset); SMBIOS_TABLE_SET_STR(4, part_number_str, type4.part); =20 + threads_per_socket =3D machine_topo_get_threads_per_socket(ms); + t->core_count =3D (ms->smp.cores > 255) ? 0xFF : ms->smp.cores; t->core_enabled =3D t->core_count; =20 - t->thread_count =3D (ms->smp.threads > 255) ? 0xFF : ms->smp.threads; + t->thread_count =3D (threads_per_socket > 255) ? 0xFF : threads_per_so= cket; =20 t->processor_characteristics =3D cpu_to_le16(0x02); /* Unknown */ t->processor_family2 =3D cpu_to_le16(0x01); /* Other */ =20 if (tbl_len =3D=3D SMBIOS_TYPE_4_LEN_V30) { t->core_count2 =3D t->core_enabled2 =3D cpu_to_le16(ms->smp.cores); - t->thread_count2 =3D cpu_to_le16(ms->smp.threads); + t->thread_count2 =3D cpu_to_le16(threads_per_socket); } =20 SMBIOS_BUILD_TABLE_POST; --=20 2.34.1 From nobody Sun May 19 23:41:29 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=1687959947; cv=none; d=zohomail.com; s=zohoarc; b=jeGizEMmJzJ+lUqcNfH0FVTp9yQn8gu2nDwRN2iHXLZmqkL+gdTw+ldsqtIvanluGvyJkchesbgpS/Zw2kaU33SnYZ2DFWDY2wX9dgMol0j2tzZpWnKO/xdMuJRu/TQxTOcjQ9RVs2kF0O4AIQt5ruj/5r2IFr18CNT2NVG09TY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687959947; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pQPCFqww5rt5v96SQbtd7wYb8Se00GBcd8a3Ubgk5BE=; b=BiElZMDvsKo2UJmZnn2u+8UNQUS1ZcR3XG6LV3xzfa7UsFw06X/AOdq29BA/hkNxrT48V5hVP+mjBBUjXMTaBBihS45SZRLWkqv0zW6kEHOK3nwHjmo/rgcikmebPRA0UgwLcv8O1BOIWswOYLN39nYt0hV0lTjvRIfiU6NfvxY= 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 1687959947105342.4835505557968; Wed, 28 Jun 2023 06:45:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEVTw-0005EG-Pp; Wed, 28 Jun 2023 09:45:17 -0400 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 1qEVTl-0005Cf-H8 for qemu-devel@nongnu.org; Wed, 28 Jun 2023 09:45:07 -0400 Received: from mga07.intel.com ([134.134.136.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qEVTi-00089l-91 for qemu-devel@nongnu.org; Wed, 28 Jun 2023 09:45:03 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2023 06:44:59 -0700 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.28]) by FMSMGA003.fm.intel.com with ESMTP; 28 Jun 2023 06:44:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687959902; x=1719495902; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=o69eaL3+onIsEWii+kpARMjg37wbuabYwIfkzHgP+uw=; b=Wyhw/21a+7B+bsIzDNHiJnLU+g8NPQB/bRchFexFH1n3b/g0ZNvY1HXV 2I3NEOFVBsmbyJkC29yH/1UeyVi5Pv1si+yqitFfAHjnyMgBOPE9YWjyG 9T/9EYgUsAAlgywIGG2269ijFC2/wLfY9F57V2mcaZ2LG2YR7A/8lUK9Z Y5nyGnMlYQstCAO5bUXkZsiwkIa1RUIU+cQeMUg0AGzwcf29IMugFp5vM tNmCFKB+BkxNS6NcFy0rRy6RFIS+yLYMpzteopL9HDR8TBcOxdXsEs2hq l0TNbLg1RFiTZ44yvAWx1Tk0Ee6BqDlaI3OFk1by3olSxZwtoOKSi7ea6 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="427854153" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="427854153" X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10754"; a="806905501" X-IronPort-AV: E=Sophos;i="6.01,165,1684825200"; d="scan'208";a="806905501" From: Zhao Liu To: "Michael S . Tsirkin" , Igor Mammedov , Ani Sinha , Eduardo Habkost , Yanan Wang Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [PATCH v4 4/4] hw/smbios: Fix core count in type4 Date: Wed, 28 Jun 2023 21:54:37 +0800 Message-Id: <20230628135437.1145805-5-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230628135437.1145805-1-zhao1.liu@linux.intel.com> References: <20230628135437.1145805-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=134.134.136.100; envelope-from=zhao1.liu@linux.intel.com; helo=mga07.intel.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1687959948548100011 Content-Type: text/plain; charset="utf-8" From: Zhao Liu From SMBIOS 3.0 specification, core count field means: Core Count is the number of cores detected by the BIOS for this processor socket. [1] Before 003f230e37d7 ("machine: Tweak the order of topology members in struct CpuTopology"), MachineState.smp.cores means "the number of cores in one package", and it's correct to use smp.cores for core count. But 003f230e37d7 changes the smp.cores' meaning to "the number of cores in one die" and doesn't change the original smp.cores' use in smbios as well, which makes core count in type4 go wrong. Fix this issue with the correct "cores per socket" caculation. [1] SMBIOS 3.0.0, section 7.5.6, Processor Information - Core Count Fixes: 003f230e37d7 ("machine: Tweak the order of topology members in struc= t CpuTopology") Signed-off-by: Zhao Liu Acked-by: Igor Mammedov --- v4: * None. v3: * Use the wrapped helper to get cores per socket. v2: * Calculate cores_per_socket in a different way from threads_per_socket. * Add the sanity check to ensure consistency of results between these 2 ways. This can help not miss any future change of cpu topology. --- hw/smbios/smbios.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index 3aae9328c014..10cd22f610ef 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -714,6 +714,7 @@ static void smbios_build_type_4_table(MachineState *ms,= unsigned instance) char sock_str[128]; size_t tbl_len =3D SMBIOS_TYPE_4_LEN_V28; unsigned threads_per_socket; + unsigned cores_per_socket; =20 if (smbios_ep_type =3D=3D SMBIOS_ENTRY_POINT_TYPE_64) { tbl_len =3D SMBIOS_TYPE_4_LEN_V30; @@ -749,8 +750,9 @@ static void smbios_build_type_4_table(MachineState *ms,= unsigned instance) SMBIOS_TABLE_SET_STR(4, part_number_str, type4.part); =20 threads_per_socket =3D machine_topo_get_threads_per_socket(ms); + cores_per_socket =3D machine_topo_get_cores_per_socket(ms); =20 - t->core_count =3D (ms->smp.cores > 255) ? 0xFF : ms->smp.cores; + t->core_count =3D (cores_per_socket > 255) ? 0xFF : cores_per_socket; t->core_enabled =3D t->core_count; =20 t->thread_count =3D (threads_per_socket > 255) ? 0xFF : threads_per_so= cket; @@ -759,7 +761,7 @@ static void smbios_build_type_4_table(MachineState *ms,= unsigned instance) t->processor_family2 =3D cpu_to_le16(0x01); /* Other */ =20 if (tbl_len =3D=3D SMBIOS_TYPE_4_LEN_V30) { - t->core_count2 =3D t->core_enabled2 =3D cpu_to_le16(ms->smp.cores); + t->core_count2 =3D t->core_enabled2 =3D cpu_to_le16(cores_per_sock= et); t->thread_count2 =3D cpu_to_le16(threads_per_socket); } =20 --=20 2.34.1