1 //===--------------------- DispatchStatistics.cpp ---------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file implements the DispatchStatistics interface.
12 //===----------------------------------------------------------------------===//
14 #include "Views/DispatchStatistics.h"
15 #include "llvm/Support/Format.h"
20 void DispatchStatistics::onEvent(const HWStallEvent
&Event
) {
21 if (Event
.Type
< HWStallEvent::LastGenericEvent
)
22 HWStalls
[Event
.Type
]++;
25 void DispatchStatistics::onEvent(const HWInstructionEvent
&Event
) {
26 if (Event
.Type
!= HWInstructionEvent::Dispatched
)
29 const auto &DE
= static_cast<const HWInstructionDispatchedEvent
&>(Event
);
30 NumDispatched
+= DE
.MicroOpcodes
;
33 void DispatchStatistics::printDispatchHistogram(raw_ostream
&OS
) const {
35 raw_string_ostream
TempStream(Buffer
);
36 TempStream
<< "\n\nDispatch Logic - "
37 << "number of cycles where we saw N micro opcodes dispatched:\n";
38 TempStream
<< "[# dispatched], [# cycles]\n";
39 for (const std::pair
<const unsigned, unsigned> &Entry
:
40 DispatchGroupSizePerCycle
) {
41 double Percentage
= ((double)Entry
.second
/ NumCycles
) * 100.0;
42 TempStream
<< " " << Entry
.first
<< ", " << Entry
.second
43 << " (" << format("%.1f", floor((Percentage
* 10) + 0.5) / 10)
51 static void printStalls(raw_ostream
&OS
, unsigned NumStalls
,
58 double Percentage
= ((double)NumStalls
/ NumCycles
) * 100.0;
59 OS
<< NumStalls
<< " ("
60 << format("%.1f", floor((Percentage
* 10) + 0.5) / 10) << "%)";
63 void DispatchStatistics::printDispatchStalls(raw_ostream
&OS
) const {
65 raw_string_ostream
SS(Buffer
);
66 SS
<< "\n\nDynamic Dispatch Stall Cycles:\n";
67 SS
<< "RAT - Register unavailable: ";
68 printStalls(SS
, HWStalls
[HWStallEvent::RegisterFileStall
], NumCycles
);
69 SS
<< "\nRCU - Retire tokens unavailable: ";
70 printStalls(SS
, HWStalls
[HWStallEvent::RetireControlUnitStall
], NumCycles
);
71 SS
<< "\nSCHEDQ - Scheduler full: ";
72 printStalls(SS
, HWStalls
[HWStallEvent::SchedulerQueueFull
], NumCycles
);
73 SS
<< "\nLQ - Load queue full: ";
74 printStalls(SS
, HWStalls
[HWStallEvent::LoadQueueFull
], NumCycles
);
75 SS
<< "\nSQ - Store queue full: ";
76 printStalls(SS
, HWStalls
[HWStallEvent::StoreQueueFull
], NumCycles
);
77 SS
<< "\nGROUP - Static restrictions on the dispatch group: ";
78 printStalls(SS
, HWStalls
[HWStallEvent::DispatchGroupStall
], NumCycles
);
79 SS
<< "\nUSH - Uncategorised Structural Hazard: ";
80 printStalls(SS
, HWStalls
[HWStallEvent::CustomBehaviourStall
], NumCycles
);
86 json::Value
DispatchStatistics::toJSON() const {
87 json::Object
JO({{"RAT", HWStalls
[HWStallEvent::RegisterFileStall
]},
88 {"RCU", HWStalls
[HWStallEvent::RetireControlUnitStall
]},
89 {"SCHEDQ", HWStalls
[HWStallEvent::SchedulerQueueFull
]},
90 {"LQ", HWStalls
[HWStallEvent::LoadQueueFull
]},
91 {"SQ", HWStalls
[HWStallEvent::StoreQueueFull
]},
92 {"GROUP", HWStalls
[HWStallEvent::DispatchGroupStall
]},
93 {"USH", HWStalls
[HWStallEvent::CustomBehaviourStall
]}});