]> www.infradead.org Git - users/jedix/linux-maple.git/commit
pgo: add clang's Profile Guided Optimization infrastructure
authorSami Tolvanen <samitolvanen@google.com>
Wed, 7 Apr 2021 21:17:04 +0000 (14:17 -0700)
committerKees Cook <keescook@chromium.org>
Wed, 19 May 2021 21:15:51 +0000 (14:15 -0700)
commite1af496cbe9b4517428601a4e44fee3602dd3c15
tree080d1cbb0a2d1c3e4f4c7f1a929a4d16f054950f
parentd07f6ca923ea0927a1024dfccafc5b53b61cfecc
pgo: add clang's Profile Guided Optimization infrastructure

Enable the use of clang's Profile-Guided Optimization[1]. To generate a
profile, the kernel is instrumented with PGO counters, a representative
workload is run, and the raw profile data is collected from
/sys/kernel/debug/pgo/profraw.

The raw profile data must be processed by clang's "llvm-profdata" tool
before it can be used during recompilation:

  $ cp /sys/kernel/debug/pgo/profraw vmlinux.profraw
  $ llvm-profdata merge --output=vmlinux.profdata vmlinux.profraw

Multiple raw profiles may be merged during this step.

The data can now be used by the compiler:

  $ make LLVM=1 KCFLAGS=-fprofile-use=vmlinux.profdata ...

This initial submission is restricted to x86, as that's the platform we
know works. This restriction can be lifted once other platforms have
been verified to work with PGO.

Note that this method of profiling the kernel is clang-native, unlike
the clang support in kernel/gcov.

[1] https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Co-developed-by: Bill Wendling <morbo@google.com>
Signed-off-by: Bill Wendling <morbo@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Fangrui Song <maskray@google.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20210407211704.367039-1-morbo@google.com
24 files changed:
Documentation/dev-tools/index.rst
Documentation/dev-tools/pgo.rst [new file with mode: 0644]
MAINTAINERS
Makefile
arch/Kconfig
arch/x86/Kconfig
arch/x86/boot/Makefile
arch/x86/boot/compressed/Makefile
arch/x86/crypto/Makefile
arch/x86/entry/vdso/Makefile
arch/x86/kernel/vmlinux.lds.S
arch/x86/platform/efi/Makefile
arch/x86/purgatory/Makefile
arch/x86/realmode/rm/Makefile
arch/x86/um/vdso/Makefile
drivers/firmware/efi/libstub/Makefile
include/asm-generic/vmlinux.lds.h
kernel/Makefile
kernel/pgo/Kconfig [new file with mode: 0644]
kernel/pgo/Makefile [new file with mode: 0644]
kernel/pgo/fs.c [new file with mode: 0644]
kernel/pgo/instrument.c [new file with mode: 0644]
kernel/pgo/pgo.h [new file with mode: 0644]
scripts/Makefile.lib