kbuild: rust: add AutoFDO support
Subsystems (3)
Alice Ryhl
reviewerPATCH v2 1/1 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 an 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 conjuction with my helpers inlining series [2], which confirmed that this worked correctly for helpers too once [3] was fixed in the helpers inlining series.
---
Changes in v2:
- Discuss RUSTFLAGS_ naming in commit message.
- Update commit message with information about additional testing that has now been carried out.
- Pick up tags.
- Link to v1: https://lore.kernel.org/r/[email protected]
--- scripts/Makefile.autofdo | 6 +++++- scripts/Makefile.lib | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-)
scripts/Makefile.autofdo +5 -1
@@ -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
scripts/Makefile.lib +3 -0
@@ -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 #
---
base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
change-id: 20260309-autofdo-8d01e7977fed
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Quoted 29 lines · Alice Ryhl
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_CLANGto match the naming of the config option, which is calledCONFIG_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 an 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 conjuction with my helpers inlining series [2], which confirmed that this worked correctly for helpers too once [3] was fixed in the helpers inlining series.
Quoted 7 lines
Reviewed-by Rong Xu <[email protected]>Reviewed-by Gary Guo <[email protected]>Tested-by Alice Ryhl <[email protected]>Signed-off-by Alice Ryhl <[email protected]>
If Rong/Han or Kbuild want to pick this up, then:
Otherwise, please let me know -- thanks!
Cheers,
Miguel
Quoted 38 lines · Miguel Ojeda
Quoted 29 lines · Alice Ryhl
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_CLANGto match the naming of the config option, which is calledCONFIG_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 an 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 conjuction with my helpers inlining series [2], which confirmed that this worked correctly for helpers too once [3] was fixed in the helpers inlining series.
Quoted 7 lines
Reviewed-by Rong Xu <[email protected]>Reviewed-by Gary Guo <[email protected]>Tested-by Alice Ryhl <[email protected]>Signed-off-by Alice Ryhl <[email protected]>
Quoted 5 lines
If Rong/Han or
Kbuildwant to pick this up, then:Acked-by Miguel Ojeda <[email protected]>Otherwise, please let me know -- thanks!
Unless Nicolas feels strongly otherwise, I think you can just take this via the Rust tree.
Cheers,
Nathan
Quoted 45 lines · Nathan Chancellor
Quoted 38 lines · Miguel Ojeda
Quoted 29 lines · Alice Ryhl
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_CLANGto match the naming of the config option, which is calledCONFIG_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 an 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 conjuction with my helpers inlining series [2], which confirmed that this worked correctly for helpers too once [3] was fixed in the helpers inlining series.
Quoted 7 lines
Reviewed-by Rong Xu <[email protected]>Reviewed-by Gary Guo <[email protected]>Tested-by Alice Ryhl <[email protected]>Signed-off-by Alice Ryhl <[email protected]>Quoted 5 lines
If Rong/Han or
Kbuildwant to pick this up, then:Acked-by Miguel Ojeda <[email protected]>Otherwise, please let me know -- thanks!
Quoted 7 lines
Unless Nicolas feels strongly otherwise, I think you can just take this via the Rust tree.
Cheers,
Nathan
No objections from me either.
Thanks!
Signature · 1 line
Nicolas
A message that is not in the archive (sent off-list or not yet received): CAF1bQ=TxmN4q1mw8YL_62wnEsNbz4tCy8uHwS2GOX39o=7=hsA@mail.gmail.com
Quoted 4 lines · Rong Xu
This patch LGTM. Thanks to everyone for improving AutoFDO support.
Reviewed-by Rong Xu <[email protected]>
Thanks Rong (your review was already there :)
So I guess that means you prefer that we (e.g. Rust) picks it.
Cheers,
Miguel
Miguel Ojeda
AppliedQuoted 29 lines · Alice Ryhl
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_CLANGto match the naming of the config option, which is calledCONFIG_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 an 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 conjuction with my helpers inlining series [2], which confirmed that this worked correctly for helpers too once [3] was fixed in the helpers inlining series.
Quoted 7 lines
Reviewed-by Rong Xu <[email protected]>Reviewed-by Gary Guo <[email protected]>Tested-by Alice Ryhl <[email protected]>Signed-off-by Alice Ryhl <[email protected]>
Applied to rust-next -- thanks everyone!
[ Reworded for typos. - Miguel ]
I also tested with a merge of rust-fixes + cross-compile + etc.
Cheers,
Miguel