8#include "pedigree/kernel/debugger/commands/IrqDiagnosticRenderer.h"
11constexpr uint16_t KnownMaskReasons = IrqMaskNoHandler | IrqMaskAdministrativelyDisabled |
12 IrqMaskAwaitingAcknowledgement |
13 IrqMaskAwaitingThreadedCompletion | IrqMaskMitigated |
14 IrqMaskShuttingDown | IrqMaskControllerContention;
16const char* yesNo(
bool value) {
17 return value ?
"yes" :
"no";
22 case IrqDelivery::None:
24 case IrqDelivery::Hard:
26 case IrqDelivery::Threaded:
28 case IrqDelivery::Mixed:
36 case IrqTrigger::Edge:
38 case IrqTrigger::Level:
40 case IrqTrigger::Synthetic:
48 case IrqControllerAck::None:
50 case IrqControllerAck::BeforeHardStage:
52 case IrqControllerAck::AfterHardStage:
60 case IrqLineRelease::AfterHardStage:
62 case IrqLineRelease::AfterThreadedCompletion:
63 return "after-threaded";
70 case IrqWorkerDebugState::Unavailable:
72 case IrqWorkerDebugState::None:
74 case IrqWorkerDebugState::SemaphoreWait:
76 case IrqWorkerDebugState::ConditionWait:
78 case IrqWorkerDebugState::Joining:
80 case IrqWorkerDebugState::FutexWait:
82 case IrqWorkerDebugState::EventWait:
84 case IrqWorkerDebugState::ProcessWait:
85 return "process-wait";
86 case IrqWorkerDebugState::CallbackDrain:
87 return "callback-drain";
94 case IrqWorkerWaitReason::Unavailable:
96 case IrqWorkerWaitReason::Waiting:
98 case IrqWorkerWaitReason::Signalled:
100 case IrqWorkerWaitReason::Event:
102 case IrqWorkerWaitReason::Unwinding:
104 case IrqWorkerWaitReason::Terminating:
105 return "terminating";
106 case IrqWorkerWaitReason::Spurious:
114 case IrqControllerPromptState::NotRequired:
116 case IrqControllerPromptState::Submitted:
118 case IrqControllerPromptState::Failed:
124void appendMaskReason(
IrqDiagnosticString& line,
bool& first, uint16_t reasons, uint16_t reason,
126 if (!(reasons & reason)) {
138 if (reasons == IrqMaskNone) {
144 appendMaskReason(line, first, reasons, IrqMaskNoHandler,
"no-handler");
145 appendMaskReason(line, first, reasons, IrqMaskAdministrativelyDisabled,
"admin-disabled");
146 appendMaskReason(line, first, reasons, IrqMaskAwaitingAcknowledgement,
"awaiting-ack");
147 appendMaskReason(line, first, reasons, IrqMaskAwaitingThreadedCompletion,
"awaiting-threaded");
148 appendMaskReason(line, first, reasons, IrqMaskMitigated,
"mitigated");
149 appendMaskReason(line, first, reasons, IrqMaskShuttingDown,
"shutting-down");
150 appendMaskReason(line, first, reasons, IrqMaskControllerContention,
"controller-contention");
152 const uint16_t unknown = reasons & ~KnownMaskReasons;
157 line +=
"unknown:0x";
158 line.append(unknown, 16);
163 line +=
" hard[pins=";
164 line.append(snapshot.activeHardDispatchCount);
166 if (!snapshot.activeHardDispatchCount) {
168 }
else if (snapshot.activeHardDispatchCount == 1 && snapshot.activeHardDispatchGeneration) {
169 line.append(snapshot.activeHardDispatchGeneration);
177 if (!present || !started || observed < started) {
180 line.append(observed - started);
185 line +=
"\n worker=0x";
186 line.append(snapshot.workerIdentity, 16);
188 if (!snapshot.activeThreadedDispatchCount) {
190 }
else if (snapshot.activeThreadedDispatchCount == 1 && snapshot.activeThreadedHandlerIdentity) {
192 line.append(snapshot.activeThreadedHandlerIdentity, 16);
197 line.append(snapshot.activeThreadedDispatchCount);
198 line +=
" cookie[pub=";
199 line.append(snapshot.publicationCookie);
201 line.append(snapshot.pendingCookie);
203 line.append(snapshot.activeCookie);
205 line.append(snapshot.completedCookie);
206 line +=
"] batches=";
207 line.append(snapshot.completedBatches);
208 line +=
" fail[publish=";
209 line.append(snapshot.publicationFailures);
211 line.append(snapshot.removalRejections);
212 line +=
" controller=";
213 line.append(snapshot.controllerContentions);
215 line.append(snapshot.diagnosticPublicationFailures);
216 line +=
"] prompt[controller attempts=";
217 line.append(snapshot.controllerPromptAttempts);
218 line +=
" failures=";
219 line.append(snapshot.controllerPromptFailures);
221 line.append(snapshot.controllerPromptDestination, 16);
223 line += controllerPromptStateName(snapshot.controllerPromptState);
224 line +=
"] state[ack=";
225 line += yesNo(snapshot.acknowledgementPending);
226 line +=
" threaded=";
227 line += yesNo(snapshot.threadedPending);
229 line += yesNo(snapshot.dispatcherInitialised);
231 line += yesNo(snapshot.dispatcherActive);
233 line += yesNo(snapshot.dispatcherClosed);
235 line += yesNo(snapshot.hardStageActive);
240 line +=
" ns[pending=";
241 appendAge(line, snapshot.pendingCookie != 0, snapshot.observationTimestamp,
242 snapshot.pendingSinceTimestamp);
244 appendAge(line, snapshot.activeCookie != 0, snapshot.observationTimestamp,
245 snapshot.activeCallbackStartedTimestamp);
247 line.append(snapshot.lastWakeLatency);
249 line.append(snapshot.maximumWakeLatency);
251 line.append(snapshot.lastCallbackRuntime);
253 line.append(snapshot.maximumCallbackRuntime);
259 if (!snapshot.workerDiagnosticAvailable) {
260 line +=
"unavailable]\n";
265 line += workerDebugStateName(snapshot.workerDebugState);
267 line.append(snapshot.workerDebugAddress, 16);
268 if (!snapshot.workerWaitActive) {
269 line +=
" wait=none]\n";
274 line.append(snapshot.workerWaitQueue, 16);
275 line +=
" channel=0x";
276 line.append(snapshot.workerWaitChannelOwner, 16);
278 line.append(snapshot.workerWaitChannelValue, 16);
280 line += workerWaitReasonName(snapshot.workerWaitReason);
282 line.append(snapshot.workerWaitStateLevel);
284 line += yesNo(snapshot.workerWaitQueued);
293 line.append(snapshot.line);
295 if (!snapshot.snapshotGeneration) {
296 line +=
" SNAPSHOT MISS\n";
300 line.append(snapshot.snapshotGeneration);
302 line += yesNo(snapshot.configured);
303 line +=
" handlers=";
304 line.append(snapshot.handlerCount);
305 line +=
" delivery=";
306 line += deliveryName(snapshot.delivery);
308 line += snapshot.configured ? triggerName(snapshot.trigger) :
"n/a";
310 line += snapshot.configured ? controllerAckName(snapshot.controllerAck) :
"n/a";
312 line += snapshot.configured ? lineReleaseName(snapshot.lineRelease) :
"n/a";
314 line += snapshot.requestedEnabled ?
"on" :
"off";
316 line += yesNo(snapshot.effectiveMasked);
318 appendMaskReasons(line, snapshot.maskReasons);
322 line.append(snapshot.dispatchGeneration);
324 line.append(snapshot.acknowledgedGeneration);
325 line +=
" count[irq=";
326 line.append(snapshot.interruptCount);
328 line.append(snapshot.spuriousCount);
329 line +=
" unhandled=";
330 line.append(snapshot.unhandledCount);
332 appendHardDispatchState(line, snapshot);
333 appendWorkerState(line, snapshot);
334 appendTimingState(line, snapshot);
335 appendWorkerDebugState(line, snapshot);