1/* @ajax/mesh-load-share: the GPU share a program's nodes obtained (load.rs Nl,
2 * Share, share, quantile): from the node load records' counters (mesh-abi NL_*:
3 * time observed, time lost to someone else, gaps, queue delay), summed over a
4 * program's nodes and over a window of samples. */
5#ifndef MESH_LOAD_SHARE_H
6#define MESH_LOAD_SHARE_H
78#include <stdbool.h>
9#include <stddef.h>
10#include <stdint.h>
1112/* One node load record's counters (NL_*). */
13typedef struct {
14 uint64_t obs, lost;
15 uint32_t gaps, queue_us;
16} mesh_nl;
1718/* The counters' advance since prev; a counter that went down was reset (a reload zeroes them): no delta. */
19mesh_nl mesh_nl_delta(const mesh_nl *now, const mesh_nl *prev);
20/* Adds d (its lost time at most its observed time). */
21void mesh_nl_add(mesh_nl *sum, const mesh_nl *d);
2223/* The figures derived from summed node load deltas. */
24typedef struct {
25 bool has_share; /* false: nothing observed */
26 float share;
27 float slice_us, gap_us; /* mean run between gaps / mean gap (0 when no gap) */
28 float queue_us; /* Metal: mean commit -> GPU start per command buffer */
29} mesh_share;
3031mesh_share mesh_share_of(const mesh_nl *d);
3233/* The q-quantile (0..=1, nearest rank) of a sorted array; 0 when empty. */
34uint32_t mesh_quantile(const uint32_t *sorted, size_t n, double q);
3536#endif