summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc
Commit message (Collapse)AuthorAgeFilesLines
* compiler-rt: Rename .cc file in lib/tsan/rtl to .cppNico Weber2019-08-011-539/+0
| | | | | | Like r367463, but for tsan/rtl. llvm-svn: 367564
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* tsan: fix deficiency in MutexReadOrWriteUnlockDmitry Vyukov2018-06-221-1/+1
| | | | | | | | | | MutexUnlock uses ReleaseStore on s->clock, which is the right thing to do. However MutexReadOrWriteUnlock for writers uses Release on s->clock. Make MutexReadOrWriteUnlock also use ReleaseStore for consistency and performance. Unfortunately, I don't think any test can detect this as this only potentially affects performance. llvm-svn: 335322
* tsan: improve "destroy of a locked mutex" reportsDmitry Vyukov2018-04-271-2/+2
| | | | | | | | | | | | | | | 1. Allow to suppress by current stack. We generally allow to suppress by all main stacks. Current is probably the stack one wants to use to suppress such reports. 2. Fix last lock stack restoration. We trimmed shadow value by storing it in u32. This magically worked for the test that provoked the report on the main thread. But this breaks for locks in any other threads. llvm-svn: 331023
* [tsan] Add Mutex annotation flag for constant-initialized ↵Dmitry Vyukov2017-10-201-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | __tsan_mutex_linker_init behavior Add a new flag, _⁠_tsan_mutex_not_static, which has the opposite sense of _⁠_tsan_mutex_linker_init. When the new _⁠_tsan_mutex_not_static flag is passed to _⁠_tsan_mutex_destroy, tsan ignores the destruction unless the mutex was also created with the _⁠_tsan_mutex_not_static flag. This is useful for constructors that otherwise woud set _⁠_tsan_mutex_linker_init but cannot, because they are declared constexpr. Google has a custom mutex with two constructors, a "linker initialized" constructor that relies on zero-initialization and sets ⁠_⁠_tsan_mutex_linker_init, and a normal one which sets no tsan flags. The "linker initialized" constructor is morally constexpr, but we can't declare it constexpr because of the need to call into tsan as a side effect. With this new flag, the normal c'tor can set _⁠_tsan_mutex_not_static, the "linker initialized" constructor can rely on tsan's lazy initialization, and _⁠_tsan_mutex_destroy can still handle both cases correctly. Author: Greg Falcon (gfalcon) Reviewed in: https://reviews.llvm.org/D39095 llvm-svn: 316209
* tsan: prepare clock for future changesDmitry Vyukov2017-07-121-6/+6
| | | | | | | Pass ClockCache to ThreadClock::set and introduce ThreadCache::ResetCached. For now both are unused, but will reduce future diffs. llvm-svn: 307784
* tsan: support linker init flag in __tsan_mutex_destroyDmitry Vyukov2017-05-011-2/+2
| | | | | | | | | | | | | | For a linker init mutex with lazy flag setup (no __tsan_mutex_create call), it is possible that no lock/unlock happened before the destroy call. Then when destroy runs we still don't know that it is a linker init mutex and will emulate a memory write. This in turn can lead to false positives as the mutex is in fact linker initialized. Support linker init flag in destroy annotation to resolve this. llvm-svn: 301795
* tsan: add new mutex annotationsDmitry Vyukov2017-03-261-39/+79
| | | | | | | | | | | | | | There are several problems with the current annotations (AnnotateRWLockCreate and friends): - they don't fully support deadlock detection (we need a hook _before_ mutex lock) - they don't support insertion of random artificial delays to perturb execution (again we need a hook _before_ mutex lock) - they don't support setting extended mutex attributes like read/write reentrancy (only "linker init" was bolted on) - they don't support setting mutex attributes if a mutex don't have a "constructor" (e.g. static, Java, Go mutexes) - they don't ignore synchronization inside of lock/unlock operations which leads to slowdown and false negatives The new annotations solve of the above problems. See tsan_interface.h for the interface specification and comments. Reviewed in https://reviews.llvm.org/D31093 llvm-svn: 298809
* tsan: always define SANITIZER_GODmitry Vyukov2016-10-281-4/+4
| | | | | | | | | | | | | | | | | | | | | | Currently we either define SANITIZER_GO for Go or don't define it at all for C++. This works fine with preprocessor (ifdef/ifndef/defined), but does not work for C++ if statements (e.g. if (SANITIZER_GO) {...}). Also this is different from majority of SANITIZER_FOO macros which are always defined to either 0 or 1. Always define SANITIZER_GO to either 0 or 1. This allows to use SANITIZER_GO in expressions and in flag default values. Also remove kGoMode and kCppMode, which were meant to be used in expressions, but they are not defined in sanitizer_common code, so SANITIZER_GO become prevalent. Also convert some preprocessor checks to C++ if's or ternary expressions. Majority of this change is done mechanically with: sed "s#ifdef SANITIZER_GO#if SANITIZER_GO#g" sed "s#ifndef SANITIZER_GO#if \!SANITIZER_GO#g" sed "s#defined(SANITIZER_GO)#SANITIZER_GO#g" llvm-svn: 285443
* tsan: don't create sync objects on acquireDmitry Vyukov2016-06-271-3/+5
| | | | | | | Creating sync objects on acquire is pointless: acquire of a just created sync object if a no-op. llvm-svn: 273862
* tsan: rely on AnnotateRWLockCreateStatic to detect linker-initialized mutexesDmitry Vyukov2016-06-031-14/+15
| | | | | | | | | The new annotation was added a while ago, but was not actually used. Use the annotation to detect linker-initialized mutexes instead of the broken IsGlobalVar which has both false positives and false negatives. Remove IsGlobalVar mess. llvm-svn: 271663
* tsan: change tsan/Go interface for obtaining the current ProcessorDmitry Vyukov2016-04-271-7/+7
| | | | | | | | | | | | | | | Current interface assumes that Go calls ProcWire/ProcUnwire to establish the association between thread and proc. With the wisdom of hindsight, this interface does not work very well. I had to sprinkle Go scheduler with wire/unwire calls, and any mistake leads to hard to debug crashes. This is not something one wants to maintian. Fortunately, there is a simpler solution. We can ask Go runtime as to what is the current Processor, and that question is very easy to answer on Go side. Switch to such interface. llvm-svn: 267703
* tsan: split thread into logical and physical stateDmitry Vyukov2016-04-271-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | This is reincarnation of http://reviews.llvm.org/D17648 with the bug fix pointed out by Adhemerval (zatrazz). Currently ThreadState holds both logical state (required for race-detection algorithm, user-visible) and physical state (various caches, most notably malloc cache). Move physical state in a new Process entity. Besides just being the right thing from abstraction point of view, this solves several problems: Cache everything on P level in Go. Currently we cache on a mix of goroutine and OS thread levels. This unnecessary increases memory consumption. Properly handle free operations in Go. Frees are issue by GC which don't have goroutine context. As the result we could not do anything more than just clearing shadow. For example, we leaked sync objects and heap block descriptors. This will allow to get rid of libc malloc in Go (now we have Processor context for internal allocator cache). This in turn will allow to get rid of dependency on libc entirely. Potentially we can make Processor per-CPU in C++ mode instead of per-thread, which will reduce resource consumption. The distinction between Thread and Processor is currently used only by Go, C++ creates Processor per OS thread, which is equivalent to the current scheme. llvm-svn: 267678
* [tsan] Detect uses of uninitialized, destroyed and invalid mutexesKuba Brecka2016-03-161-0/+8
| | | | | | | | This patch adds a new TSan report type, ReportTypeMutexInvalidAccess, which is triggered when pthread_mutex_lock or pthread_mutex_unlock returns EINVAL (this means the mutex is invalid, uninitialized or already destroyed). Differential Revision: http://reviews.llvm.org/D18132 llvm-svn: 263641
* tsan: revert r262037Dmitry Vyukov2016-02-261-7/+7
| | | | | | Broke aarch64 and darwin bots. llvm-svn: 262046
* tsan: split thread into logical and physical stateDmitry Vyukov2016-02-261-7/+7
| | | | | | | | | | | | | | | | | | | | Currently ThreadState holds both logical state (required for race-detection algorithm, user-visible) and physical state (various caches, most notably malloc cache). Move physical state in a new Process entity. Besides just being the right thing from abstraction point of view, this solves several problems: 1. Cache everything on P level in Go. Currently we cache on a mix of goroutine and OS thread levels. This unnecessary increases memory consumption. 2. Properly handle free operations in Go. Frees are issue by GC which don't have goroutine context. As the result we could not do anything more than just clearing shadow. For example, we leaked sync objects and heap block descriptors. 3. This will allow to get rid of libc malloc in Go (now we have Processor context for internal allocator cache). This in turn will allow to get rid of dependency on libc entirely. 4. Potentially we can make Processor per-CPU in C++ mode instead of per-thread, which will reduce resource consumption. The distinction between Thread and Processor is currently used only by Go, C++ creates Processor per OS thread, which is equivalent to the current scheme. llvm-svn: 262037
* [tsan] workaround for a crash in deadlock detector, bug ↵Kostya Serebryany2015-09-011-1/+1
| | | | | | https://github.com/google/sanitizers/issues/594 llvm-svn: 246592
* Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko2015-04-111-6/+2
| | | | | | | | | | | | The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix \ -format llvm-svn: 234680
* [tsan] remove TSAN_GO in favor of SANITIZER_GOKostya Serebryany2014-12-091-2/+2
| | | | llvm-svn: 223732
* [TSan] Use StackTrace from sanitizer_common where applicableAlexey Samsonov2014-11-031-12/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This change removes `__tsan::StackTrace` class. There are now three alternatives: # Lightweight `__sanitizer::StackTrace`, which doesn't own a buffer of PCs. It is used in functions that need stack traces in read-only mode, and helps to prevent unnecessary allocations/copies (e.g. for StackTraces fetched from StackDepot). # `__sanitizer::BufferedStackTrace`, which stores buffer of PCs in a constant array. It is used in TraceHeader (non-Go version) # `__tsan::VarSizeStackTrace`, which owns buffer of PCs, dynamically allocated via TSan internal allocator. Test Plan: compiler-rt test suite Reviewers: dvyukov, kcc Reviewed By: kcc Subscribers: llvm-commits, kcc Differential Revision: http://reviews.llvm.org/D6004 llvm-svn: 221194
* [Sanitizer] Make StackTrace a lightweight reference to array of PCs, andAlexey Samsonov2014-10-261-3/+2
| | | | | | | | | | | | | | | | | | | | | | introduce a BufferedStackTrace class, which owns this array. Summary: This change splits __sanitizer::StackTrace class into a lightweight __sanitizer::StackTrace, which doesn't own array of PCs, and BufferedStackTrace, which owns it. This would allow us to simplify the interface of StackDepot, and eventually merge __sanitizer::StackTrace with __tsan::StackTrace. Test Plan: regression test suite. Reviewers: kcc, dvyukov Reviewed By: dvyukov Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5985 llvm-svn: 220635
* [TSan] Use common flags in the same way as all the other sanitizersAlexey Samsonov2014-09-101-11/+12
| | | | llvm-svn: 217559
* tsan: allocate vector clocks using slab allocatorDmitry Vyukov2014-08-051-6/+6
| | | | | | | | | | Vector clocks is the most actively allocated object in tsan runtime. Current internal allocator is not scalable enough to handle allocation of clocks in scalable way (too small caches). This changes transforms clocks to 2-level array with 512-byte blocks. Since all blocks are of the same size, it's possible to cache them more efficiently in per-thread caches. llvm-svn: 214912
* [tsan] fix deadlock detector's interoperation with java locks ↵Kostya Serebryany2014-07-081-1/+1
| | | | | | (https://code.google.com/p/thread-sanitizer/issues/detail?id=67) llvm-svn: 212529
* [tsan] fix pthread_rwlock_tryrdlock interceptor, don't try to detect ↵Kostya Serebryany2014-07-081-2/+2
| | | | | | deadlocks when reporting bad unlock llvm-svn: 212526
* tsan: fix mutex in Go modeDmitry Vyukov2014-06-061-1/+1
| | | | | | In Go it's legal to unlock from a different goroutine. llvm-svn: 210358
* tsan: disable reporting of mutex misuses in GoDmitry Vyukov2014-06-061-0/+4
| | | | llvm-svn: 210353
* [TSan] Reduce the stack frame size of ReportDeadlockAlexey Samsonov2014-06-051-1/+1
| | | | llvm-svn: 210301
* tsan: refactor storage of meta information for heap blocks and sync objectsDmitry Vyukov2014-05-291-25/+44
| | | | | | | | | | | | | | | The new storage (MetaMap) is based on direct shadow (instead of a hashmap + per-block lists). This solves a number of problems: - eliminates quadratic behaviour in SyncTab::GetAndLock (https://code.google.com/p/thread-sanitizer/issues/detail?id=26) - eliminates contention in SyncTab - eliminates contention in internal allocator during allocation of sync objects - removes a bunch of ad-hoc code in java interface - reduces java shadow from 2x to 1/2x - allows to memorize heap block meta info for Java and Go - allows to cleanup sync object meta info for Go - which in turn enabled deadlock detector for Go llvm-svn: 209810
* tsan: refactor suppressions machineryDmitry Vyukov2014-05-281-8/+6
| | | | | | | | | | The refactoring makes suppressions more flexible and allow to suppress based on arbitrary number of stacks. In particular it fixes: https://code.google.com/p/thread-sanitizer/issues/detail?id=64 "Make it possible to suppress deadlock reports by any stack (not just first)" llvm-svn: 209757
* tsan: allow to suppress all reportsDmitry Vyukov2014-04-251-2/+2
| | | | | | Fixes issue https://code.google.com/p/thread-sanitizer/issues/detail?id=45 llvm-svn: 207218
* tsan: better reports for "unlock of an unlocked mutex"Dmitry Vyukov2014-04-251-3/+6
| | | | llvm-svn: 207211
* tsan: better reports for "read lock of a write locked mutex"Dmitry Vyukov2014-04-251-33/+27
| | | | llvm-svn: 207209
* tsan: improve "read unlock of a write locked mutex" reportDmitry Vyukov2014-04-251-4/+18
| | | | llvm-svn: 207208
* tsan: better report for bad mutex unlocksDmitry Vyukov2014-04-251-11/+16
| | | | | | | + fixes crashes due to races on symbolizer, see https://code.google.com/p/thread-sanitizer/issues/detail?id=55 llvm-svn: 207206
* tsan: better reports for "double lock of a mutex"Dmitry Vyukov2014-04-251-3/+16
| | | | | | | + fixes crashes due to races on symbolizer, see: https://code.google.com/p/thread-sanitizer/issues/detail?id=55 llvm-svn: 207204
* tsan: optimize vector clock operationsDmitry Vyukov2014-03-241-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make vector clock operations O(1) for several important classes of use cases. See comments for details. Below are stats from a large server app, 77% of all clock operations are handled as O(1). Clock acquire : 25983645 empty clock : 6288080 fast from release-store : 14917504 contains my tid : 4515743 repeated (fast) : 2141428 full (slow) : 2636633 acquired something : 1426863 Clock release : 2544216 resize : 6241 fast1 : 197693 fast2 : 1016293 fast3 : 2007 full (slow) : 1797488 was acquired : 709227 clear tail : 1 last overflow : 0 Clock release store : 3446946 resize : 200516 fast : 469265 slow : 2977681 clear tail : 0 Clock acquire-release : 820028 llvm-svn: 204656
* [sanitizer] print threads in deadlock reportKostya Serebryany2014-03-211-1/+7
| | | | llvm-svn: 204461
* [sanitizer] more human-readable deadlock reportsKostya Serebryany2014-03-211-1/+1
| | | | llvm-svn: 204454
* tsan: deobfuscate global ctx variableDmitry Vyukov2014-03-201-17/+8
| | | | llvm-svn: 204327
* tsan: add test for second_deadlock_stack flagDmitry Vyukov2014-03-191-1/+1
| | | | llvm-svn: 204240
* tsan: preliminary support for Go deadlock detectorDmitry Vyukov2014-03-191-6/+0
| | | | llvm-svn: 204228
* [sanitizer] deadlock detector: a) initial support for suppressions, b) be ↵Kostya Serebryany2014-03-191-4/+12
| | | | | | more robust in case we failed to extract a stack trace for one of the locks llvm-svn: 204225
* [sanitizer] make the deadlock detector print 2*N stack traces on ↵Kostya Serebryany2014-03-171-8/+8
| | | | | | lock-order-inversion with N locks (i.e. print stack traces for both lock acquisitions in every edge in the graph). More improvements to follow llvm-svn: 204042
* [tsan] fox the GO buildKostya Serebryany2014-03-171-0/+2
| | | | llvm-svn: 204037
* [sanitizer] fix build warnings; add an output test for the deadlock detecorKostya Serebryany2014-03-171-1/+1
| | | | llvm-svn: 204035
* [sanitizer] print more stack traces when reporting a deadlock (even more to ↵Kostya Serebryany2014-03-171-0/+9
| | | | | | come) llvm-svn: 204034
* [sanitizer] in bitvector-based deadlock detector split onLock into ↵Kostya Serebryany2014-03-131-2/+4
| | | | | | onLockBefore and onLockAfter hooks llvm-svn: 203796
* tsan: implement new version of standalong deadlock detectorDmitry Vyukov2014-03-051-29/+76
| | | | | | | intercept pthread_cond (it is required to properly track state of mutexes) detect cycles in mutex graph llvm-svn: 202975
* tsan: refactor deadlock detectorDmitry Vyukov2014-02-281-60/+48
| | | | | | | | Introduce DDetector interface between the tool and the DD itself. It will help to experiment with other DD implementation, as well as reuse DD in other tools. llvm-svn: 202485
OpenPOWER on IntegriCloud