This is an archive of the discontinued LLVM Phabricator instance.

[TSan] Add a runtime flag to print full thread creation stacks up to the main thread
ClosedPublic

Authored by Enna1 on Mar 21 2022, 5:32 AM.

Details

Summary

Currently, we only print how threads involved in data race are created from their parent threads.
Add a runtime flag 'print_full_thread_history' to print thread creation stacks for the threads involved in the data race and their ancestors up to the main thread.

Diff Detail

Event Timeline

Enna1 created this revision.Mar 21 2022, 5:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2022, 5:32 AM
Enna1 requested review of this revision.Mar 21 2022, 5:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2022, 5:32 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

clang-format: please reformat the code

Please also fix clang-format warnings.

compiler-rt/lib/tsan/rtl/tsan_flags.inc
84

Asan has print_full_thread_history flag, use the same name.

compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
837

Can't this be done in 1 loop and w/o worklist?
Just iterating over all threads and then taking and adding parents until we reach main thread.

compiler-rt/test/tsan/report_full_thread_create_stack.cpp
41 ↗(On Diff #416902)

Please add actual thread numbers. They must be stable, right.

Enna1 updated this revision to Diff 417164.Mar 21 2022, 7:22 PM
Enna1 retitled this revision from [TSan] Add a runtime flag to print full thread creation stack to [TSan] Add a runtime flag to print full thread creation stacks up to the main thread.
Enna1 edited the summary of this revision. (Show Details)

Address review comments. PTAL, thanks!

Enna1 edited the summary of this revision. (Show Details)Mar 21 2022, 7:22 PM
Enna1 marked 2 inline comments as done.
dvyukov added inline comments.Mar 22 2022, 12:38 AM
compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
830

Humm... It looks like it's doing a different thing now as compared to the previous version (add one vs all parents). What is the intended behavior? If the current version is wrong, please extend the test to catch it.
I expected to see something along the following lines:

Tid tid = rep_desc->threads[i]->parent_tid;
while (tid != tid == kMainTid && tid != kInvalidTid) {
  rep.AddThread(tid);
  tid = ctx->thread_registry.GetThreadLocked(tid)->parent;
}
Enna1 added inline comments.Mar 22 2022, 1:02 AM
compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
830

emm, I think the code of this version does the same thing as the previous version?
rep_desc->threads.Size() is changed when we call rep.AddThread() to add new thread into rep
Say in one iteration of for loop, we add threads[i]->parent_tid into rep, and in the next iteration of for loop, we add threads[i]->parent_tid->parent_tid into rep.
Maybe this version is confusing, I' happy to change code as you expected :)

Enna1 added inline comments.Mar 22 2022, 1:10 AM
compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
830

Sorry, I misunderstand, I will update patch.

dvyukov accepted this revision.Mar 22 2022, 1:25 AM
dvyukov added inline comments.
compiler-rt/lib/tsan/rtl/tsan_rtl_report.cpp
830

You are right. The code is fine as is, no need to change.

This revision is now accepted and ready to land.Mar 22 2022, 1:25 AM
Enna1 added a comment.Mar 23 2022, 8:13 AM

Thanks for your review. I don't have commit accesss, Can you commit this for me? Thanks!