Matt Davis | 248acf6 | 2018-06-14 20:58:54 +0000 | [diff] [blame] | 1 | //===--------------------- RetireControlUnitStatistics.cpp ------*- C++ -*-===// |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
Andrea Di Biagio | 53e6ade | 2018-03-09 12:50:42 +0000 | [diff] [blame] | 10 | /// |
Andrea Di Biagio | f41ad5c | 2018-04-11 12:12:53 +0000 | [diff] [blame] | 11 | /// This file implements the RetireControlUnitStatistics interface. |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Matt Davis | 10aa09f | 2018-08-24 20:24:53 +0000 | [diff] [blame] | 15 | #include "Views/RetireControlUnitStatistics.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Format.h" |
| 17 | |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 18 | namespace llvm { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 19 | namespace mca { |
| 20 | |
Andrea Di Biagio | 07a8255 | 2018-11-23 12:12:57 +0000 | [diff] [blame^] | 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 | |
Matt Davis | 0906a7f | 2018-07-12 16:56:17 +0000 | [diff] [blame] | 32 | void RetireControlUnitStatistics::onEvent(const HWInstructionEvent &Event) { |
Andrea Di Biagio | 07a8255 | 2018-11-23 12:12:57 +0000 | [diff] [blame^] | 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; |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 43 | ++NumRetired; |
Andrea Di Biagio | 07a8255 | 2018-11-23 12:12:57 +0000 | [diff] [blame^] | 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; |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Andrea Di Biagio | db158be | 2018-10-22 16:28:07 +0000 | [diff] [blame] | 56 | void RetireControlUnitStatistics::printView(raw_ostream &OS) const { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 57 | std::string Buffer; |
| 58 | raw_string_ostream TempStream(Buffer); |
| 59 | TempStream << "\n\nRetire Control Unit - " |
| 60 | << "number of cycles where we saw N instructions retired:\n"; |
| 61 | TempStream << "[# retired], [# cycles]\n"; |
| 62 | |
| 63 | for (const std::pair<unsigned, unsigned> &Entry : RetiredPerCycle) { |
| 64 | TempStream << " " << Entry.first; |
| 65 | if (Entry.first < 10) |
| 66 | TempStream << ", "; |
| 67 | else |
| 68 | TempStream << ", "; |
| 69 | TempStream << Entry.second << " (" |
| 70 | << format("%.1f", ((double)Entry.second / NumCycles) * 100.0) |
| 71 | << "%)\n"; |
| 72 | } |
| 73 | |
Andrea Di Biagio | 07a8255 | 2018-11-23 12:12:57 +0000 | [diff] [blame^] | 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 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 86 | TempStream.flush(); |
| 87 | OS << Buffer; |
| 88 | } |
| 89 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 90 | } // namespace mca |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 91 | } // namespace llvm |