Commit 9d2993e8 authored by Daniel Kurtz's avatar Daniel Kurtz Committed by Commit Bot

Rename "IntelUarch" to the more generic "CpuUarch"

Currently the Microarchitecture table in cpu_identity only supports
Intel Microarchitectures.  In the future we will also want to support
AMD microarchitectures, so rename all of the "IntelUarch" to the more
generic "CpuUarch".

BUG=b:69376360
TEST=unit_tests --gtest_filter="CpuIdentityTest.*"
R=chongjiang@chromium.org, sque@chromium.org

Change-Id: I57a7df62f86abba5203ab685cde62ee73db3da42
Reviewed-on: https://chromium-review.googlesource.com/1006372
Commit-Queue: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: default avatarSimon Que <sque@chromium.org>
Cr-Commit-Position: refs/heads/master@{#554588}
parent 69c8ef95
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace internal { namespace internal {
const IntelUarchTableEntry kIntelUarchTable[] = { const CpuUarchTableEntry kCpuUarchTable[] = {
// These were found on various sources on the Internet. Main ones are: // These were found on various sources on the Internet. Main ones are:
// http://instlatx64.atw.hu/ for CPUID to model name and // http://instlatx64.atw.hu/ for CPUID to model name and
// http://www.cpu-world.com for model name to microarchitecture // http://www.cpu-world.com for model name to microarchitecture
...@@ -61,11 +61,11 @@ const IntelUarchTableEntry kIntelUarchTable[] = { ...@@ -61,11 +61,11 @@ const IntelUarchTableEntry kIntelUarchTable[] = {
{"0F_06", "Presler"}, {"0F_06", "Presler"},
}; };
const IntelUarchTableEntry* kIntelUarchTableEnd = const CpuUarchTableEntry* kCpuUarchTableEnd =
kIntelUarchTable + arraysize(kIntelUarchTable); kCpuUarchTable + arraysize(kCpuUarchTable);
bool IntelUarchTableCmp(const IntelUarchTableEntry& a, bool CpuUarchTableCmp(const CpuUarchTableEntry& a,
const IntelUarchTableEntry& b) { const CpuUarchTableEntry& b) {
return strcmp(a.family_model, b.family_model) < 0; return strcmp(a.family_model, b.family_model) < 0;
} }
...@@ -77,16 +77,16 @@ CPUIdentity::CPUIdentity(const CPUIdentity& other) = default; ...@@ -77,16 +77,16 @@ CPUIdentity::CPUIdentity(const CPUIdentity& other) = default;
CPUIdentity::~CPUIdentity() {} CPUIdentity::~CPUIdentity() {}
std::string GetIntelUarch(const CPUIdentity& cpuid) { std::string GetCpuUarch(const CPUIdentity& cpuid) {
if (cpuid.vendor != "GenuineIntel") if (cpuid.vendor != "GenuineIntel")
return std::string(); // Non-Intel return std::string(); // Non-Intel
std::string family_model = std::string family_model =
base::StringPrintf("%02X_%02X", cpuid.family, cpuid.model); base::StringPrintf("%02X_%02X", cpuid.family, cpuid.model);
const internal::IntelUarchTableEntry search_elem = {family_model.c_str(), ""}; const internal::CpuUarchTableEntry search_elem = {family_model.c_str(), ""};
auto* bound = std::lower_bound(internal::kIntelUarchTable, auto* bound = std::lower_bound(internal::kCpuUarchTable,
internal::kIntelUarchTableEnd, search_elem, internal::kCpuUarchTableEnd, search_elem,
internal::IntelUarchTableCmp); internal::CpuUarchTableCmp);
if (bound->family_model != family_model) if (bound->family_model != family_model)
return std::string(); // Unknown uarch return std::string(); // Unknown uarch
return bound->uarch; return bound->uarch;
......
...@@ -31,10 +31,10 @@ struct CPUIdentity { ...@@ -31,10 +31,10 @@ struct CPUIdentity {
// Get the CPUIdentity based on the actual system. // Get the CPUIdentity based on the actual system.
CPUIdentity GetCPUIdentity(); CPUIdentity GetCPUIdentity();
// Return the Intel microarchitecture based on the family and model derived // Return the CPU microarchitecture based on the family and model derived
// from |cpuid|, and kIntelUarchTable, or the empty string for non-Intel or // from |cpuid|, and kCpuUarchTable, or the empty string for non-Intel or
// unknown microarchitectures. // unknown microarchitectures.
std::string GetIntelUarch(const CPUIdentity& cpuid); std::string GetCpuUarch(const CPUIdentity& cpuid);
// Simplify a CPU model name. The rules are: // Simplify a CPU model name. The rules are:
// - Replace spaces with hyphens. // - Replace spaces with hyphens.
...@@ -46,16 +46,15 @@ namespace internal { ...@@ -46,16 +46,15 @@ namespace internal {
// Exposed for unit testing. // Exposed for unit testing.
struct IntelUarchTableEntry { struct CpuUarchTableEntry {
const char *family_model; const char *family_model;
const char *uarch; const char *uarch;
}; };
bool IntelUarchTableCmp(const IntelUarchTableEntry& a, bool CpuUarchTableCmp(const CpuUarchTableEntry& a, const CpuUarchTableEntry& b);
const IntelUarchTableEntry& b);
extern const IntelUarchTableEntry kIntelUarchTable[]; extern const CpuUarchTableEntry kCpuUarchTable[];
extern const IntelUarchTableEntry* kIntelUarchTableEnd; extern const CpuUarchTableEntry* kCpuUarchTableEnd;
} // namespace internal } // namespace internal
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
TEST(CpuIdentityTest, IntelUarchTableIsSorted) { TEST(CpuIdentityTest, CpuUarchTableIsSorted) {
EXPECT_TRUE(std::is_sorted( EXPECT_TRUE(std::is_sorted(
internal::kIntelUarchTable, internal::kCpuUarchTable,
internal::kIntelUarchTableEnd, internal::kCpuUarchTableEnd,
internal::IntelUarchTableCmp)); internal::CpuUarchTableCmp));
} }
TEST(CpuIdentityTest, DefaultCommandsBasedOnUarch_IvyBridge) { TEST(CpuIdentityTest, DefaultCommandsBasedOnUarch_IvyBridge) {
...@@ -24,7 +24,7 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnUarch_IvyBridge) { ...@@ -24,7 +24,7 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnUarch_IvyBridge) {
cpuid.family = 0x06; cpuid.family = 0x06;
cpuid.model = 0x3a; // IvyBridge cpuid.model = 0x3a; // IvyBridge
cpuid.model_name = ""; cpuid.model_name = "";
EXPECT_EQ("IvyBridge", GetIntelUarch(cpuid)); EXPECT_EQ("IvyBridge", GetCpuUarch(cpuid));
} }
TEST(CpuIdentityTest, DefaultCommandsBasedOnUarch_SandyBridge) { TEST(CpuIdentityTest, DefaultCommandsBasedOnUarch_SandyBridge) {
...@@ -34,7 +34,7 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnUarch_SandyBridge) { ...@@ -34,7 +34,7 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnUarch_SandyBridge) {
cpuid.family = 0x06; cpuid.family = 0x06;
cpuid.model = 0x2a; // SandyBridge cpuid.model = 0x2a; // SandyBridge
cpuid.model_name = ""; cpuid.model_name = "";
EXPECT_EQ("SandyBridge", GetIntelUarch(cpuid)); EXPECT_EQ("SandyBridge", GetCpuUarch(cpuid));
} }
TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_x86_32) { TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_x86_32) {
...@@ -44,7 +44,7 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_x86_32) { ...@@ -44,7 +44,7 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_x86_32) {
cpuid.family = 0x06; cpuid.family = 0x06;
cpuid.model = 0x2f; // Westmere cpuid.model = 0x2f; // Westmere
cpuid.model_name = ""; cpuid.model_name = "";
EXPECT_EQ("Westmere", GetIntelUarch(cpuid)); EXPECT_EQ("Westmere", GetCpuUarch(cpuid));
} }
TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_Unknown) { TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_Unknown) {
...@@ -54,7 +54,7 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_Unknown) { ...@@ -54,7 +54,7 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_Unknown) {
cpuid.family = 0; cpuid.family = 0;
cpuid.model = 0; cpuid.model = 0;
cpuid.model_name = ""; cpuid.model_name = "";
EXPECT_EQ("", GetIntelUarch(cpuid)); EXPECT_EQ("", GetCpuUarch(cpuid));
} }
TEST(CpuIdentityTest, SimplifyCPUModelName) { TEST(CpuIdentityTest, SimplifyCPUModelName) {
......
...@@ -203,21 +203,20 @@ const std::vector<RandomSelector::WeightAndValue> GetDefaultCommands_x86_64( ...@@ -203,21 +203,20 @@ const std::vector<RandomSelector::WeightAndValue> GetDefaultCommands_x86_64(
using WeightAndValue = RandomSelector::WeightAndValue; using WeightAndValue = RandomSelector::WeightAndValue;
std::vector<WeightAndValue> cmds; std::vector<WeightAndValue> cmds;
DCHECK_EQ(cpuid.arch, "x86_64"); DCHECK_EQ(cpuid.arch, "x86_64");
const std::string intel_uarch = GetIntelUarch(cpuid); const std::string cpu_uarch = GetCpuUarch(cpuid);
// Haswell and newer big Intel cores support LBR callstack profiling. This // Haswell and newer big Intel cores support LBR callstack profiling. This
// requires kernel support, which was added in kernel 4.4, and it was // requires kernel support, which was added in kernel 4.4, and it was
// backported to kernel 3.18. Prefer LBR callstack profiling where supported // backported to kernel 3.18. Prefer LBR callstack profiling where supported
// instead of FP callchains, because the former works with binaries compiled // instead of FP callchains, because the former works with binaries compiled
// with frame pointers disabled, such as the ARC runtime. // with frame pointers disabled, such as the ARC runtime.
const char *callgraph_cmd = kPerfRecordFPCallgraphCmd; const char *callgraph_cmd = kPerfRecordFPCallgraphCmd;
if (MicroarchitectureHasLBRCallgraph(intel_uarch) && if (MicroarchitectureHasLBRCallgraph(cpu_uarch) &&
KernelReleaseHasLBRCallgraph(cpuid.release)) { KernelReleaseHasLBRCallgraph(cpuid.release)) {
callgraph_cmd = kPerfRecordLBRCallgraphCmd; callgraph_cmd = kPerfRecordLBRCallgraphCmd;
} }
if (intel_uarch == "IvyBridge" || if (cpu_uarch == "IvyBridge" || cpu_uarch == "Haswell" ||
intel_uarch == "Haswell" || cpu_uarch == "Broadwell") {
intel_uarch == "Broadwell") {
cmds.push_back(WeightAndValue(45.0, kPerfRecordCyclesCmd)); cmds.push_back(WeightAndValue(45.0, kPerfRecordCyclesCmd));
cmds.push_back(WeightAndValue(20.0, callgraph_cmd)); cmds.push_back(WeightAndValue(20.0, callgraph_cmd));
cmds.push_back(WeightAndValue(15.0, kPerfRecordLBRCmd)); cmds.push_back(WeightAndValue(15.0, kPerfRecordLBRCmd));
...@@ -227,8 +226,8 @@ const std::vector<RandomSelector::WeightAndValue> GetDefaultCommands_x86_64( ...@@ -227,8 +226,8 @@ const std::vector<RandomSelector::WeightAndValue> GetDefaultCommands_x86_64(
cmds.push_back(WeightAndValue(5.0, kPerfRecordCacheMissesCmd)); cmds.push_back(WeightAndValue(5.0, kPerfRecordCacheMissesCmd));
return cmds; return cmds;
} }
if (intel_uarch == "SandyBridge" || intel_uarch == "Skylake" || if (cpu_uarch == "SandyBridge" || cpu_uarch == "Skylake" ||
intel_uarch == "Kabylake") { cpu_uarch == "Kabylake") {
cmds.push_back(WeightAndValue(50.0, kPerfRecordCyclesCmd)); cmds.push_back(WeightAndValue(50.0, kPerfRecordCyclesCmd));
cmds.push_back(WeightAndValue(20.0, callgraph_cmd)); cmds.push_back(WeightAndValue(20.0, callgraph_cmd));
cmds.push_back(WeightAndValue(15.0, kPerfRecordLBRCmd)); cmds.push_back(WeightAndValue(15.0, kPerfRecordLBRCmd));
...@@ -237,8 +236,8 @@ const std::vector<RandomSelector::WeightAndValue> GetDefaultCommands_x86_64( ...@@ -237,8 +236,8 @@ const std::vector<RandomSelector::WeightAndValue> GetDefaultCommands_x86_64(
cmds.push_back(WeightAndValue(5.0, kPerfRecordCacheMissesCmd)); cmds.push_back(WeightAndValue(5.0, kPerfRecordCacheMissesCmd));
return cmds; return cmds;
} }
if (intel_uarch == "Silvermont" || intel_uarch == "Airmont" || if (cpu_uarch == "Silvermont" || cpu_uarch == "Airmont" ||
intel_uarch == "Goldmont") { cpu_uarch == "Goldmont") {
cmds.push_back(WeightAndValue(50.0, kPerfRecordCyclesCmd)); cmds.push_back(WeightAndValue(50.0, kPerfRecordCyclesCmd));
cmds.push_back(WeightAndValue(20.0, callgraph_cmd)); cmds.push_back(WeightAndValue(20.0, callgraph_cmd));
cmds.push_back(WeightAndValue(15.0, kPerfRecordLBRCmdAtom)); cmds.push_back(WeightAndValue(15.0, kPerfRecordLBRCmdAtom));
...@@ -401,7 +400,7 @@ std::string FindBestCpuSpecifierFromParams( ...@@ -401,7 +400,7 @@ std::string FindBestCpuSpecifierFromParams(
}; };
MatchSpecificity match_level = NO_MATCH; MatchSpecificity match_level = NO_MATCH;
const std::string intel_uarch = GetIntelUarch(cpuid); const std::string cpu_uarch = GetCpuUarch(cpuid);
const std::string simplified_cpu_model = const std::string simplified_cpu_model =
SimplifyCPUModelName(cpuid.model_name); SimplifyCPUModelName(cpuid.model_name);
...@@ -420,8 +419,8 @@ std::string FindBestCpuSpecifierFromParams( ...@@ -420,8 +419,8 @@ std::string FindBestCpuSpecifierFromParams(
match_level = SYSTEM_ARCH; match_level = SYSTEM_ARCH;
ret = cpu_specifier; ret = cpu_specifier;
} }
if (match_level < CPU_UARCH && if (match_level < CPU_UARCH && !cpu_uarch.empty() &&
!intel_uarch.empty() && cpu_specifier == intel_uarch) { cpu_specifier == cpu_uarch) {
match_level = CPU_UARCH; match_level = CPU_UARCH;
ret = cpu_specifier; ret = cpu_specifier;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment