Clang Profile Guided Optimizations Support Sent In For Linux 5.14
Earlier this month I wrote about Clang PGO likely coming for Linux 5.14 and indeed the pull request was sent in on Monday. While GCC PGO for the Linux kernel was previously shot down, it looks like this new infrastructure will make it in for this new cycle.
This Clang PGO support for the kernel was worked on by Google engineers, similar to the many other LLVM/Clang build improvements for the Linux kernel. Compiler profile-guided optimizations (PGO) allows first building the software (in this case, the kernel) with profiling bits enabled so the developer/administrator can then run their desired workloads while generating a profile. A second build of the same software is then conducted afterwards while leveraging that profile data so the compiler can make more educated decisions in the name of achieving greater performance for the workloads targeted during that profile generation.
The Clang PGO infrastructure allows for raw profile data to be collected via /sys/kernel/debug/pgo/profraw. That raw profile data then needs to be processed using the llvm-profdata tool at which stage multiple profiles can also be merged. When rebuilding for the PGO-optimized kernel, the processed profile data can be passed back in via the compiler flags, such as make LLVM=1 KCFLAGS=-fprofile-use=vmlinux.profdata.
With the code submitted on Monday, the Clang PGO support is only for the main kernel image. Patches are still in the works for allowing individual kernel modules to utilize PGO.
Also sent in as part of Monday's pull was extending the Clang x86_64 LTO (Link Time Optimization) support merged the prior cycle to now also work for 32-bit x86 kernel builds.
More details on these LLVM/Clang compiler support improvements for Linux 5.14 via this PR.