Skip to content

Commit b703629

Browse files
committed
Address reviewers 2
1 parent b526d2b commit b703629

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ static cl::opt<bool>
4949
cl::desc("aggregate basic samples (without LBR info)"),
5050
cl::cat(AggregatorCategory));
5151

52-
cl::opt<bool> ArmSPE("spe",
53-
cl::desc("Enable Arm SPE mode. Can combine with `--nl` "
54-
"to use in no-lbr mode"),
52+
cl::opt<bool> ArmSPE("spe", cl::desc("Enable Arm SPE mode."),
5553
cl::cat(AggregatorCategory));
5654

5755
static cl::opt<std::string>
@@ -181,7 +179,10 @@ void DataAggregator::start() {
181179
findPerfExecutable();
182180

183181
if (opts::ArmSPE) {
184-
// pid from_ip to_ip predicted/missed not-taken?
182+
// pid from_ip to_ip flags
183+
// where flags could be:
184+
// P/M: whether branch was Predicted or Mispredicted.
185+
// N: optionally appears when the branch was Not-Taken (ie fall-through)
185186
// 12345 0x123/0x456/PN/-/-/8/RET/-
186187
launchPerfProcess("SPE brstack events", MainEventsPPI,
187188
"script -F pid,brstack --itrace=bl",
@@ -1012,7 +1013,8 @@ ErrorOr<DataAggregator::LBREntry> DataAggregator::parseLBREntry() {
10121013
if (std::error_code EC = MispredStrRes.getError())
10131014
return EC;
10141015
StringRef MispredStr = MispredStrRes.get();
1015-
// SPE brstack mispredicted flags might be two characters long: 'PN' or 'MN'.
1016+
// SPE brstack mispredicted flags might be up to two characters long:
1017+
// 'PN' or 'MN'. Where 'N' optionally appears.
10161018
bool ValidStrSize = opts::ArmSPE
10171019
? MispredStr.size() >= 1 && MispredStr.size() <= 2
10181020
: MispredStr.size() == 1;
@@ -1542,7 +1544,7 @@ void DataAggregator::printBranchStacksDiagnostics(
15421544
std::error_code DataAggregator::parseBranchEvents() {
15431545
std::string BranchEventTypeStr =
15441546
!opts::ArmSPE ? "branch events" : "SPE branch events in LBR-format";
1545-
outs() << "PERF2BOLT: " << BranchEventTypeStr << "...\n";
1547+
outs() << "PERF2BOLT: parse " << BranchEventTypeStr << "...\n";
15461548
NamedRegionTimer T("parseBranch", "Parsing " + BranchEventTypeStr,
15471549
TimerGroupName, TimerGroupDesc, opts::TimeAggregator);
15481550

@@ -1599,8 +1601,11 @@ std::error_code DataAggregator::parseBranchEvents() {
15991601
else
16001602
errs()
16011603
<< "PERF2BOLT-WARNING: all recorded samples for this binary lack "
1602-
"SPE brstack entries. Record profile with:"
1603-
"perf record arm_spe_0/branch_filter=1/";
1604+
"SPE brstack entries. The minimum required version of "
1605+
"Linux-perf is v6.14 or higher for brstack support. "
1606+
"With an older Linux-perf you may get zero samples. "
1607+
"Plese also make sure about you recorded profile with: "
1608+
"perf record -e 'arm_spe_0/branch_filter=1/'.";
16041609
} else {
16051610
printBranchStacksDiagnostics(NumTotalSamples - NumSamples);
16061611
}

bolt/test/perf2bolt/AArch64/perf2bolt-spe.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
REQUIRES: system-linux,perf,target=aarch64{{.*}}
44

5+
RUN: %clang %cflags %p/../../Inputs/asm_foo.s %p/../../Inputs/asm_main.c -o %t.exe
6+
57
RUN: perf record -e cycles -q -o %t.perf.data -- %t.exe 2> /dev/null
68

79
RUN: (perf2bolt -p %t.perf.data -o %t.perf.boltdata --spe %t.exe 2> /dev/null; exit 0) | FileCheck %s --check-prefix=CHECK-SPE-LBR

bolt/test/perf2bolt/X86/perf2bolt-spe.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ REQUIRES: system-linux,x86_64-linux
44

55
RUN: %clang %cflags %p/../../Inputs/asm_foo.s %p/../../Inputs/asm_main.c -o %t.exe
66
RUN: touch %t.empty.perf.data
7-
RUN: not perf2bolt -p %t.empty.perf.data -o %t.perf.boltdata --nl --spe --pa %t.exe 2>&1 | FileCheck %s
7+
RUN: not perf2bolt -p %t.empty.perf.data -o %t.perf.boltdata --spe --pa %t.exe 2>&1 | FileCheck %s
88

99
CHECK: perf2bolt: -spe is available only on AArch64.

bolt/unittests/Profile/PerfSpeEvents.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ struct PerfSpeEventsTestHelper : public testing::Test {
7373
std::unique_ptr<ObjectFile> ObjFile;
7474
std::unique_ptr<BinaryContext> BC;
7575

76-
/// Compare LBREntries
76+
// @return true if LBREntries are equal.
7777
bool checkLBREntry(const LBREntry &Lhs, const LBREntry &Rhs) {
7878
return Lhs.From == Rhs.From && Lhs.To == Rhs.To &&
7979
Lhs.Mispred == Rhs.Mispred;
8080
}
8181

82-
/// Parse and check SPE brstack as LBR
82+
// Parse and check SPE brstack as LBR.
8383
void parseAndCheckBrstackEvents(
8484
uint64_t PID,
8585
const std::vector<SmallVector<LBREntry, 2>> &ExpectedSamples) {
@@ -102,12 +102,9 @@ struct PerfSpeEventsTestHelper : public testing::Test {
102102
EXPECT_EQ(Sample.LBR.size(), ExpectedSamples[NumSamples].size());
103103

104104
// Check the parsed LBREntries.
105-
const auto *ActualIter = Sample.LBR.begin();
106-
const auto *ExpectIter = ExpectedSamples[NumSamples].begin();
107-
while (ActualIter != Sample.LBR.end() &&
108-
ExpectIter != ExpectedSamples[NumSamples].end())
109-
EXPECT_TRUE(checkLBREntry(*ActualIter++, *ExpectIter++));
110-
105+
for (auto [Actual, Expected] :
106+
zip_equal(Sample.LBR, ExpectedSamples[NumSamples]))
107+
EXPECT_TRUE(checkLBREntry(Actual, Expected));
111108
++NumSamples;
112109
}
113110
}
@@ -135,7 +132,7 @@ TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstack) {
135132
" 1234 0xe001/0xe002/P/-/-/14/RET/-\n"
136133
" 1234 0xf001/0xf002/MN/-/-/8/COND/-\n";
137134

138-
std::vector<SmallVector<LBREntry, 2>> ExpectedSamples = {
135+
std::vector<SmallVector<LBREntry>> ExpectedSamples = {
139136
{{{0xa001, 0xa002, false}}}, {{{0xb001, 0xb002, false}}},
140137
{{{0xc001, 0xc002, false}}}, {{{0xd001, 0xd002, true}}},
141138
{{{0xe001, 0xe002, false}}}, {{{0xf001, 0xf002, true}}},

0 commit comments

Comments
 (0)