The Pedigree Project 0.1
LatencyAccounting.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef PEDIGREE_KERNEL_LATENCYACCOUNTING_H
3#define PEDIGREE_KERNEL_LATENCYACCOUNTING_H
4
5#include "pedigree/kernel/compiler.h"
6
7#include <config.h>
8#include <stddef.h>
9#include <stdint.h>
10
11namespace LatencyAccounting {
12enum Field : size_t {
13 OnlineSince,
14 IrqOffNanoseconds,
15 IrqOffCount,
16 IrqOffMax,
17 IrqOffMaxEnd,
18 IrqOffMaxSite,
19 IrqOffOver1ms,
20 IrqOffOver10ms,
21 IrqOffOpenSince,
22 IrqOffOpenSite,
23 DeferredCpuNanoseconds,
24 DeferredWallNanoseconds,
25 DeferredCount,
26 DeferredMax,
27 Count,
28};
29
30struct Snapshot {
31 uint64_t values[Count] = {};
32};
33
34#if PEDIGREE_LATENCY_ACCOUNTING
35// Local writers run with IRQs masked. CPU contributions also accept NMI entry.
36void armCpu();
37bool active();
38void recordDeferredCpu(uint64_t elapsed);
39void recordDeferredWall(uint64_t elapsed);
40EXPORTED_PUBLIC bool snapshot(size_t cpu, Snapshot& result);
41#else
42inline void armCpu() {}
43inline bool snapshot(size_t, Snapshot&) {
44 return false;
45}
46#endif
47} // namespace LatencyAccounting
48
49#if PEDIGREE_LATENCY_ACCOUNTING
50// Called before enabling IRQs or after masking them, with kernel GS installed.
51extern "C" EXPORTED_PUBLIC void pedigree_irq_time_state(bool enabled);
52#endif
53#endif