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] |
| 20 | /// 0, 7 (5.4%) |
| 21 | /// 1, 4 (3.1%) |
| 22 | /// 2, 8 (6.2%) |
| 23 | /// |
| 24 | /// Scheduler's queue usage: |
| 25 | /// JALU01, 0/20 |
| 26 | /// JFPU01, 18/18 |
| 27 | /// JLSAGU, 0/12 |
| 28 | /// |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | |
| 31 | #ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H |
| 32 | #define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H |
| 33 | |
Matt Davis | 10aa09f | 2018-08-24 20:24:53 +0000 | [diff] [blame^] | 34 | #include "Views/View.h" |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/SmallVector.h" |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCSubtargetInfo.h" |
Andrea Di Biagio | a88281d | 2018-06-18 17:04:56 +0000 | [diff] [blame] | 37 | #include <map> |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 38 | |
| 39 | namespace mca { |
| 40 | |
| 41 | class SchedulerStatistics : public View { |
Andrea Di Biagio | 074ff7c | 2018-04-11 12:31:44 +0000 | [diff] [blame] | 42 | const llvm::MCSchedModel &SM; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 43 | |
Andrea Di Biagio | a88281d | 2018-06-18 17:04:56 +0000 | [diff] [blame] | 44 | using Histogram = std::map<unsigned, unsigned>; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 45 | Histogram IssuedPerCycle; |
| 46 | |
| 47 | unsigned NumIssued; |
| 48 | unsigned NumCycles; |
| 49 | |
| 50 | // Tracks the usage of a scheduler's queue. |
| 51 | struct BufferUsage { |
| 52 | unsigned SlotsInUse; |
| 53 | unsigned MaxUsedSlots; |
| 54 | }; |
| 55 | |
Andrea Di Biagio | a88281d | 2018-06-18 17:04:56 +0000 | [diff] [blame] | 56 | std::map<unsigned, BufferUsage> BufferedResources; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 57 | |
| 58 | void updateHistograms() { |
| 59 | IssuedPerCycle[NumIssued]++; |
| 60 | NumIssued = 0; |
| 61 | } |
| 62 | |
| 63 | void printSchedulerStatistics(llvm::raw_ostream &OS) const; |
Andrea Di Biagio | 074ff7c | 2018-04-11 12:31:44 +0000 | [diff] [blame] | 64 | void printSchedulerUsage(llvm::raw_ostream &OS) const; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 65 | |
| 66 | public: |
Andrea Di Biagio | 074ff7c | 2018-04-11 12:31:44 +0000 | [diff] [blame] | 67 | SchedulerStatistics(const llvm::MCSubtargetInfo &STI) |
Matt Davis | 0906a7f | 2018-07-12 16:56:17 +0000 | [diff] [blame] | 68 | : SM(STI.getSchedModel()), NumIssued(0), NumCycles(0) {} |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 69 | |
Matt Davis | 0906a7f | 2018-07-12 16:56:17 +0000 | [diff] [blame] | 70 | void onEvent(const HWInstructionEvent &Event) override; |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 71 | |
Andrea Di Biagio | 3e64644 | 2018-04-12 10:49:40 +0000 | [diff] [blame] | 72 | void onCycleBegin() override { NumCycles++; } |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 73 | |
Andrea Di Biagio | 3e64644 | 2018-04-12 10:49:40 +0000 | [diff] [blame] | 74 | void onCycleEnd() override { updateHistograms(); } |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 75 | |
| 76 | // Increases the number of used scheduler queue slots of every buffered |
| 77 | // resource in the Buffers set. |
| 78 | void onReservedBuffers(llvm::ArrayRef<unsigned> Buffers) override; |
| 79 | |
| 80 | // Decreases by one the number of used scheduler queue slots of every |
| 81 | // buffered resource in the Buffers set. |
| 82 | void onReleasedBuffers(llvm::ArrayRef<unsigned> Buffers) override; |
| 83 | |
| 84 | void printView(llvm::raw_ostream &OS) const override { |
| 85 | printSchedulerStatistics(OS); |
Andrea Di Biagio | 074ff7c | 2018-04-11 12:31:44 +0000 | [diff] [blame] | 86 | printSchedulerUsage(OS); |
Andrea Di Biagio | 1cc29c0 | 2018-04-11 11:37:46 +0000 | [diff] [blame] | 87 | } |
| 88 | }; |
| 89 | } // namespace mca |
| 90 | |
| 91 | #endif |