Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===--------------------- BackendStatistics.h ------------------*- C++ -*-===// |
| 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 |
| 10 | /// |
| 11 | /// This file implements a printer class for printing generic Backend |
| 12 | /// statistics related to the dispatch logic, scheduler and retire unit. |
| 13 | /// |
| 14 | /// Example: |
| 15 | /// ======== |
| 16 | /// |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 17 | /// Dynamic Dispatch Stall Cycles: |
| 18 | /// RAT - Register unavailable: 0 |
| 19 | /// RCU - Retire tokens unavailable: 0 |
| 20 | /// SCHEDQ - Scheduler full: 42 |
| 21 | /// LQ - Load queue full: 0 |
| 22 | /// SQ - Store queue full: 0 |
| 23 | /// GROUP - Static restrictions on the dispatch group: 0 |
| 24 | /// |
| 25 | /// |
| 26 | /// Register Alias Table: |
| 27 | /// Total number of mappings created: 210 |
| 28 | /// Max number of mappings used: 35 |
| 29 | /// |
| 30 | /// |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 31 | /// Dispatch Logic - number of cycles where we saw N instructions dispatched: |
| 32 | /// [# dispatched], [# cycles] |
| 33 | /// 0, 15 (11.5%) |
| 34 | /// 5, 4 (3.1%) |
| 35 | /// |
| 36 | /// Schedulers - number of cycles where we saw N instructions issued: |
| 37 | /// [# issued], [# cycles] |
| 38 | /// 0, 7 (5.4%) |
| 39 | /// 1, 4 (3.1%) |
| 40 | /// 2, 8 (6.2%) |
| 41 | /// |
| 42 | /// Retire Control Unit - number of cycles where we saw N instructions retired: |
| 43 | /// [# retired], [# cycles] |
| 44 | /// 0, 9 (6.9%) |
| 45 | /// 1, 6 (4.6%) |
| 46 | /// 2, 1 (0.8%) |
| 47 | /// 4, 3 (2.3%) |
| 48 | /// |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 49 | /// |
| 50 | /// Scheduler's queue usage: |
| 51 | /// JALU01, 0/20 |
| 52 | /// JFPU01, 18/18 |
| 53 | /// JLSAGU, 0/12 |
| 54 | /// |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 55 | //===----------------------------------------------------------------------===// |
| 56 | |
| 57 | #ifndef LLVM_TOOLS_LLVM_MCA_BACKENDSTATISTICS_H |
| 58 | #define LLVM_TOOLS_LLVM_MCA_BACKENDSTATISTICS_H |
| 59 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 60 | #include "Backend.h" |
| 61 | #include "View.h" |
Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame] | 62 | #include "llvm/ADT/SmallVector.h" |
Andrea Di Biagio | 09771ad | 2018-03-16 22:21:52 +0000 | [diff] [blame] | 63 | #include "llvm/MC/MCSubtargetInfo.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 64 | #include "llvm/Support/raw_ostream.h" |
| 65 | #include <map> |
| 66 | |
| 67 | namespace mca { |
| 68 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 69 | class BackendStatistics : public View { |
Andrea Di Biagio | 09771ad | 2018-03-16 22:21:52 +0000 | [diff] [blame] | 70 | const llvm::MCSubtargetInfo &STI; |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 71 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 72 | using Histogram = std::map<unsigned, unsigned>; |
| 73 | Histogram DispatchGroupSizePerCycle; |
| 74 | Histogram RetiredPerCycle; |
| 75 | Histogram IssuedPerCycle; |
| 76 | |
| 77 | unsigned NumDispatched; |
| 78 | unsigned NumIssued; |
| 79 | unsigned NumRetired; |
| 80 | unsigned NumCycles; |
| 81 | |
Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame] | 82 | // Counts dispatch stall events caused by unavailability of resources. There |
| 83 | // is one counter for every generic stall kind (see class HWStallEvent). |
| 84 | llvm::SmallVector<unsigned, 8> HWStalls; |
| 85 | |
Andrea Di Biagio | a3f2e48 | 2018-03-20 18:20:39 +0000 | [diff] [blame] | 86 | // Tracks the usage of a scheduler's queue. |
| 87 | struct BufferUsage { |
| 88 | unsigned SlotsInUse; |
| 89 | unsigned MaxUsedSlots; |
| 90 | }; |
| 91 | |
| 92 | // There is a map entry for each buffered resource in the scheduling model. |
| 93 | // Every time a buffer is consumed/freed, this view updates the corresponding |
| 94 | // entry. |
| 95 | llvm::DenseMap<unsigned, BufferUsage> BufferedResources; |
| 96 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 97 | void updateHistograms() { |
| 98 | DispatchGroupSizePerCycle[NumDispatched]++; |
| 99 | IssuedPerCycle[NumIssued]++; |
| 100 | RetiredPerCycle[NumRetired]++; |
| 101 | NumDispatched = 0; |
| 102 | NumIssued = 0; |
| 103 | NumRetired = 0; |
| 104 | } |
| 105 | |
Andrea Di Biagio | 12ef526 | 2018-03-21 18:11:05 +0000 | [diff] [blame] | 106 | // Used to track the number of physical registers used in a register file. |
| 107 | struct RegisterFileUsage { |
| 108 | unsigned TotalMappings; |
| 109 | unsigned MaxUsedMappings; |
| 110 | unsigned CurrentlyUsedMappings; |
| 111 | }; |
| 112 | |
| 113 | // There is one entry for each register file implemented by the processor. |
| 114 | llvm::SmallVector<RegisterFileUsage, 4> RegisterFiles; |
| 115 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 116 | void printRetireUnitStatistics(llvm::raw_ostream &OS) const; |
| 117 | void printDispatchUnitStatistics(llvm::raw_ostream &OS) const; |
| 118 | void printSchedulerStatistics(llvm::raw_ostream &OS) const; |
| 119 | |
Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame] | 120 | void printDispatchStalls(llvm::raw_ostream &OS) const; |
Andrea Di Biagio | 12ef526 | 2018-03-21 18:11:05 +0000 | [diff] [blame] | 121 | void printRATStatistics(llvm::raw_ostream &OS) const; |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 122 | void printRCUStatistics(llvm::raw_ostream &OS, const Histogram &Histogram, |
| 123 | unsigned Cycles) const; |
| 124 | void printDispatchUnitUsage(llvm::raw_ostream &OS, const Histogram &Stats, |
| 125 | unsigned Cycles) const; |
| 126 | void printIssuePerCycle(const Histogram &IssuePerCycle, |
| 127 | unsigned TotalCycles) const; |
Andrea Di Biagio | a3f2e48 | 2018-03-20 18:20:39 +0000 | [diff] [blame] | 128 | void printSchedulerUsage(llvm::raw_ostream &OS, |
| 129 | const llvm::MCSchedModel &SM) const; |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 130 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 131 | public: |
Andrea Di Biagio | 12ef526 | 2018-03-21 18:11:05 +0000 | [diff] [blame] | 132 | BackendStatistics(const llvm::MCSubtargetInfo &sti) |
Andrea Di Biagio | 94fafdf | 2018-03-24 16:05:36 +0000 | [diff] [blame^] | 133 | : STI(sti), NumDispatched(0), NumIssued(0), NumRetired(0), NumCycles(0), |
| 134 | HWStalls(HWStallEvent::LastGenericEvent), |
Andrea Di Biagio | 12ef526 | 2018-03-21 18:11:05 +0000 | [diff] [blame] | 135 | // TODO: The view currently assumes a single register file. This will |
| 136 | // change in future. |
| 137 | RegisterFiles(1) {} |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 138 | |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 139 | void onInstructionEvent(const HWInstructionEvent &Event) override; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 140 | |
| 141 | void onCycleBegin(unsigned Cycle) override { NumCycles++; } |
| 142 | |
| 143 | void onCycleEnd(unsigned Cycle) override { updateHistograms(); } |
| 144 | |
Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame] | 145 | void onStallEvent(const HWStallEvent &Event) override { |
| 146 | if (Event.Type < HWStallEvent::LastGenericEvent) |
| 147 | HWStalls[Event.Type]++; |
| 148 | } |
| 149 | |
Andrea Di Biagio | a3f2e48 | 2018-03-20 18:20:39 +0000 | [diff] [blame] | 150 | // Increases the number of used scheduler queue slots of every buffered |
| 151 | // resource in the Buffers set. |
Andrea Di Biagio | 04de0b4 | 2018-03-20 20:18:36 +0000 | [diff] [blame] | 152 | void onReservedBuffers(llvm::ArrayRef<unsigned> Buffers) override; |
Andrea Di Biagio | a3f2e48 | 2018-03-20 18:20:39 +0000 | [diff] [blame] | 153 | |
| 154 | // Decreases by one the number of used scheduler queue slots of every |
| 155 | // buffered resource in the Buffers set. |
Andrea Di Biagio | 04de0b4 | 2018-03-20 20:18:36 +0000 | [diff] [blame] | 156 | void onReleasedBuffers(llvm::ArrayRef<unsigned> Buffers) override; |
Andrea Di Biagio | a3f2e48 | 2018-03-20 18:20:39 +0000 | [diff] [blame] | 157 | |
Andrea Di Biagio | 8af3fe8 | 2018-03-08 16:08:43 +0000 | [diff] [blame] | 158 | void printView(llvm::raw_ostream &OS) const override { |
Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame] | 159 | printDispatchStalls(OS); |
Andrea Di Biagio | 12ef526 | 2018-03-21 18:11:05 +0000 | [diff] [blame] | 160 | printRATStatistics(OS); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 161 | printDispatchUnitStatistics(OS); |
| 162 | printSchedulerStatistics(OS); |
| 163 | printRetireUnitStatistics(OS); |
Andrea Di Biagio | a3f2e48 | 2018-03-20 18:20:39 +0000 | [diff] [blame] | 164 | printSchedulerUsage(OS, STI.getSchedModel()); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 165 | } |
| 166 | }; |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 167 | } // namespace mca |
| 168 | |
| 169 | #endif |