SchedulerStatistics.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //===--------------------- SchedulerStatistics.h ----------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. /// \file
  9. ///
  10. /// This file defines class SchedulerStatistics. Class SchedulerStatistics is a
  11. /// View that listens to instruction issue events in order to print general
  12. /// statistics related to the hardware schedulers.
  13. ///
  14. /// Example:
  15. /// ========
  16. ///
  17. /// Schedulers - number of cycles where we saw N instructions issued:
  18. /// [# issued], [# cycles]
  19. /// 0, 6 (2.9%)
  20. /// 1, 106 (50.7%)
  21. /// 2, 97 (46.4%)
  22. ///
  23. /// Scheduler's queue usage:
  24. /// [1] Resource name.
  25. /// [2] Average number of used buffer entries.
  26. /// [3] Maximum number of used buffer entries.
  27. /// [4] Total number of buffer entries.
  28. ///
  29. /// [1] [2] [3] [4]
  30. /// JALU01 0 0 20
  31. /// JFPU01 15 18 18
  32. /// JLSAGU 0 0 12
  33. //
  34. //===----------------------------------------------------------------------===//
  35. #ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
  36. #define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H
  37. #include "llvm/ADT/SmallVector.h"
  38. #include "llvm/MC/MCSubtargetInfo.h"
  39. #include "llvm/MCA/View.h"
  40. #include <map>
  41. namespace llvm {
  42. namespace mca {
  43. class SchedulerStatistics final : public View {
  44. const llvm::MCSchedModel &SM;
  45. unsigned LQResourceID;
  46. unsigned SQResourceID;
  47. unsigned NumIssued;
  48. unsigned NumCycles;
  49. unsigned MostRecentLoadDispatched;
  50. unsigned MostRecentStoreDispatched;
  51. // Tracks the usage of a scheduler's queue.
  52. struct BufferUsage {
  53. unsigned SlotsInUse;
  54. unsigned MaxUsedSlots;
  55. uint64_t CumulativeNumUsedSlots;
  56. };
  57. using Histogram = std::map<unsigned, unsigned>;
  58. Histogram IssueWidthPerCycle;
  59. std::vector<BufferUsage> Usage;
  60. void updateHistograms();
  61. void printSchedulerStats(llvm::raw_ostream &OS) const;
  62. void printSchedulerUsage(llvm::raw_ostream &OS) const;
  63. public:
  64. SchedulerStatistics(const llvm::MCSubtargetInfo &STI);
  65. void onEvent(const HWInstructionEvent &Event) override;
  66. void onCycleBegin() override { NumCycles++; }
  67. void onCycleEnd() override { updateHistograms(); }
  68. // Increases the number of used scheduler queue slots of every buffered
  69. // resource in the Buffers set.
  70. void onReservedBuffers(const InstRef &IR,
  71. llvm::ArrayRef<unsigned> Buffers) override;
  72. // Decreases by one the number of used scheduler queue slots of every
  73. // buffered resource in the Buffers set.
  74. void onReleasedBuffers(const InstRef &IR,
  75. llvm::ArrayRef<unsigned> Buffers) override;
  76. void printView(llvm::raw_ostream &OS) const override;
  77. StringRef getNameAsString() const override { return "SchedulerStatistics"; }
  78. bool isSerializable() const override { return false; }
  79. };
  80. } // namespace mca
  81. } // namespace llvm
  82. #endif