This is an archive of the discontinued LLVM Phabricator instance.

tsan: extend MutexSet to memorize mutex address/stack_id
ClosedPublic

Authored by dvyukov on Aug 11 2021, 9:22 AM.

Details

Summary

We currently memorize u64 id + epoch for each mutex.
The new tsan runtime will memorize address + stack_id instead.
But switching to address + stack_id requires new trace,
which in turn requires new MutexSet and some other changes.
Extend MutexSet to support both new and old info to break
the dependency cycles. The plan is to remove the old
info/methods after switching to the new runtime.

Diff Detail

Event Timeline

dvyukov requested review of this revision.Aug 11 2021, 9:22 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 11 2021, 9:22 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka accepted this revision.Aug 11 2021, 1:29 PM
vitalybuka added inline comments.
compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp
22

memset(this...)?

88–95

Does min_seq makes a difference from:

uptr min_index = 0;
for (uptr i = 1; i < size_; i++)
  if (descs_[i].seq < descs_[min_index].seq)
    min_index = i;
This revision is now accepted and ready to land.Aug 11 2021, 1:29 PM
vitalybuka added inline comments.Aug 11 2021, 1:50 PM
compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp
88–95

hm, it does for clang, but not gcc
https://godbolt.org/z/vW9EEzKW8

dvyukov updated this revision to Diff 365934.Aug 12 2021, 1:44 AM

removed min_seq variable

dvyukov marked 2 inline comments as done.Aug 12 2021, 1:44 AM
dvyukov added inline comments.
compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp
22

memset(this) is somewhat ugly hack (technically UB and can break if we add virtual functions):
https://stackoverflow.com/questions/53339268/what-trait-concept-can-guarantee-memsetting-an-object-is-well-defined

The current memset avoids a very specific problem with compiler-emitted memset. It's not that we generally want these C hacks to save few lines. So I would prefer to initialize normal variables as one would do it normally.

melver accepted this revision.Aug 12 2021, 3:27 AM
melver added inline comments.
compiler-rt/lib/tsan/rtl/tsan_mutexset.cpp
20

These could actually be initialized inline at definition.

dvyukov updated this revision to Diff 365961.Aug 12 2021, 4:17 AM

initialize seq_/size_ fields inline at declaration

dvyukov marked an inline comment as done.Aug 12 2021, 4:18 AM
This revision was landed with ongoing or failed builds.Aug 12 2021, 4:18 AM
This revision was automatically updated to reflect the committed changes.