[PATCH] D15258: [PGO] Remove data races on Data->Values field

David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 4 20:00:43 PST 2015


davidxl created this revision.
davidxl added a reviewer: betulb.
davidxl added a subscriber: llvm-commits.

The Values field of the per-function data structure is overloaded for two different purposes. At runtime time, the field points to the in-memory value profile data, but when the data is serialized to disk, its value will be changed to point to internals of value profile data's serialization buffer (continuous) -- which are later relocated during profile reading.

Current implementation simply overwrites the pointer during profile dumping -- this won't work well with multi-threaded program -- after Values field is modified, runtime code may either crash or corrupt the data. Zerolized Value field may also be re-initialized with addresses which will be garbage in reading time.  Introducing synchronization mechanism will greatly affect runtime performance.

The solution is simple -- instead of overwriting the "Data" data structure, the per-func data array will be copied to a small buffer and written out after the Values are fixed up in the buffer. The Data's Values field will be kept intact.  There is no need to clear the memory either. In some use cases, the user code will just clear the counters and all the data allocated for VP can be reused.

http://reviews.llvm.org/D15258

Files:
  lib/profile/InstrProfiling.c
  lib/profile/InstrProfilingFile.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15258.41977.patch
Type: text/x-patch
Size: 5071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151205/084d52eb/attachment.bin>


More information about the llvm-commits mailing list