summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray/xray_buffer_queue.h
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2018-10-29 02:18:14 +0000
committerDean Michael Berris <dberris@google.com>2018-10-29 02:18:14 +0000
commit36d9746630fd4fb71fef627057fdd5b899cfd221 (patch)
treef8d8c5c09d763e15a4f84f75dd7e0fe04473e06b /compiler-rt/lib/xray/xray_buffer_queue.h
parent42aa87143d0ce47ddcba5eab82c4a66b76b7b2dd (diff)
downloadbcm5719-llvm-36d9746630fd4fb71fef627057fdd5b899cfd221.tar.gz
bcm5719-llvm-36d9746630fd4fb71fef627057fdd5b899cfd221.zip
[XRay] Use more portable control block
Summary: In D53560, we assumed a specific layout for memory without using an explicit structure. This follow-up change uses more portable layout control by using unions in a struct, and consolidating the memory management code in the buffer queue. We also take the opportunity to improve the documentation on the types and operations, along with simplifying some of the logic in the buffer queue implementation. Reviewers: mboerger, eizan Subscribers: jfb, llvm-commits Differential Revision: https://reviews.llvm.org/D53802 llvm-svn: 345485
Diffstat (limited to 'compiler-rt/lib/xray/xray_buffer_queue.h')
-rw-r--r--compiler-rt/lib/xray/xray_buffer_queue.h27
1 files changed, 23 insertions, 4 deletions
diff --git a/compiler-rt/lib/xray/xray_buffer_queue.h b/compiler-rt/lib/xray/xray_buffer_queue.h
index 91e104e5eb5..a60f7c18eed 100644
--- a/compiler-rt/lib/xray/xray_buffer_queue.h
+++ b/compiler-rt/lib/xray/xray_buffer_queue.h
@@ -31,6 +31,26 @@ namespace __xray {
/// trace collection.
class BufferQueue {
public:
+ /// ControlBlock represents the memory layout of how we interpret the backing
+ /// store for all buffers managed by a BufferQueue instance. The ControlBlock
+ /// has the reference count as the first member, sized according to
+ /// platform-specific cache-line size. We never use the Buffer member of the
+ /// union, which is only there for compiler-supported alignment and sizing.
+ ///
+ /// This ensures that the `Data` member will be placed at least kCacheLineSize
+ /// bytes from the beginning of the structure.
+ struct ControlBlock {
+ union {
+ atomic_uint64_t RefCount;
+ char Buffer[kCacheLineSize];
+ };
+
+ /// We need to make this size 1, to conform to the C++ rules for array data
+ /// members. Typically, we want to subtract this 1 byte for sizing
+ /// information.
+ char Data[1];
+ };
+
struct Buffer {
atomic_uint64_t Extents{0};
uint64_t Generation{0};
@@ -39,7 +59,7 @@ public:
private:
friend class BufferQueue;
- unsigned char *BackingStore = nullptr;
+ ControlBlock *BackingStore = nullptr;
size_t Count = 0;
};
@@ -119,9 +139,8 @@ private:
SpinMutex Mutex;
atomic_uint8_t Finalizing;
- // A pointer to a contiguous block of memory to serve as the backing store for
- // all the individual buffers handed out.
- uint8_t *BackingStore;
+ // The collocated ControlBlock and buffer storage.
+ ControlBlock *BackingStore;
// A dynamically allocated array of BufferRep instances.
BufferRep *Buffers;
OpenPOWER on IntegriCloud