[all-commits] [llvm/llvm-project] d3db13: [profile] Support counter relocation at runtime

Petr Hosek via All-commits all-commits at lists.llvm.org
Fri Jan 17 15:02:41 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: d3db13af7e5c01632fbf28149a2d4f9c4841aeba
      https://github.com/llvm/llvm-project/commit/d3db13af7e5c01632fbf28149a2d4f9c4841aeba
  Author: Petr Hosek <phosek at google.com>
  Date:   2020-01-17 (Fri, 17 Jan 2020)

  Changed paths:
    M clang/docs/SourceBasedCodeCoverage.rst
    M clang/lib/Driver/ToolChains/Darwin.cpp
    M compiler-rt/lib/profile/CMakeLists.txt
    M compiler-rt/lib/profile/InstrProfiling.h
    A compiler-rt/lib/profile/InstrProfilingBiasVar.c
    M compiler-rt/lib/profile/InstrProfilingBuffer.c
    M compiler-rt/lib/profile/InstrProfilingFile.c
    M compiler-rt/lib/profile/InstrProfilingInternal.h
    M compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
    M compiler-rt/test/profile/ContinuousSyncMode/basic.c
    R compiler-rt/test/profile/ContinuousSyncMode/lit.local.cfg.py
    M compiler-rt/test/profile/ContinuousSyncMode/multiple-DSOs.c
    M compiler-rt/test/profile/ContinuousSyncMode/online-merging.c
    M compiler-rt/test/profile/ContinuousSyncMode/pid-substitution.c
    A compiler-rt/test/profile/ContinuousSyncMode/runtime-counter-relocation.c
    M compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c
    M compiler-rt/test/profile/ContinuousSyncMode/set-filename.c
    M llvm/include/llvm/ProfileData/InstrProf.h
    M llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
    M llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
    A llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll

  Log Message:
  -----------
  [profile] Support counter relocation at runtime

This is an alternative to the continous mode that was implemented in
D68351. This mode relies on padding and the ability to mmap a file over
the existing mapping which is generally only available on POSIX systems
and isn't suitable for other platforms.

This change instead introduces the ability to relocate counters at
runtime using a level of indirection. On every counter access, we add a
bias to the counter address. This bias is stored in a symbol that's
provided by the profile runtime and is initially set to zero, meaning no
relocation. The runtime can mmap the profile into memory at abitrary
location, and set bias to the offset between the original and the new
counter location, at which point every subsequent counter access will be
to the new location, which allows updating profile directly akin to the
continous mode.

The advantage of this implementation is that doesn't require any special
OS support. The disadvantage is the extra overhead due to additional
instructions required for each counter access (overhead both in terms of
binary size and performance) plus duplication of counters (i.e. one copy
in the binary itself and another copy that's mmapped).

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




More information about the All-commits mailing list