This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Align BranchInfo and FuncBranchData in DataAggregator::recordTrace
ClosedPublic

Authored by Amir on May 27 2023, 9:24 AM.

Details

Summary

DataAggregator::recordTrace serves two purposes:

  • Attaching LBR fallthrough ("trace") information to CFG (getBranchInfo), which eventually gets emitted as YAML profile.
  • Populating vector of offsets that gets added to FuncBranchData, which eventually gets emitted as fdata profile.

recordTrace is invoked from getFallthroughsInTrace which checks its return
status and passes on the collected vector of offsets to doTrace.

However, if a malformed trace is passed to recordTrace it might partially
attach the profile to CFG and exit with false, not propagating the vector of
offsets to doTrace. This leads to a difference between fdata and yaml profile
collected from the same binary and the same perf file.

(Skylake LBR errata might produce such malformed traces where the last entry
is duplicated, resulting in invalid fallthrough path between the last two
entries).

There are two ways to handle this mismatch: conservative (aligned with fdata),
or aggressive (aligned with yaml). Conservative approach would discard the
trace entirely, buffering the CFG updates until all fallthroughs are confirmed.
Aggressive approach would apply CFG updates and return the matching
fallthroughs in the vector even if the trace is invalid (doesn't correspond to
a valid fallthrough path). I chose to go with the former (conservative/fdata)
approach which produces more accurate profile.

We can't rely on pre-filtering such traces early (in LBR sample processing) as
DataAggregator is used for both perf samples and pre-aggregated perf information
which loses branch stack information.

Test Plan: https://github.com/rafaelauler/bolt-tests/pull/22

Diff Detail

Event Timeline

Amir created this revision.May 27 2023, 9:24 AM
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Amir requested review of this revision.May 27 2023, 9:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 27 2023, 9:24 AM
Amir edited the summary of this revision. (Show Details)May 27 2023, 9:44 AM
rafauler accepted this revision.May 30 2023, 4:23 PM

LGTM with nits

bolt/lib/Profile/DataAggregator.cpp
902–903

Remove this check and assert at function start that Branches is never nullpr? Since now you're relying on branches being non-null..

This revision is now accepted and ready to land.May 30 2023, 4:23 PM
Amir updated this revision to Diff 526856.May 30 2023, 5:31 PM

Pass Branches by ref, clang-format

Amir marked an inline comment as done.May 30 2023, 5:32 PM