[PATCH] D69740: [profile] Support counter relocation at runtime

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 16:16:48 PDT 2019


phosek created this revision.
phosek added reviewers: davidxl, vsk.
Herald added subscribers: llvm-commits, hiraditya, mgorny.
Herald added a project: LLVM.

This is an alternative to the continous mode that was implemented in
D68351 <https://reviews.llvm.org/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).


Repository:
  rL LLVM

https://reviews.llvm.org/D69740

Files:
  compiler-rt/lib/profile/CMakeLists.txt
  compiler-rt/lib/profile/InstrProfiling.h
  compiler-rt/lib/profile/InstrProfilingBiasVar.c
  compiler-rt/lib/profile/InstrProfilingFile.c
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69740.227548.patch
Type: text/x-patch
Size: 13924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191101/140393a9/attachment.bin>


More information about the llvm-commits mailing list