[PATCH] D38431: [ProfileData] Fix data racing in merging indexed profiles

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 29 16:32:48 PDT 2017


vsk added inline comments.


================
Comment at: lib/ProfileData/InstrProfReader.cpp:736
 Error IndexedInstrProfReader::readNextRecord(NamedInstrProfRecord &Record) {
-  static unsigned RecordIndex = 0;
+  thread_local static unsigned RecordIndex = 0;
 
----------------
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?


================
Comment at: tools/llvm-profdata/llvm-profdata.cpp:230
     // Load the inputs in parallel (N/NumThreads serial steps).
-    unsigned Ctx = 0;
-    for (const auto &Input : Inputs) {
-      Pool.async(loadInput, Input, Contexts[Ctx].get());
-      Ctx = (Ctx + 1) % NumThreads;
+    unsigned ChunkSize = Inputs.size() / NumThreads;
+    unsigned ChunkRemainder = Inputs.size() % NumThreads;
----------------
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?


https://reviews.llvm.org/D38431





More information about the llvm-commits mailing list