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