DispatchStatistics.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //===--------------------- DispatchStatistics.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 implements a view that prints a few statistics related to the
  11. /// dispatch logic. It collects and analyzes instruction dispatch events as
  12. /// well as static/dynamic dispatch stall events.
  13. ///
  14. /// Example:
  15. /// ========
  16. ///
  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. /// Dispatch Logic - number of cycles where we saw N micro opcodes dispatched:
  27. /// [# dispatched], [# cycles]
  28. /// 0, 15 (11.5%)
  29. /// 2, 4 (3.1%)
  30. ///
  31. //===----------------------------------------------------------------------===//
  32. #ifndef LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H
  33. #define LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H
  34. #include "Views/View.h"
  35. #include "llvm/ADT/SmallVector.h"
  36. #include "llvm/MC/MCSubtargetInfo.h"
  37. #include <map>
  38. namespace llvm {
  39. namespace mca {
  40. class DispatchStatistics : public View {
  41. unsigned NumDispatched;
  42. unsigned NumCycles;
  43. // Counts dispatch stall events caused by unavailability of resources. There
  44. // is one counter for every generic stall kind (see class HWStallEvent).
  45. llvm::SmallVector<unsigned, 8> HWStalls;
  46. using Histogram = std::map<unsigned, unsigned>;
  47. Histogram DispatchGroupSizePerCycle;
  48. void updateHistograms() {
  49. DispatchGroupSizePerCycle[NumDispatched]++;
  50. NumDispatched = 0;
  51. }
  52. void printDispatchHistogram(llvm::raw_ostream &OS) const;
  53. void printDispatchStalls(llvm::raw_ostream &OS) const;
  54. public:
  55. DispatchStatistics()
  56. : NumDispatched(0), NumCycles(0),
  57. HWStalls(HWStallEvent::LastGenericEvent) {}
  58. void onEvent(const HWStallEvent &Event) override;
  59. void onEvent(const HWInstructionEvent &Event) override;
  60. void onCycleBegin() override { NumCycles++; }
  61. void onCycleEnd() override { updateHistograms(); }
  62. void printView(llvm::raw_ostream &OS) const override {
  63. printDispatchStalls(OS);
  64. printDispatchHistogram(OS);
  65. }
  66. StringRef getNameAsString() const override { return "DispatchStatistics"; }
  67. };
  68. } // namespace mca
  69. } // namespace llvm
  70. #endif