[llvm] r314990 - [ProfileData] Fix data racing in merging indexed profiles

Rong Xu via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 10:05:20 PDT 2017


Author: xur
Date: Thu Oct  5 10:05:20 2017
New Revision: 314990

URL: http://llvm.org/viewvc/llvm-project?rev=314990&view=rev
Log:
[ProfileData] Fix data racing in merging indexed profiles

There is data racing to the static variable RecordIndex in index profile reader
when merging in multiple threads. Make it a member variable in
IndexedInstrProfReader to fix this.

Differential Revision: https://reviews.llvm.org/D38431

Added:
    llvm/trunk/test/tools/llvm-profdata/Inputs/multiple-profdata-merge.proftext
    llvm/trunk/test/tools/llvm-profdata/multiple-profdata-merge.test
Modified:
    llvm/trunk/include/llvm/ProfileData/InstrProfReader.h
    llvm/trunk/lib/ProfileData/InstrProfReader.cpp

Modified: llvm/trunk/include/llvm/ProfileData/InstrProfReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProfReader.h?rev=314990&r1=314989&r2=314990&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProfReader.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProfReader.h Thu Oct  5 10:05:20 2017
@@ -397,6 +397,8 @@ private:
   std::unique_ptr<InstrProfReaderIndexBase> Index;
   /// Profile summary data.
   std::unique_ptr<ProfileSummary> Summary;
+  // Index to the current record in the record array.
+  unsigned RecordIndex;
 
   // Read the profile summary. Return a pointer pointing to one byte past the
   // end of the summary data if it exists or the input \c Cur.
@@ -405,7 +407,7 @@ private:
 
 public:
   IndexedInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
-      : DataBuffer(std::move(DataBuffer)) {}
+      : DataBuffer(std::move(DataBuffer)), RecordIndex(0) {}
   IndexedInstrProfReader(const IndexedInstrProfReader &) = delete;
   IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
 

Modified: llvm/trunk/lib/ProfileData/InstrProfReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProfReader.cpp?rev=314990&r1=314989&r2=314990&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProfReader.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProfReader.cpp Thu Oct  5 10:05:20 2017
@@ -733,8 +733,6 @@ Error IndexedInstrProfReader::getFunctio
 }
 
 Error IndexedInstrProfReader::readNextRecord(NamedInstrProfRecord &Record) {
-  static unsigned RecordIndex = 0;
-
   ArrayRef<NamedInstrProfRecord> Data;
 
   Error E = Index->getRecords(Data);

Added: llvm/trunk/test/tools/llvm-profdata/Inputs/multiple-profdata-merge.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/multiple-profdata-merge.proftext?rev=314990&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/Inputs/multiple-profdata-merge.proftext (added)
+++ llvm/trunk/test/tools/llvm-profdata/Inputs/multiple-profdata-merge.proftext Thu Oct  5 10:05:20 2017
@@ -0,0 +1,106 @@
+# IR level Instrumentation Flag
+:ir
+foo
+# Func Hash:
+36982789018
+# Num Counters:
+4
+# Counter Values:
+700000
+700000
+0
+0
+
+foo
+# Func Hash:
+59188585735
+# Num Counters:
+6
+# Counter Values:
+400000
+400000
+0
+0
+0
+0
+
+foo
+# Func Hash:
+27904764724
+# Num Counters:
+3
+# Counter Values:
+200000
+200000
+0
+
+foo
+# Func Hash:
+60466382370
+# Num Counters:
+6
+# Counter Values:
+0
+100000
+0
+0
+0
+0
+
+bar
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo2
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo3
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo4
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo5
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+0
+
+foo1
+# Func Hash:
+12884901887
+# Num Counters:
+1
+# Counter Values:
+100000
+
+main
+# Func Hash:
+29212902728
+# Num Counters:
+2
+# Counter Values:
+1400000
+14
+

Added: llvm/trunk/test/tools/llvm-profdata/multiple-profdata-merge.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/multiple-profdata-merge.test?rev=314990&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/multiple-profdata-merge.test (added)
+++ llvm/trunk/test/tools/llvm-profdata/multiple-profdata-merge.test Thu Oct  5 10:05:20 2017
@@ -0,0 +1,11 @@
+Test multi-thread merge of multiple profdata files.
+
+RUN: llvm-profdata merge %p/Inputs/multiple-profdata-merge.proftext -o %t
+RUN: llvm-profdata merge -j 4 %t %t %t %t -o %t_2
+RUN: llvm-profdata show %t_2 | FileCheck %s
+
+; CHECK:Total functions: 11
+; CHECK:Maximum function count: 5600000
+; CHECK:Maximum internal block count: 2800000
+
+




More information about the llvm-commits mailing list