Skip to content

Commit 07a8255

Browse files
committed
[llvm-mca][View] Improved Retire Control Unit Statistics.
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
1 parent 972e348 commit 07a8255

File tree

10 files changed

+87
-16
lines changed

10 files changed

+87
-16
lines changed

llvm/docs/CommandGuide/llvm-mca.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ sections.
516516
1, 102 (16.7%)
517517
2, 399 (65.4%)
518518
519+
Total ROB Entries: 64
520+
Max Used ROB Entries: 35 ( 54.7% )
521+
Average Used ROB Entries per cy: 32 ( 50.0% )
522+
519523
520524
Register File statistics:
521525
Total number of mappings created: 900

llvm/test/tools/llvm-mca/X86/BdVer2/rcu-statistics.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@
6060
# CHECK-NEXT: 1, 9 (40.9%)
6161
# CHECK-NEXT: 3, 1 (4.5%)
6262
# CHECK-NEXT: 4, 1 (4.5%)
63+
64+
# CHECK: Total ROB Entries: 128
65+
# CHECK-NEXT: Max Used ROB Entries: 16 ( 12.5% )
66+
# CHECK-NEXT: Average Used ROB Entries per cy: 9 ( 7.0% )

llvm/test/tools/llvm-mca/X86/BtVer2/rcu-statistics.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@
5858
# CHECK-NEXT: [# retired], [# cycles]
5959
# CHECK-NEXT: 0, 23 (74.2%)
6060
# CHECK-NEXT: 2, 8 (25.8%)
61+
62+
# CHECK: Total ROB Entries: 64
63+
# CHECK-NEXT: Max Used ROB Entries: 16 ( 25.0% )
64+
# CHECK-NEXT: Average Used ROB Entries per cy: 11 ( 17.2% )

llvm/test/tools/llvm-mca/X86/option-all-stats-1.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ add %eax, %eax
6262
# FULLREPORT-NEXT: 0, 3 (2.9%)
6363
# FULLREPORT-NEXT: 1, 100 (97.1%)
6464

65+
# FULLREPORT: Total ROB Entries: 64
66+
# FULLREPORT-NEXT: Max Used ROB Entries: 22 ( 34.4% )
67+
# FULLREPORT-NEXT: Average Used ROB Entries per cy: 17 ( 26.6% )
68+
6569
# FULLREPORT: Register File statistics:
6670
# FULLREPORT-NEXT: Total number of mappings created: 200
6771
# FULLREPORT-NEXT: Max number of mappings used: 44

llvm/test/tools/llvm-mca/X86/option-all-stats-2.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ add %eax, %eax
6363
# ALL-NEXT: 0, 3 (2.9%)
6464
# ALL-NEXT: 1, 100 (97.1%)
6565

66+
# ALL: Total ROB Entries: 64
67+
# ALL-NEXT: Max Used ROB Entries: 22 ( 34.4% )
68+
# ALL-NEXT: Average Used ROB Entries per cy: 17 ( 26.6% )
69+
6670
# ALL: Register File statistics:
6771
# ALL-NEXT: Total number of mappings created: 200
6872
# ALL-NEXT: Max number of mappings used: 44

llvm/test/tools/llvm-mca/X86/option-all-views-1.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ add %eax, %eax
6464
# FULLREPORT-NEXT: 0, 3 (2.9%)
6565
# FULLREPORT-NEXT: 1, 100 (97.1%)
6666

67+
# FULLREPORT: Total ROB Entries: 64
68+
# FULLREPORT-NEXT: Max Used ROB Entries: 22 ( 34.4% )
69+
# FULLREPORT-NEXT: Average Used ROB Entries per cy: 17 ( 26.6% )
70+
6771
# FULLREPORT: Register File statistics:
6872
# FULLREPORT-NEXT: Total number of mappings created: 200
6973
# FULLREPORT-NEXT: Max number of mappings used: 44

llvm/test/tools/llvm-mca/X86/option-all-views-2.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ add %eax, %eax
6363
# ALL-NEXT: 0, 3 (2.9%)
6464
# ALL-NEXT: 1, 100 (97.1%)
6565

66+
# ALL: Total ROB Entries: 64
67+
# ALL-NEXT: Max Used ROB Entries: 22 ( 34.4% )
68+
# ALL-NEXT: Average Used ROB Entries per cy: 17 ( 26.6% )
69+
6670
# ALL: Register File statistics:
6771
# ALL-NEXT: Total number of mappings created: 200
6872
# ALL-NEXT: Max number of mappings used: 44

