Re: [PATCH v5] pgo: add clang's Profile Guided Optimization infrastructure

From: Nick Desaulniers
Date: Tue Jan 19 2021 - 20:03:41 EST

On Sat, Jan 16, 2021 at 1:44 AM Bill Wendling <morbo@xxxxxxxxxx> wrote:
> From: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
> 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]
> Signed-off-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
> Co-developed-by: Bill Wendling <morbo@xxxxxxxxxx>
> Signed-off-by: Bill Wendling <morbo@xxxxxxxxxx>
> ---
> v2: - Added "__llvm_profile_instrument_memop" based on Nathan Chancellor's
> testing.
> - Corrected documentation, re PGO flags when using LTO, based on Fangrui
> Song's comments.
> v3: - Added change log section based on Sedat Dilek's comments.
> v4: - Remove non-x86 Makfile changes and se "hweight64" instead of using our
> own popcount implementation, based on Nick Desaulniers's comment.
> v5: - Correct padding calculation, discovered by Nathan Chancellor.

Specifically for v5:
Tested-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>

If anything changes drastically, please drop that and I'll retest it;
otherwise for changes to the commit message or docs, feel free to
carry it forward.

I'll try to provide code review by EOW, assuming we can stop
regressing LLVM so I can focus. (Ha!)
~Nick Desaulniers