==> include/mesh/load_host.h <==1/* @ajax/mesh-load-host: this machine's side of the load telemetry (load.rs):
2 *
3 * - `mesh_host_read`: one sample of the host (per-CPU times, load average,
4 * PSI, memory, swap, meshd's own CPU, RSS and threads, free disk for the
5 * catalog, the hottest thermal zone), from Linux's /proc and /sys;
6 * - `mesh_host_derive`: rates between two samples (per-CPU utilisation by core
7 * class, iowait, PSI shares, meshd's CPU, swap-outs);
8 * - `mesh_machine_bytes`: the host block's machine region (S_LOAD..S_MLOAD);
9 * - `mesh_exec_totals`: the CPU executors' sums into it;
10 * - `mesh_loadrep`: the member summary sent to the cluster as F_LOADREP. */
11#ifndef MESH_LOAD_HOST_H
12#define MESH_LOAD_HOST_H
13
14#include "mesh/abi/host_load.h"
15#include "mesh/abi/host_mload.h"
16#include "mesh/abi/host_pload.h"
17#include "mesh/load_proc.h"
18#include "mesh/load_share.h"
19
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdint.h>
23
24/* What one host sample read. */
25typedef struct {
26 mesh_cpu_times cpu_all;
27 mesh_cpu_times cpus[MESH_MAX_CPUS];
28 bool have[MESH_MAX_CPUS]; /* per CPU id: online (a line in /proc/stat) */
29 size_t ncpus; /* the highest id + 1 */
30 float loadavg[3];
31 bool has_psi;
32 mesh_psi psi[3]; /* cpu, memory, io */
33 uint32_t mem_total_mb, mem_avail_mb, swap_total_mb, swap_used_mb, compressed_mb;
34 bool has_mem_level;
35 uint32_t mem_level;
36 float mem_free;
37 uint64_t swap_out;
38 uint64_t self_cpu_us;
39 float self_rss_mb;
40 uint32_t self_threads;
41 uint32_t disk_free_mb, disk_total_mb;
42 bool has_thermal;
43 uint32_t thermal;
44 bool has_temp;
45 float temp_c;
46 bool has_gpu_util;
47 float gpu_util;
48} mesh_host_sample;
49
50/* Per-CPU core classes (MESH_CORE_*) for n CPUs, and what they came from
51 * ("cpu_capacity", "cpuinfo_max_freq" or "none"). */
52const char *mesh_core_classes(uint8_t *out, size_t n);
53bool mesh_has_psi(void);
54/* One sample; dir: the file system whose free space counts (the catalog). 0, or -1 and *err. */
55int mesh_host_read(mesh_host_sample *h, const char *dir, bool psi, char **err);
56
57/* Rates between two host samples. */
58typedef struct {
59 float util[MESH_MAX_CPUS];
60 bool have_util[MESH_MAX_CPUS];
61 size_t n;
62 float all, big, little, iowait;
63 bool has_psi;
64 float psi[5]; /* some cpu, some mem, full mem, some io, full io */
65 float meshd_cpu, swap_out_s;
66} mesh_host_derived;
67
68void mesh_host_derive(const mesh_host_sample *now, const mesh_host_sample *prev, const uint8_t *cls, size_t ncls, double dt,
69 mesh_host_derived *d);
70
71#define MESH_MACHINE_BYTES (MESH_S_MLOAD - MESH_S_LOAD)
72
73/* The machine region (S_LOAD .. S_MLOAD): MESH_MACHINE_BYTES into out. */
74void mesh_machine_bytes(uint8_t out[MESH_MACHINE_BYTES], const mesh_host_sample *h, const mesh_host_derived *d, const uint8_t *cls,
75 size_t ncls, const mesh_share *gpu1, const mesh_share *gpu10, uint32_t max_gap_ns, float gaps_s, float obs,
76 uint64_t at_ms, uint32_t samples, uint32_t sample_us);
77
78/* The CPU executors' totals into the machine region: the PLF_HOST program
79 * records' CPU and RSS, wasm lanes, and the native workers' and log counts. */
80void mesh_exec_totals(uint8_t m[MESH_MACHINE_BYTES], const uint8_t (*recs)[MESH_PLOAD_BYTES], const uint32_t *execs, size_t n,
81 uint32_t workers, uint32_t spawns, uint32_t crashes, uint64_t log_dropped);
82
83/* This machine's member summary (mload(k) from ML_SHARE on: F_LOADREP's body). */
84void mesh_loadrep(uint8_t out[MESH_LOADREP_BYTES], const uint8_t m[MESH_MACHINE_BYTES]);
85
86#endif