code wiki / _hdl_build / nx_perf_counters.nx
nx_perf_counters.nx
buildroot/runtime/_hdl_build/nx_perf_counters.nx
about
nx_perf_counters.nx -- bits-up hardware performance counters via perf_event_open,
PURE NishiLang (no libc, no `perf` binary, no C). The STATE-INDEPENDENT energy
path: instruction / cycle / cache counts do NOT care whether the node is charging
or on AC -- they are the CPU's own activity, read straight from the silicon's
performance-monitoring unit. They feed a calibrated per-event energy model that
yields real joules on ANY hardware in ANY power state. (Battery-discharge was a
weak fallback; THIS is the S-class answer -- a real measurement everywhere.)
Research (Cardinal #4, real sources): event-driven / PMC-based power modeling --
Bellosa, "The Benefits of Event-Driven Energy Accounting," ACM SIGOPS EW 2000;
Isci & Martonosi, "Runtime Power Monitoring using PMCs," MICRO 2003; Bircher &
John, "Complete System Power Estimation using PMCs," ISPASS 2007; per-operation
energy figures from Horowitz, "Computing's Energy Problem," ISSCC 2014.
perf_event_open(2) is the Linux interface; the attr struct is built byte-exact.
dependencies 1 imports · 1 importers
imports: nx_syscalls.nx
imported by: nx_perf_counters_test.nx
structs
| none |
consts
| 19 | const SYS_PERF_EVENT_OPEN: i64 = 298 |
| 22 | const SYS_PERF_EVENT_OPEN: i64 = 241 |
| 25 | const PERF_TYPE_HARDWARE: i64 = 0 |
| 26 | const PERF_TYPE_SOFTWARE: i64 = 1 |
| 27 | const PERF_COUNT_HW_CPU_CYCLES: i64 = 0 |
| 28 | const PERF_COUNT_HW_INSTRUCTIONS: i64 = 1 |
| 33 | const PERF_COUNT_SW_CPU_CLOCK: i64 = 0 |
| 34 | const PERF_COUNT_SW_TASK_CLOCK: i64 = 1 |
functions
| 40 | func pc_open2(type: i64, config: i64) -> i64 |
| 50 | func pc_open(config: i64) -> i64 { return pc_open2(PERF_TYPE_HARDWARE, config) } calls 1: pc_open2 |
| 55 | func pc_open_best(out: *i64) -> i64 |
| 64 | func pc_read(fd: i64) -> i64 |