Skip to content

Commit

Permalink
linux-cachyos: AutoFDO Integration
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Jung <[email protected]>
  • Loading branch information
ptr1337 committed Nov 5, 2024
1 parent b00fa51 commit 16574ec
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions linux-cachyos/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,22 @@ _build_nvidia_open=${_build_nvidia_open-}
# Build a debug package with non-stripped vmlinux
_build_debug=${_build_debug-}

if [[ "$_use_llvm_lto" = "thin" || "$_use_llvm_lto" = "full" ]] && [ "$_use_lto_suffix" = "y" ]; then
_pkgsuffix=cachyos-lto
elif [ "$_use_llvm_lto" = "none" ] && [ -z "$_use_kcfi" ] && [ "$_use_gcc_suffix" = "y" ]; then
_pkgsuffix=cachyos-gcc
else
_pkgsuffix=cachyos
fi

# Enable AUTOFDO_CLANG for the first compilation to create a kernel, which can be used for profiling
# This only works for Clang compiled kernels, therefore thin or full lto needs to be set in _use_llvm_lto
# Workflow:
# https://cachyos.org/blog/2411-kernel-autofdo/
# 1. Compile Kernel with _autofdo=y
# 2. Boot the kernel in QEMU or on your system, see Workload
# 3. Profile the kernel and convert the profile, see Generating the Profile for AutoFDO
# 4. Put the profile into the sourcedir and name the profile "perf.afdo"
# 5. Enable _autofdo_use
_autfodo=${_autofdo-}

# Enable after you have put the profile into the sourcedir
_autofdo_use=${_autofdo_use-}

# Dropping checks, because AutoFDO only works for Clang compiled kernels
_pkgsuffix=cachyos-autofdo
pkgbase="linux-$_pkgsuffix"
_major=6.11
_minor=6
Expand Down Expand Up @@ -466,6 +474,12 @@ prepare() {

echo "Selecting '$_hugepage' TRANSPARENT_HUGEPAGE config..."

# Enable Clang AutoFDO
# Add additonal check if Thin or Full LTO is enabled otherwise die
if [ "$autofdo" ] || [ "$autofdo_use" ]; then
scripts/config -e AUTOFDO_CLANG
fi

echo "Enable USER_NS_UNPRIVILEGED"
scripts/config -e USER_NS

Expand Down Expand Up @@ -546,7 +560,16 @@ prepare() {

build() {
cd "$_srcname"
make "${BUILD_FLAGS[@]}" -j"$(nproc)" all

# Use AutoFDO Profile named perf.afdo
# Maybe we can find a way to make this dyamic, but for now keep it hardcoded
# As soon LLVM 19 is in arch repository, we can also think about Propellor
if [ -n "$autofdo_use" ]; then
make "${BUILD_FLAGS[@]}" CLANG_AUTOFDO_PROFILE=${srcdir}/perf.afdo -j"$(nproc)" all
else
make "${BUILD_FLAGS[@]}" -j"$(nproc)" all
fi

make -C tools/bpf/bpftool vmlinux.h feature-clang-bpf-co-re=1

local MODULE_FLAGS=(
Expand Down

0 comments on commit 16574ec

Please sign in to comment.