[BOLT] Ignore LBR from kernel interrupts

Summary: This change adds a switch (`ignore-interrupt-lbr`) to ignores LBR from perf input that is result of kernel interrupts. These asynchronous flow of user/kernel transition will make BOLT think that profile is stale, thus bailout optimization for functions. Ideally, user mode filter need to be set for `perf record` so we don't have asynchronous LBRs. However these are identifiable as kernel address space is known, so we can ignore any LBRs that come from or go into kernel addresses during aggregation. This is under a switch and off by default in case we need to BOLT kernel module.

(cherry picked from FBD17170107)
This commit is contained in:
Wenlei He 2019-09-03 10:01:26 -07:00 committed by Maksim Panchenko
parent cc4b2fb614
commit 8cd1ba599b
2 changed files with 21 additions and 0 deletions

View File

@ -110,6 +110,13 @@ WriteAutoFDOData("autofdo",
cl::ZeroOrMore,
cl::cat(AggregatorCategory));
static cl::opt<bool>
IgnoreInterruptLBR("ignore-interrupt-lbr",
cl::desc("Ignore kernel interrupt LBR that happens asynchronously"),
cl::init(false),
cl::ZeroOrMore,
cl::cat(AggregatorCategory));
}
namespace {
@ -898,6 +905,8 @@ ErrorOr<DataAggregator::PerfBranchSample> DataAggregator::parseBranchSample() {
if (std::error_code EC = LBRRes.getError())
return EC;
auto LBR = LBRRes.get();
if (ignoreKernelInterrupt(LBR))
continue;
if (!BC->HasFixedLoadAddress)
adjustLBR(LBR, MMapInfoIter->second);
Res.LBR.push_back(LBR);
@ -1081,6 +1090,11 @@ bool DataAggregator::hasData() {
return true;
}
bool DataAggregator::ignoreKernelInterrupt(LBREntry &LBR) const {
return opts::IgnoreInterruptLBR &&
(LBR.From >= KernelBaseAddr || LBR.To >= KernelBaseAddr);
}
std::error_code DataAggregator::printLBRHeatMap() {
outs() << "PERF2BOLT: parse branch events...\n";
NamedRegionTimer T("parseBranch", "Parsing branch events", TimerGroupName,

View File

@ -136,6 +136,10 @@ class DataAggregator : public DataReader {
PerfProcessInfo MMapEventsPPI;
PerfProcessInfo TaskEventsPPI;
/// Kernel VM starts at fixed based address
/// https://www.kernel.org/doc/Documentation/x86/x86_64/mm.txt
static constexpr uint64_t KernelBaseAddr = 0xffff800000000000;
/// Current list of created temporary files
std::vector<std::string> TempFiles;
@ -389,6 +393,9 @@ class DataAggregator : public DataReader {
adjustAddress(LBR.To, MMI);
}
/// Ignore kernel/user transition LBR if requested
bool ignoreKernelInterrupt(LBREntry &LBR) const;
public:
DataAggregator(raw_ostream &Diag, StringRef BinaryName)
: DataReader(Diag), BinaryName(llvm::sys::path::filename(BinaryName)) {}