tsan: split thread into logical and physical state
authorDmitry Vyukov <dvyukov@google.com>
Fri, 26 Feb 2016 16:57:14 +0000 (16:57 +0000)
committerDmitry Vyukov <dvyukov@google.com>
Fri, 26 Feb 2016 16:57:14 +0000 (16:57 +0000)
commitb8868b9bead799ba7c9b5f0c2df07db4d2966fed
tree5d5fc99e8446d828ae48c8d14c2aecfdf663d154
parent4402a32b3237c718e339ecb50b76d2bfb87d260d
tsan: split thread into logical and physical state

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
18 files changed:
compiler-rt/lib/tsan/CMakeLists.txt
compiler-rt/lib/tsan/go/build.bat
compiler-rt/lib/tsan/go/buildgo.sh
compiler-rt/lib/tsan/go/test.c
compiler-rt/lib/tsan/go/tsan_go.cc
compiler-rt/lib/tsan/rtl/tsan_defs.h
compiler-rt/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/lib/tsan/rtl/tsan_interface_java.cc
compiler-rt/lib/tsan/rtl/tsan_mman.cc
compiler-rt/lib/tsan/rtl/tsan_mman.h
compiler-rt/lib/tsan/rtl/tsan_rtl.cc
compiler-rt/lib/tsan/rtl/tsan_rtl.h
compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc
compiler-rt/lib/tsan/rtl/tsan_rtl_proc.cc [new file with mode: 0644]
compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cc
compiler-rt/lib/tsan/rtl/tsan_sync.cc
compiler-rt/lib/tsan/rtl/tsan_sync.h
compiler-rt/lib/tsan/tests/unit/tsan_sync_test.cc