[llvm-mca][View] Improved Retire Control Unit Statistics.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Fri, 23 Nov 2018 12:12:57 +0000 (12:12 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Fri, 23 Nov 2018 12:12:57 +0000 (12:12 +0000)
RetireControlUnitStatistics now reports extra information about the ROB and the
avg/maximum number of entries consumed over the entire simulation.

Example:
  Retire Control Unit - number of cycles where we saw N instructions retired:
  [# retired], [# cycles]
   0,           109  (17.9%)
   1,           102  (16.7%)
   2,           399  (65.4%)

  Total ROB Entries:                64
  Max Used ROB Entries:             35  ( 54.7% )
  Average Used ROB Entries per cy:  32  ( 50.0% )

Documentation in llvm/docs/CommandGuide/llvmn-mca.rst has been updated to
reflect this change.

llvm-svn: 347493

llvm/docs/CommandGuide/llvm-mca.rst
llvm/test/tools/llvm-mca/X86/BdVer2/rcu-statistics.s
llvm/test/tools/llvm-mca/X86/BtVer2/rcu-statistics.s
llvm/test/tools/llvm-mca/X86/option-all-stats-1.s
llvm/test/tools/llvm-mca/X86/option-all-stats-2.s
llvm/test/tools/llvm-mca/X86/option-all-views-1.s
llvm/test/tools/llvm-mca/X86/option-all-views-2.s
llvm/tools/llvm-mca/Views/RetireControlUnitStatistics.cpp
llvm/tools/llvm-mca/Views/RetireControlUnitStatistics.h
llvm/tools/llvm-mca/llvm-mca.cpp

index 100136e..bc50794 100644 (file)
@@ -516,6 +516,10 @@ sections.
    1,           102  (16.7%)
    2,           399  (65.4%)
 
+  Total ROB Entries:                64
+  Max Used ROB Entries:             35  ( 54.7% )
+  Average Used ROB Entries per cy:  32  ( 50.0% )
+
 
   Register File statistics:
   Total number of mappings created:    900
index 42467f7..e0f27cc 100644 (file)
@@ -60,3 +60,7 @@
 # CHECK-NEXT:  1,           9  (40.9%)
 # CHECK-NEXT:  3,           1  (4.5%)
 # CHECK-NEXT:  4,           1  (4.5%)
+
+# CHECK:      Total ROB Entries:                128
+# CHECK-NEXT: Max Used ROB Entries:             16  ( 12.5% )
+# CHECK-NEXT: Average Used ROB Entries per cy:  9  ( 7.0% )
index 4a1f870..59fbd48 100644 (file)
@@ -58,3 +58,7 @@
 # CHECK-NEXT: [# retired], [# cycles]
 # CHECK-NEXT:  0,           23  (74.2%)
 # CHECK-NEXT:  2,           8  (25.8%)
+
+# CHECK:      Total ROB Entries:                64
+# CHECK-NEXT: Max Used ROB Entries:             16  ( 25.0% )
+# CHECK-NEXT: Average Used ROB Entries per cy:  11  ( 17.2% )
index dd3fafb..d226558 100644 (file)
@@ -62,6 +62,10 @@ add %eax, %eax
 # FULLREPORT-NEXT:  0,           3  (2.9%)
 # FULLREPORT-NEXT:  1,           100  (97.1%)
 
+# FULLREPORT:      Total ROB Entries:                64
+# FULLREPORT-NEXT: Max Used ROB Entries:             22  ( 34.4% )
+# FULLREPORT-NEXT: Average Used ROB Entries per cy:  17  ( 26.6% )
+
 # FULLREPORT:      Register File statistics:
 # FULLREPORT-NEXT: Total number of mappings created:    200
 # FULLREPORT-NEXT: Max number of mappings used:         44
index a7002d9..e752d82 100644 (file)
@@ -63,6 +63,10 @@ add %eax, %eax
 # ALL-NEXT:   0,           3  (2.9%)
 # ALL-NEXT:   1,           100  (97.1%)
 
+# ALL:       Total ROB Entries:                64
+# ALL-NEXT:  Max Used ROB Entries:             22  ( 34.4% )
+# ALL-NEXT:  Average Used ROB Entries per cy:  17  ( 26.6% )
+
 # ALL:       Register File statistics:
 # ALL-NEXT:  Total number of mappings created:    200
 # ALL-NEXT:  Max number of mappings used:         44
index b0545ab..298a54b 100644 (file)
@@ -64,6 +64,10 @@ add %eax, %eax
 # FULLREPORT-NEXT:     0,           3  (2.9%)
 # FULLREPORT-NEXT:     1,           100  (97.1%)
 
+# FULLREPORT:         Total ROB Entries:                64
+# FULLREPORT-NEXT:    Max Used ROB Entries:             22  ( 34.4% )
+# FULLREPORT-NEXT:    Average Used ROB Entries per cy:  17  ( 26.6% )
+
 # FULLREPORT:         Register File statistics:
 # FULLREPORT-NEXT:    Total number of mappings created:    200
 # FULLREPORT-NEXT:    Max number of mappings used:         44
index 66eb3bb..0afd21f 100644 (file)
@@ -63,6 +63,10 @@ add %eax, %eax
 # ALL-NEXT:         0,           3  (2.9%)
 # ALL-NEXT:         1,           100  (97.1%)
 
+# ALL:             Total ROB Entries:                64
+# ALL-NEXT:        Max Used ROB Entries:             22  ( 34.4% )
+# ALL-NEXT:        Average Used ROB Entries per cy:  17  ( 26.6% )
+
 # ALL:             Register File statistics:
 # ALL-NEXT:        Total number of mappings created:    200
 # ALL-NEXT:        Max number of mappings used:         44
index 7e2fd31..54eb28f 100644 (file)
 namespace llvm {
 namespace mca {
 
+RetireControlUnitStatistics::RetireControlUnitStatistics(const MCSchedModel &SM)
+    : NumRetired(0), NumCycles(0), EntriesInUse(0), MaxUsedEntries(0),
+      SumOfUsedEntries(0) {
+  TotalROBEntries = SM.MicroOpBufferSize;
+  if (SM.hasExtraProcessorInfo()) {
+    const MCExtraProcessorInfo &EPI = SM.getExtraProcessorInfo();
+    if (EPI.ReorderBufferSize)
+      TotalROBEntries = EPI.ReorderBufferSize;
+  }
+}
+
 void RetireControlUnitStatistics::onEvent(const HWInstructionEvent &Event) {
-  if (Event.Type == HWInstructionEvent::Retired)
+  if (Event.Type == HWInstructionEvent::Dispatched) {
+    unsigned NumEntries =
+        static_cast<const HWInstructionDispatchedEvent &>(Event).MicroOpcodes;
+    EntriesInUse += NumEntries;
+  }
+
+  if (Event.Type == HWInstructionEvent::Retired) {
+    unsigned ReleasedEntries = Event.IR.getInstruction()->getDesc().NumMicroOps;
+    assert(EntriesInUse >= ReleasedEntries && "Invalid internal state!");
+    EntriesInUse -= ReleasedEntries;
     ++NumRetired;
+  }
+}
+
+void RetireControlUnitStatistics::onCycleEnd() {
+  // Update histogram
+  RetiredPerCycle[NumRetired]++;
+  NumRetired = 0;
+  ++NumCycles;
+  MaxUsedEntries = std::max(MaxUsedEntries, EntriesInUse);
+  SumOfUsedEntries += EntriesInUse;
 }
 
 void RetireControlUnitStatistics::printView(raw_ostream &OS) const {
@@ -41,6 +71,18 @@ void RetireControlUnitStatistics::printView(raw_ostream &OS) const {
                << "%)\n";
   }
 
+  unsigned AvgUsage = (double)SumOfUsedEntries / NumCycles;
+  double MaxUsagePercentage = ((double)MaxUsedEntries / TotalROBEntries) * 100.0;
+  double NormalizedMaxPercentage = floor((MaxUsagePercentage * 10) + 0.5) / 10;
+  double AvgUsagePercentage = ((double)AvgUsage / TotalROBEntries) * 100.0;
+  double NormalizedAvgPercentage = floor((AvgUsagePercentage * 10) + 0.5) / 10;
+
+  TempStream << "\nTotal ROB Entries:                " << TotalROBEntries
+             << "\nMax Used ROB Entries:             " << MaxUsedEntries
+             << format("  ( %.1f%% )", NormalizedMaxPercentage)
+             << "\nAverage Used ROB Entries per cy:  " << AvgUsage
+             << format("  ( %.1f%% )\n", NormalizedAvgPercentage);
+
   TempStream.flush();
   OS << Buffer;
 }
index 9a4821e..02aa13b 100644 (file)
 ///
 /// Retire Control Unit - number of cycles where we saw N instructions retired:
 /// [# retired], [# cycles]
-///  0,           9  (6.9%)
-///  1,           6  (4.6%)
-///  2,           1  (0.8%)
-///  4,           3  (2.3%)
+///  0,           109  (17.9%)
+///  1,           102  (16.7%)
+///  2,           399  (65.4%)
+///
+/// Total ROB Entries:                64
+/// Max Used ROB Entries:             35  ( 54.7% )
+/// Average Used ROB Entries per cy:  32  ( 50.0% )
 ///
 //===----------------------------------------------------------------------===//
 
@@ -27,7 +30,7 @@
 #define LLVM_TOOLS_LLVM_MCA_RETIRECONTROLUNITSTATISTICS_H
 
 #include "Views/View.h"
-#include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/MC/MCSchedule.h"
 #include <map>
 
 namespace llvm {
@@ -39,21 +42,19 @@ class RetireControlUnitStatistics : public View {
 
   unsigned NumRetired;
   unsigned NumCycles;
-
-  void updateHistograms() {
-    RetiredPerCycle[NumRetired]++;
-    NumRetired = 0;
-  }
+  unsigned TotalROBEntries;
+  unsigned EntriesInUse;
+  unsigned MaxUsedEntries;
+  unsigned SumOfUsedEntries;
 
 public:
-  RetireControlUnitStatistics() : NumRetired(0), NumCycles(0) {}
+  RetireControlUnitStatistics(const MCSchedModel &SM);
 
   void onEvent(const HWInstructionEvent &Event) override;
-  void onCycleBegin() override { NumCycles++; }
-  void onCycleEnd() override { updateHistograms(); }
-
+  void onCycleEnd() override;
   void printView(llvm::raw_ostream &OS) const override;
 };
+
 } // namespace mca
 } // namespace llvm
 
index f6e72f3..8b792be 100644 (file)
@@ -472,7 +472,7 @@ int main(int argc, char **argv) {
       Printer.addView(llvm::make_unique<mca::SchedulerStatistics>(*STI));
 
     if (PrintRetireStats)
-      Printer.addView(llvm::make_unique<mca::RetireControlUnitStatistics>());
+      Printer.addView(llvm::make_unique<mca::RetireControlUnitStatistics>(SM));
 
     if (PrintRegisterFileStats)
       Printer.addView(llvm::make_unique<mca::RegisterFileStatistics>(*STI));