RetireControlUnitStatistics.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //===--------------------- RetireControlUnitStatistics.cpp ------*- 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 implements the RetireControlUnitStatistics interface.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #include "Views/RetireControlUnitStatistics.h"
  15. #include "llvm/Support/Format.h"
  16. namespace llvm {
  17. namespace mca {
  18. RetireControlUnitStatistics::RetireControlUnitStatistics(const MCSchedModel &SM)
  19. : NumRetired(0), NumCycles(0), EntriesInUse(0), MaxUsedEntries(0),
  20. SumOfUsedEntries(0) {
  21. TotalROBEntries = SM.MicroOpBufferSize;
  22. if (SM.hasExtraProcessorInfo()) {
  23. const MCExtraProcessorInfo &EPI = SM.getExtraProcessorInfo();
  24. if (EPI.ReorderBufferSize)
  25. TotalROBEntries = EPI.ReorderBufferSize;
  26. }
  27. }
  28. void RetireControlUnitStatistics::onEvent(const HWInstructionEvent &Event) {
  29. if (Event.Type == HWInstructionEvent::Dispatched) {
  30. unsigned NumEntries =
  31. static_cast<const HWInstructionDispatchedEvent &>(Event).MicroOpcodes;
  32. EntriesInUse += NumEntries;
  33. }
  34. if (Event.Type == HWInstructionEvent::Retired) {
  35. unsigned ReleasedEntries = Event.IR.getInstruction()->getDesc().NumMicroOps;
  36. assert(EntriesInUse >= ReleasedEntries && "Invalid internal state!");
  37. EntriesInUse -= ReleasedEntries;
  38. ++NumRetired;
  39. }
  40. }
  41. void RetireControlUnitStatistics::onCycleEnd() {
  42. // Update histogram
  43. RetiredPerCycle[NumRetired]++;
  44. NumRetired = 0;
  45. ++NumCycles;
  46. MaxUsedEntries = std::max(MaxUsedEntries, EntriesInUse);
  47. SumOfUsedEntries += EntriesInUse;
  48. }
  49. void RetireControlUnitStatistics::printView(raw_ostream &OS) const {
  50. std::string Buffer;
  51. raw_string_ostream TempStream(Buffer);
  52. TempStream << "\n\nRetire Control Unit - "
  53. << "number of cycles where we saw N instructions retired:\n";
  54. TempStream << "[# retired], [# cycles]\n";
  55. for (const std::pair<unsigned, unsigned> &Entry : RetiredPerCycle) {
  56. TempStream << " " << Entry.first;
  57. if (Entry.first < 10)
  58. TempStream << ", ";
  59. else
  60. TempStream << ", ";
  61. TempStream << Entry.second << " ("
  62. << format("%.1f", ((double)Entry.second / NumCycles) * 100.0)
  63. << "%)\n";
  64. }
  65. unsigned AvgUsage = (double)SumOfUsedEntries / NumCycles;
  66. double MaxUsagePercentage = ((double)MaxUsedEntries / TotalROBEntries) * 100.0;
  67. double NormalizedMaxPercentage = floor((MaxUsagePercentage * 10) + 0.5) / 10;
  68. double AvgUsagePercentage = ((double)AvgUsage / TotalROBEntries) * 100.0;
  69. double NormalizedAvgPercentage = floor((AvgUsagePercentage * 10) + 0.5) / 10;
  70. TempStream << "\nTotal ROB Entries: " << TotalROBEntries
  71. << "\nMax Used ROB Entries: " << MaxUsedEntries
  72. << format(" ( %.1f%% )", NormalizedMaxPercentage)
  73. << "\nAverage Used ROB Entries per cy: " << AvgUsage
  74. << format(" ( %.1f%% )\n", NormalizedAvgPercentage);
  75. TempStream.flush();
  76. OS << Buffer;
  77. }
  78. } // namespace mca
  79. } // namespace llvm