From nobody Sat Nov 20 00:40:47 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 27461189048A; Sat, 20 Nov 2021 00:40:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HwvpS0gZ0z3m3H; Sat, 20 Nov 2021 00:40:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EB2121252B; Sat, 20 Nov 2021 00:40:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AK0elDf046184; Sat, 20 Nov 2021 00:40:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AK0eluA046183; Sat, 20 Nov 2021 00:40:47 GMT (envelope-from git) Date: Sat, 20 Nov 2021 00:40:47 GMT Message-Id: <202111200040.1AK0eluA046183@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 1ae5513db3b2 - stable/12 - Prefer CPUID leaf 1Fh for Intel CPU topology detection. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 1ae5513db3b28e929d487d954d4e1c8a4c70fde9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=1ae5513db3b28e929d487d954d4e1c8a4c70fde9 commit 1ae5513db3b28e929d487d954d4e1c8a4c70fde9 Author: Alexander Motin AuthorDate: 2021-11-06 04:48:37 +0000 Commit: Alexander Motin CommitDate: 2021-11-20 00:32:54 +0000 Prefer CPUID leaf 1Fh for Intel CPU topology detection. Leaf 1Fh is a prefered extended version of 0Bh. It is supported by new Lader Lake CPUs, though does not report anything new so far. MFC after: 2 weeks (cherry picked from commit 6badb512a94df667f0df1484fb288ece186305bd) --- sys/x86/x86/mp_x86.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index 73565360007b..41dc36672135 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -366,7 +366,7 @@ topo_probe_intel_0x4(void) /* * Determine topology of processing units for Intel CPUs - * using CPUID Leaf 11, if supported. + * using CPUID Leaf 1Fh or 0Bh, if supported. * See: * - Intel 64 Architecture Processor Topology Enumeration * - Intel 64 and IA-32 ArchitecturesSoftware Developer’s Manual, @@ -376,13 +376,23 @@ topo_probe_intel_0x4(void) static void topo_probe_intel_0xb(void) { - u_int p[4]; + u_int leaf; + u_int p[4] = { 0 }; int bits; int type; int i; - /* Fall back if CPU leaf 11 doesn't really exist. */ - cpuid_count(0x0b, 0, p); + /* Prefer leaf 1Fh (V2 Extended Topology Enumeration). */ + if (cpu_high >= 0x1f) { + leaf = 0x1f; + cpuid_count(leaf, 0, p); + } + /* Fall back to leaf 0Bh (Extended Topology Enumeration). */ + if (p[1] == 0) { + leaf = 0x0b; + cpuid_count(leaf, 0, p); + } + /* Fall back to leaf 04h (Deterministic Cache Parameters). */ if (p[1] == 0) { topo_probe_intel_0x4(); return; @@ -390,7 +400,7 @@ topo_probe_intel_0xb(void) /* We only support three levels for now. */ for (i = 0; ; i++) { - cpuid_count(0x0b, i, p); + cpuid_count(leaf, i, p); bits = p[0] & 0x1f; type = (p[2] >> 8) & 0xff; @@ -398,13 +408,12 @@ topo_probe_intel_0xb(void) if (type == 0) break; - /* TODO: check for duplicate (re-)assignment */ if (type == CPUID_TYPE_SMT) core_id_shift = bits; else if (type == CPUID_TYPE_CORE) pkg_id_shift = bits; - else - printf("unknown CPU level type %d\n", type); + else if (bootverbose) + printf("Topology level type %d shift: %d\n", type, bits); } if (pkg_id_shift < core_id_shift) {