-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'kbuild-v6.13' of git://git.kernel.org/pub/scm/linux/kernel…
…/git/masahiroy/linux-kbuild Pull Kbuild updates from Masahiro Yamada: - Add generic support for built-in boot DTB files - Enable TAB cycling for dialog buttons in nconfig - Fix issues in streamline_config.pl - Refactor Kconfig - Add support for Clang's AutoFDO (Automatic Feedback-Directed Optimization) - Add support for Clang's Propeller, a profile-guided optimization. - Change the working directory to the external module directory for M= builds - Support building external modules in a separate output directory - Enable objtool for *.mod.o and additional kernel objects - Use lz4 instead of deprecated lz4c - Work around a performance issue with "git describe" - Refactor modpost * tag 'kbuild-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (85 commits) kbuild: rename .tmp_vmlinux.kallsyms0.syms to .tmp_vmlinux0.syms gitignore: Don't ignore 'tags' directory kbuild: add dependency from vmlinux to resolve_btfids modpost: replace tdb_hash() with hash_str() kbuild: deb-pkg: add python3:native to build dependency genksyms: reduce indentation in export_symbol() modpost: improve error messages in device_id_check() modpost: rename alias symbol for MODULE_DEVICE_TABLE() modpost: rename variables in handle_moddevtable() modpost: move strstarts() to modpost.h modpost: convert do_usb_table() to a generic handler modpost: convert do_of_table() to a generic handler modpost: convert do_pnp_device_entry() to a generic handler modpost: convert do_pnp_card_entries() to a generic handler modpost: call module_alias_printf() from all do_*_entry() functions modpost: pass (struct module *) to do_*_entry() functions modpost: remove DEF_FIELD_ADDR_VAR() macro modpost: deduplicate MODULE_ALIAS() for all drivers modpost: introduce module_alias_printf() helper modpost: remove unnecessary check in do_acpi_entry() ...
- Loading branch information
Showing
73 changed files
with
1,471 additions
and
1,010 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,7 @@ series | |
|
||
# ctags files | ||
tags | ||
!tags/ | ||
TAGS | ||
|
||
# cscope files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
.. SPDX-License-Identifier: GPL-2.0 | ||
=================================== | ||
Using AutoFDO with the Linux kernel | ||
=================================== | ||
|
||
This enables AutoFDO build support for the kernel when using | ||
the Clang compiler. AutoFDO (Auto-Feedback-Directed Optimization) | ||
is a type of profile-guided optimization (PGO) used to enhance the | ||
performance of binary executables. It gathers information about the | ||
frequency of execution of various code paths within a binary using | ||
hardware sampling. This data is then used to guide the compiler's | ||
optimization decisions, resulting in a more efficient binary. AutoFDO | ||
is a powerful optimization technique, and data indicates that it can | ||
significantly improve kernel performance. It's especially beneficial | ||
for workloads affected by front-end stalls. | ||
|
||
For AutoFDO builds, unlike non-FDO builds, the user must supply a | ||
profile. Acquiring an AutoFDO profile can be done in several ways. | ||
AutoFDO profiles are created by converting hardware sampling using | ||
the "perf" tool. It is crucial that the workload used to create these | ||
perf files is representative; they must exhibit runtime | ||
characteristics similar to the workloads that are intended to be | ||
optimized. Failure to do so will result in the compiler optimizing | ||
for the wrong objective. | ||
|
||
The AutoFDO profile often encapsulates the program's behavior. If the | ||
performance-critical codes are architecture-independent, the profile | ||
can be applied across platforms to achieve performance gains. For | ||
instance, using the profile generated on Intel architecture to build | ||
a kernel for AMD architecture can also yield performance improvements. | ||
|
||
There are two methods for acquiring a representative profile: | ||
(1) Sample real workloads using a production environment. | ||
(2) Generate the profile using a representative load test. | ||
When enabling the AutoFDO build configuration without providing an | ||
AutoFDO profile, the compiler only modifies the dwarf information in | ||
the kernel without impacting runtime performance. It's advisable to | ||
use a kernel binary built with the same AutoFDO configuration to | ||
collect the perf profile. While it's possible to use a kernel built | ||
with different options, it may result in inferior performance. | ||
|
||
One can collect profiles using AutoFDO build for the previous kernel. | ||
AutoFDO employs relative line numbers to match the profiles, offering | ||
some tolerance for source changes. This mode is commonly used in a | ||
production environment for profile collection. | ||
|
||
In a profile collection based on a load test, the AutoFDO collection | ||
process consists of the following steps: | ||
|
||
#. Initial build: The kernel is built with AutoFDO options | ||
without a profile. | ||
|
||
#. Profiling: The above kernel is then run with a representative | ||
workload to gather execution frequency data. This data is | ||
collected using hardware sampling, via perf. AutoFDO is most | ||
effective on platforms supporting advanced PMU features like | ||
LBR on Intel machines. | ||
|
||
#. AutoFDO profile generation: Perf output file is converted to | ||
the AutoFDO profile via offline tools. | ||
|
||
The support requires a Clang compiler LLVM 17 or later. | ||
|
||
Preparation | ||
=========== | ||
|
||
Configure the kernel with:: | ||
|
||
CONFIG_AUTOFDO_CLANG=y | ||
|
||
Customization | ||
============= | ||
|
||
The default CONFIG_AUTOFDO_CLANG setting covers kernel space objects for | ||
AutoFDO builds. One can, however, enable or disable AutoFDO build for | ||
individual files and directories by adding a line similar to the following | ||
to the respective kernel Makefile: | ||
|
||
- For enabling a single file (e.g. foo.o) :: | ||
|
||
AUTOFDO_PROFILE_foo.o := y | ||
|
||
- For enabling all files in one directory :: | ||
|
||
AUTOFDO_PROFILE := y | ||
|
||
- For disabling one file :: | ||
|
||
AUTOFDO_PROFILE_foo.o := n | ||
|
||
- For disabling all files in one directory :: | ||
|
||
AUTOFDO_PROFILE := n | ||
|
||
Workflow | ||
======== | ||
|
||
Here is an example workflow for AutoFDO kernel: | ||
|
||
1) Build the kernel on the host machine with LLVM enabled, | ||
for example, :: | ||
|
||
$ make menuconfig LLVM=1 | ||
|
||
Turn on AutoFDO build config:: | ||
|
||
CONFIG_AUTOFDO_CLANG=y | ||
|
||
With a configuration that with LLVM enabled, use the following command:: | ||
|
||
$ scripts/config -e AUTOFDO_CLANG | ||
|
||
After getting the config, build with :: | ||
|
||
$ make LLVM=1 | ||
|
||
2) Install the kernel on the test machine. | ||
|
||
3) Run the load tests. The '-c' option in perf specifies the sample | ||
event period. We suggest using a suitable prime number, like 500009, | ||
for this purpose. | ||
|
||
- For Intel platforms:: | ||
|
||
$ perf record -e BR_INST_RETIRED.NEAR_TAKEN:k -a -N -b -c <count> -o <perf_file> -- <loadtest> | ||
|
||
- For AMD platforms: | ||
|
||
The supported systems are: Zen3 with BRS, or Zen4 with amd_lbr_v2. To check, | ||
|
||
For Zen3:: | ||
|
||
$ cat proc/cpuinfo | grep " brs" | ||
|
||
For Zen4:: | ||
|
||
$ cat proc/cpuinfo | grep amd_lbr_v2 | ||
|
||
The following command generated the perf data file:: | ||
|
||
$ perf record --pfm-events RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a -N -b -c <count> -o <perf_file> -- <loadtest> | ||
|
||
4) (Optional) Download the raw perf file to the host machine. | ||
|
||
5) To generate an AutoFDO profile, two offline tools are available: | ||
create_llvm_prof and llvm_profgen. The create_llvm_prof tool is part | ||
of the AutoFDO project and can be found on GitHub | ||
(https://github.com/google/autofdo), version v0.30.1 or later. | ||
The llvm_profgen tool is included in the LLVM compiler itself. It's | ||
important to note that the version of llvm_profgen doesn't need to match | ||
the version of Clang. It needs to be the LLVM 19 release of Clang | ||
or later, or just from the LLVM trunk. :: | ||
|
||
$ llvm-profgen --kernel --binary=<vmlinux> --perfdata=<perf_file> -o <profile_file> | ||
|
||
or :: | ||
|
||
$ create_llvm_prof --binary=<vmlinux> --profile=<perf_file> --format=extbinary --out=<profile_file> | ||
|
||
Note that multiple AutoFDO profile files can be merged into one via:: | ||
|
||
$ llvm-profdata merge -o <profile_file> <profile_1> <profile_2> ... <profile_n> | ||
|
||
6) Rebuild the kernel using the AutoFDO profile file with the same config as step 1, | ||
(Note CONFIG_AUTOFDO_CLANG needs to be enabled):: | ||
|
||
$ make LLVM=1 CLANG_AUTOFDO_PROFILE=<profile_file> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
.. SPDX-License-Identifier: GPL-2.0 | ||
===================================== | ||
Using Propeller with the Linux kernel | ||
===================================== | ||
|
||
This enables Propeller build support for the kernel when using Clang | ||
compiler. Propeller is a profile-guided optimization (PGO) method used | ||
to optimize binary executables. Like AutoFDO, it utilizes hardware | ||
sampling to gather information about the frequency of execution of | ||
different code paths within a binary. Unlike AutoFDO, this information | ||
is then used right before linking phase to optimize (among others) | ||
block layout within and across functions. | ||
|
||
A few important notes about adopting Propeller optimization: | ||
|
||
#. Although it can be used as a standalone optimization step, it is | ||
strongly recommended to apply Propeller on top of AutoFDO, | ||
AutoFDO+ThinLTO or Instrument FDO. The rest of this document | ||
assumes this paradigm. | ||
|
||
#. Propeller uses another round of profiling on top of | ||
AutoFDO/AutoFDO+ThinLTO/iFDO. The whole build process involves | ||
"build-afdo - train-afdo - build-propeller - train-propeller - | ||
build-optimized". | ||
|
||
#. Propeller requires LLVM 19 release or later for Clang/Clang++ | ||
and the linker(ld.lld). | ||
|
||
#. In addition to LLVM toolchain, Propeller requires a profiling | ||
conversion tool: https://github.com/google/autofdo with a release | ||
after v0.30.1: https://github.com/google/autofdo/releases/tag/v0.30.1. | ||
|
||
The Propeller optimization process involves the following steps: | ||
|
||
#. Initial building: Build the AutoFDO or AutoFDO+ThinLTO binary as | ||
you would normally do, but with a set of compile-time / link-time | ||
flags, so that a special metadata section is created within the | ||
kernel binary. The special section is only intend to be used by the | ||
profiling tool, it is not part of the runtime image, nor does it | ||
change kernel run time text sections. | ||
|
||
#. Profiling: The above kernel is then run with a representative | ||
workload to gather execution frequency data. This data is collected | ||
using hardware sampling, via perf. Propeller is most effective on | ||
platforms supporting advanced PMU features like LBR on Intel | ||
machines. This step is the same as profiling the kernel for AutoFDO | ||
(the exact perf parameters can be different). | ||
|
||
#. Propeller profile generation: Perf output file is converted to a | ||
pair of Propeller profiles via an offline tool. | ||
|
||
#. Optimized build: Build the AutoFDO or AutoFDO+ThinLTO optimized | ||
binary as you would normally do, but with a compile-time / | ||
link-time flag to pick up the Propeller compile time and link time | ||
profiles. This build step uses 3 profiles - the AutoFDO profile, | ||
the Propeller compile-time profile and the Propeller link-time | ||
profile. | ||
|
||
#. Deployment: The optimized kernel binary is deployed and used | ||
in production environments, providing improved performance | ||
and reduced latency. | ||
|
||
Preparation | ||
=========== | ||
|
||
Configure the kernel with:: | ||
|
||
CONFIG_AUTOFDO_CLANG=y | ||
CONFIG_PROPELLER_CLANG=y | ||
|
||
Customization | ||
============= | ||
|
||
The default CONFIG_PROPELLER_CLANG setting covers kernel space objects | ||
for Propeller builds. One can, however, enable or disable Propeller build | ||
for individual files and directories by adding a line similar to the | ||
following to the respective kernel Makefile: | ||
|
||
- For enabling a single file (e.g. foo.o):: | ||
|
||
PROPELLER_PROFILE_foo.o := y | ||
|
||
- For enabling all files in one directory:: | ||
|
||
PROPELLER_PROFILE := y | ||
|
||
- For disabling one file:: | ||
|
||
PROPELLER_PROFILE_foo.o := n | ||
|
||
- For disabling all files in one directory:: | ||
|
||
PROPELLER__PROFILE := n | ||
|
||
|
||
Workflow | ||
======== | ||
|
||
Here is an example workflow for building an AutoFDO+Propeller kernel: | ||
|
||
1) Assuming an AutoFDO profile is already collected following | ||
instructions in the AutoFDO document, build the kernel on the host | ||
machine, with AutoFDO and Propeller build configs :: | ||
|
||
CONFIG_AUTOFDO_CLANG=y | ||
CONFIG_PROPELLER_CLANG=y | ||
|
||
and :: | ||
|
||
$ make LLVM=1 CLANG_AUTOFDO_PROFILE=<autofdo-profile-name> | ||
|
||
2) Install the kernel on the test machine. | ||
|
||
3) Run the load tests. The '-c' option in perf specifies the sample | ||
event period. We suggest using a suitable prime number, like 500009, | ||
for this purpose. | ||
|
||
- For Intel platforms:: | ||
|
||
$ perf record -e BR_INST_RETIRED.NEAR_TAKEN:k -a -N -b -c <count> -o <perf_file> -- <loadtest> | ||
|
||
- For AMD platforms:: | ||
|
||
$ perf record --pfm-event RETIRED_TAKEN_BRANCH_INSTRUCTIONS:k -a -N -b -c <count> -o <perf_file> -- <loadtest> | ||
|
||
Note you can repeat the above steps to collect multiple <perf_file>s. | ||
|
||
4) (Optional) Download the raw perf file(s) to the host machine. | ||
|
||
5) Use the create_llvm_prof tool (https://github.com/google/autofdo) to | ||
generate Propeller profile. :: | ||
|
||
$ create_llvm_prof --binary=<vmlinux> --profile=<perf_file> | ||
--format=propeller --propeller_output_module_name | ||
--out=<propeller_profile_prefix>_cc_profile.txt | ||
--propeller_symorder=<propeller_profile_prefix>_ld_profile.txt | ||
|
||
"<propeller_profile_prefix>" can be something like "/home/user/dir/any_string". | ||
|
||
This command generates a pair of Propeller profiles: | ||
"<propeller_profile_prefix>_cc_profile.txt" and | ||
"<propeller_profile_prefix>_ld_profile.txt". | ||
|
||
If there are more than 1 perf_file collected in the previous step, | ||
you can create a temp list file "<perf_file_list>" with each line | ||
containing one perf file name and run:: | ||
|
||
$ create_llvm_prof --binary=<vmlinux> --profile=@<perf_file_list> | ||
--format=propeller --propeller_output_module_name | ||
--out=<propeller_profile_prefix>_cc_profile.txt | ||
--propeller_symorder=<propeller_profile_prefix>_ld_profile.txt | ||
|
||
6) Rebuild the kernel using the AutoFDO and Propeller | ||
profiles. :: | ||
|
||
CONFIG_AUTOFDO_CLANG=y | ||
CONFIG_PROPELLER_CLANG=y | ||
|
||
and :: | ||
|
||
$ make LLVM=1 CLANG_AUTOFDO_PROFILE=<profile_file> CLANG_PROPELLER_PROFILE_PREFIX=<propeller_profile_prefix> |
Oops, something went wrong.