<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/115333>115333</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AArch64] BOLT does not support SPE branch data
</td>
</tr>
<tr>
<th>Labels</th>
<td>
BOLT
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
paschalis-mpeis
</td>
</tr>
</table>
<pre>
## Purpose
In some upcoming Linux kernel release, perf will gain the ability to process additional branch entries of
Arm's Statistical Profiling Extension ([SPE](https://developer.arm.com/documentation/101136/22-1-3/MAP/Arm-Statistical-Profiling-Extension--SPE-)). ATM, those changes are part of [perf-tools-next](https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/log/?h=perf-tools-next).
The purpose of this issue is to raise awareness to the community that BOLT will need some changes to be able to take advantage of this additional information. Below, I briefly explain what this extra information is, how to check one is on the right version, and some pointers of how it may be used in the future.
## What extra branch information will be provided
With the upcoming update, perf will gain the ability to process [all sampled branches](https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=c1b67c85108f99af0a80aa9e59a2b94ad95428d7) and not just the branch misses. Each branch sample will be pointing to the [correct target](https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=19966d792b9e6b055aeb2f0e573b4d4573d5e15b) (ip → to_ip).
In short, with SPE one can get a statistical sample of the branches, where each event will have a Source and a Destination (fields ip → addr).
## Ensuring the updated perf version is used
Currently, one can use the updated perf by compiling [perf-tools-next](https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/log/?h=perf-tools-next).
The relevant patches are merged, which are: [#patch1](https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=19966d792b9e6b055aeb2f0e573b4d4573d5e15b), [#patch2](https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=c1b67c85108f99af0a80aa9e59a2b94ad95428d7), [#patch3](https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=edff8dad3f9a483259140fb814586b39da430a38), [#patch4](https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/?h=perf-tools-next&id=35f5aa9ccc83f4a4171cdb6ba023e514e2b2ecff).
A couple of checks need to be done:
1. Verify if the machine has SPE available. If not, enable SPE (see [guide](https://developer.arm.com/documentation/ka005362/1-0)).
2. Confirm perf is on the correct version and can process all branches. It should report 'branch' instead of 'branch-miss' events.
Both checks can be performed using:
```bash
perf record -e arm_spe/branch_filter=1/u 2>/dev/null -- ls . \
&& (perf script -F event,ip,addr 2> /dev/null | grep -v branch-miss -q \
&& echo "SUCCESS: perf can process all SPE branch samples" \
|| echo "FAILURE: perf cannot process all SPE branch samples") \
|| echo "FAILURE: SPE is not available"
```
## How the additional information may be used
There can be two approaches of supporting SPE in BOLT. Some relevant points of how this information may be aligned to existing BOLT infrastructure are discussed briefly below.
### Using the BasicAggregation format:
For this format, one could parse the source and destination branches and create two simple events. Those can then be processed by BOLT as normal, under the `-nl` flag. They will use an accurate sample of branch locations with hotness counts for the source and the destination blocks.
### Using the LBR format:
For this format, one could convert the source and destination branches into the LBR format. The trace will have a pretty shallow depth of 2, being: { 'destination', 'source' }, matching the expected branch history.
The `flags` field in `perf script` could be toggled on to distinguish between branch misses and hits. There seems to be no point in using the branch fall-through information, due to how SPE operates: in contrast with LBR, SPE is a non-contiguous statistical sampling. In other words, ignoring fall-throughs would be dropping information that BOLT cannot infer.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWM2O2zgSfhr2pSBDoizbOvTB7m5jG8hgG9OZneOAEksSJxSpJan-eftFkbLbTrKYmT0MskAQJxJZv19VfSXhveoN4i2rDqy6vxFzGKy7nYRvB6GVz8YJlb9prHy_ZbxkvISn2U3WI8vvW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