[PATCH] D109637: [llvm-profgen] Ignore broken LBR samples
Hongtao Yu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 10 16:37:24 PDT 2021
hoy created this revision.
Herald added subscribers: modimo, wenlei.
hoy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Perf script can sometimes give disordered LBR samples like below.
b022500
32de0044
3386e1d1
7f118e05720c
7f118df2d81f
0x2a0b9622/0x2a0b9610/P/-/-/1 0x2a0b79ff/0x2a0b9618/P/-/-/2 0x2a0b7a4a/0x2a0b79e8/P/-/-/1 0x2a0b7a33/0x2a0b7a46/P/-/-/1 0x2a0b7a42/0x2a0b7a23/P/-/-/1 0x2a0b7a21/0x2a0b7a37/P/-/-/2 0x2a0b79e6/0x2a0b7a07/P/-/-/1 0x2a0b79d4/0x2a0b79dc/P/-/-/2 0x2a0b7a03/0x2a0b79aa/P/-/-/1 0x2a0b79a8/0x2a0b7a00/P/-/-/234 0x2a0b9613/0x2a0b7930/P/-/-/1 0x2a0b9622/0x2a0b9610/P/-/-/1 0x2a0b79ff/0x2a0b9618/P/-/-/2 0x2a0b7a4a/0x2aWarning:
Processed 10263226 events and lost 1 chunks!
Note that the last LBR record 0x2a0b7a4a/0x2aWarning: . Currently llvm-profgen does not detect that and as a result an uninitialized branch target value will be used. The uninitialized value can cause creepy instruction ranges created which which in turn will result in a completely wrong profile. An example is like
.... @ _ZN5folly13loadUnalignedIsEET_PKv]:18446744073709551615:18446744073709551615
1: 18446744073709551615
!CFGChecksum: 4294967295
!Attributes: 0
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109637
Files:
llvm/tools/llvm-profgen/PerfReader.cpp
llvm/tools/llvm-profgen/PerfReader.h
llvm/tools/llvm-profgen/ProfileGenerator.cpp
Index: llvm/tools/llvm-profgen/ProfileGenerator.cpp
===================================================================
--- llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -183,6 +183,7 @@
for (auto Item : Ranges) {
uint64_t Begin = Item.first.first;
uint64_t End = Item.first.second;
+ assert(Begin <= End && "invalid instruction range");
uint64_t Count = Item.second;
if (Boundaries.find(Begin) == Boundaries.end())
Boundaries[Begin] = BoundaryPoint();
@@ -194,7 +195,7 @@
}
uint64_t BeginAddress = UINT64_MAX;
- int Count = 0;
+ uint64_t Count = 0;
for (auto Item : Boundaries) {
uint64_t Address = Item.first;
BoundaryPoint &Point = Item.second;
@@ -208,6 +209,7 @@
assert((BeginAddress != UINT64_MAX) &&
"First boundary point cannot be 'end' point");
DisjointRanges[{BeginAddress, Address}] = Count;
+ assert(Count >= Point.EndCount && "mismatched live ranges");
Count -= Point.EndCount;
BeginAddress = Address + 1;
}
Index: llvm/tools/llvm-profgen/PerfReader.h
===================================================================
--- llvm/tools/llvm-profgen/PerfReader.h
+++ llvm/tools/llvm-profgen/PerfReader.h
@@ -373,6 +373,7 @@
BranchSample BranchCounter;
void recordRangeCount(uint64_t Start, uint64_t End, uint64_t Repeat) {
+ assert(Start <= End && "invalid instruction range");
RangeCounter[{Start, End}] += Repeat;
}
void recordBranchCount(uint64_t Source, uint64_t Target, uint64_t Repeat) {
Index: llvm/tools/llvm-profgen/PerfReader.cpp
===================================================================
--- llvm/tools/llvm-profgen/PerfReader.cpp
+++ llvm/tools/llvm-profgen/PerfReader.cpp
@@ -422,8 +422,11 @@
Token.split(Addresses, "/");
uint64_t Src;
uint64_t Dst;
- Addresses[0].substr(2).getAsInteger(16, Src);
- Addresses[1].substr(2).getAsInteger(16, Dst);
+
+ // Stop at broken LBR records.
+ if (Addresses[0].substr(2).getAsInteger(16, Src) ||
+ Addresses[1].substr(2).getAsInteger(16, Dst))
+ break;
bool SrcIsInternal = Binary->addressIsCode(Src);
bool DstIsInternal = Binary->addressIsCode(Dst);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109637.372033.patch
Type: text/x-patch
Size: 2255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210910/d0ec07b6/attachment.bin>
More information about the llvm-commits
mailing list