From 045d84f4e6d7d6bbccaa6d965669a068fc329809 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 20 Jan 2021 22:23:43 +0000 Subject: [PATCH] D94954: Fixes Snapdragon Kryo CPU core detection All of these families were claiming to be a73 based, which was causing -mcpu/mtune=native to never use the newer features available to these cores. Goes through each and bumps the individual cores to their respective Big counterparts. Since this code path doesn't support big.little detection, there was already a precedent set with the Qualcomm line to choose the big cores only. Adds a comment on each line for the product's name that the part number refers to. Confirmed on-device and through Linux header naming convections. Additionally newer SoCs mix CPU implementer parts from multiple implementers. Both 0x41 (ARM) and 0x51 (Qualcomm) in the Snapdragon case This was causing a desync in information where the scan at the start to find the implementer would mismatch the part scan later on. Now scan for both implementer and part at the start so these stay in sync. Differential Revision: https://reviews.llvm.org/D94954 --- llvm/lib/Support/Host.cpp | 163 ++++++++++++++++++---------------------- llvm/unittests/Support/Host.cpp | 26 +++++++ 2 files changed, 98 insertions(+), 91 deletions(-) diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp index ea561ab..a1bd3cc 100644 --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -161,11 +161,14 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) { // Look for the CPU implementer line. StringRef Implementer; StringRef Hardware; + StringRef Part; for (unsigned I = 0, E = Lines.size(); I != E; ++I) { if (Lines[I].startswith("CPU implementer")) Implementer = Lines[I].substr(15).ltrim("\t :"); if (Lines[I].startswith("Hardware")) Hardware = Lines[I].substr(8).ltrim("\t :"); + if (Lines[I].startswith("CPU part")) + Part = Lines[I].substr(8).ltrim("\t :"); } if (Implementer == "0x41") { // ARM Ltd. @@ -175,111 +178,89 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) { return "cortex-a53"; - // Look for the CPU part line. - for (unsigned I = 0, E = Lines.size(); I != E; ++I) - if (Lines[I].startswith("CPU part")) - // The CPU part is a 3 digit hexadecimal number with a 0x prefix. The - // values correspond to the "Part number" in the CP15/c0 register. The - // contents are specified in the various processor manuals. - // This corresponds to the Main ID Register in Technical Reference Manuals. - // and is used in programs like sys-utils - return StringSwitch(Lines[I].substr(8).ltrim("\t :")) - .Case("0x926", "arm926ej-s") - .Case("0xb02", "mpcore") - .Case("0xb36", "arm1136j-s") - .Case("0xb56", "arm1156t2-s") - .Case("0xb76", "arm1176jz-s") - .Case("0xc08", "cortex-a8") - .Case("0xc09", "cortex-a9") - .Case("0xc0f", "cortex-a15") - .Case("0xc20", "cortex-m0") - .Case("0xc23", "cortex-m3") - .Case("0xc24", "cortex-m4") - .Case("0xd22", "cortex-m55") - .Case("0xd02", "cortex-a34") - .Case("0xd04", "cortex-a35") - .Case("0xd03", "cortex-a53") - .Case("0xd07", "cortex-a57") - .Case("0xd08", "cortex-a72") - .Case("0xd09", "cortex-a73") - .Case("0xd0a", "cortex-a75") - .Case("0xd0b", "cortex-a76") - .Case("0xd0d", "cortex-a77") - .Case("0xd41", "cortex-a78") - .Case("0xd44", "cortex-x1") - .Case("0xd0c", "neoverse-n1") - .Case("0xd49", "neoverse-n2") - .Default("generic"); + // The CPU part is a 3 digit hexadecimal number with a 0x prefix. The + // values correspond to the "Part number" in the CP15/c0 register. The + // contents are specified in the various processor manuals. + // This corresponds to the Main ID Register in Technical Reference Manuals. + // and is used in programs like sys-utils + return StringSwitch(Part) + .Case("0x926", "arm926ej-s") + .Case("0xb02", "mpcore") + .Case("0xb36", "arm1136j-s") + .Case("0xb56", "arm1156t2-s") + .Case("0xb76", "arm1176jz-s") + .Case("0xc08", "cortex-a8") + .Case("0xc09", "cortex-a9") + .Case("0xc0f", "cortex-a15") + .Case("0xc20", "cortex-m0") + .Case("0xc23", "cortex-m3") + .Case("0xc24", "cortex-m4") + .Case("0xd22", "cortex-m55") + .Case("0xd02", "cortex-a34") + .Case("0xd04", "cortex-a35") + .Case("0xd03", "cortex-a53") + .Case("0xd07", "cortex-a57") + .Case("0xd08", "cortex-a72") + .Case("0xd09", "cortex-a73") + .Case("0xd0a", "cortex-a75") + .Case("0xd0b", "cortex-a76") + .Case("0xd0d", "cortex-a77") + .Case("0xd41", "cortex-a78") + .Case("0xd44", "cortex-x1") + .Case("0xd0c", "neoverse-n1") + .Case("0xd49", "neoverse-n2") + .Default("generic"); } if (Implementer == "0x42" || Implementer == "0x43") { // Broadcom | Cavium. - for (unsigned I = 0, E = Lines.size(); I != E; ++I) { - if (Lines[I].startswith("CPU part")) { - return StringSwitch(Lines[I].substr(8).ltrim("\t :")) - .Case("0x516", "thunderx2t99") - .Case("0x0516", "thunderx2t99") - .Case("0xaf", "thunderx2t99") - .Case("0x0af", "thunderx2t99") - .Case("0xa1", "thunderxt88") - .Case("0x0a1", "thunderxt88") - .Default("generic"); - } - } + return StringSwitch(Part) + .Case("0x516", "thunderx2t99") + .Case("0x0516", "thunderx2t99") + .Case("0xaf", "thunderx2t99") + .Case("0x0af", "thunderx2t99") + .Case("0xa1", "thunderxt88") + .Case("0x0a1", "thunderxt88") + .Default("generic"); } if (Implementer == "0x46") { // Fujitsu Ltd. - for (unsigned I = 0, E = Lines.size(); I != E; ++I) { - if (Lines[I].startswith("CPU part")) { - return StringSwitch(Lines[I].substr(8).ltrim("\t :")) - .Case("0x001", "a64fx") - .Default("generic"); - } - } + return StringSwitch(Part) + .Case("0x001", "a64fx") + .Default("generic"); } if (Implementer == "0x4e") { // NVIDIA Corporation - for (unsigned I = 0, E = Lines.size(); I != E; ++I) { - if (Lines[I].startswith("CPU part")) { - return StringSwitch(Lines[I].substr(8).ltrim("\t :")) - .Case("0x004", "carmel") - .Default("generic"); - } - } + return StringSwitch(Part) + .Case("0x004", "carmel") + .Default("generic"); } if (Implementer == "0x48") // HiSilicon Technologies, Inc. - // Look for the CPU part line. - for (unsigned I = 0, E = Lines.size(); I != E; ++I) - if (Lines[I].startswith("CPU part")) - // The CPU part is a 3 digit hexadecimal number with a 0x prefix. The - // values correspond to the "Part number" in the CP15/c0 register. The - // contents are specified in the various processor manuals. - return StringSwitch(Lines[I].substr(8).ltrim("\t :")) - .Case("0xd01", "tsv110") - .Default("generic"); + // The CPU part is a 3 digit hexadecimal number with a 0x prefix. The + // values correspond to the "Part number" in the CP15/c0 register. The + // contents are specified in the various processor manuals. + return StringSwitch(Part) + .Case("0xd01", "tsv110") + .Default("generic"); if (Implementer == "0x51") // Qualcomm Technologies, Inc. - // Look for the CPU part line. - for (unsigned I = 0, E = Lines.size(); I != E; ++I) - if (Lines[I].startswith("CPU part")) - // The CPU part is a 3 digit hexadecimal number with a 0x prefix. The - // values correspond to the "Part number" in the CP15/c0 register. The - // contents are specified in the various processor manuals. - return StringSwitch(Lines[I].substr(8).ltrim("\t :")) - .Case("0x06f", "krait") // APQ8064 - .Case("0x201", "kryo") - .Case("0x205", "kryo") - .Case("0x211", "kryo") - .Case("0x800", "cortex-a73") - .Case("0x801", "cortex-a73") - .Case("0x802", "cortex-a73") - .Case("0x803", "cortex-a73") - .Case("0x804", "cortex-a73") - .Case("0x805", "cortex-a73") - .Case("0xc00", "falkor") - .Case("0xc01", "saphira") - .Default("generic"); - + // The CPU part is a 3 digit hexadecimal number with a 0x prefix. The + // values correspond to the "Part number" in the CP15/c0 register. The + // contents are specified in the various processor manuals. + return StringSwitch(Part) + .Case("0x06f", "krait") // APQ8064 + .Case("0x201", "kryo") + .Case("0x205", "kryo") + .Case("0x211", "kryo") + .Case("0x800", "cortex-a73") // Kryo 2xx Gold + .Case("0x801", "cortex-a73") // Kryo 2xx Silver + .Case("0x802", "cortex-a75") // Kryo 3xx Gold + .Case("0x803", "cortex-a75") // Kryo 3xx Silver + .Case("0x804", "cortex-a76") // Kryo 4xx Gold + .Case("0x805", "cortex-a76") // Kryo 4xx/5xx Silver + .Case("0xc00", "falkor") + .Case("0xc01", "saphira") + .Default("generic"); if (Implementer == "0x53") { // Samsung Electronics Co., Ltd. // The Exynos chips have a convoluted ID scheme that doesn't seem to follow // any predictive pattern across variants and parts. diff --git a/llvm/unittests/Support/Host.cpp b/llvm/unittests/Support/Host.cpp index b452048..c85fd99 100644 --- a/llvm/unittests/Support/Host.cpp +++ b/llvm/unittests/Support/Host.cpp @@ -282,6 +282,32 @@ CPU revision : 0 )"; EXPECT_EQ(sys::detail::getHostCPUNameForARM(CarmelProcCpuInfo), "carmel"); + + // Snapdragon mixed implementer quirk + const std::string Snapdragon865ProcCPUInfo = R"( +processor : 0 +BogoMIPS : 38.40 +Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp +CPU implementer : 0x51 +CPU architecture: 8 +CPU variant : 0xd +CPU part : 0x805 +CPU revision : 14 +processor : 1 +processor : 2 +processor : 3 +processor : 4 +processor : 5 +processor : 6 +BogoMIPS : 38.40 +Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp +CPU implementer : 0x41 +CPU architecture: 8 +CPU variant : 0x1 +CPU part : 0xd0d +CPU revision : 0 +)"; + EXPECT_EQ(sys::detail::getHostCPUNameForARM(Snapdragon865ProcCPUInfo), "cortex-a77"); } #if defined(__APPLE__) || defined(_AIX) -- 2.7.4