Description
TSan supports ignoring certain reads/writes by a begin/end style annotation mechanism. This is e.g. used by Archer to filter out provably race free regions in OpenMP code for the sake of performance.
Calling AnnotateIgnoreWritesBegin
causes an ignore bit to be set in the current thread's local state, which lies in thread-local storage.
Looking at MemoryAccess
in the TSan runtime (which as far as I can tell ends up being called for most instrumented reads/writes), I noticed that the "early" exit due to a set ignore bit happens later than I would have expected:
llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl_access.cpp
Lines 432 to 442 in 47605ff
The ignore bit is only evaluated after the shadow memory has already been loaded and the access has been deemed to not be already recorded.
In other situations (MemoryAccess16
and UnalignedMemoryAccess
), the ignore bit check is performed first thing.
I am curious as to why that is the case. Is access to the thread-local ThreadState
/FastState
more expensive than accessing and comparing the shadow memory?