This is an archive of the discontinued LLVM Phabricator instance.

tsan: do not instrument not captured values
AbandonedPublic

Authored by dvyukov on Jan 20 2015, 8:54 AM.
Tokens
"The World Burns" token, awarded by dvyukov.

Details

Summary

Consider the following code:

P p;
p.x = 1;
p.y = 2;
foo(&p);

P escapes and so tsan instruments accesses to it. However, before address of the variable is actually taken, it is not shared and so cannot participate in data races. So there is no point in instrumenting these initial memory accesses.

I've built some tests in WebRTC with and without this change. With this change number of __tsan_read/write calls is reduced by 20-40%, binary size decreases by 5-10% and execution time drops by ~5%. For example:

$ ls -l old/modules_unittests new/modules_unittests
-rwxr-x--- 1 dvyukov 41708976 Jan 20 18:35 old/modules_unittests
-rwxr-x--- 1 dvyukov 38294008 Jan 20 18:29 new/modules_unittests
$ objdump -d old/modules_unittests | egrep "callq.*tsan_(read|write|unaligned)" | wc -l
239871
$ objdump -d new/modules_unittests | egrep "callq.*
tsan_(read|write|unaligned)" | wc -l
148365

Diff Detail

Event Timeline

dvyukov updated this revision to Diff 18439.Jan 20 2015, 8:54 AM
dvyukov retitled this revision from to tsan: do not instrument not captured values.
dvyukov updated this object.
dvyukov edited the test plan for this revision. (Show Details)
dvyukov added reviewers: kcc, samsonov, eugenis.
dvyukov added a subscriber: Unknown Object (MLST).
kcc edited edge metadata.Jan 21 2015, 5:18 PM

Cool.
Do you have any numbers? (E.g. the %% of cases where it fires on SPEC)?

Two comments inlined

lib/Transforms/Instrumentation/ThreadSanitizer.cpp
341

Don't we want to reuse DT from previous passes, i.e. require it in getAnalysisUsage() ?

test/Instrumentation/ThreadSanitizer/capture.ll
18

CHECK-LABEL, here and below

dvyukov updated this revision to Diff 18805.Jan 27 2015, 3:03 AM
dvyukov edited edge metadata.

Chandler, I've tested the approach where we ignore only completely non-captured variables, and it seems to give most of the benefit.
Number of __tsan_(read|write|unaligned) calls in webrtc modules_unittest was 240592; with my original patch -- 149078; with only PointerMayBeCaptured -- 149624.

Looks much simpler now as well. And also I don't need to figure out how to reuse DominatorTree from a previous pass :)

PTAL

dvyukov added a reviewer: chandlerc.

Chandler, please take another look

kcc added a comment.Jan 27 2015, 10:36 AM

LGTM

This looks much nicer!
(Still, please give Chandler and chance to look)

Chandler, do you want to take another look? Otherwise I am submitting it.

chandlerc resigned from this revision.Mar 29 2015, 2:28 PM
chandlerc removed a reviewer: chandlerc.

Resigning as my memory is that we went with a different approach. If you need review here still, please add me back.

dvyukov abandoned this revision.Apr 15 2021, 1:19 AM