Commit Graph

48 Commits

Author SHA1 Message Date
Alexey Samsonov 40733a8024 [TSan] Use StackTrace from sanitizer_common where applicable
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
2014-11-03 22:23:44 +00:00
Dmitry Vyukov afdcc96d9f tsan: optimize memory access functions
The optimization is two-fold:
First, the algorithm now uses SSE instructions to
handle all 4 shadow slots at once. This makes processing
faster.
Second, if shadow contains the same access, we do not
store the event into trace. This increases effective
trace size, that is, tsan can remember up to 10x more
previous memory accesses.

Perofrmance impact:
Before:
[       OK ] DISABLED_BENCH.Mop8Read (2461 ms)
[       OK ] DISABLED_BENCH.Mop8Write (1836 ms)
After:
[       OK ] DISABLED_BENCH.Mop8Read (1204 ms)
[       OK ] DISABLED_BENCH.Mop8Write (976 ms)
But this measures only fast-path.
On large real applications the speedup is ~20%.

Trace size impact:
On app1:
Memory accesses                   :       1163265870
  Including same                  :        791312905 (68%)
on app2:
Memory accesses                   :        166875345
  Including same                  :        150449689 (90%)
90% of filtered events means that trace size is effectively 10x larger.

llvm-svn: 209897
2014-05-30 13:36:29 +00:00
Dmitry Vyukov bde4c9c773 tsan: refactor storage of meta information for heap blocks and sync objects
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
2014-05-29 13:50:54 +00:00
Dmitry Vyukov 547089e2a5 tsan: allow to disable history collection
The mode is enabled with -DTSAN_NO_HISTORY=1 flag.
Intended mostly for research purposes (how fast can it go w/o history).

llvm-svn: 208878
2014-05-15 12:51:48 +00:00
Dmitry Vyukov b5eb8f0212 tsan: fix vector clocks
the new optimizations break when thread ids gets reused (clocks go backwards)
add the necessary tests as well

llvm-svn: 206035
2014-04-11 15:38:03 +00:00
Dmitry Vyukov 3238e1c913 tsan: better diagnostics if thread finishes with ignores enabled
print thread creation stack
and stacks where ignores were enabled.

llvm-svn: 195836
2013-11-27 11:30:28 +00:00
Dmitry Vyukov 464ebbd67b tsan: move shadow stack from thread descriptors to fixed addresses
This allows to increase max shadow stack size to 64K,
and reliably catch shadow stack overflows instead of silently
corrupting memory.

llvm-svn: 192797
2013-10-16 15:35:12 +00:00
Sergey Matveev d109eb052b [tsan] Move some suppressions-related code to common.
Factor out code to be reused in LSan. Also switch from linked list to vector.

llvm-svn: 184957
2013-06-26 15:37:14 +00:00
Dmitry Vyukov b365d40415 tsan: print matched suppressions if print_suppressions=1 flag is provided
llvm-svn: 178159
2013-03-27 17:59:57 +00:00
Alexey Samsonov 9aecdfe34d [TSan] Switch TSan runtime to use ThreadRegistry class from sanitizer_common
llvm-svn: 177154
2013-03-15 13:48:44 +00:00
Dmitry Vyukov ba4291480d tsan: detect races between plain and atomic memory accesses
llvm-svn: 174163
2013-02-01 09:42:06 +00:00
Dmitry Vyukov 087efd23d6 tsan: fix CPP_WEAK definition (it must be the other way around)
llvm-svn: 173932
2013-01-30 14:38:44 +00:00
Dmitry Vyukov d6b9348bf3 tsan: introduce a helped macro CPP_WEAK (Go linker does not support weak symbols)
llvm-svn: 173917
2013-01-30 09:46:53 +00:00
Dmitry Vyukov fd5ebcd1b0 tsan: add mutexsets to reports
With this change reports say what mutexes the threads hold around the racy memory accesses.

