[PATCH] D39526: [XRay] Use optimistic logging model for FDR mode

Dean Michael Berris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 1 20:35:17 PDT 2017


dberris created this revision.
Herald added a subscriber: hiraditya.

Before this change, the FDR mode implementation relied on at thread-exit
handling to return buffers back to the (global) buffer queue. This
introduces issues with the initialisation of the thread_local objects
which, even through the use of pthread_setspecific(...) may eventually
call into an allocation function. Similar to previous changes in this
line, we're finding that there is a huge potential for deadlocks when
initialising these thread-locals when the memory allocation
implementation is also xray-instrumented.

This change cuts across both LLVM and compiler-rt to allow us to update
both the XRay runtime implementation as well as the library support for
loading these new versions of the FDR mode logging. Version 2 of the FDR
logging implementation makes the following changes:

- Introduction of a new 'BufferExtents' metadata record that's closer to the beginning of the buffer, counting as mandatory records in a buffer.
- Removal of the "end of buffer" records. This is in-line with the changes we described above, to allow for optimistic logging without explicit record writing at thread exit.

The optimistic logging model operates under the following assumptions:

- Threads writing to the buffers will potentially race with the thread attempting to flush the log. To avoid this situation from occuring, we make sure that when we've finalized the logging implementation, that threads will see this finalization state on the next write, and either choose to not write records the thread would have written or write the record(s) in two phases -- first write the record(s), then update the extents metadata.
- We change the buffer queue implementation so that once it's handed out a buffer to a thread, that we assume that buffer is marked "used" to be able to capture partial writes. None of this will be safe to handle if threads are racing to write the extents records and the reader thread is attempting to flush the log. The optimism comes from the finalization routine being required to complete before we attempt to flush the log.

This is a fairly significant semantics change for the FDR
implementation. This is why we've decided to update the version number
for FDR mode logs. The tools, however, still need to be able to support
older versions of the log until we finally deprecate those earlier
versions.


https://reviews.llvm.org/D39526

Files:
  compiler-rt/lib/xray/tests/unit/fdr_logging_test.cc
  compiler-rt/lib/xray/xray_buffer_queue.cc
  compiler-rt/lib/xray/xray_fdr_log_records.h
  compiler-rt/lib/xray/xray_fdr_logging.cc
  compiler-rt/lib/xray/xray_fdr_logging_impl.h
  llvm/lib/XRay/Trace.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39526.121232.patch
Type: text/x-patch
Size: 41712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171102/f80761dd/attachment.bin>


More information about the llvm-commits mailing list