llvm/tools/llvm-mca/Views/RetireControlUnitStatistics.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,39 @@
1818
namespace llvm {
1919
namespace mca {
2020

21+
RetireControlUnitStatistics::RetireControlUnitStatistics(const MCSchedModel &SM)
22+
: NumRetired(0), NumCycles(0), EntriesInUse(0), MaxUsedEntries(0),
23+
SumOfUsedEntries(0) {
24+
TotalROBEntries = SM.MicroOpBufferSize;
25+
if (SM.hasExtraProcessorInfo()) {
26+
const MCExtraProcessorInfo &EPI = SM.getExtraProcessorInfo();
27+
if (EPI.ReorderBufferSize)
28+
TotalROBEntries = EPI.ReorderBufferSize;
29+
}
30+
}
31+
2132
void RetireControlUnitStatistics::onEvent(const HWInstructionEvent &Event) {
22-
if (Event.Type == HWInstructionEvent::Retired)
33+
if (Event.Type == HWInstructionEvent::Dispatched) {
34+
unsigned NumEntries =
35+
static_cast<const HWInstructionDispatchedEvent &>(Event).MicroOpcodes;
36+
EntriesInUse += NumEntries;
37+
}
38+
39+
if (Event.Type == HWInstructionEvent::Retired) {
40+
unsigned ReleasedEntries = Event.IR.getInstruction()->getDesc().NumMicroOps;
41+
assert(EntriesInUse >= ReleasedEntries && "Invalid internal state!");
42+
EntriesInUse -= ReleasedEntries;
2343
++NumRetired;
44+
}
45+
}
46+
47+
void RetireControlUnitStatistics::onCycleEnd() {
48+
// Update histogram
49+
RetiredPerCycle[NumRetired]++;
50+
NumRetired = 0;
51+
++NumCycles;
52+
MaxUsedEntries = std::max(MaxUsedEntries, EntriesInUse);
53+
SumOfUsedEntries += EntriesInUse;
2454
}
2555

2656
void RetireControlUnitStatistics::printView(raw_ostream &OS) const {
@@ -41,6 +71,18 @@ void RetireControlUnitStatistics::printView(raw_ostream &OS) const {
4171
<< "%)\n";
4272
}
4373

74+
unsigned AvgUsage = (double)SumOfUsedEntries / NumCycles;
75+
double MaxUsagePercentage = ((double)MaxUsedEntries / TotalROBEntries) * 100.0;
76+
double NormalizedMaxPercentage = floor((MaxUsagePercentage * 10) + 0.5) / 10;
77+
double AvgUsagePercentage = ((double)AvgUsage / TotalROBEntries) * 100.0;
78+
double NormalizedAvgPercentage = floor((AvgUsagePercentage * 10) + 0.5) / 10;
79+
80+
TempStream << "\nTotal ROB Entries: " << TotalROBEntries
81+
<< "\nMax Used ROB Entries: " << MaxUsedEntries
82+
<< format(" ( %.1f%% )", NormalizedMaxPercentage)
83+
<< "\nAverage Used ROB Entries per cy: " << AvgUsage
84+
<< format(" ( %.1f%% )\n", NormalizedAvgPercentage);
85+
4486
TempStream.flush();
4587
OS << Buffer;
4688
}

llvm/tools/llvm-mca/Views/RetireControlUnitStatistics.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@
1616
///
1717
/// Retire Control Unit - number of cycles where we saw N instructions retired:
1818
/// [# retired], [# cycles]
19-
/// 0, 9 (6.9%)
20-
/// 1, 6 (4.6%)
21-
/// 2, 1 (0.8%)
22-
/// 4, 3 (2.3%)
19+
/// 0, 109 (17.9%)
20+
/// 1, 102 (16.7%)
21+
/// 2, 399 (65.4%)
22+
///
23+
/// Total ROB Entries: 64
24+
/// Max Used ROB Entries: 35 ( 54.7% )
25+
/// Average Used ROB Entries per cy: 32 ( 50.0% )
2326
///
2427
//===----------------------------------------------------------------------===//
2528

2629
#ifndef LLVM_TOOLS_LLVM_MCA_RETIRECONTROLUNITSTATISTICS_H
2730
#define LLVM_TOOLS_LLVM_MCA_RETIRECONTROLUNITSTATISTICS_H
2831

2932
#include "Views/View.h"
30-
#include "llvm/MC/MCSubtargetInfo.h"
33+
#include "llvm/MC/MCSchedule.h"
3134
#include <map>
3235

3336
namespace llvm {
@@ -39,21 +42,19 @@ class RetireControlUnitStatistics : public View {
3942

4043
unsigned NumRetired;
4144
unsigned NumCycles;
42-
43-
void updateHistograms() {
44-
RetiredPerCycle[NumRetired]++;
45-
NumRetired = 0;
46-
}
45+
unsigned TotalROBEntries;
46+
unsigned EntriesInUse;
47+
unsigned MaxUsedEntries;
48+
unsigned SumOfUsedEntries;
4749

4850
public:
49-
RetireControlUnitStatistics() : NumRetired(0), NumCycles(0) {}
51+
RetireControlUnitStatistics(const MCSchedModel &SM);
5052

5153
void onEvent(const HWInstructionEvent &Event) override;
52-
void onCycleBegin() override { NumCycles++; }
53-
void onCycleEnd() override { updateHistograms(); }
54-
54+
void onCycleEnd() override;
5555
void printView(llvm::raw_ostream &OS) const override;
5656
};
57+
5758
} // namespace mca
5859
} // namespace llvm
5960

llvm/tools/llvm-mca/llvm-mca.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ int main(int argc, char **argv) {
472472
Printer.addView(llvm::make_unique<mca::SchedulerStatistics>(*STI));
473473

474474
if (PrintRetireStats)
475-
Printer.addView(llvm::make_unique<mca::RetireControlUnitStatistics>());
475+
Printer.addView(llvm::make_unique<mca::RetireControlUnitStatistics>(SM));
476476

477477
if (PrintRegisterFileStats)
478478
Printer.addView(llvm::make_unique<mca::RegisterFileStatistics>(*STI));

0 commit comments

Comments
 (0)