OSDN Git Service

[profile] Support counter relocation at runtime
authorPetr Hosek <phosek@google.com>
Fri, 4 Oct 2019 20:29:56 +0000 (13:29 -0700)
committerPetr Hosek <phosek@google.com>
Fri, 17 Jan 2020 23:02:23 +0000 (15:02 -0800)
commitd3db13af7e5c01632fbf28149a2d4f9c4841aeba
tree416668c51d7b5c2782c408a8b8052b6d0d70007d
parent383ff4eac1db8313ec522ba3ac0903aaeda7ff63
[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
21 files changed:
clang/docs/SourceBasedCodeCoverage.rst
clang/lib/Driver/ToolChains/Darwin.cpp
compiler-rt/lib/profile/CMakeLists.txt
compiler-rt/lib/profile/InstrProfiling.h
compiler-rt/lib/profile/InstrProfilingBiasVar.c [new file with mode: 0644]
compiler-rt/lib/profile/InstrProfilingBuffer.c
compiler-rt/lib/profile/InstrProfilingFile.c
compiler-rt/lib/profile/InstrProfilingInternal.h
compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
compiler-rt/test/profile/ContinuousSyncMode/basic.c
compiler-rt/test/profile/ContinuousSyncMode/lit.local.cfg.py [deleted file]
compiler-rt/test/profile/ContinuousSyncMode/multiple-DSOs.c
compiler-rt/test/profile/ContinuousSyncMode/online-merging.c
compiler-rt/test/profile/ContinuousSyncMode/pid-substitution.c
compiler-rt/test/profile/ContinuousSyncMode/runtime-counter-relocation.c [new file with mode: 0644]
compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c
compiler-rt/test/profile/ContinuousSyncMode/set-filename.c
llvm/include/llvm/ProfileData/InstrProf.h
llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Instrumentation/InstrProfiling/runtime-counter-relocation.ll [new file with mode: 0644]