This is an archive of the discontinued LLVM Phabricator instance.

[ProfileData] Fix data racing in merging indexed profiles
ClosedPublic

Authored by xur on Sep 29 2017, 2:56 PM.

Details

Summary

There are some data races when merging multiple indexed profiles with multiple threads.
(1) the static variable RecordIndex in index profile reader needs to be thread_local.
Otherwise, multiple function entries with different hashes in the profile lead to segfault.
(2) thread partition in loading the profile does not seem to be right: we are submitting a separated thread for each input and multiple threads can access the same WriteContext.
This patch fixes the above issues.

Diff Detail

Repository
rL LLVM

Event Timeline

xur created this revision.Sep 29 2017, 2:56 PM
vsk added inline comments.Sep 29 2017, 4:32 PM
lib/ProfileData/InstrProfReader.cpp
736 ↗(On Diff #117228)

Why isn't this just a member variable?

If we used "thread_local", wouldn't there still be a bug if you instantiated and used two IndexedInstrProfReaders?

tools/llvm-profdata/llvm-profdata.cpp
230 ↗(On Diff #117228)

I don't understand the problem here. Each time a WriterContext is accessed, the accessing thread immediately acquires a unique lock on the context. Where does the racing access occur?

xur updated this revision to Diff 117423.Oct 2 2017, 2:10 PM

Integrated the review comments from vsk.

vsk accepted this revision.Oct 2 2017, 2:12 PM

Thanks! Lgtm.

This revision is now accepted and ready to land.Oct 2 2017, 2:12 PM
This revision was automatically updated to reflect the committed changes.