<div dir="ltr">Just submitted r288860 which should provide this explicit dependency to pthread. Hopefully that works, otherwise I'm going to need a bit more help/insight into why the sanitizer bot's build is so different from the others.<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 7, 2016 at 10:04 AM Dean Michael Berris <<a href="mailto:dberris@google.com">dberris@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Oops, thanks Mike -- let me try and fix that now.</div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Wed, Dec 7, 2016 at 6:53 AM Mike Aizatsky <<a href="mailto:aizatsky@google.com" class="gmail_msg" target="_blank">aizatsky@google.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Dean,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I think this breaks sanitizer bot:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/345" class="gmail_msg" target="_blank">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/345</a><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">gtest-all.cc.x86_64.o: In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::~ThreadLocal()':</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1349: undefined reference to `pthread_getspecific'</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1353: undefined reference to `pthread_key_delete'</div><div class="gmail_msg">gtest-all.cc.x86_64.o: In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::~ThreadLocal()':</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1349: undefined reference to `pthread_getspecific'</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1353: undefined reference to `pthread_key_delete'</div><div class="gmail_msg">gtest-all.cc.x86_64.o: In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const':</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1385: undefined reference to `pthread_getspecific'</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1392: undefined reference to `pthread_setspecific'</div><div class="gmail_msg">gtest-all.cc.x86_64.o: In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::GetOrCreateValue() const':</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1385: undefined reference to `pthread_getspecific'</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1392: undefined reference to `pthread_setspecific'</div><div class="gmail_msg">gtest-all.cc.x86_64.o: In function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::CreateKey()':</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1378: undefined reference to `pthread_key_create'</div><div class="gmail_msg">gtest-all.cc.x86_64.o: In function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::CreateKey()':</div><div class="gmail_msg">/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h:1378: undefined reference to `pthread_key_create'</div><div class="gmail_msg">clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)</div><div class="gmail_msg">make[3]: *** [lib/xray/tests/unit/CMakeFiles/XRayBufferQueueTest] Error 1</div><div class="gmail_msg">make[2]: *** [lib/xray/tests/unit/CMakeFiles/XRayBufferQueueTest.dir/all] Error 2</div></div><div class="gmail_msg"><br class="gmail_msg"></div></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Mon, Dec 5, 2016 at 10:34 PM Dean Michael Berris via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dberris<br class="gmail_msg">
Date: Tue Dec 6 00:24:08 2016<br class="gmail_msg">
New Revision: 288775<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=288775&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=288775&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
[XRay][compiler-rt] XRay Buffer Queue<br class="gmail_msg">
<br class="gmail_msg">
This implements a simple buffer queue to manage a pre-allocated queue of<br class="gmail_msg">
fixed-sized buffers to hold XRay records. We need this to support<br class="gmail_msg">
Flight Data Recorder (FDR) mode. We also implement this as a sub-library<br class="gmail_msg">
first to allow for development before actually using it in an<br class="gmail_msg">
implementation.<br class="gmail_msg">
<br class="gmail_msg">
Some important properties of the buffer queue:<br class="gmail_msg">
<br class="gmail_msg">
- Thread-safe enqueueing/dequeueing of fixed-size buffers.<br class="gmail_msg">
- Pre-allocation of buffers at construction.<br class="gmail_msg">
<br class="gmail_msg">
This is a re-roll of the previous attempt to submit, because it caused<br class="gmail_msg">
failures in arm and aarch64.<br class="gmail_msg">
<br class="gmail_msg">
Reviewers: majnemer, echristo, rSerge<br class="gmail_msg">
<br class="gmail_msg">
Subscribers: tberghammer, danalbert, srhines, modocache, mehdi_amini, mgorny, llvm-commits<br class="gmail_msg">
<br class="gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D26232" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D26232</a><br class="gmail_msg">
<br class="gmail_msg">
Added:<br class="gmail_msg">
compiler-rt/trunk/lib/xray/tests/CMakeLists.txt<br class="gmail_msg">
compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt<br class="gmail_msg">
compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc<br class="gmail_msg">
compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc<br class="gmail_msg">
compiler-rt/trunk/lib/xray/xray_buffer_queue.cc<br class="gmail_msg">
compiler-rt/trunk/lib/xray/xray_buffer_queue.h<br class="gmail_msg">
compiler-rt/trunk/test/xray/Unit/<a href="http://lit.site.cfg.in" rel="noreferrer" class="gmail_msg" target="_blank">lit.site.cfg.in</a><br class="gmail_msg">
Modified:<br class="gmail_msg">
compiler-rt/trunk/lib/xray/CMakeLists.txt<br class="gmail_msg">
compiler-rt/trunk/test/xray/CMakeLists.txt<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/lib/xray/CMakeLists.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/CMakeLists.txt?rev=288775&r1=288774&r2=288775&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/CMakeLists.txt?rev=288775&r1=288774&r2=288775&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/CMakeLists.txt (original)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/CMakeLists.txt Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -1,11 +1,15 @@<br class="gmail_msg">
# Build for the XRay runtime support library.<br class="gmail_msg">
<br class="gmail_msg">
+# Core XRay runtime library implementation files.<br class="gmail_msg">
set(XRAY_SOURCES<br class="gmail_msg">
xray_init.cc<br class="gmail_msg">
xray_interface.cc<br class="gmail_msg">
xray_flags.cc<br class="gmail_msg">
- xray_inmemory_log.cc<br class="gmail_msg">
-)<br class="gmail_msg">
+ xray_inmemory_log.cc)<br class="gmail_msg">
+<br class="gmail_msg">
+# XRay flight data recorder (FDR) implementation files.<br class="gmail_msg">
+set(XRAY_FDR_SOURCES<br class="gmail_msg">
+ xray_buffer_queue.cc)<br class="gmail_msg">
<br class="gmail_msg">
set(x86_64_SOURCES<br class="gmail_msg">
xray_x86_64.cc<br class="gmail_msg">
@@ -28,31 +32,48 @@ include_directories(..)<br class="gmail_msg">
include_directories(../../include)<br class="gmail_msg">
<br class="gmail_msg">
set(XRAY_CFLAGS ${SANITIZER_COMMON_CFLAGS})<br class="gmail_msg">
-<br class="gmail_msg">
set(XRAY_COMMON_DEFINITIONS XRAY_HAS_EXCEPTIONS=1)<br class="gmail_msg">
append_list_if(<br class="gmail_msg">
COMPILER_RT_HAS_XRAY_COMPILER_FLAG XRAY_SUPPORTED=1 XRAY_COMMON_DEFINITIONS)<br class="gmail_msg">
<br class="gmail_msg">
add_compiler_rt_object_libraries(RTXray<br class="gmail_msg">
- ARCHS ${XRAY_SUPPORTED_ARCH}<br class="gmail_msg">
- SOURCES ${XRAY_SOURCES} CFLAGS ${XRAY_CFLAGS}<br class="gmail_msg">
- DEFS ${XRAY_COMMON_DEFINITIONS})<br class="gmail_msg">
+ ARCHS ${XRAY_SUPPORTED_ARCH}<br class="gmail_msg">
+ SOURCES ${XRAY_SOURCES} CFLAGS ${XRAY_CFLAGS}<br class="gmail_msg">
+ DEFS ${XRAY_COMMON_DEFINITIONS})<br class="gmail_msg">
+<br class="gmail_msg">
+add_compiler_rt_object_libraries(RTXrayFDR<br class="gmail_msg">
+ ARCHS ${XRAY_SUPPORTED_ARCH}<br class="gmail_msg">
+ SOURCES ${XRAY_FDR_SOURCES} CFLAGS ${XRAY_CFLAGS}<br class="gmail_msg">
+ DEFS ${XRAY_COMMON_DEFINITIONS})<br class="gmail_msg">
<br class="gmail_msg">
add_compiler_rt_component(xray)<br class="gmail_msg">
+add_compiler_rt_component(xray-fdr)<br class="gmail_msg">
<br class="gmail_msg">
set(XRAY_COMMON_RUNTIME_OBJECT_LIBS<br class="gmail_msg">
RTSanitizerCommon<br class="gmail_msg">
RTSanitizerCommonLibc)<br class="gmail_msg">
<br class="gmail_msg">
-foreach (arch ${XRAY_SUPPORTED_ARCH})<br class="gmail_msg">
- if (CAN_TARGET_${arch})<br class="gmail_msg">
- add_compiler_rt_runtime(clang_rt.xray<br class="gmail_msg">
- STATIC<br class="gmail_msg">
- ARCHS ${arch}<br class="gmail_msg">
- SOURCES ${${arch}_SOURCES}<br class="gmail_msg">
- CFLAGS ${XRAY_CFLAGS}<br class="gmail_msg">
- DEFS ${XRAY_COMMON_DEFINITIONS}<br class="gmail_msg">
- OBJECT_LIBS ${XRAY_COMMON_RUNTIME_OBJECT_LIBS}<br class="gmail_msg">
- PARENT_TARGET xray)<br class="gmail_msg">
- endif ()<br class="gmail_msg">
+foreach(arch ${XRAY_SUPPORTED_ARCH})<br class="gmail_msg">
+ if(CAN_TARGET_${arch})<br class="gmail_msg">
+ add_compiler_rt_runtime(clang_rt.xray<br class="gmail_msg">
+ STATIC<br class="gmail_msg">
+ ARCHS ${arch}<br class="gmail_msg">
+ SOURCES ${${arch}_SOURCES}<br class="gmail_msg">
+ CFLAGS ${XRAY_CFLAGS}<br class="gmail_msg">
+ DEFS ${XRAY_COMMON_DEFINITIONS}<br class="gmail_msg">
+ OBJECT_LIBS ${XRAY_COMMON_RUNTIME_OBJECT_LIBS}<br class="gmail_msg">
+ PARENT_TARGET xray)<br class="gmail_msg">
+ add_compiler_rt_runtime(clang_rt.xray-fdr<br class="gmail_msg">
+ STATIC<br class="gmail_msg">
+ ARCHS ${arch}<br class="gmail_msg">
+ SOURCES ${XRAY_FDR_SOURCES}<br class="gmail_msg">
+ CFLAGS ${XRAY_CFLAGS}<br class="gmail_msg">
+ DEFS ${XRAY_COMMON_DEFINITIONS}<br class="gmail_msg">
+ OBJECT_LIBS ${XRAY_COMMON_RUNTIME_OBJECT_LIBS}<br class="gmail_msg">
+ PARENT_TARGET xray-fdr)<br class="gmail_msg">
+ endif()<br class="gmail_msg">
endforeach()<br class="gmail_msg">
+<br class="gmail_msg">
+if(COMPILER_RT_INCLUDE_TESTS)<br class="gmail_msg">
+ add_subdirectory(tests)<br class="gmail_msg">
+endif()<br class="gmail_msg">
<br class="gmail_msg">
Added: compiler-rt/trunk/lib/xray/tests/CMakeLists.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/CMakeLists.txt?rev=288775&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/CMakeLists.txt?rev=288775&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/tests/CMakeLists.txt (added)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/tests/CMakeLists.txt Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -0,0 +1,58 @@<br class="gmail_msg">
+include_directories(..)<br class="gmail_msg">
+<br class="gmail_msg">
+add_custom_target(XRayUnitTests)<br class="gmail_msg">
+set_target_properties(XRayUnitTests PROPERTIES FOLDER "XRay unittests")<br class="gmail_msg">
+<br class="gmail_msg">
+set(XRAY_UNITTEST_CFLAGS<br class="gmail_msg">
+ ${XRAY_CFLAGS}<br class="gmail_msg">
+ ${COMPILER_RT_UNITTEST_CFLAGS}<br class="gmail_msg">
+ ${COMPILER_RT_GTEST_CFLAGS}<br class="gmail_msg">
+ -I${COMPILER_RT_SOURCE_DIR}/include<br class="gmail_msg">
+ -I${COMPILER_RT_SOURCE_DIR}/lib/xray)<br class="gmail_msg">
+<br class="gmail_msg">
+macro(xray_compile obj_list source arch)<br class="gmail_msg">
+ get_filename_component(basename ${source} NAME)<br class="gmail_msg">
+ set(output_obj "${basename}.${arch}.o")<br class="gmail_msg">
+ get_target_flags_for_arch(${arch} TARGET_CFLAGS)<br class="gmail_msg">
+ if(NOT COMPILER_RT_STANDALONE_BUILD)<br class="gmail_msg">
+ list(APPEND COMPILE_DEPS gtest_main xray-fdr)<br class="gmail_msg">
+ endif()<br class="gmail_msg">
+ clang_compile(${output_obj} ${source}<br class="gmail_msg">
+ CFLAGS ${XRAY_UNITTEST_CFLAGS} ${TARGET_CFLAGS}<br class="gmail_msg">
+ DEPS ${COMPILE_DEPS})<br class="gmail_msg">
+ list(APPEND ${obj_list} ${output_obj})<br class="gmail_msg">
+endmacro()<br class="gmail_msg">
+<br class="gmail_msg">
+macro(add_xray_unittest testname)<br class="gmail_msg">
+ set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH})<br class="gmail_msg">
+ if (APPLE)<br class="gmail_msg">
+ darwin_filter_host_archs(XRAY_SUPPORTED_ARCH)<br class="gmail_msg">
+ endif()<br class="gmail_msg">
+ if(UNIX)<br class="gmail_msg">
+ foreach(arch ${XRAY_TEST_ARCH})<br class="gmail_msg">
+ cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})<br class="gmail_msg">
+ set(TEST_OBJECTS)<br class="gmail_msg">
+ foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE})<br class="gmail_msg">
+ xray_compile(TEST_OBJECTS ${SOURCE} ${arch} ${TEST_HEADERS})<br class="gmail_msg">
+ endforeach()<br class="gmail_msg">
+ get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)<br class="gmail_msg">
+ set(TEST_DEPS ${TEST_OBJECTS})<br class="gmail_msg">
+ if(NOT COMPILER_RT_STANDALONE_BUILD)<br class="gmail_msg">
+ list(APPEND TEST_DEPS gtest_main xray-fdr)<br class="gmail_msg">
+ endif()<br class="gmail_msg">
+ if(NOT APPLE)<br class="gmail_msg">
+ add_compiler_rt_test(XRayUnitTests ${testname}<br class="gmail_msg">
+ OBJECTS ${TEST_OBJECTS}<br class="gmail_msg">
+ DEPS ${TEST_DEPS}<br class="gmail_msg">
+ LINK_FLAGS ${TARGET_LINK_FLAGS}<br class="gmail_msg">
+ -lstdc++ -lm ${CMAKE_THREAD_LIBS_INIT}<br class="gmail_msg">
+ -L${COMPILER_RT_LIBRARY_OUTPUT_DIR} -lclang_rt.xray-fdr-${arch})<br class="gmail_msg">
+ endif()<br class="gmail_msg">
+ # FIXME: Figure out how to run even just the unit tests on APPLE.<br class="gmail_msg">
+ endforeach()<br class="gmail_msg">
+ endif()<br class="gmail_msg">
+endmacro()<br class="gmail_msg">
+<br class="gmail_msg">
+if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)<br class="gmail_msg">
+ add_subdirectory(unit)<br class="gmail_msg">
+endif()<br class="gmail_msg">
<br class="gmail_msg">
Added: compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt?rev=288775&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt?rev=288775&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt (added)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/tests/unit/CMakeLists.txt Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -0,0 +1,2 @@<br class="gmail_msg">
+add_xray_unittest(XRayBufferQueueTest SOURCES<br class="gmail_msg">
+ buffer_queue_test.cc xray_unit_test_main.cc)<br class="gmail_msg">
<br class="gmail_msg">
Added: compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc?rev=288775&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc?rev=288775&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc (added)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/tests/unit/buffer_queue_test.cc Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -0,0 +1,80 @@<br class="gmail_msg">
+//===-- buffer_queue_test.cc ----------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is a part of XRay, a function call tracing system.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+#include "xray_buffer_queue.h"<br class="gmail_msg">
+#include "gtest/gtest.h"<br class="gmail_msg">
+<br class="gmail_msg">
+#include <future><br class="gmail_msg">
+#include <unistd.h><br class="gmail_msg">
+<br class="gmail_msg">
+namespace __xray {<br class="gmail_msg">
+<br class="gmail_msg">
+static constexpr size_t kSize = 4096;<br class="gmail_msg">
+<br class="gmail_msg">
+TEST(BufferQueueTest, API) { BufferQueue Buffers(kSize, 1); }<br class="gmail_msg">
+<br class="gmail_msg">
+TEST(BufferQueueTest, GetAndRelease) {<br class="gmail_msg">
+ BufferQueue Buffers(kSize, 1);<br class="gmail_msg">
+ BufferQueue::Buffer Buf;<br class="gmail_msg">
+ ASSERT_FALSE(Buffers.getBuffer(Buf));<br class="gmail_msg">
+ ASSERT_NE(nullptr, Buf.Buffer);<br class="gmail_msg">
+ ASSERT_FALSE(Buffers.releaseBuffer(Buf));<br class="gmail_msg">
+ ASSERT_EQ(nullptr, Buf.Buffer);<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+TEST(BufferQueueTest, GetUntilFailed) {<br class="gmail_msg">
+ BufferQueue Buffers(kSize, 1);<br class="gmail_msg">
+ BufferQueue::Buffer Buf0;<br class="gmail_msg">
+ EXPECT_FALSE(Buffers.getBuffer(Buf0));<br class="gmail_msg">
+ BufferQueue::Buffer Buf1;<br class="gmail_msg">
+ EXPECT_EQ(std::errc::not_enough_memory, Buffers.getBuffer(Buf1));<br class="gmail_msg">
+ EXPECT_FALSE(Buffers.releaseBuffer(Buf0));<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+TEST(BufferQueueTest, ReleaseUnknown) {<br class="gmail_msg">
+ BufferQueue Buffers(kSize, 1);<br class="gmail_msg">
+ BufferQueue::Buffer Buf;<br class="gmail_msg">
+ Buf.Buffer = reinterpret_cast<void *>(0xdeadbeef);<br class="gmail_msg">
+ Buf.Size = kSize;<br class="gmail_msg">
+ EXPECT_EQ(std::errc::argument_out_of_domain, Buffers.releaseBuffer(Buf));<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+TEST(BufferQueueTest, ErrorsWhenFinalising) {<br class="gmail_msg">
+ BufferQueue Buffers(kSize, 2);<br class="gmail_msg">
+ BufferQueue::Buffer Buf;<br class="gmail_msg">
+ ASSERT_FALSE(Buffers.getBuffer(Buf));<br class="gmail_msg">
+ ASSERT_NE(nullptr, Buf.Buffer);<br class="gmail_msg">
+ ASSERT_FALSE(Buffers.finalize());<br class="gmail_msg">
+ BufferQueue::Buffer OtherBuf;<br class="gmail_msg">
+ ASSERT_EQ(std::errc::state_not_recoverable, Buffers.getBuffer(OtherBuf));<br class="gmail_msg">
+ ASSERT_EQ(std::errc::state_not_recoverable, Buffers.finalize());<br class="gmail_msg">
+ ASSERT_FALSE(Buffers.releaseBuffer(Buf));<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+TEST(BufferQueueTest, MultiThreaded) {<br class="gmail_msg">
+ BufferQueue Buffers(kSize, 100);<br class="gmail_msg">
+ auto F = [&] {<br class="gmail_msg">
+ BufferQueue::Buffer B;<br class="gmail_msg">
+ while (!Buffers.getBuffer(B)) {<br class="gmail_msg">
+ Buffers.releaseBuffer(B);<br class="gmail_msg">
+ }<br class="gmail_msg">
+ };<br class="gmail_msg">
+ auto T0 = std::async(std::launch::async, F);<br class="gmail_msg">
+ auto T1 = std::async(std::launch::async, F);<br class="gmail_msg">
+ auto T2 = std::async(std::launch::async, [&] {<br class="gmail_msg">
+ while (!Buffers.finalize())<br class="gmail_msg">
+ ;<br class="gmail_msg">
+ });<br class="gmail_msg">
+ F();<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+} // namespace __xray<br class="gmail_msg">
<br class="gmail_msg">
Added: compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc?rev=288775&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc?rev=288775&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc (added)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/tests/unit/xray_unit_test_main.cc Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -0,0 +1,18 @@<br class="gmail_msg">
+//===-- xray_unit_test_main.cc --------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is a part of XRay, a function call tracing system.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+#include "gtest/gtest.h"<br class="gmail_msg">
+<br class="gmail_msg">
+int main(int argc, char **argv) {<br class="gmail_msg">
+ testing::InitGoogleTest(&argc, argv);<br class="gmail_msg">
+ return RUN_ALL_TESTS();<br class="gmail_msg">
+}<br class="gmail_msg">
<br class="gmail_msg">
Added: compiler-rt/trunk/lib/xray/xray_buffer_queue.cc<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_buffer_queue.cc?rev=288775&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_buffer_queue.cc?rev=288775&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/xray_buffer_queue.cc (added)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/xray_buffer_queue.cc Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -0,0 +1,65 @@<br class="gmail_msg">
+//===-- xray_buffer_queue.cc -----------------------------------*- C++ -*-===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is a part of XRay, a dynamic runtime instruementation system.<br class="gmail_msg">
+//<br class="gmail_msg">
+// Defines the interface for a buffer queue implementation.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+#include "xray_buffer_queue.h"<br class="gmail_msg">
+#include <cassert><br class="gmail_msg">
+#include <cstdlib><br class="gmail_msg">
+<br class="gmail_msg">
+using namespace __xray;<br class="gmail_msg">
+<br class="gmail_msg">
+BufferQueue::BufferQueue(std::size_t B, std::size_t N)<br class="gmail_msg">
+ : BufferSize(B), Buffers(N) {<br class="gmail_msg">
+ for (auto &Buf : Buffers) {<br class="gmail_msg">
+ void *Tmp = malloc(BufferSize);<br class="gmail_msg">
+ Buf.Buffer = Tmp;<br class="gmail_msg">
+ Buf.Size = B;<br class="gmail_msg">
+ if (Tmp != 0)<br class="gmail_msg">
+ OwnedBuffers.insert(Tmp);<br class="gmail_msg">
+ }<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+std::error_code BufferQueue::getBuffer(Buffer &Buf) {<br class="gmail_msg">
+ if (Finalizing.load(std::memory_order_acquire))<br class="gmail_msg">
+ return std::make_error_code(std::errc::state_not_recoverable);<br class="gmail_msg">
+ std::lock_guard<std::mutex> Guard(Mutex);<br class="gmail_msg">
+ if (Buffers.empty())<br class="gmail_msg">
+ return std::make_error_code(std::errc::not_enough_memory);<br class="gmail_msg">
+ Buf = Buffers.front();<br class="gmail_msg">
+ Buffers.pop_front();<br class="gmail_msg">
+ return {};<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+std::error_code BufferQueue::releaseBuffer(Buffer &Buf) {<br class="gmail_msg">
+ if (OwnedBuffers.count(Buf.Buffer) == 0)<br class="gmail_msg">
+ return std::make_error_code(std::errc::argument_out_of_domain);<br class="gmail_msg">
+ std::lock_guard<std::mutex> Guard(Mutex);<br class="gmail_msg">
+ Buffers.push_back(Buf);<br class="gmail_msg">
+ Buf.Buffer = nullptr;<br class="gmail_msg">
+ Buf.Size = BufferSize;<br class="gmail_msg">
+ return {};<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+std::error_code BufferQueue::finalize() {<br class="gmail_msg">
+ if (Finalizing.exchange(true, std::memory_order_acq_rel))<br class="gmail_msg">
+ return std::make_error_code(std::errc::state_not_recoverable);<br class="gmail_msg">
+ return {};<br class="gmail_msg">
+}<br class="gmail_msg">
+<br class="gmail_msg">
+BufferQueue::~BufferQueue() {<br class="gmail_msg">
+ for (auto &Buf : Buffers) {<br class="gmail_msg">
+ free(Buf.Buffer);<br class="gmail_msg">
+ Buf.Buffer = nullptr;<br class="gmail_msg">
+ Buf.Size = 0;<br class="gmail_msg">
+ }<br class="gmail_msg">
+}<br class="gmail_msg">
<br class="gmail_msg">
Added: compiler-rt/trunk/lib/xray/xray_buffer_queue.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_buffer_queue.h?rev=288775&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_buffer_queue.h?rev=288775&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/xray/xray_buffer_queue.h (added)<br class="gmail_msg">
+++ compiler-rt/trunk/lib/xray/xray_buffer_queue.h Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -0,0 +1,86 @@<br class="gmail_msg">
+//===-- xray_buffer_queue.h ------------------------------------*- C++ -*-===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// The LLVM Compiler Infrastructure<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is distributed under the University of Illinois Open Source<br class="gmail_msg">
+// License. See LICENSE.TXT for details.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+//<br class="gmail_msg">
+// This file is a part of XRay, a dynamic runtime instrumentation system.<br class="gmail_msg">
+//<br class="gmail_msg">
+// Defines the interface for a buffer queue implementation.<br class="gmail_msg">
+//<br class="gmail_msg">
+//===----------------------------------------------------------------------===//<br class="gmail_msg">
+#ifndef XRAY_BUFFER_QUEUE_H<br class="gmail_msg">
+#define XRAY_BUFFER_QUEUE_H<br class="gmail_msg">
+<br class="gmail_msg">
+#include <atomic><br class="gmail_msg">
+#include <cstdint><br class="gmail_msg">
+#include <deque><br class="gmail_msg">
+#include <mutex><br class="gmail_msg">
+#include <system_error><br class="gmail_msg">
+#include <unordered_set><br class="gmail_msg">
+<br class="gmail_msg">
+namespace __xray {<br class="gmail_msg">
+<br class="gmail_msg">
+/// BufferQueue implements a circular queue of fixed sized buffers (much like a<br class="gmail_msg">
+/// freelist) but is concerned mostly with making it really quick to initialise,<br class="gmail_msg">
+/// finalise, and get/return buffers to the queue. This is one key component of<br class="gmail_msg">
+/// the "flight data recorder" (FDR) mode to support ongoing XRay function call<br class="gmail_msg">
+/// trace collection.<br class="gmail_msg">
+class BufferQueue {<br class="gmail_msg">
+public:<br class="gmail_msg">
+ struct Buffer {<br class="gmail_msg">
+ void *Buffer = nullptr;<br class="gmail_msg">
+ std::size_t Size = 0;<br class="gmail_msg">
+ };<br class="gmail_msg">
+<br class="gmail_msg">
+private:<br class="gmail_msg">
+ std::size_t BufferSize;<br class="gmail_msg">
+ std::deque<Buffer> Buffers;<br class="gmail_msg">
+ std::mutex Mutex;<br class="gmail_msg">
+ std::unordered_set<void *> OwnedBuffers;<br class="gmail_msg">
+ std::atomic<bool> Finalizing;<br class="gmail_msg">
+<br class="gmail_msg">
+public:<br class="gmail_msg">
+ /// Initialise a queue of size |N| with buffers of size |B|.<br class="gmail_msg">
+ BufferQueue(std::size_t B, std::size_t N);<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Updates |Buf| to contain the pointer to an appropriate buffer. Returns an<br class="gmail_msg">
+ /// error in case there are no available buffers to return when we will run<br class="gmail_msg">
+ /// over the upper bound for the total buffers.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// Requirements:<br class="gmail_msg">
+ /// - BufferQueue is not finalising.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// Returns:<br class="gmail_msg">
+ /// - std::errc::not_enough_memory on exceeding MaxSize.<br class="gmail_msg">
+ /// - no error when we find a Buffer.<br class="gmail_msg">
+ /// - std::errc::state_not_recoverable on finalising BufferQueue.<br class="gmail_msg">
+ std::error_code getBuffer(Buffer &Buf);<br class="gmail_msg">
+<br class="gmail_msg">
+ /// Updates |Buf| to point to nullptr, with size 0.<br class="gmail_msg">
+ ///<br class="gmail_msg">
+ /// Returns:<br class="gmail_msg">
+ /// - ...<br class="gmail_msg">
+ std::error_code releaseBuffer(Buffer &Buf);<br class="gmail_msg">
+<br class="gmail_msg">
+ bool finalizing() const { return Finalizing.load(std::memory_order_acquire); }<br class="gmail_msg">
+<br class="gmail_msg">
+ // Sets the state of the BufferQueue to finalizing, which ensures that:<br class="gmail_msg">
+ //<br class="gmail_msg">
+ // - All subsequent attempts to retrieve a Buffer will fail.<br class="gmail_msg">
+ // - All releaseBuffer operations will not fail.<br class="gmail_msg">
+ //<br class="gmail_msg">
+ // After a call to finalize succeeds, all subsequent calls to finalize will<br class="gmail_msg">
+ // fail with std::errc::state_not_recoverable.<br class="gmail_msg">
+ std::error_code finalize();<br class="gmail_msg">
+<br class="gmail_msg">
+ // Cleans up allocated buffers.<br class="gmail_msg">
+ ~BufferQueue();<br class="gmail_msg">
+};<br class="gmail_msg">
+<br class="gmail_msg">
+} // namespace __xray<br class="gmail_msg">
+<br class="gmail_msg">
+#endif // XRAY_BUFFER_QUEUE_H<br class="gmail_msg">
<br class="gmail_msg">
Modified: compiler-rt/trunk/test/xray/CMakeLists.txt<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/xray/CMakeLists.txt?rev=288775&r1=288774&r2=288775&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/xray/CMakeLists.txt?rev=288775&r1=288774&r2=288775&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/test/xray/CMakeLists.txt (original)<br class="gmail_msg">
+++ compiler-rt/trunk/test/xray/CMakeLists.txt Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -25,6 +25,15 @@ if (COMPILER_RT_BUILD_XRAY AND COMPILER_<br class="gmail_msg">
endforeach()<br class="gmail_msg">
endif()<br class="gmail_msg">
<br class="gmail_msg">
+# Add unit tests.<br class="gmail_msg">
+if(COMPILER_RT_INCLUDE_TESTS)<br class="gmail_msg">
+ configure_lit_site_cfg(<br class="gmail_msg">
+ ${CMAKE_CURRENT_SOURCE_DIR}/Unit/<a href="http://lit.site.cfg.in" rel="noreferrer" class="gmail_msg" target="_blank">lit.site.cfg.in</a><br class="gmail_msg">
+ ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)<br class="gmail_msg">
+ list(APPEND XRAY_TEST_DEPS XRayUnitTests)<br class="gmail_msg">
+ list(APPEND XRAY_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)<br class="gmail_msg">
+endif()<br class="gmail_msg">
+<br class="gmail_msg">
add_lit_testsuite(check-xray "Running the XRay tests"<br class="gmail_msg">
${XRAY_TESTSUITES}<br class="gmail_msg">
DEPENDS ${XRAY_TEST_DEPS})<br class="gmail_msg">
<br class="gmail_msg">
Added: compiler-rt/trunk/test/xray/Unit/<a href="http://lit.site.cfg.in" rel="noreferrer" class="gmail_msg" target="_blank">lit.site.cfg.in</a><br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/xray/Unit/lit.site.cfg.in?rev=288775&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/xray/Unit/lit.site.cfg.in?rev=288775&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- compiler-rt/trunk/test/xray/Unit/<a href="http://lit.site.cfg.in" rel="noreferrer" class="gmail_msg" target="_blank">lit.site.cfg.in</a> (added)<br class="gmail_msg">
+++ compiler-rt/trunk/test/xray/Unit/<a href="http://lit.site.cfg.in" rel="noreferrer" class="gmail_msg" target="_blank">lit.site.cfg.in</a> Tue Dec 6 00:24:08 2016<br class="gmail_msg">
@@ -0,0 +1,12 @@<br class="gmail_msg">
+@LIT_SITE_CFG_IN_HEADER@<br class="gmail_msg">
+<br class="gmail_msg">
+import os<br class="gmail_msg">
+<br class="gmail_msg">
+# Load common config for all compiler-rt unit tests.<br class="gmail_msg">
+lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")<br class="gmail_msg">
+<br class="gmail_msg">
+# Setup config name.<br class="gmail_msg">
+<a href="http://config.name" rel="noreferrer" class="gmail_msg" target="_blank">config.name</a> = 'XRay-Unit'<br class="gmail_msg">
+<br class="gmail_msg">
+config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/xray/tests"<br class="gmail_msg">
+config.test_source_root = config.test_exec_root<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div><div dir="ltr" class="gmail_msg">-- <br class="gmail_msg"></div><div data-smartmail="gmail_signature" class="gmail_msg"><div dir="ltr" class="gmail_msg">Mike<br class="gmail_msg">Sent from phone</div></div>
</blockquote></div></blockquote></div>