skip to content
==> include/mesh/abi/program_table.h <==
1/* @ajax/mesh-abi-program-table: The program table (PT_*): one entry per slot, its states, policies, flags and arg modes.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_PROGRAM_TABLE_H
5#define MESH_ABI_PROGRAM_TABLE_H
6
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10#include "mesh/abi/base.h"
11
12#define MESH_PROG_TABLE 0x1000
13#define MESH_PT_BYTES 0x80
14/* Entry fields (offsets within the entry), all u32 unless stated.  Written by */
15/* meshd only while the slot's kernel is not running (load/upgrade happen in a */
16/* blink), under the seqlock PT_GEN: odd while being rewritten, even when stable. */
17#define MESH_PT_STATE 0x00 /* ST_* */
18#define MESH_PT_GEN 0x04
19#define MESH_PT_NAME 0x08 /* [u8; 16], NUL padded, [a-z0-9-]{1,15} */
20#define MESH_PT_VIEW_OFF 0x18 /* mailbox offset of the view (in the view heap), 0 when view_bytes = 0 */
21#define MESH_PT_VIEW_BYTES 0x1c
22#define MESH_PT_SNAP_BYTES 0x20 /* view prefix the snapshot copies (<= view_bytes) */
23#define MESH_PT_NODES 0x24 /* blocks of the kernel (<= PROG_MAX_NODES) */
24#define MESH_PT_WARPS 0x28 /* warps per node (block): 32 x warps threads, 1..=MAX_WARPS */
25#define MESH_PT_POLICY 0x2c /* POLICY_* */
26#define MESH_PT_HZ 0x30 /* periodic only */
27#define MESH_PT_FANOUT 0x34 /* tasks per publish */
28#define MESH_PT_PEER 0x38 /* PEER_MODE_* */
29#define MESH_PT_READS_MASK 0x3c /* bit s: may read slot s's view (READS_ALL: every slot) */
30#define MESH_PT_INPUT_OFF 0x40 /* view offset of the input queue (IQ_*), 0 + len 0 = none */
31#define MESH_PT_INPUT_LEN 0x44 /* data bytes (a power of two) */
32#define MESH_PT_REQ_OFF 0x48 /* view offset/max of the request window (on_demand bytes) */
33#define MESH_PT_REQ_MAX 0x4c
34#define MESH_PT_RESP_OFF 0x50
35#define MESH_PT_RESP_MAX 0x54
36#define MESH_PT_PTX_HASH 0x58 /* u64 fnv1a64 of the PTX bytes */
37#define MESH_PT_REGS 0x60 /* cuFuncGetAttribute(NUM_REGS) of mesh_main */
38#define MESH_PT_CODE_BYTES 0x64 /* cubin bytes */
39#define MESH_PT_VIEW_ABI 0x68
40#define MESH_PT_FLAGS 0x6c /* FL_* */
41#define MESH_PT_ARG_MODE 0x70 /* ARG_* */
42#define MESH_PT_ARG_OFF 0x74 /* view offset for ARG_VIEW_U32 */
43#define MESH_PT_RT_ABI 0x78 /* the module's MESH_RT_ABI as read at load */
44#define MESH_PT_LOADS 0x7c /* images loaded into this slot (1 + upgrades + rollbacks) */
45#define MESH_ST_EMPTY 0u
46#define MESH_ST_LOADED 1u
47#define MESH_ST_RUNNING 2u
48#define MESH_ST_STOPPING 3u
49#define MESH_ST_FAILED 4u
50#define MESH_STATES_LEN 5
51extern const char *const MESH_STATES[5];
52#define MESH_POLICY_CONTINUOUS 0u
53#define MESH_POLICY_PERIODIC 1u
54#define MESH_POLICY_ON_DEMAND 2u
55/* `policy = "job"` (plan F5): meshd publishes nothing on its own; the
56 * program's tasks are the items of the fleet's jobs (OP_JOB), leased to this
57 * member by the leader (mesh-host jobs.rs), plus `task`/`req` on demand. */
58#define MESH_POLICY_JOB 3u
59#define MESH_POLICIES_LEN 4
60extern const char *const MESH_POLICIES[4];
61#define MESH_PEER_MODE_NONE 0u
62#define MESH_PEER_MODE_LOCKSTEP 1u
63#define MESH_PEER_MODES_LEN 2
64extern const char *const MESH_PEER_MODES[2];
65#define MESH_READS_ALL 0xffffffffu
66/* `in_flight = "batch"`: the next publish waits until the whole previous batch completed. */
67#define MESH_FL_BATCH 1u
68#define MESH_FL_AUTOSTART 2u
69/* Task arg: the index 0..fanout-1, or the u32 at view offset PT_ARG_OFF. */
70#define MESH_ARG_INDEX 0u
71#define MESH_ARG_VIEW_U32 1u
72
73/* Slot s's entry in the program table. */
74static inline size_t mesh_prog_entry(uint32_t slot) { return MESH_PROG_TABLE + MESH_PT_BYTES * (size_t)slot; }
75
76/* The Rust const asserts that only involve this package. */
77_Static_assert(MESH_POLICIES_LEN == MESH_POLICY_JOB  + 1, "POLICIES.len() == POLICY_JOB as usize + 1");
78_Static_assert(MESH_PT_LOADS + 4 <= MESH_PT_BYTES, "PT_LOADS + 4 <= PT_BYTES");
79_Static_assert((MESH_PT_PTX_HASH % 8 == 0), "PT_PTX_HASH.is_multiple_of(8)");
80
81#endif