create_llvm_prof: "Bogus LBR data" errors with AMD Zen4 LBRv2 kernel profiling
- Dominant language
- C++
- Stars
- 619
- Forks
- 127
- PR merge metrics
- No merged PRs in 30d
Description
## Description
I'm attempting to use AutoFDO for kernel profiling on an AMD Zen4 processor (Ryzen 9 7950X) but `create_llvm_prof` v0.30.1 is producing empty profiles with numerous "Bogus LBR data" warnings.
## Environment
- **CPU**: AMD Ryzen 9 7950X (Zen4 with `amd_lbr_v2` flag)
- **Kernel**: 6.17.7 with `CONFIG_AUTOFDO_CLANG=y`, `CONFIG_PERF_EVENTS_AMD_BRS=y`
- **LLVM**: 21.1.5
- **create_llvm_prof**: v0.30.1 (latest release)
- **OS**: Arch Linux (CachyOS)
## Profiling Command
```bash
sudo perf record --pfm-events RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a -N -b -c 500009 -m 512 -o kernel.data -- sleep 600
```
## Perf Data Quality
The captured perf data appears valid:
- 36,791 samples captured
- No lost samples
- Symbols resolve correctly in `perf report`
- Shows kernel functions like `psi_group_change`, `tcp_sendmsg_locked`, `link_path_walk`
Example `perf report` output:
```
# Samples: 36K of event 'RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k'
# Event count (approx.): 587595
#
# Overhead Samples Command Source Symbol Target Symbol
# ........ ............ ............... ............................... ...............................
#
1.75% 10274 swapper [k] psi_group_change [k] psi_group_change
1.10% 6438 tokio-runtime-w [k] tcp_sendmsg_locked [k] tcp_sendmsg_locked
1.07% 6306 tokio-runtime-w [k] psi_group_change [k] psi_group_change
0.63% 3688 tokio-runtime-w [k] link_path_walk [k] link_path_walk
```
## create_llvm_prof Command & Output
```bash
create_llvm_prof --binary=/usr/lib/modules/6.17.7-2-cachyos-lto/build/vmlinux \
--profile=kernel.data --format=extbinary --out=kernel.afdo
```
**Results:**
- 220+ warnings: `Bogus LBR data (range is too large)`
- Final warning: `Got an empty profile map. The output file might still be not empty (e.g., containing symbol list in binary format) but might be not helpful as a profile`
- Output file: 330 bytes (essentially empty)
**Sample Warnings:**
```
[WARNING:/home/runner/work/autofdo/autofdo/third_party/perf_data_converter/src/quipper/perf_reader.cc:1322] Skipping 268 bytes of metadata: HEADER_CPU_TOPOLOGY
[WARNING:/home/runner/work/autofdo/autofdo/third_party/perf_data_converter/src/quipper/perf_reader.cc:1069] Skipping unsupported event PERF_RECORD_ID_INDEX
[INFO:/home/runner/work/autofdo/autofdo/third_party/perf_data_converter/src/quipper/perf_reader.cc:1060] Number of events stored: 38715
[INFO:/home/runner/work/autofdo/autofdo/third_party/perf_data_converter/src/quipper/perf_parser.cc:272] Parser processed: 741 MMAP/MMAP2 events, 620 COMM events, 475 FORK events, 28 EXIT events, 36791 SAMPLE events, 36755 of these were mapped
WARNING: Logging before InitGoogleLogging() is written to STDERR
W20251108 06:31:36.290036 3368 sample_reader.cc:345] Bogus LBR data (range is too large): 1bc->13c139 index=5
W20251108 06:31:36.290303 3368 sample_reader.cc:345] Bogus LBR data (range is too large): 1bc->133e4c index=1
W20251108 06:31:36.290390 3368 sample_reader.cc:345] Bogus LBR data (range is too large): 1bc->133e4c index=2
W20251108 06:31:36.290395 3368 sample_reader.cc:345] Bogus LBR data (range is too large): 1bc->133e4c index=1
[... 220+ similar warnings ...]
I20251108 06:31:36.370162 3368 symbol_map.cc:459] Binary=/usr/lib/modules/6.17.7-2-cachyos-lto/build/vmlinux is considered as a kernel image
I20251108 06:31:36.370239 3368 symbol_map.cc:477] Adding loadable exec segment: offset=0 vaddr=ffffffff81000000
W20251108 06:31:36.647958 3368 llvm_profile_writer.cc:50] Got an empty profile map. The output file might still be not empty (e.g., containing symbol list in binary format) but might be not helpful as a profile
```
## Also Tested
1. **llvm-profgen (LLVM 21.1.5)**: Fails with different error
```bash
llvm-profgen --binary=/usr/lib/modules/6.17.7-2-cachyos-lto/build/vmlinux \
--perfdata=kernel.data -o kernel.afdo
```
Output: `llvm-profgen: error: No relevant mmap event is found in perf data.`
2. **Without `-N` flag**: Same "Bogus LBR data" errors
3. **Different security settings**: Tested with `kptr_restrict=0` and `perf_event_paranoid=-1`
## CPU Information
```bash
$ cat /proc/cpuinfo | grep "model name" | head -n1
model name : AMD Ryzen 9 7950X 16-Core Processor
$ cat /proc/cpuinfo | grep flags | head -n1 | grep -o "amd_lbr[^ ]*\|ibs"
amd_lbr_v2
ibs
amd_lbr_pmc_freeze
$ cat /proc/config.gz | zgrep AMD_BRS
CONFIG_PERF_EVENTS_AMD_BRS=y
```
## Question
Is AMD Zen4 LBRv2 currently supported for kernel profiling with `create_llvm_prof`?
The tool appears designed primarily for userspace profiling. Documentation mentions testing on:
- Intel Skylake (with LBR)
- AMD Zen3 (with BRS)
But doesn't explicitly cover Zen4 LBRv2 for kernel profiling.
**Related:** Issue #144 shows similar kernel profiling problems (though with different error: "use_lbr was enabled but range_count_map was empty"). That issue from 2022 is still open, suggesting kernel AutoFDO profiling has ongoing challenges across platforms.
If Zen4 LBRv2 kernel profiling is not currently supported, is this a planned feature? Any workarounds would be appreciated.
## Additional Context
- Userspace profiling with `create_llvm_prof` works fine on this CPU
- The workflow follows the CachyOS kernel AutoFDO blog post (https://cachyos.org/blog/2411-kernel-autofdo/)
- The kernel was built specifically for AutoFDO profiling with proper configuration
- Same workflow reportedly succeeds on Intel processors
Contributor guide
Assessment
This issue has not been assessed yet.