1/* @ajax/mesh-abi-exchange: The exchange page of a lockstep group's rounds.
2 *
3 * Part of alpha-c-mesh, a C port of alpha-rust-mesh (README.md says from where). */
4#ifndef MESH_ABI_EXCHANGE_H
5#define MESH_ABI_EXCHANGE_H
67#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
1011/* ---------------------------------------------------------------- exchange */
12/* N machines (H_SYSTEMS, up to MAX_SYSTEMS) training as one, owned by the one
13 * program with peer = lockstep (`Ctx::exchange`). Each system writes only its
14 * own words; meshd's peer relay (TCP, a full mesh) mirrors system k's slot
15 * region and counter to every other machine at the same offsets.
16 * ex_counter(k): u64, system k's round counter (= its step + 1). The page is
17 * meshd's: it zeroes it while the lockstep program is halted (load,
18 * reset, a view reset, unload), and each peer HELLO zeroes its copy
19 * of the peer's region; the program never clears it
20 * ex_slots(k): system k's two slots (parity 0, 1), EX_SLOT_BYTES each:
21 * { loss_sum, g0, g1, g2, g3, 0, 0, 0 } (f32 x 8)
22 * Round n (u64, never wraps): write slot[n % 2][self], fence.sys, counter[self] = n
23 * (release); wait (bounded in all: PEER_POLLS x PEER_POLL_NS) for counter[j] >= n
24 * of every other system j, fence, read slot[n % 2][j] of all N; apply their sum
25 * folded in system order ((s0 + s1) + s2) + ... (bitwise-identical updates on
26 * every machine). A timed-out round is never skipped: the program keeps it
27 * pending and the next task waits for the same round again. */
28#define MESH_EX_BASE 0x2A000
29#define MESH_EX_BYTES 0x1000
30#define MESH_EX_SLOT_BYTES 0x20
31#define MESH_EX_REGION_BYTES 0x40
32#define MESH_PEER_POLLS 50000u
33#define MESH_PEER_POLL_NS 2000u
3435/* System k's round counter (u64) and its two slots on the exchange page. */
36static inline size_t mesh_ex_counter(uint32_t k) { return MESH_EX_BASE + 8 * (size_t)k; }
37static inline size_t mesh_ex_slots(uint32_t k) { return MESH_EX_BASE + 0x100 + 0x40 * (size_t)k; }
3839#endif