[all-commits] [llvm/llvm-project] a23f62: Supplement instr profile with sample profile.

wmi-11 via All-commits all-commits at lists.llvm.org
Mon Jul 27 20:36:01 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: a23f62343cb79a3306fa64545db1d61c2d76b9ca
      https://github.com/llvm/llvm-project/commit/a23f62343cb79a3306fa64545db1d61c2d76b9ca
  Author: Wei Mi <wmi at google.com>
  Date:   2020-07-27 (Mon, 27 Jul 2020)

  Changed paths:
    M llvm/docs/CommandGuide/llvm-profdata.rst
    M llvm/include/llvm/ProfileData/InstrProf.h
    M llvm/include/llvm/ProfileData/InstrProfWriter.h
    M llvm/lib/ProfileData/InstrProf.cpp
    M llvm/lib/ProfileData/InstrProfWriter.cpp
    M llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
    M llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
    A llvm/test/Transforms/PGOProfile/Inputs/sample-profile.proftext
    A llvm/test/Transforms/PGOProfile/Inputs/suppl-profile.proftext
    A llvm/test/Transforms/PGOProfile/suppl-profile.ll
    A llvm/test/tools/llvm-profdata/Inputs/mix_instr.proftext
    A llvm/test/tools/llvm-profdata/Inputs/mix_sample.proftext
    M llvm/test/tools/llvm-profdata/overflow-instr.test
    A llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
    M llvm/tools/llvm-profdata/llvm-profdata.cpp

  Log Message:
  -----------
  Supplement instr profile with sample profile.

PGO profile is usually more precise than sample profile. However, PGO profile
needs to be collected from loadtest and loadtest may not be representative
enough to the production workload. Sample profile collected from production
can be used as a supplement -- for functions cold in loadtest but warm/hot
in production, we can scale up the related function in PGO profile if the
function is warm or hot in sample profile.

The implementation contains changes in compiler side and llvm-profdata side.
Given an instr profile and a sample profile, for a function cold in PGO
profile but warm/hot in sample profile, llvm-profdata will either mark
all the counters in the profile to be -1 or scale up the max count in the
function to be above hot threshold, depending on the zero counter ratio in
the profile. The assumption is if there are too many counters being zero
in the function profile, the profile is more likely to cause harm than good,
then llvm-profdata will mark all the counters to be -1 indicating the
function is hot but the profile is unaccountable. In compiler side, if a
function profile with all -1 counters is seen, the function entry count will
be set to be above hot threshold but its internal profile will be dropped.

In the long run, it may be useful to let compiler support using PGO profile
and sample profile at the same time, but that requires more careful design
and more substantial changes to make two profiles work seamlessly. The patch
here serves as a simple intermediate solution.

Differential Revision: https://reviews.llvm.org/D81981




More information about the All-commits mailing list