From nobody Mon Nov 25 10:44:57 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=1716476541; cv=none; d=zohomail.com; s=zohoarc; b=m0MqWgJ1yKaF+wZYqxeJHjTT/TX0PSTgNCEqfFFTSvxWFLNozH1Gxecw3Gv4HMGx/Ov3xHbFe9yZQ9/BH5sP/bt7l8B0W9FMpnE7K2Pg+0N7EagPLWIxHdQQwqZVJcuggpXgpPalxTfUo58Pox8ZQQgDiETXv/22hKJHjwwBBD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476541; 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=mwV0yaFJVqKJSmAFwAeX+chM6jTzpTKGi6dHJnBLf0k=; b=mVAz6DmKDjXVaAhAq1Cagp5nkdFd8kKBujp7FOuCaVIr2My9sbvFg2826TrRIHBYlPPD9sptGewRI+Ok5/4szoK3+2qBIYEWTUzGkQciBmRcTOUIXKhHhSo8R8F9Bsrbr+gNseZJ4bJZUYS0Ojq+RJJLYY+hUKSFHxH6c+2AuHg= 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 1716476541713587.0849914830709; Thu, 23 May 2024 08:02:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9wn-0007G8-AM; Thu, 23 May 2024 11:01:37 -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 1sA9wU-0006ob-1X for qemu-devel@nongnu.org; Thu, 23 May 2024 11:01:18 -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 1sA9wO-0004rX-8K for qemu-devel@nongnu.org; Thu, 23 May 2024 11:01:14 -0400 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-eaF1E9msM1aRulN_NtGoQw-1; Thu, 23 May 2024 11:01:10 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a59ad2436f8so114938666b.2 for ; Thu, 23 May 2024 08:01:09 -0700 (PDT) Received: from avogadro.local ([151.95.155.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5fa6e4d4c3sm720172366b.22.2024.05.23.08.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 08:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476471; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mwV0yaFJVqKJSmAFwAeX+chM6jTzpTKGi6dHJnBLf0k=; b=JA5VX9gyf4AHdiJkyiyk7QqlxbqCi/sAJC/aYWhugM2dCMdW0ihsUiGlPOsV5Qzkb8FjGN 7c0xiA9O6V5Dg3haHVvIFJ4rfy5rgvTqMcYPu+xicLvojiaqTlCFdO1PZ4ILOzVS0kQrGp YtzYlqu+EX8wn0lKSsfsh/BLAkCqirU= X-MC-Unique: eaF1E9msM1aRulN_NtGoQw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476468; x=1717081268; 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=mwV0yaFJVqKJSmAFwAeX+chM6jTzpTKGi6dHJnBLf0k=; b=CR0JFjGb4OHMY3NYN5oiZcz7LO6ISUcuAFqLwaBnaT5CVujGw3vkb62zONKhRh/gll 6U2n0MiGSqrbHSkAjX/eyf7Y+ef3LoZtzjZHqQxIUgizxdrlCULWEuyKDuoS/I3Rh4nt EkQPHVoZaGjuzrFXqZDjc9/G531rscgR7/F4oDXYhNu7nOH82cJi6kYElTwrAXWBQG4G T5Y9HJVvXeNDKXP2RQ7QWo5Ojss5hPSkN5HVU4JMLdbl0WTl/40LOGeypi0gKxjUjB3A ukzODz93imIGHwrXJ7+9umYlJ9/Et+z+h+yrKyVYur5SntTRWh2BttZt4DP/ALcsEzI8 P8jw== X-Gm-Message-State: AOJu0Yy9SnkyyHUwVJ1pgAWkjQ1hTGFNQnAKfDYlGPCl3dVqnve3PcwN CUk0mxqAuEGx1MRKZ2vg06qUsdG6JtD70l+ivXqgzEQX1cLpfQ7XpgVFbmTTe86oaDDcqicEv4n bHxfIZQ7RGxea1Q2J9sHMEDK33jwaPn0aU1aor2848eYC+zuPyJTp1Uqn/Ivyy+yEwZx3A2aXDq kTmaGtLqTocl4XB8rRV+U2OyfjCWODRR5e9Qag X-Received: by 2002:a17:906:254d:b0:a5a:88a9:3ef5 with SMTP id a640c23a62f3a-a622812e4femr331519266b.39.1716476468026; Thu, 23 May 2024 08:01:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHb2pvwBpXQweIh+EVpst7RURPmvK8GQkeesuouQvuOgxInbbWjzKNU6TdCzYnLEcxJdqQf8Q== X-Received: by 2002:a17:906:254d:b0:a5a:88a9:3ef5 with SMTP id a640c23a62f3a-a622812e4femr331517366b.39.1716476467661; Thu, 23 May 2024 08:01:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yongwei Ma , Babu Moger , Xiaoyao Li Subject: [PULL 12/23] i386/cpu: Decouple CPUID[0x1F] subleaf with specific topology level Date: Thu, 23 May 2024 17:00:25 +0200 Message-ID: <20240523150036.1050011-13-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-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: 1716476542121100006 Content-Type: text/plain; charset="utf-8" From: Zhao Liu At present, the subleaf 0x02 of CPUID[0x1F] is bound to the "die" level. In fact, the specific topology level exposed in 0x1F depends on the platform's support for extension levels (module, tile and die). To help expose "module" level in 0x1F, decouple CPUID[0x1F] subleaf with specific topology level. Tested-by: Yongwei Ma Signed-off-by: Zhao Liu Tested-by: Babu Moger Reviewed-by: Xiaoyao Li Message-ID: <20240424154929.1487382-12-zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 135 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 110 insertions(+), 25 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d350eb8a736..f95d539eeff 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -269,6 +269,115 @@ static void encode_cache_cpuid4(CPUCacheInfo *cache, (cache->complex_indexing ? CACHE_COMPLEX_IDX : 0); } =20 +static uint32_t num_threads_by_topo_level(X86CPUTopoInfo *topo_info, + enum CPUTopoLevel topo_level) +{ + switch (topo_level) { + case CPU_TOPO_LEVEL_SMT: + return 1; + case CPU_TOPO_LEVEL_CORE: + return topo_info->threads_per_core; + case CPU_TOPO_LEVEL_DIE: + return topo_info->threads_per_core * topo_info->cores_per_die; + case CPU_TOPO_LEVEL_PACKAGE: + return topo_info->threads_per_core * topo_info->cores_per_die * + topo_info->dies_per_pkg; + default: + g_assert_not_reached(); + } + return 0; +} + +static uint32_t apicid_offset_by_topo_level(X86CPUTopoInfo *topo_info, + enum CPUTopoLevel topo_level) +{ + switch (topo_level) { + case CPU_TOPO_LEVEL_SMT: + return 0; + case CPU_TOPO_LEVEL_CORE: + return apicid_core_offset(topo_info); + case CPU_TOPO_LEVEL_DIE: + return apicid_die_offset(topo_info); + case CPU_TOPO_LEVEL_PACKAGE: + return apicid_pkg_offset(topo_info); + default: + g_assert_not_reached(); + } + return 0; +} + +static uint32_t cpuid1f_topo_type(enum CPUTopoLevel topo_level) +{ + switch (topo_level) { + case CPU_TOPO_LEVEL_INVALID: + return CPUID_1F_ECX_TOPO_LEVEL_INVALID; + case CPU_TOPO_LEVEL_SMT: + return CPUID_1F_ECX_TOPO_LEVEL_SMT; + case CPU_TOPO_LEVEL_CORE: + return CPUID_1F_ECX_TOPO_LEVEL_CORE; + case CPU_TOPO_LEVEL_DIE: + return CPUID_1F_ECX_TOPO_LEVEL_DIE; + default: + /* Other types are not supported in QEMU. */ + g_assert_not_reached(); + } + return 0; +} + +static void encode_topo_cpuid1f(CPUX86State *env, uint32_t count, + X86CPUTopoInfo *topo_info, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + X86CPU *cpu =3D env_archcpu(env); + unsigned long level, next_level; + uint32_t num_threads_next_level, offset_next_level; + + assert(count + 1 < CPU_TOPO_LEVEL_MAX); + + /* + * Find the No.(count + 1) topology level in avail_cpu_topo bitmap. + * The search starts from bit 1 (CPU_TOPO_LEVEL_INVALID + 1). + */ + level =3D CPU_TOPO_LEVEL_INVALID; + for (int i =3D 0; i <=3D count; i++) { + level =3D find_next_bit(env->avail_cpu_topo, + CPU_TOPO_LEVEL_PACKAGE, + level + 1); + + /* + * CPUID[0x1f] doesn't explicitly encode the package level, + * and it just encodes the invalid level (all fields are 0) + * into the last subleaf of 0x1f. + */ + if (level =3D=3D CPU_TOPO_LEVEL_PACKAGE) { + level =3D CPU_TOPO_LEVEL_INVALID; + break; + } + } + + if (level =3D=3D CPU_TOPO_LEVEL_INVALID) { + num_threads_next_level =3D 0; + offset_next_level =3D 0; + } else { + next_level =3D find_next_bit(env->avail_cpu_topo, + CPU_TOPO_LEVEL_PACKAGE, + level + 1); + num_threads_next_level =3D num_threads_by_topo_level(topo_info, + next_level); + offset_next_level =3D apicid_offset_by_topo_level(topo_info, + next_level); + } + + *eax =3D offset_next_level; + /* The count (bits 15-00) doesn't need to be reliable. */ + *ebx =3D num_threads_next_level & 0xffff; + *ecx =3D (count & 0xff) | (cpuid1f_topo_type(level) << 8); + *edx =3D cpu->apic_id; + + assert(!(*eax & ~0x1f)); +} + /* Encode cache info for CPUID[0x80000005].ECX or CPUID[0x80000005].EDX */ static uint32_t encode_cache_cpuid80000005(CPUCacheInfo *cache) { @@ -6447,31 +6556,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, break; } =20 - *ecx =3D count & 0xff; - *edx =3D cpu->apic_id; - switch (count) { - case 0: - *eax =3D apicid_core_offset(&topo_info); - *ebx =3D topo_info.threads_per_core; - *ecx |=3D CPUID_1F_ECX_TOPO_LEVEL_SMT << 8; - break; - case 1: - *eax =3D apicid_die_offset(&topo_info); - *ebx =3D topo_info.cores_per_die * topo_info.threads_per_core; - *ecx |=3D CPUID_1F_ECX_TOPO_LEVEL_CORE << 8; - break; - case 2: - *eax =3D apicid_pkg_offset(&topo_info); - *ebx =3D threads_per_pkg; - *ecx |=3D CPUID_1F_ECX_TOPO_LEVEL_DIE << 8; - break; - default: - *eax =3D 0; - *ebx =3D 0; - *ecx |=3D CPUID_1F_ECX_TOPO_LEVEL_INVALID << 8; - } - assert(!(*eax & ~0x1f)); - *ebx &=3D 0xffff; /* The count doesn't need to be reliable. */ + encode_topo_cpuid1f(env, count, &topo_info, eax, ebx, ecx, edx); break; case 0xD: { /* Processor Extended State */ --=20 2.45.1