-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[BOLT] Delta-encode offsets in BAT #76900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aaupov
merged 12 commits into
main
from
users/aaupov/spr/bolt-delta-encode-offsets-in-bat
Jan 11, 2024
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
70f16bc
[𝘀𝗽𝗿] changes to main this commit is based on
aaupov 274a3fc
[𝘀𝗽𝗿] initial version
aaupov 69adc82
[𝘀𝗽𝗿] changes introduced through rebase
aaupov 9fbaf3e
Updated BAT.md
aaupov 1be1ef6
[𝘀𝗽𝗿] changes introduced through rebase
aaupov 1e952a1
rebase
aaupov 05edcb0
[𝘀𝗽𝗿] changes introduced through rebase
aaupov dc37143
rebase
aaupov 275e479
[𝘀𝗽𝗿] changes introduced through rebase
aaupov f6160f6
rebase
aaupov b3eb819
[𝘀𝗽𝗿] changes introduced through rebase
kazutakahirata df874e3
Rename Input/OutputAddr to Offset in BAT.md
aaupov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# BOLT Address Translation (BAT) | ||
# Purpose | ||
A regular profile collection for BOLT involves collecting samples from | ||
unoptimized binary. BOLT Address Translation allows collecting profile | ||
from BOLT-optimized binary and using it for optimizing the input (pre-BOLT) | ||
binary. | ||
|
||
# Overview | ||
BOLT Address Translation is an extra section (`.note.bolt_bat`) inserted by BOLT | ||
into the output binary containing translation tables and split functions linkage | ||
information. This information enables mapping the profile back from optimized | ||
binary onto the original binary. | ||
|
||
# Usage | ||
`--enable-bat` flag controls the generation of BAT section. Sampled profile | ||
needs to be passed along with the optimized binary containing BAT section to | ||
`perf2bolt` which reads BAT section and produces fdata profile for the original | ||
binary. Note that YAML profile generation is not supported since BAT doesn't | ||
contain the metadata for input functions. | ||
|
||
# Internals | ||
## Section contents | ||
The section is organized as follows: | ||
- Functions table | ||
- Address translation tables | ||
- Fragment linkage table | ||
|
||
## Construction and parsing | ||
BAT section is created from `BoltAddressTranslation` class which captures | ||
address translation information provided by BOLT linker. It is then encoded as a | ||
note section in the output binary. | ||
|
||
During profile conversion when BAT-enabled binary is passed to perf2bolt, | ||
`BoltAddressTranslation` class is populated from BAT section. The class is then | ||
queried by `DataAggregator` during sample processing to reconstruct addresses/ | ||
offsets in the input binary. | ||
|
||
## Encoding format | ||
The encoding is specified in | ||
[BoltAddressTranslation.h](/bolt/include/bolt/Profile/BoltAddressTranslation.h) | ||
and [BoltAddressTranslation.cpp](/bolt/lib/Profile/BoltAddressTranslation.cpp). | ||
|
||
### Layout | ||
The general layout is as follows: | ||
``` | ||
Functions table header | ||
|------------------| | ||
| Function entry | | ||
| |--------------| | | ||
| | OutOff InOff | | | ||
| |--------------| | | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Fragment linkage header | ||
|------------------| | ||
| ColdAddr HotAddr | | ||
~~~~~~~~~~~~~~~~~~~~ | ||
``` | ||
|
||
### Functions table | ||
Header: | ||
| Entry | Encoding | Description | | ||
| ------ | ----- | ----------- | | ||
| `NumFuncs` | ULEB128 | Number of functions in the functions table | | ||
|
||
The header is followed by Functions table with `NumFuncs` entries. | ||
| Entry | Encoding | Description | | ||
| ------ | ------| ----------- | | ||
| `Address` | ULEB128 | Function address in the output binary | | ||
| `NumEntries` | ULEB128 | Number of address translation entries for a function | | ||
|
||
Function header is followed by `NumEntries` pairs of offsets for current | ||
function. | ||
|
||
### Address translation table | ||
Delta encoding means that only the difference with the previous corresponding | ||
entry is encoded. Offsets implicitly start at zero. | ||
| Entry | Encoding | Description | | ||
| ------ | ------| ----------- | | ||
| `OutputAddr` | Delta, ULEB128 | Function offset in output binary | | ||
| `InputAddr` | Delta, SLEB128 | Function offset in input binary with `BRANCHENTRY` LSB bit | | ||
|
||
`BRANCHENTRY` bit denotes whether a given offset pair is a control flow source | ||
(branch or call instruction). If not set, it signifies a control flow target | ||
(basic block offset). | ||
|
||
### Fragment linkage table | ||
Following Functions table, fragment linkage table is encoded to link split | ||
cold fragments with main (hot) fragment. | ||
Header: | ||
| Entry | Encoding | Description | | ||
| ------ | ------------ | ----------- | | ||
| `NumColdEntries` | ULEB128 | Number of split functions in the functions table | | ||
|
||
`NumColdEntries` pairs of addresses follow: | ||
| Entry | Encoding | Description | | ||
| ------ | ------| ----------- | | ||
| `ColdAddress` | ULEB128 | Cold fragment address in output binary | | ||
| `HotAddress` | ULEB128 | Hot fragment address in output binary | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.