summaryrefslogtreecommitdiff
path: root/lib/xray/tests
AgeCommit message (Collapse)Author
2017-11-21[XRay] Use optimistic logging model for FDR modeDean Michael Berris
Summary: 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. In this change, we limit the call to pthread_setspecific(...) to provide a non-null value to associate to the key created with pthread_key_create(...). While this doesn't completely eliminate the potential for the deadlock(s), it does allow us to still clean up at thread exit when we need to. The change is that we don't need to do more work when starting and ending a thread's lifetime. We also have a test to make sure that we actually can safely recycle the buffers in case we end up re-using the buffer(s) available from the queue on multiple thread entry/exits. 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 outside of the buffer's contents but are written before the actual buffer. This data is associated to the Buffer handed out by the BufferQueue rather than a record that occupies bytes in the actual 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. Reviewers: dblaikie, pelikan, kpw Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D39526 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318733 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10Revert "[XRay][darwin] Initial XRay in Darwin Support"Dean Michael Berris
This reverts r317875. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317877 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[XRay][darwin] Initial XRay in Darwin SupportDean Michael Berris
Summary: This change implements the changes required in both clang and compiler-rt to allow building XRay-instrumented binaries in Darwin. For now we limit this to x86_64. We also start building the XRay runtime library in compiler-rt for osx. A caveat to this is that we don't have the tests set up and running yet, which we'll do in a set of follow-on changes. This patch uses the monorepo layout for the coordinated change across multiple projects. Reviewers: kubamracek Subscribers: mgorny, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D39114 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317875 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-14[xray] Fix CMake for X-RAY testsGeorge Karpenkov
Correctly depend on llvm-xray, make sure unit tests are being run. Differential Revision: https://reviews.llvm.org/D38917 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@315827 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-31[XRay][compiler-rt] Enable the XRay compiler-rt unit tests.Dean Michael Berris
Summary: Before this change we seemed to not be running the unit tests, and therefore we set out to run them. In the process of making this happen we found a divergence between the implementation and the tests. This includes changes to both the CMake files as well as the implementation and headers of the XRay runtime. We've also updated documentation on the changed functions. Reviewers: kpw, eizan Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D37290 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@312202 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-21Fix multi-architecture build for lib/xray.George Karpenkov
Differential Revision: https://reviews.llvm.org/D36881 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@311379 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-15[sanitizers CMake] NFC Refactor the logic for compiling and generating testsGeorge Karpenkov
into a function. Most CMake configuration under compiler-rt/lib/*/tests have almost-the-same-but-not-quite functions of the form add_X_[unit]tests for compiling and running the tests. Much of the logic is duplicated with minor variations across different sub-folders. This can harm productivity for multiple reasons: For newcomers, resulting CMake files are very large, hard to understand, and hide the intention of the code. Changes for enabling certain architectures end up being unnecessarily large, as they get duplicated across multiple folders. Adding new sub-projects requires more effort than it should, as a developer has to again copy-n-paste the configuration, and it's not even clear from which sub-project it should be copy-n-pasted. With this change the logic of compile-and-generate-a-set-of-tests is extracted into a function, which hopefully makes writing and reading CMake much easier. Differential Revision: https://reviews.llvm.org/D36116 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@310971 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-28[sanitizer tests CMake] Factor out CMake logic for compiling sanitizer testsGeorge Karpenkov
Currently there's a large amount of CMake logic duplication for compiling sanitizer tests. If we add more sanitizers, the duplication will get even worse. This change factors out common compilation commands into a macro available to all sanitizers. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309405 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-11[XRay][compiler-rt] Remove the xray_fdr_log_printer_toolDean Michael Berris
Summary: We can move this functionality into LLVM's tools instead, as it no longer is strictly required for the compiler-rt testing infrastructure. It also is blocking the successful bootstrapping of the clang compiler due to a missing virtual destructor in one of the flag parsing library. Since this binary isn't critical for the XRay runtime testing effort anymore (yet), we remove it in the meantime with the hope of moving the functionality in LLVM proper instead. Reviewers: kpw, pelikan, rnk, seurer, eugenis Subscribers: llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D31926 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299916 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-27[XRay][compiler-rt] Use sanitizer_common's atomic opsDean Michael Berris
Instead of std::atomic APIs for atomic operations, we instead use APIs include with sanitizer_common. This allows us to, at runtime, not have to depend on potentially dynamically provided implementations of these atomic operations. Fixes http://llvm.org/PR32274. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298833 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-22[XRay][compiler-rt] Remove dependency on <system_error>Dean Michael Berris
Summary: Depending on C++11 <system_error> introduces a link-time requirement to C++11 symbols. Removing it allows us to depend on header-only C++11 and up libraries. Partially fixes http://llvm.org/PR32274 -- we know there's more invasive work to be done, but we're doing it incrementally. Reviewers: dblaikie, kpw, pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31233 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298480 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-17[XRay][compiler-rt] Add missing include for <functional>Dean Michael Berris
Fixes http://llvm.org/PR32313 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298037 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-15[XRay] [compiler-rt] Refactor logic for xray fdr logging. NFC.Dean Michael Berris
Summary: Separated the IO and the thread local storage state machine of logging from the writing of log records once the contents are deterministic. Finer granularity functions are provided as inline functions in the same header such that stack does not grow due to the functions being separated. An executable utility xray_fdr_log_printer is also implemented to use the finest granularity functions to produce binary test data in the FDR format with a relatively convenient text input. For example, one can take a file with textual contents layed out in rows and feed it to the binary to generate data that llvm-xray convert can then read. This is a convenient way to build a test suite for llvm-xray convert to ensure it's robust to the fdr format. Example: $cat myFile.txt NewBuffer : { time = 2 , Tid=5} NewCPU : { CPU =1 , TSC = 123} Function : { FuncId = 5, TSCDelta = 3, EntryType = Entry } Function : { FuncId = 5, TSCDelta = 5, EntryType = Exit} TSCWrap : { TSC = 678 } Function : { FuncId = 6, TSCDelta = 0, EntryType = Entry } Function : { FuncId = 6, TSCDelta = 50, EntryType = Exit } EOB : { } $cat myFile.txt | ./bin/xray_fdr_log_printer > /tmp/binarydata.bin $./bin/llvm-xray convert -output-format=yaml -output=- /tmp/binarydata.bin yaml format comes out as expected. Reviewers: dberris, pelikan Reviewed By: dberris Subscribers: llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D30850 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@297801 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-23[xray] Unbreak unittest after r295967.Benjamin Kramer
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295969 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-15[XRay] Fix gtest error code comparison. NFC.Tim Shen
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295248 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-15[Compiler-rt][XRAY][MIPS] Support xray on mips/mipsel/mips64/mips64elSagar Thakur
Summary: Adds support for xray on mips/mipsel/mips64/mips64el. Reviewed by sdardis, dberris Differential: D27699 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295166 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-07[XRay][compiler-rt][NFC] Turn ProudCase functions to humbleCase functionsDean Michael Berris
Summary: As pointed out in casual reading of the XRay codebase, that we had some interesting named functions that didn't quite follow the LLVM coding conventions. Reviewers: chandlerc, dblaikie Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29625 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@294373 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-25[XRay][compiler-rt] XRay Flight Data Recorder ModeDean Michael Berris
Summary: In this change we introduce the notion of a "flight data recorder" mode for XRay logging, where XRay logs in-memory first, and write out data on-demand as required (as opposed to the naive implementation that keeps logging while tracing is "on"). This depends on D26232 where we implement the core data structure for holding the buffers that threads will be using to write out records of operation. This implementation only currently works on x86_64 and depends heavily on the TSC math to write out smaller records to the inmemory buffers. Also, this implementation defines two different kinds of records with different sizes (compared to the current naive implementation): a MetadataRecord (16 bytes) and a FunctionRecord (8 bytes). MetadataRecord entries are meant to write out information like the thread ID for which the metadata record is defined for, whether the execution of a thread moved to a different CPU, etc. while a FunctionRecord represents the different kinds of function call entry/exit records we might encounter in the course of a thread's execution along with a delta from the last time the logging handler was called. While this implementation is not exactly what is described in the original XRay whitepaper, this one gives us an initial implementation that we can iterate and build upon. Reviewers: echristo, rSerge, majnemer Subscribers: mehdi_amini, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D27038 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293015 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-03Revert "[XRay][compiler-rt] XRay Flight Data Recorder Mode"Dean Michael Berris
This reverts rL290852 as it breaks aarch64 and arm. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290854 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-03[XRay][compiler-rt] XRay Flight Data Recorder ModeDean Michael Berris
Summary: In this change we introduce the notion of a "flight data recorder" mode for XRay logging, where XRay logs in-memory first, and write out data on-demand as required (as opposed to the naive implementation that keeps logging while tracing is "on"). This depends on D26232 where we implement the core data structure for holding the buffers that threads will be using to write out records of operation. This implementation only currently works on x86_64 and depends heavily on the TSC math to write out smaller records to the inmemory buffers. Also, this implementation defines two different kinds of records with different sizes (compared to the current naive implementation): a MetadataRecord (16 bytes) and a FunctionRecord (8 bytes). MetadataRecord entries are meant to write out information like the thread ID for which the metadata record is defined for, whether the execution of a thread moved to a different CPU, etc. while a FunctionRecord represents the different kinds of function call entry/exit records we might encounter in the course of a thread's execution along with a delta from the last time the logging handler was called. While this implementation is not exactly what is described in the original XRay whitepaper, this one gives us an initial implementation that we can iterate and build upon. Reviewers: echristo, rSerge, majnemer Subscribers: mehdi_amini, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D27038 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290852 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-13[XRay][compiler-rt] Use explicit comparisons in unit tests.Dean Michael Berris
Summary: This should improve the error messages generated providing a bit more information when the failures are printed out. One example of a contrived error looks like: ``` Expected: (Buffers.getBuffer(Buf)) != (std::error_code()), actual: system:0 vs system:0 ``` Because we're using error codes, the default printing gets us more useful information in case of failure. This is a follow-up on D26232. Reviewers: rSerge Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27495 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@289501 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-06[XRay][compiler-rt] Explicitly add dependency to pthreadDean Michael Berris
This should fix the sanitizer bootstrap builds. Follow-up to D26232. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@288860 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-06[XRay][compiler-rt] Only add unit tests if we're building XRay.Dean Michael Berris
As constructed before this patch, in case we run into case where we don't actually build the XRay library, we really ought to not be adding the unit test runs. This should fix the bootstrap build failures. This is a follow-up further to D26232. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@288788 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-06[XRay][compiler-rt] XRay Buffer QueueDean Michael Berris
This implements a simple buffer queue to manage a pre-allocated queue of fixed-sized buffers to hold XRay records. We need this to support Flight Data Recorder (FDR) mode. We also implement this as a sub-library first to allow for development before actually using it in an implementation. Some important properties of the buffer queue: - Thread-safe enqueueing/dequeueing of fixed-size buffers. - Pre-allocation of buffers at construction. This is a re-roll of the previous attempt to submit, because it caused failures in arm and aarch64. Reviewers: majnemer, echristo, rSerge Subscribers: tberghammer, danalbert, srhines, modocache, mehdi_amini, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D26232 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@288775 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-25Revert "[XRay][compiler-rt] XRay Buffer Queue"Dean Michael Berris
Broke the build on arm7 and aarch64. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@287911 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-25[XRay][compiler-rt] XRay Buffer QueueDean Michael Berris
Summary: This implements a simple buffer queue to manage a pre-allocated queue of fixed-sized buffers to hold XRay records. We need this to support Flight Data Recorder (FDR) mode. We also implement this as a sub-library first to allow for development before actually using it in an implementation. Some important properties of the buffer queue: - Thread-safe enqueueing/dequeueing of fixed-size buffers. - Pre-allocation of buffers at construction. Reviewers: majnemer, rSerge, echristo Subscribers: mehdi_amini, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D26232 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@287910 91177308-0d34-0410-b5e6-96231b3b80d8