code wiki / _hdl_build / nx_perf_counters.nx

nx_perf_counters.nx

buildroot/runtime/_hdl_build/nx_perf_counters.nx

3661 B72 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic perf
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_perf_counters.nx nx_perf_counters_test.nx

imports: nx_syscalls.nx

imported by: nx_perf_counters_test.nx

structs

none

consts

19const SYS_PERF_EVENT_OPEN: i64 = 298
22const SYS_PERF_EVENT_OPEN: i64 = 241
25const PERF_TYPE_HARDWARE: i64 = 0
26const PERF_TYPE_SOFTWARE: i64 = 1
27const PERF_COUNT_HW_CPU_CYCLES: i64 = 0
28const PERF_COUNT_HW_INSTRUCTIONS: i64 = 1
33const PERF_COUNT_SW_CPU_CLOCK: i64 = 0
34const PERF_COUNT_SW_TASK_CLOCK: i64 = 1

functions

40func pc_open2(type: i64, config: i64) -> i64
called by 2: pc_openpc_open_best calls 1: sys_mmap
50func pc_open(config: i64) -> i64 { return pc_open2(PERF_TYPE_HARDWARE, config) }
calls 1: pc_open2
55func pc_open_best(out: *i64) -> i64
called by 1: main calls 1: pc_open2
64func pc_read(fd: i64) -> i64
called by 1: main calls 2: sys_mmapsys_read