This is an archive of the discontinued LLVM Phabricator instance.

tsan: remove quadratic behavior in pthread_join
ClosedPublic

Authored by dvyukov on Nov 16 2021, 6:56 AM.

Details

Summary

pthread_join needs to map pthread_t of the joined thread to our Tid.
Currently we do this with linear search over all threads.
This has quadratic complexity and becomes much worse with the new
tsan runtime, which memorizes all threads that ever existed.

To resolve this add a hash map of live threads only (that are still
associated with pthread_t) and use it for the mapping.

With the new tsan runtime some programs spent 1/3 of time in this mapping.
After this change the mapping disappears from profiles.

Depends on D113996.

Diff Detail

Event Timeline

dvyukov requested review of this revision.Nov 16 2021, 6:56 AM
dvyukov created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 16 2021, 6:56 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
melver added inline comments.Nov 16 2021, 8:15 AM
compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.cpp
171

Insert seems to have its own CHECK.

Although I find the API could be improved.. I'll comment on the other patch.

dvyukov marked an inline comment as done.Nov 16 2021, 9:20 AM

PTAL

melver accepted this revision.Nov 16 2021, 9:23 AM
This revision is now accepted and ready to land.Nov 16 2021, 9:23 AM
vitalybuka accepted this revision.Nov 17 2021, 7:34 PM
This revision was landed with ongoing or failed builds.Nov 17 2021, 7:41 PM
This revision was automatically updated to reflect the committed changes.