Skip to content

Commit d7d44df

Browse files
committed
Address reviewers 2
1 parent b1516a9 commit d7d44df

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",
@@ -1008,7 +1009,8 @@ ErrorOr<LBREntry> DataAggregator::parseLBREntry() {
10081009
if (std::error_code EC = MispredStrRes.getError())
10091010
return EC;
10101011
StringRef MispredStr = MispredStrRes.get();
1011-
// SPE brstack mispredicted flags might be two characters long: 'PN' or 'MN'.
1012+
// SPE brstack mispredicted flags might be up to two characters long:
1013+
// 'PN' or 'MN'. Where 'N' optionally appears.
10121014
bool ValidStrSize = opts::ArmSPE
10131015
? MispredStr.size() >= 1 && MispredStr.size() <= 2
10141016
: MispredStr.size() == 1;
@@ -1537,7 +1539,7 @@ void DataAggregator::printBranchStacksDiagnostics(
15371539
std::error_code DataAggregator::parseBranchEvents() {
15381540
std::string BranchEventTypeStr =
15391541
!opts::ArmSPE ? "branch events" : "SPE branch events in LBR-format";
1540-
outs() << "PERF2BOLT: " << BranchEventTypeStr << "...\n";
1542+
outs() << "PERF2BOLT: parse " << BranchEventTypeStr << "...\n";
15411543
NamedRegionTimer T("parseBranch", "Parsing " + BranchEventTypeStr,
15421544
TimerGroupName, TimerGroupDesc, opts::TimeAggregator);
15431545

@@ -1594,8 +1596,11 @@ std::error_code DataAggregator::parseBranchEvents() {
15941596
else
15951597
errs()
15961598
<< "PERF2BOLT-WARNING: all recorded samples for this binary lack "
1597-
"SPE brstack entries. Record profile with:"
1598-
"perf record arm_spe_0/branch_filter=1/";
1599+
"SPE brstack entries. The minimum required version of "
1600+
"Linux-perf is v6.14 or higher for brstack support. "
1601+
"With an older Linux-perf you may get zero samples. "
1602+
"Plese also make sure about you recorded profile with: "
1603+
"perf record -e 'arm_spe_0/branch_filter=1/'.";
15991604
} else {
16001605
printBranchStacksDiagnostics(NumTotalSamples - NumSamples);
16011606
}

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
@@ -71,13 +71,13 @@ struct PerfSpeEventsTestHelper : public testing::Test {
7171
std::unique_ptr<ObjectFile> ObjFile;
7272
std::unique_ptr<BinaryContext> BC;
7373

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

80-
/// Parse and check SPE brstack as LBR
80+
// Parse and check SPE brstack as LBR.
8181
void parseAndCheckBrstackEvents(
8282
uint64_t PID,
8383
const std::vector<SmallVector<LBREntry, 2>> &ExpectedSamples) {
@@ -100,12 +100,9 @@ struct PerfSpeEventsTestHelper : public testing::Test {
100100
EXPECT_EQ(Sample.LBR.size(), ExpectedSamples[NumSamples].size());
101101

102102
// Check the parsed LBREntries.
103-
const auto *ActualIter = Sample.LBR.begin();
104-
const auto *ExpectIter = ExpectedSamples[NumSamples].begin();
105-
while (ActualIter != Sample.LBR.end() &&
106-
ExpectIter != ExpectedSamples[NumSamples].end())
107-
EXPECT_TRUE(checkLBREntry(*ActualIter++, *ExpectIter++));
108-
103+
for (auto [Actual, Expected] :
104+
zip_equal(Sample.LBR, ExpectedSamples[NumSamples]))
105+
EXPECT_TRUE(checkLBREntry(Actual, Expected));
109106
++NumSamples;
110107
}
111108
}
@@ -133,7 +130,7 @@ TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstack) {
133130
" 1234 0xe001/0xe002/P/-/-/14/RET/-\n"
134131
" 1234 0xf001/0xf002/MN/-/-/8/COND/-\n";
135132

136-
std::vector<SmallVector<LBREntry, 2>> ExpectedSamples = {
133+
std::vector<SmallVector<LBREntry>> ExpectedSamples = {
137134
{{{0xa001, 0xa002, false}}}, {{{0xb001, 0xb002, false}}},
138135
{{{0xc001, 0xc002, false}}}, {{{0xd001, 0xd002, true}}},
139136
{{{0xe001, 0xe002, false}}}, {{{0xf001, 0xf002, true}}},

0 commit comments

Comments
 (0)