From eb77e7266aefa93c1f86a306a15700280d5a1117 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 28 Sep 2017 17:41:32 -0700 Subject: [PATCH] kernel - Add poor-man's AMD TOPOEXT support * Add a poor-man's TOPOEXT support which should properly detect the Ryzen topology. I don't know about EPYC, though. And it might muff the topology for older AMD cpus (also don't know). --- sys/platform/pc64/x86_64/mp_machdep.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sys/platform/pc64/x86_64/mp_machdep.c b/sys/platform/pc64/x86_64/mp_machdep.c index c45474c6ca..1c8757ffd7 100644 --- a/sys/platform/pc64/x86_64/mp_machdep.c +++ b/sys/platform/pc64/x86_64/mp_machdep.c @@ -1727,6 +1727,32 @@ detect_amd_topology(int count_htt_cores) core_bits = shift; } + if (amd_feature2 & AMDID2_TOPOEXT) { + u_int p[4]; + int i; + int type; + int level; + int share_count; + for (i = 0; i < 256; ++i) { + cpuid_count(0x8000001d, i, p); + type = p[0] & 0x1f; + level = (p[0] >> 5) & 0x7; + share_count = 1 + ((p[0] >> 14) & 0xfff); + + if (type == 0) + break; + if (bootverbose) + kprintf("Topology probe i=%2d type=%d level=%d share_count=%d\n", + i, type, level, share_count); + if (type == 1 && share_count) { /* CPUID_TYPE_SMT */ + for (shift = 0; (1 << shift) < count_htt_cores / share_count; ++shift) + ; + core_bits = shift; + break; + } + } + } + logical_CPU_bits = count_htt_cores >> core_bits; for (shift = 0; (1 << shift) < logical_CPU_bits; ++shift) ; -- 2.41.0