==> include/mesh/load_proc.h <==1/* @ajax/mesh-load-proc: the pure parsers of load.rs: /proc/stat's CPU times,
2 * the big/little core classes, PSI (the /proc/pressure files), /proc/meminfo,
3 * /proc/loadavg and `key value` / `Key: value` files. Errors are the Rust's
4 * text. The OS readers that feed them are mesh-load-host. */
5#ifndef MESH_LOAD_PROC_H
6#define MESH_LOAD_PROC_H
7
8#include <stdbool.h>
9#include <stddef.h>
10#include <stdint.h>
11
12/* One CPU's (or all CPUs') time counters, in the OS's units. */
13typedef struct {
14 uint64_t busy, total, iowait;
15} mesh_cpu_times;
16
17/* Busy and iowait fractions between two readings (0, 0 when no time passed). */
18void mesh_cpu_times_since(const mesh_cpu_times *now, const mesh_cpu_times *prev, float *busy, float *io);
19
20/* `/proc/stat`'s cpu and cpuN lines: the aggregate, and per CPU id (offline CPUs:
21 * have[i] false). per and have hold MESH_MAX_CPUS entries; *n is the highest id + 1. */
22int mesh_parse_proc_stat(const char *text, mesh_cpu_times *all, mesh_cpu_times *per, bool *have, size_t *n, char **err);
23
24/* Core classes (MESH_CORE_*) from per-CPU performance figures (cpu_capacity or
25 * cpuinfo_max_freq; have[i] false: unknown): within 10 % of the fastest is big. */
26void mesh_classify(const uint64_t *perf, const bool *have, size_t n, uint8_t *out);
27/* The classes' busy fractions (all, big, little): means of the known per-CPU figures. */
28void mesh_class_util(const float *util, const bool *have, const uint8_t *cls, size_t n, float *all, float *big, float *little);
29
30/* A /proc/pressure file's `some` and `full` lines. */
31typedef struct {
32 float some_avg10;
33 uint64_t some_total;
34 float full_avg10;
35 uint64_t full_total;
36} mesh_psi;
37
38int mesh_parse_psi(const char *text, mesh_psi *out, char **err);
39/* The share of dt_us some task stalled, from two PSI totals (us). */
40float mesh_psi_rate(uint64_t now, uint64_t prev, uint64_t dt_us);
41
42typedef struct {
43 uint64_t total_kb, avail_kb, swap_total_kb, swap_free_kb;
44} mesh_meminfo;
45
46int mesh_parse_meminfo(const char *text, mesh_meminfo *out, char **err);
47int mesh_parse_loadavg(const char *text, float out[3], char **err);
48/* A `key value` file's value (/proc/vmstat pswpout), or a `Key: value` one's
49 * (/proc/self/status VmRSS, Threads): true and *out, or false. */
50bool mesh_proc_field(const char *text, const char *key, uint64_t *out);
51
52#endif