This is an archive of the discontinued LLVM Phabricator instance.

[XRay] Move-only Allocator, FunctionCallTrie, and Array
ClosedPublic

Authored by dberris on Nov 27 2018, 9:35 PM.

Details

Summary

This change makes the allocator and function call trie implementations
move-aware and remove the FunctionCallTrie's reliance on a
heap-allocated set of allocators.

The change makes it possible to always have storage associated with
Allocator instances, not necessarily having heap-allocated memory
obtainable from these allocator instances. We also use thread-local
uninitialised storage.

We've also re-worked the segmented array implementation to have more
precondition and post-condition checks when built in debug mode. This
enables us to better implement some of the operations with surrounding
documentation as well. The trim algorithm now has more documentation
on the implementation, reducing the requirement to handle special
conditions, and being more rigorous on the computations involved.

In this change we also introduce an initialisation guard, through which
we prevent an initialisation operation from racing with a cleanup
operation.

We also ensure that the ThreadTries array is not destroyed while copies
into the elements are still being performed by other threads submitting
profiles.

Note that this change still has an issue with accessing thread-local
storage from signal handlers that are instrumented with XRay. We also
learn that with the testing of this patch, that there will be cases
where calls to mmap(...) (through internal_mmap(...)) might be called in
signal handlers, but are not async-signal-safe. Subsequent patches will
address this, by re-using the BufferQueue type used in the FDR mode
implementation for pre-allocated memory segments per active, tracing
thread.

We still want to land this change despite the known issues, with fixes
forthcoming.

Diff Detail

Event Timeline

dberris created this revision.Nov 27 2018, 9:35 PM
mboerger added inline comments.Nov 27 2018, 11:02 PM
compiler-rt/lib/xray/xray_profiling.cc
58 ↗(On Diff #175624)

That sentence is hard to parse.

compiler-rt/lib/xray/xray_segmented_array.h
351 ↗(On Diff #175624)

why change size?

dberris updated this revision to Diff 175636.Nov 28 2018, 12:31 AM
dberris marked 2 inline comments as done.

Addressing comments by @mboerger.

dberris added inline comments.Nov 28 2018, 12:32 AM
compiler-rt/lib/xray/xray_segmented_array.h
351 ↗(On Diff #175624)

Was experimenting with seeing whether layout was affected by picking an explicit 64-bit unsigned as opposed to using size_t. Forgot to revert. :)

This revision is now accepted and ready to land.Nov 29 2018, 8:25 PM
This revision was automatically updated to reflect the committed changes.
Herald added a subscriber: Restricted Project. · View Herald TranscriptDec 4 2018, 10:47 PM