llvm-svn: 169493
2012-12-06 12:16:15 +00:00
Dmitry Vyukov 55b47cad33 tsan: fix trace handling when trace is reused between threads
llvm-svn: 169259
2012-12-04 12:19:53 +00:00
Dmitry Vyukov eb3d36e649 tsan: address several review comments
llvm-svn: 168789
2012-11-28 13:01:32 +00:00
Dmitry Vyukov f34db58c20 tsan: switch to 4 shadow cells by default (since that's what we use everywhere now)
llvm-svn: 168059
2012-11-15 18:44:22 +00:00
Dmitry Vyukov 9952b674ca tsan: use GORACE env for options for Go
llvm-svn: 167575
2012-11-08 11:32:40 +00:00
Dmitry Vyukov c015712992 tsan: lazily allocate shadow for Go
llvm-svn: 167464
2012-11-06 16:00:16 +00:00
Dmitry Vyukov 1d4120b210 tsan: fix constant types
llvm-svn: 167453
2012-11-06 13:21:06 +00:00
Dmitry Vyukov 23ecb4acd9 tsan: fix code style
llvm-svn: 163326
2012-09-06 16:11:30 +00:00
Dmitry Vyukov c87e7280b8 tsan: increase max shadow stack size + reduce memory consumption at the same time (by not memorizing full stacks in traces)
llvm-svn: 163322
2012-09-06 15:18:14 +00:00
Dmitry Vyukov 954fc8c3e4 tsan: switch to new allocator
llvm-svn: 161953
2012-08-15 15:35:15 +00:00
Dmitry Vyukov 5bfac97ff9 tsan: use dynamic shadow stack for Go
llvm-svn: 160288
2012-07-16 16:44:47 +00:00
Dmitry Vyukov 03d32ecd4f tsan: Go language support
llvm-svn: 159754
2012-07-05 16:18:28 +00:00
Dmitry Vyukov 6fa46f7003 tsan/asan: unify atomics (move atomics from tsan to sanitizer_common)
llvm-svn: 159437
2012-06-29 16:58:33 +00:00
Dmitry Vyukov 5bb47a6e0e tsan: remove own memset/memcpy/memcmp (too messy)
llvm-svn: 159430
2012-06-29 15:19:14 +00:00
Dmitry Vyukov 090f345522 tsan: prevent insertion of unwanted memset/memcpy/memcmp into runtime
llvm-svn: 159294
2012-06-27 21:00:23 +00:00
Dmitry Vyukov de1fd1c83b tsan: do not call malloc/free in memory access handling routine.
This improves signal-/fork-safety of instrumented programs.

llvm-svn: 158988
2012-06-22 11:08:55 +00:00
Alexey Samsonov 3efd6fc26c [Sanitizer] Use DEFINE_REAL macro in TSan runtime to call libc implementations of functions. Move strchr to sanitizer_libc.
llvm-svn: 158517
2012-06-15 12:24:07 +00:00
Alexey Samsonov 96ef49a71e [Sanitizer] Move internal_memcmp to common sanitizer libc
llvm-svn: 158450
2012-06-14 14:04:54 +00:00
Alexey Samsonov f516d39c1f [TSan] use efficient real_memcpy inside runtime
llvm-svn: 158260
2012-06-09 09:14:24 +00:00
Alexey Samsonov 59036d2c06 [Sanitizer] add internal_memset and internal_strrchr to sanitizer_common/
llvm-svn: 158202
2012-06-08 14:11:12 +00:00
Alexey Samsonov 6cfc34ea7f [TSan] s/internal_memset/real_memset
llvm-svn: 158200
2012-06-08 13:59:39 +00:00
Alexey Samsonov 91e1a7eb17 [Sanitizer] move internal_strdup and internal_memcpy to common runtime. Make internal allocations from TSan runtime call InternalAlloc from common runtime
llvm-svn: 158148
2012-06-07 11:54:08 +00:00
Alexey Samsonov e428779dbf [Sanitizer] Use common CHECK machinery. Currently each tool has to define its own CheckFailed function.
llvm-svn: 158075
2012-06-06 15:22:20 +00:00
Alexey Samsonov ee07290628 [Sanitizer] Move more functions/constants to sanitizer_common.
llvm-svn: 158056
2012-06-06 09:26:25 +00:00
Alexey Samsonov 5bbf8290a7 [Sanitizer] rename sanitizer_defs.h to sanitizer_internal_defs.h
llvm-svn: 158001
2012-06-05 14:25:27 +00:00
Alexey Samsonov 8602c65719 [Sanitizer] remove using namespace __sanitizer lines
llvm-svn: 157999
2012-06-05 14:05:09 +00:00
Alexey Samsonov ef2e2cfd33 [Sanitizer] Use common defines for ASan and TSan runtime. Split defines between interface defines (can be visible in user code that includes interface ASan/TSan headers) and internal defines.
llvm-svn: 157998
2012-06-05 13:50:57 +00:00
Alexey Samsonov 90f9630c80 [Sanitizer]: move internal_strcmp to sanitizer_common
llvm-svn: 157926
2012-06-04 13:27:49 +00:00
Dmitry Vyukov 7339eb197b tsan: do not call into libc in symbolizer and in other code (this causes recursion and crashes)
llvm-svn: 157466
2012-05-25 11:15:04 +00:00
Dmitry Vyukov 30c32a8819 tsan: fix compilation with newest clang
llvm-svn: 157391
2012-05-24 14:50:33 +00:00
Dmitry Vyukov 302cebb8f1 tsan: add shadow memory flush + fix few bugs
llvm-svn: 157270
2012-05-22 18:07:45 +00:00
Dmitry Vyukov f6985e3ab9 tsan: reduce per-thread memory usage
llvm-svn: 157252
2012-05-22 14:34:43 +00:00
Dmitry Vyukov fee5b7d2e0 tsan: detect accesses to freed memory
http://codereview.appspot.com/6214052

llvm-svn: 156990
2012-05-17 14:17:51 +00:00
Kostya Serebryany 07c4805175 [tsan] run more kinds of builds as presubmit test (and fix gcc debug build)
llvm-svn: 156616
2012-05-11 14:42:24 +00:00
Kostya Serebryany 4ad375f0a9 [tsan] First commit of ThreadSanitizer (TSan) run-time library.
Algorithm description: http://code.google.com/p/thread-sanitizer/wiki/ThreadSanitizerAlgorithm

Status:
The tool is known to work on large real-life applications, but still has quite a few rough edges.
Nothing is guaranteed yet.

The tool works on x86_64 Linux.
Support for 64-bit MacOS 10.7+ is planned for late 2012.
Support for 32-bit OSes is doable, but problematic and not yet planed.

Further commits coming:
  - tests
  - makefiles
  - documentation
  - clang driver patch

The code was previously developed at http://code.google.com/p/data-race-test/source/browse/trunk/v2/
by Dmitry Vyukov and Kostya Serebryany with contributions from
Timur Iskhodzhanov, Alexander Potapenko, Alexey Samsonov and Evgeniy Stepanov.

llvm-svn: 156542
2012-05-10 13:48:04 +00:00