skip to content
==> include/mesh/sched_member.h <==
1/* @ajax/mesh-sched-member: one fleet member as the scheduler sees it -- F_JOIN's capabilities,
2 * F_PERF's (CPUs, RAM, the view heap, link RTTs, failures) and F_LOADREP's live load -- and a
3 * program's measured performance on a member (F_PERF), keyed by (program, member). */
4#ifndef MESH_SCHED_MEMBER_H
5#define MESH_SCHED_MEMBER_H
6
7#include "mesh/abi/base.h"
8#include "mesh/strmap.h"
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13
14/* Rust's Option<f32>. */
15typedef struct {
16    bool some;
17    float v;
18} mof32;
19
20static inline mof32 mof32_some(float v) { return (mof32){true, v}; }
21static inline mof32 mof32_none(void) { return (mof32){false, 0}; }
22static inline bool mof32_eq(mof32 a, mof32 b) { return a.some == b.some && (!a.some || a.v == b.v); }
23
24typedef struct {
25    uint32_t id;
26    bool up;
27    uint64_t down_ms;  /* how long it has been down (0 while up) */
28    bool cordoned;
29    char host[64];
30    char gpu[32];      /* its GPU executor (cuda, metal; wasm for a CPU-only member) */
31    char arch[32];
32    uint32_t cc, sms, blocks_per_sm;
33    /* Its GPU's limits for one node (F_JOIN): threads and shared bytes per block; 0: not reported. */
34    uint32_t max_threads, max_shared;
35    uint32_t cpus, cores_big, cores_little, ram_mb, mem_avail_mb, disk_free_mb;
36    mof32 gpu_share;   /* meshd's GPU share over 10 s */
37    float cpu_util, cpu_big, cpu_little; /* host CPU utilisation 0..1, by class */
38    mof32 psi_cpu, psi_mem;
39    float meshd_cpu;
40    mof32 rtt_us[MESH_MAX_SYSTEMS]; /* link RTT to each member in µs */
41    size_t nrtt;                    /* Rust's Vec length (a k past it is None) */
42    char *busy;         /* the owner policy holds it busy (why); NULL: not busy */
43    bool load_known;    /* its load report arrived */
44    uint32_t heap_kb, slots_free; /* the view heap's largest free run (KiB) and free slots */
45    ms_map fails;       /* programs that failed here: name -> why */
46} msm_member;
47
48/* Member::default (everything zero, strings empty). */
49msm_member msm_member_default(void);
50msm_member msm_member_clone(const msm_member *m);
51void msm_member_free(msm_member *m);
52void msm_set_str(char *dst, size_t cap, const char *s);
53#define MSM_SET(field, s) msm_set_str((field), sizeof(field), (s))
54
55/* Its executors: the GPU's, then wasm and native (every meshd has them). Returns the count (<= 3). */
56size_t msm_executors(const msm_member *m, const char *out[3]);
57/* The executor a program listing backends[0..n) runs on here (the first one listed it has), or NULL. */
58const char *msm_exec_for(const msm_member *m, char *const *backends, size_t n);
59mof32 msm_rtt_to(const msm_member *m, uint32_t k); /* 0 to itself */
60
61/* A program's measured performance on one member (F_PERF). */
62typedef struct {
63    uint64_t hash;
64    char exec[16];
65    bool run;
66    mof32 task_us; /* mean node busy time per task (µs), else the trace p50 */
67    float tasks_s;
68    float cpu;     /* CPU cores it uses (wasm and native) */
69    mof32 share;
70    float rss_mb;
71} msm_perf;
72
73bool msm_perf_eq(const msm_perf *a, const msm_perf *b);
74
75/* BTreeMap<(String, u32), Perf>: sorted by (program name, member). */
76typedef struct {
77    char **name;
78    uint32_t *member;
79    msm_perf *perf;
80    size_t n, cap;
81} msm_perfs;
82
83const msm_perf *msm_perfs_get(const msm_perfs *p, const char *name, uint32_t member);
84void msm_perfs_set(msm_perfs *p, const char *name, uint32_t member, const msm_perf *perf);
85/* Index range [*lo, *hi) of the entries of program name (Rust's range((name, 0)..=(name, MAX))). */
86void msm_perfs_range(const msm_perfs *p, const char *name, size_t *lo, size_t *hi);
87void msm_perfs_remove_at(msm_perfs *p, size_t i);
88msm_perfs msm_perfs_clone(const msm_perfs *p);
89void msm_perfs_free(msm_perfs *p);
90
91#endif