From nobody Mon Nov 25 09:39:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1716476502; cv=none; d=zohomail.com; s=zohoarc; b=E8lCOo5q5/X51H6tHyMWHDQ6bWuXYGdRvJbvYMnFQ4uR5Ws5ZEasY0KxBsj8ZJbhSEZAhBfinunzgteG374jnvrPkcmgtEKT5TNO+g8tUCE0IhZDO23akv4a+zu91gXkT/rd7Cdg6NAlVDrDxGJkMeh/rHUw/iPsX75/0JWOSk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476502; h=Content-Type: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=05/Tfu6Nc2hb7Y7EBfsPD9418bWLTWo42rB2fId09dI=; b=nn2M4qqmLuqIAJX0SEbn23pNp6ErwEbof5PAGzX2LFkHeI1Up9D1E47TN/IYf7ewcWnodgq32F75g5gkANmIg/4X4jUi+F8oQ5JIMc9eY2mBdSRqp8MJRHzN521Xy0lcjeMsS1BLCmK7atC0pjIBKPo9Y2Spdg349oI0NhcBmig= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 17164765028181000.3167210317708; Thu, 23 May 2024 08:01:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9wN-0006Sw-NE; Thu, 23 May 2024 11:01:11 -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 1sA9wK-0006QR-LS for qemu-devel@nongnu.org; Thu, 23 May 2024 11:01:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sA9wG-0004ql-Eb for qemu-devel@nongnu.org; Thu, 23 May 2024 11:01:06 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-647-HYBVk676MAajWX7vkbr4wg-1; Thu, 23 May 2024 11:01:02 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a59c2583f0bso101997066b.1 for ; Thu, 23 May 2024 08:01:01 -0700 (PDT) Received: from avogadro.local ([151.95.155.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a1781ce5dsm1944254666b.42.2024.05.23.08.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 08:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=05/Tfu6Nc2hb7Y7EBfsPD9418bWLTWo42rB2fId09dI=; b=Qmi5iBWUhEIVu7c0MW/++uTu+/zX13kqjm6BrkQML5CUQzdB2Lgon2O3W5dl1rCDad4AQi FHr2WiHoPWeOIrb1xSfitxE5DW9UPyqf/iWrrGM+/f0YJc14BfKsV2nIl3MezWm/dqDmAc aQ6kBXYE8lzm7SvvwqP+xqB+2toBSR4= X-MC-Unique: HYBVk676MAajWX7vkbr4wg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476460; x=1717081260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=05/Tfu6Nc2hb7Y7EBfsPD9418bWLTWo42rB2fId09dI=; b=dK6aCh9TGVVrs5oTNVkR7kFZ+CQGpRzS/TNY1TqBpXave0Duz56E6cwWRY/cS/vcno GJjuXyhqJPUb2ib5oUAAd61IAON+mYrhw/7yaJoMuMPjKFXuJTu7nkIwiJtFGRqIuhat 9EJ3v9QypFlNmlP1vzsSvM6bMbCpOSC0KrHIrv9zkETp0wa6n9ikNZSaWsgFmzEIsNEr anchVEbPxwCmB2/m75oqDX/WeGcBEH5SHNqw2FheM4pT4ydv2SWNHdKCV/+qgLDSqQGa ZoR7qXuRBy0ZJXb+4RXjmDfGobs87TUo7+jRESBb8S9WI8Lqxgw4ugPZdXGPLR6B31Aj +eJg== X-Gm-Message-State: AOJu0YxHgHHRo4oJXvvEJDztrX42RFsUkgV3ZexIaLtamzp8by3qT+cs jS19KrH0Z4FWwUzy1LPoq1bT6Al4hxZ3b8vU5ps1E1N9FGXY6ye2gINrynsQ9lze+Nv7S8SKLmn Lxr3RgJgAwAAoRn9NxbzbagXvG3850yJOX5zgMYKHiJ6VaoyTXfHQT800Fi4rcyuLUtvsZIKIlx px6f6sixqVw+CGJA80I/oNWe10aXCgEZbtZC9P X-Received: by 2002:a17:906:b1d5:b0:a59:d063:f5f3 with SMTP id a640c23a62f3a-a622818ebabmr346331666b.63.1716476460136; Thu, 23 May 2024 08:01:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGChYLkUZANX7KubOBc9U7PW6Kck59/D6CINuJZYufReVR+uKaFg9YHVQOzdytWHAWLIGgKxQ== X-Received: by 2002:a17:906:b1d5:b0:a59:d063:f5f3 with SMTP id a640c23a62f3a-a622818ebabmr346329466b.63.1716476459812; Thu, 23 May 2024 08:00:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Robert Hoo , Yongwei Ma , Xiaoyao Li , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Babu Moger Subject: [PULL 09/23] i386/cpu: Consolidate the use of topo_info in cpu_x86_cpuid() Date: Thu, 23 May 2024 17:00:22 +0200 Message-ID: <20240523150036.1050011-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523150036.1050011-1-pbonzini@redhat.com> References: <20240523150036.1050011-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain; charset=UTF-8 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: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.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 @redhat.com) X-ZM-MESSAGEID: 1716476503889100004 From: Zhao Liu In cpu_x86_cpuid(), there are many variables in representing the cpu topology, e.g., topo_info, cs->nr_cores and cs->nr_threads. Since the names of cs->nr_cores and cs->nr_threads do not accurately represent its meaning, the use of cs->nr_cores or cs->nr_threads is prone to confusion and mistakes. And the structure X86CPUTopoInfo names its members clearly, thus the variable "topo_info" should be preferred. In addition, in cpu_x86_cpuid(), to uniformly use the topology variable, replace env->dies with topo_info.dies_per_pkg as well. Suggested-by: Robert Hoo Tested-by: Yongwei Ma Signed-off-by: Zhao Liu Reviewed-by: Xiaoyao Li Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Babu Moger Message-ID: <20240424154929.1487382-9-zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 22a8ca1c9b4..363f5ee4bec 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6165,11 +6165,16 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, uint32_t limit; uint32_t signature[3]; X86CPUTopoInfo topo_info; + uint32_t cores_per_pkg; + uint32_t threads_per_pkg; =20 topo_info.dies_per_pkg =3D env->nr_dies; topo_info.cores_per_die =3D cs->nr_cores / env->nr_dies; topo_info.threads_per_core =3D cs->nr_threads; =20 + cores_per_pkg =3D topo_info.cores_per_die * topo_info.dies_per_pkg; + threads_per_pkg =3D cores_per_pkg * topo_info.threads_per_core; + /* Calculate & apply limits for different index ranges */ if (index >=3D 0xC0000000) { limit =3D env->cpuid_xlevel2; @@ -6205,8 +6210,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *ecx |=3D CPUID_EXT_OSXSAVE; } *edx =3D env->features[FEAT_1_EDX]; - if (cs->nr_cores * cs->nr_threads > 1) { - *ebx |=3D (cs->nr_cores * cs->nr_threads) << 16; + if (threads_per_pkg > 1) { + *ebx |=3D threads_per_pkg << 16; *edx |=3D CPUID_HT; } if (!cpu->enable_pmu) { @@ -6254,15 +6259,15 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, */ if (*eax & 31) { int host_vcpus_per_cache =3D 1 + ((*eax & 0x3FFC000) >> 14= ); - int vcpus_per_socket =3D cs->nr_cores * cs->nr_threads; - if (cs->nr_cores > 1) { + + if (cores_per_pkg > 1) { addressable_cores_width =3D apicid_pkg_offset(&topo_in= fo) - apicid_core_offset(&topo_inf= o); =20 *eax &=3D ~0xFC000000; *eax |=3D ((1 << addressable_cores_width) - 1) << 26; } - if (host_vcpus_per_cache > vcpus_per_socket) { + if (host_vcpus_per_cache > threads_per_pkg) { /* Share the cache at package level. */ addressable_threads_width =3D apicid_pkg_offset(&topo_= info); =20 @@ -6412,12 +6417,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, switch (count) { case 0: *eax =3D apicid_core_offset(&topo_info); - *ebx =3D cs->nr_threads; + *ebx =3D topo_info.threads_per_core; *ecx |=3D CPUID_TOPOLOGY_LEVEL_SMT; break; case 1: *eax =3D apicid_pkg_offset(&topo_info); - *ebx =3D cs->nr_cores * cs->nr_threads; + *ebx =3D threads_per_pkg; *ecx |=3D CPUID_TOPOLOGY_LEVEL_CORE; break; default: @@ -6437,7 +6442,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, break; case 0x1F: /* V2 Extended Topology Enumeration Leaf */ - if (env->nr_dies < 2) { + if (topo_info.dies_per_pkg < 2) { *eax =3D *ebx =3D *ecx =3D *edx =3D 0; break; } @@ -6447,7 +6452,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, switch (count) { case 0: *eax =3D apicid_core_offset(&topo_info); - *ebx =3D cs->nr_threads; + *ebx =3D topo_info.threads_per_core; *ecx |=3D CPUID_TOPOLOGY_LEVEL_SMT; break; case 1: @@ -6457,7 +6462,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, break; case 2: *eax =3D apicid_pkg_offset(&topo_info); - *ebx =3D cs->nr_cores * cs->nr_threads; + *ebx =3D threads_per_pkg; *ecx |=3D CPUID_TOPOLOGY_LEVEL_DIE; break; default: @@ -6685,7 +6690,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, * discards multiple thread information if it is set. * So don't set it here for Intel to make Linux guests happy. */ - if (cs->nr_cores * cs->nr_threads > 1) { + if (threads_per_pkg > 1) { if (env->cpuid_vendor1 !=3D CPUID_VENDOR_INTEL_1 || env->cpuid_vendor2 !=3D CPUID_VENDOR_INTEL_2 || env->cpuid_vendor3 !=3D CPUID_VENDOR_INTEL_3) { @@ -6752,7 +6757,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, *eax |=3D (cpu->guest_phys_bits << 16); } *ebx =3D env->features[FEAT_8000_0008_EBX]; - if (cs->nr_cores * cs->nr_threads > 1) { + if (threads_per_pkg > 1) { /* * Bits 15:12 is "The number of bits in the initial * Core::X86::Apic::ApicId[ApicId] value that indicate @@ -6760,7 +6765,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, * Bits 7:0 is "The number of threads in the package is NC+1" */ *ecx =3D (apicid_pkg_offset(&topo_info) << 12) | - ((cs->nr_cores * cs->nr_threads) - 1); + (threads_per_pkg - 1); } else { *ecx =3D 0; } --=20 2.45.1