Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 1 | //===--------------------- SchedulerStatistics.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 defines class SchedulerStatistics. Class SchedulerStatistics is a |
| 12 | /// View that listens to instruction issue events in order to print general |
| 13 | /// statistics related to the hardware schedulers. |
| 14 | /// |
| 15 | /// Example: |
| 16 | /// ======== |
| 17 | /// |
| 18 | /// Schedulers - number of cycles where we saw N instructions issued: |
| 19 | /// [# issued], [# cycles] |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 20 | /// 0, 6 (2.9%) |
| 21 | /// 1, 106 (50.7%) |
| 22 | /// 2, 97 (46.4%) |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 23 | /// |
| 24 | /// Scheduler's queue usage: |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 25 | /// [1] Resource name. |
| 26 | /// [2] Average number of used buffer entries. |
| 27 | /// [3] Maximum number of used buffer entries. |
| 28 | /// [4] Total number of buffer entries. |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 29 | /// |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 30 | /// [1] [2] [3] [4] |
| 31 | /// JALU01 0 0 20 |
| 32 | /// JFPU01 15 18 18 |
| 33 | /// JLSAGU 0 0 12 |
| 34 | // |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 35 | //===----------------------------------------------------------------------===// |
| 36 | |
| 37 | #ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H |
| 38 | #define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H |
| 39 | |
Matt Davis | 10aa09f | 2018-08-24 20:24:53 +0000 | [diff] [blame] | 40 | #include "Views/View.h" |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/SmallVector.h" |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 42 | #include "llvm/MC/MCSubtargetInfo.h" |
Andrea Di Biagio | a88281d | 2018-06-18 17:04:56 +0000 | [diff] [blame] | 43 | #include <map> |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 44 | |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame^] | 45 | namespace llvm { |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 46 | namespace mca { |
| 47 | |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 48 | class SchedulerStatistics final : public View { |
Andrea Di Biagio | 074ff7c | 2018-04-11 12:31:44 +0000 | [diff] [blame] | 49 | const llvm::MCSchedModel &SM; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 50 | unsigned NumIssued; |
| 51 | unsigned NumCycles; |
| 52 | |
| 53 | // Tracks the usage of a scheduler's queue. |
| 54 | struct BufferUsage { |
| 55 | unsigned SlotsInUse; |
| 56 | unsigned MaxUsedSlots; |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 57 | uint64_t CumulativeNumUsedSlots; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 60 | std::vector<unsigned> IssuedPerCycle; |
| 61 | std::vector<BufferUsage> Usage; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 62 | |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 63 | void updateHistograms(); |
| 64 | void printSchedulerStats(llvm::raw_ostream &OS) const; |
Andrea Di Biagio | 074ff7c | 2018-04-11 12:31:44 +0000 | [diff] [blame] | 65 | void printSchedulerUsage(llvm::raw_ostream &OS) const; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 66 | |
| 67 | public: |
Andrea Di Biagio | 074ff7c | 2018-04-11 12:31:44 +0000 | [diff] [blame] | 68 | SchedulerStatistics(const llvm::MCSubtargetInfo &STI) |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 69 | : SM(STI.getSchedModel()), NumIssued(0), NumCycles(0), |
| 70 | IssuedPerCycle(STI.getSchedModel().NumProcResourceKinds, 0), |
| 71 | Usage(STI.getSchedModel().NumProcResourceKinds, {0, 0, 0}) {} |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 72 | |
Matt Davis | 0906a7f | 2018-07-12 16:56:17 +0000 | [diff] [blame] | 73 | void onEvent(const HWInstructionEvent &Event) override; |
Andrea Di Biagio | 3e64644 | 2018-04-12 10:49:40 +0000 | [diff] [blame] | 74 | void onCycleBegin() override { NumCycles++; } |
Andrea Di Biagio | 3e64644 | 2018-04-12 10:49:40 +0000 | [diff] [blame] | 75 | void onCycleEnd() override { updateHistograms(); } |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 76 | |
| 77 | // Increases the number of used scheduler queue slots of every buffered |
| 78 | // resource in the Buffers set. |
Andrea Di Biagio | 29c5d5a | 2018-08-28 13:14:42 +0000 | [diff] [blame] | 79 | void onReservedBuffers(const InstRef &IR, |
| 80 | llvm::ArrayRef<unsigned> Buffers) override; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 81 | |
| 82 | // Decreases by one the number of used scheduler queue slots of every |
| 83 | // buffered resource in the Buffers set. |
Andrea Di Biagio | 29c5d5a | 2018-08-28 13:14:42 +0000 | [diff] [blame] | 84 | void onReleasedBuffers(const InstRef &IR, |
| 85 | llvm::ArrayRef<unsigned> Buffers) override; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 86 | |
Andrea Di Biagio | b89b96c | 2018-08-27 14:52:52 +0000 | [diff] [blame] | 87 | void printView(llvm::raw_ostream &OS) const override; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 88 | }; |
| 89 | } // namespace mca |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame^] | 90 | } // namespace llvm |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 91 | |
| 92 | #endif |