summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlice Ryhl <aliceryhl@google.com>2026-03-31 10:57:49 +0000
committerMiguel Ojeda <ojeda@kernel.org>2026-05-27 01:53:42 +0200
commita960c2cdb19e237f284a3b96eb8a0359abcf0e63 (patch)
treef378ce8937c78fc8f2488f9ab7952ef643037a8e /scripts
parentfc1ce3afa2e61b4b15e71436ece91b0441a9f4f0 (diff)
downloadlwn-a960c2cdb19e237f284a3b96eb8a0359abcf0e63.tar.gz
lwn-a960c2cdb19e237f284a3b96eb8a0359abcf0e63.zip
kbuild: rust: add AutoFDO support
This patch enables AutoFDO build support for Rust code within the Linux kernel. This allows Rust code to be profiled and optimized based on the profile. The RUSTFLAGS variable was suffixed with *_AUTOFDO_CLANG to match the naming of the config option, which is called CONFIG_AUTOFDO_CLANG. This implementation has been verified in Android, first by inspecting the object files and confirming that they look correct. After that, it was verified as below: 1. Running the binderAddInts benchmark [1] with Rust Binder built as rust_binder.ko module, using a Pixel 9 Pro. 2. Collecting a profile on a Pixel 10 Pro XL using the app-launch benchmark, which starts different apps many times, on a device with Rust Binder as a built-in kernel module. (C Binder was not present on the device.) 3. Using the collected profile, run the binderAddInts benchmark again with Rust Binder built both as a rust_binder.ko module, and as a built-in kernel module. 4. In both cases, Rust Binder without AutoFDO was approximately 13% slower than the AutoFDO optimized version. Built-in vs .ko did not make a measurable performance difference. All of the above was verified in conjunction with my helpers inlining series [2], which confirmed that this worked correctly for helpers too once [3] was fixed in the helpers inlining series. Link: https://android.googlesource.com/platform/system/extras/+/920f089/tests/binder/benchmarks/binderAddInts.cpp [1] Link: https://lore.kernel.org/r/20260203-inline-helpers-v2-0-beb8547a03c9@google.com [2] Link: https://lore.kernel.org/r/aasPsbMEsX6iGUl8@google.com [3] Reviewed-by: Rong Xu <xur@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Tested-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Nicolas Schier <nsc@kernel.org> Acked-by: Nathan Chancellor <nathan@kernel.org> Link: https://patch.msgid.link/20260331-autofdo-v2-1-eb5c5964820d@google.com [ Reworded for typos. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.autofdo6
-rw-r--r--scripts/Makefile.lib3
2 files changed, 8 insertions, 1 deletions
diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo
index 1caf2457e585..3f08acab4549 100644
--- a/scripts/Makefile.autofdo
+++ b/scripts/Makefile.autofdo
@@ -3,14 +3,18 @@
# Enable available and selected Clang AutoFDO features.
CFLAGS_AUTOFDO_CLANG := -fdebug-info-for-profiling -mllvm -enable-fs-discriminator=true -mllvm -improved-fs-discriminator=true
+RUSTFLAGS_AUTOFDO_CLANG := -Zdebug-info-for-profiling -Cllvm-args=-enable-fs-discriminator=true -Cllvm-args=-improved-fs-discriminator=true
ifndef CONFIG_DEBUG_INFO
CFLAGS_AUTOFDO_CLANG += -gmlt
+ RUSTFLAGS_AUTOFDO_CLANG += -Cdebuginfo=line-tables-only
endif
ifdef CLANG_AUTOFDO_PROFILE
CFLAGS_AUTOFDO_CLANG += -fprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -ffunction-sections
CFLAGS_AUTOFDO_CLANG += -fsplit-machine-functions
+ RUSTFLAGS_AUTOFDO_CLANG += -Zprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -Zfunction-sections=y
+ RUSTFLAGS_AUTOFDO_CLANG += -Cllvm-args=-split-machine-functions
endif
ifdef CONFIG_LTO_CLANG_THIN
@@ -21,4 +25,4 @@ ifdef CONFIG_LTO_CLANG_THIN
KBUILD_LDFLAGS += -plugin-opt=-split-machine-functions
endif
-export CFLAGS_AUTOFDO_CLANG
+export CFLAGS_AUTOFDO_CLANG RUSTFLAGS_AUTOFDO_CLANG
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0718e39cedda..eaddf6637669 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -123,6 +123,9 @@ ifeq ($(CONFIG_AUTOFDO_CLANG),y)
_c_flags += $(if $(patsubst n%,, \
$(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(is-kernel-object)), \
$(CFLAGS_AUTOFDO_CLANG))
+_rust_flags += $(if $(patsubst n%,, \
+ $(AUTOFDO_PROFILE_$(target-stem).o)$(AUTOFDO_PROFILE)$(is-kernel-object)), \
+ $(RUSTFLAGS_AUTOFDO_CLANG))
endif
#