DispatchStatistics.cpp 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //===--------------------- DispatchStatistics.cpp ---------------*- 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 the DispatchStatistics interface.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #include "Views/DispatchStatistics.h"
  14. #include "llvm/Support/Format.h"
  15. namespace llvm {
  16. namespace mca {
  17. void DispatchStatistics::onEvent(const HWStallEvent &Event) {
  18. if (Event.Type < HWStallEvent::LastGenericEvent)
  19. HWStalls[Event.Type]++;
  20. }
  21. void DispatchStatistics::onEvent(const HWInstructionEvent &Event) {
  22. if (Event.Type != HWInstructionEvent::Dispatched)
  23. return;
  24. const auto &DE = static_cast<const HWInstructionDispatchedEvent &>(Event);
  25. NumDispatched += DE.MicroOpcodes;
  26. }
  27. void DispatchStatistics::printDispatchHistogram(raw_ostream &OS) const {
  28. std::string Buffer;
  29. raw_string_ostream TempStream(Buffer);
  30. TempStream << "\n\nDispatch Logic - "
  31. << "number of cycles where we saw N micro opcodes dispatched:\n";
  32. TempStream << "[# dispatched], [# cycles]\n";
  33. for (const std::pair<const unsigned, unsigned> &Entry :
  34. DispatchGroupSizePerCycle) {
  35. double Percentage = ((double)Entry.second / NumCycles) * 100.0;
  36. TempStream << " " << Entry.first << ", " << Entry.second
  37. << " (" << format("%.1f", floor((Percentage * 10) + 0.5) / 10)
  38. << "%)\n";
  39. }
  40. TempStream.flush();
  41. OS << Buffer;
  42. }
  43. static void printStalls(raw_ostream &OS, unsigned NumStalls,
  44. unsigned NumCycles) {
  45. if (!NumStalls) {
  46. OS << NumStalls;
  47. return;
  48. }
  49. double Percentage = ((double)NumStalls / NumCycles) * 100.0;
  50. OS << NumStalls << " ("
  51. << format("%.1f", floor((Percentage * 10) + 0.5) / 10) << "%)";
  52. }
  53. void DispatchStatistics::printDispatchStalls(raw_ostream &OS) const {
  54. std::string Buffer;
  55. raw_string_ostream SS(Buffer);
  56. SS << "\n\nDynamic Dispatch Stall Cycles:\n";
  57. SS << "RAT - Register unavailable: ";
  58. printStalls(SS, HWStalls[HWStallEvent::RegisterFileStall], NumCycles);
  59. SS << "\nRCU - Retire tokens unavailable: ";
  60. printStalls(SS, HWStalls[HWStallEvent::RetireControlUnitStall], NumCycles);
  61. SS << "\nSCHEDQ - Scheduler full: ";
  62. printStalls(SS, HWStalls[HWStallEvent::SchedulerQueueFull], NumCycles);
  63. SS << "\nLQ - Load queue full: ";
  64. printStalls(SS, HWStalls[HWStallEvent::LoadQueueFull], NumCycles);
  65. SS << "\nSQ - Store queue full: ";
  66. printStalls(SS, HWStalls[HWStallEvent::StoreQueueFull], NumCycles);
  67. SS << "\nGROUP - Static restrictions on the dispatch group: ";
  68. printStalls(SS, HWStalls[HWStallEvent::DispatchGroupStall], NumCycles);
  69. SS << "\nUSH - Uncategorised Structural Hazard: ";
  70. printStalls(SS, HWStalls[HWStallEvent::CustomBehaviourStall], NumCycles);
  71. SS << '\n';
  72. SS.flush();
  73. OS << Buffer;
  74. }
  75. json::Value DispatchStatistics::toJSON() const {
  76. json::Object JO({{"RAT", HWStalls[HWStallEvent::RegisterFileStall]},
  77. {"RCU", HWStalls[HWStallEvent::RetireControlUnitStall]},
  78. {"SCHEDQ", HWStalls[HWStallEvent::SchedulerQueueFull]},
  79. {"LQ", HWStalls[HWStallEvent::LoadQueueFull]},
  80. {"SQ", HWStalls[HWStallEvent::StoreQueueFull]},
  81. {"GROUP", HWStalls[HWStallEvent::DispatchGroupStall]},
  82. {"USH", HWStalls[HWStallEvent::CustomBehaviourStall]}});
  83. return JO;
  84. }
  85. } // namespace mca
  86. } // namespace llvm