diff options
author | Dean Michael Berris <dberris@google.com> | 2017-10-04 05:20:13 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2017-10-04 05:20:13 +0000 |
commit | 06f288ce325d14aeee9b3887cfc7862f0c1735ba (patch) | |
tree | b5648b504d49a892e23ab1093761302958f72f80 /test/xray | |
parent | 640d7d1f97a1804a0833c2d1d7220fb50bab746a (diff) |
[XRay][compiler-rt] Use a hand-written circular buffer in BufferQueue
Summary:
This change removes the dependency on using a std::deque<...> for the
storage of the buffers in the buffer queue. We instead implement a
fixed-size circular buffer that's resilient to exhaustion, and preserves
the semantics of the BufferQueue.
We're moving away from using std::deque<...> for two reasons:
- We want to remove dependencies on the STL for data structures.
- We want the data structure we use to not require re-allocation in
the normal course of operation.
The internal implementation of the buffer queue uses heap-allocated
arrays that are initialized once when the BufferQueue is created, and
re-uses slots in the buffer array as buffers are returned in order.
We also change the lock used in the implementation to a spinlock
instead of a blocking mutex. We reason that since the release operations
now take very little time in the critical section, that a spinlock would
be appropriate.
This change is related to D38073.
This change is a re-submit with the following changes:
- Keeping track of the live buffers with a counter independent of the
pointers keeping track of the extents of the circular buffer.
- Additional documentation of what the data members are meant to
represent.
Reviewers: dblaikie, kpw, pelikan
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D38119
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@314877 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/xray')
-rw-r--r-- | test/xray/TestCases/Linux/fdr-thread-order.cc | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/test/xray/TestCases/Linux/fdr-thread-order.cc b/test/xray/TestCases/Linux/fdr-thread-order.cc index 6ac2114a5..8e8c421dc 100644 --- a/test/xray/TestCases/Linux/fdr-thread-order.cc +++ b/test/xray/TestCases/Linux/fdr-thread-order.cc @@ -1,37 +1,63 @@ // RUN: %clangxx_xray -g -std=c++11 %s -o %t // RUN: rm fdr-thread-order.* || true -// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false xray_logfile_base=fdr-thread-order. xray_fdr_log=true verbosity=1 xray_fdr_log_func_duration_threshold_us=0" %run %t 2>&1 | FileCheck %s -// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t "`ls fdr-thread-order.* | head -1`" | FileCheck %s --check-prefix TRACE +// RUN: XRAY_OPTIONS="patch_premain=false xray_naive_log=false \ +// RUN: xray_logfile_base=fdr-thread-order. xray_fdr_log=true verbosity=1 \ +// RUN: xray_fdr_log_func_duration_threshold_us=0" %run %t 2>&1 | \ +// RUN: FileCheck %s +// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t \ +// RUN: "`ls fdr-thread-order.* | head -1`" +// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t \ +// RUN: "`ls fdr-thread-order.* | head -1`" | \ +// RUN: FileCheck %s --check-prefix TRACE // RUN: rm fdr-thread-order.* // FIXME: Make llvm-xray work on non-x86_64 as well. // REQUIRES: x86_64-linux // REQUIRES: built-in-llvm-tree #include "xray/xray_log_interface.h" -#include <thread> +#include <atomic> #include <cassert> +#include <thread> constexpr auto kBufferSize = 16384; constexpr auto kBufferMax = 10; -thread_local uint64_t var = 0; -[[clang::xray_always_instrument]] void __attribute__((noinline)) f1() { ++var; } -[[clang::xray_always_instrument]] void __attribute__((noinline)) f2() { ++var; } +std::atomic<uint64_t> var{0}; + +[[clang::xray_always_instrument]] void __attribute__((noinline)) f1() { + for (auto i = 0; i < 1 << 20; ++i) + ++var; +} + +[[clang::xray_always_instrument]] void __attribute__((noinline)) f2() { + for (auto i = 0; i < 1 << 20; ++i) + ++var; +} int main(int argc, char *argv[]) { using namespace __xray; FDRLoggingOptions Options; + __xray_patch(); assert(__xray_log_init(kBufferSize, kBufferMax, &Options, sizeof(FDRLoggingOptions)) == XRayLogInitStatus::XRAY_LOG_INITIALIZED); - __xray_patch(); - std::thread t1([] { f1(); }); - std::thread t2([] { f2(); }); - t1.join(); - t2.join(); + + std::atomic_thread_fence(std::memory_order_acq_rel); + + { + std::thread t1([] { f1(); }); + std::thread t2([] { f2(); }); + t1.join(); + t2.join(); + } + + std::atomic_thread_fence(std::memory_order_acq_rel); __xray_log_finalize(); __xray_log_flushLog(); + __xray_unpatch(); + return var > 0 ? 0 : 1; // CHECK: {{.*}}XRay: Log file in '{{.*}}' + // CHECK-NOT: Failed } // We want to make sure that the order of the function log doesn't matter. |