From bb12a2c276a5693db350198621d53cd306e4cbd9 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Thu, 7 Oct 2021 22:32:34 +0200 Subject: [PATCH] [v1.00] Fix ambiguity in uarch detection with 0x806E9; it may be Amber/Kaby Lake (thanks to #122 for pointing this out!). We can differentiate by CPU name (hacky, but is there a better way?) --- src/x86/cpuid.c | 2 +- src/x86/uarch.c | 20 +++++++++++++++++--- src/x86/uarch.h | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index 0bedc2a..46c213c 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -176,7 +176,7 @@ struct uarch* get_cpu_uarch(struct cpuInfo* cpu) { uint32_t family = (eax >> 8) & 0xF; uint32_t efamily = (eax >> 20) & 0xFF; - return get_uarch_from_cpuid(cpu, efamily, family, emodel, model, (int)stepping); + return get_uarch_from_cpuid(cpu, eax, efamily, family, emodel, model, (int)stepping); } int64_t get_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t max_freq, bool accurate_pp) { diff --git a/src/x86/uarch.c b/src/x86/uarch.c index a235230..272218a 100644 --- a/src/x86/uarch.c +++ b/src/x86/uarch.c @@ -223,7 +223,7 @@ struct uarch* get_uarch_from_cpuid_intel(uint32_t ef, uint32_t f, uint32_t em, u CHECK_UARCH(arch, 0, 6, 8, 10, NA, "Tremont", UARCH_TREMONT, 10) // no spec update; only geekbench.com example CHECK_UARCH(arch, 0, 6, 8, 12, NA, "Tiger Lake", UARCH_TIGER_LAKE, 10) // instlatx64 CHECK_UARCH(arch, 0, 6, 8, 13, NA, "Tiger Lake", UARCH_TIGER_LAKE, 10) // instlatx64 - CHECK_UARCH(arch, 0, 6, 8, 14, 9, "Amber Lake", UARCH_AMBER_LAKE, 14) // wikichip + // CHECK_UARCH(arch, 0, 6, 8, 14, 9, ...) It is not possible to determine uarch only from CPUID dump (can be Kaby Lake or Amber Lake) CHECK_UARCH(arch, 0, 6, 8, 14, 10, "Kaby Lake", UARCH_KABY_LAKE, 14) // wikichip CHECK_UARCH(arch, 0, 6, 8, 14, 11, "Whiskey Lake", UARCH_WHISKEY_LAKE, 14) // wikichip CHECK_UARCH(arch, 0, 6, 8, 14, 12, "Comet Lake", UARCH_COMET_LAKE, 14) // wikichip @@ -364,9 +364,23 @@ struct uarch* get_uarch_from_cpuid_amd(uint32_t ef, uint32_t f, uint32_t em, uin return arch; } -struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t ef, uint32_t f, uint32_t em, uint32_t m, int s) { - if(cpu->cpu_vendor == CPU_VENDOR_INTEL) +struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t dump, uint32_t ef, uint32_t f, uint32_t em, uint32_t m, int s) { + if(cpu->cpu_vendor == CPU_VENDOR_INTEL) { + if(dump == 0x000806E9) { + // It is not possible to determine uarch only from CPUID dump (can be Kaby Lake or Amber Lake) + struct uarch* arch = emalloc(sizeof(struct uarch)); + + if(strstr(cpu->cpu_name, "Y") != NULL) { + fill_uarch(arch, "Amber Lake", UARCH_AMBER_LAKE, 14); + } + else { + fill_uarch(arch, "Kaby Lake", UARCH_KABY_LAKE, 14); + } + + return arch; + } return get_uarch_from_cpuid_intel(ef, f, em, m, s); + } else return get_uarch_from_cpuid_amd(ef, f, em, m, s); } diff --git a/src/x86/uarch.h b/src/x86/uarch.h index 74428c1..955461c 100644 --- a/src/x86/uarch.h +++ b/src/x86/uarch.h @@ -7,7 +7,7 @@ struct uarch; -struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t ef, uint32_t f, uint32_t em, uint32_t m, int s); +struct uarch* get_uarch_from_cpuid(struct cpuInfo* cpu, uint32_t dump, uint32_t ef, uint32_t f, uint32_t em, uint32_t m, int s); bool vpus_are_AVX512(struct cpuInfo* cpu); bool is_knights_landing(struct cpuInfo* cpu); int get_number_of_vpus(struct cpuInfo* cpu);