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