feat(v4, kernel): ONE adaptive heartbeat -- it paces itself on the Stadium's resident heat; every VM ticks on it, in lockstep

Captain Bob, 2026-11-17: "The adaptive heartbeat is its own thing ... It has its own independent RWOT and slope
provider. Only one output from the entire stadium is used as a load measurement for heart rate pacing. ... ONE
AS IN THE NUMBER 1 heartbeat (the adaptive one) runs the entire system." Ruled one at a time: the kernel's
heartbeat; resident heat its one input; held in POST; the Stadium charged as before today
(docs/v4.0.0/plans/2026-11-17-one-adaptive-heartbeat.md, its first version kept as superseded).

- kernel/src/heartbeat.c, timer.h: heartbeat_pace_from(load) -- its own window of samples, its own slope
  provider (v4's inference arithmetic) every HEARTBEAT_PACE_EVERY samples, Loop #7 setting its own period
  (not stable 20% faster, stable 25% slower, 1/4..4x the 10 ms base). No source (v3's path): nothing runs.
- kernel/src/vm/stadium.c: stadium_resident_heat_total(), read only -- the one output it paces by.
- v4/system/mesh.c, mesh.h: the owner's clock read at every fabric step; each tick delivered, one by one, to
  every node present -- its heartbeat cycle run, active, idle or blocked alike. The tick by execution, the
  nodes' own Loop #7 and the heartrate callback are gone.
- kernel/src/v4/sk_v4.c: the clock gives the heartbeat's bottom half its turn; 0 until POST has ended.
- Tests first, each seen to fail (does not build): kernel/tests/test_heartbeat.c (11 checks),
  test_stadium_node.c (16), test_mesh_boot.c's lockstep checks. Seven Phase 7 checks that assumed the tick by
  execution now drive the test's heartbeat (ruled). POST 990/990 with v3's heat cases as written;
  mesh-boot 103, -on 112, -noop 100, san-mesh-boot 103, every v4 program at both widths, every kernel host
  test: 0 failures. The full `sanitize` target not run (it outlasts the foreground limit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-17 20:55:14 +00:00
parent 4a5c9bfd42
commit 00be537503
12 changed files with 462 additions and 88 deletions
+10 -8
View File
@@ -198,10 +198,10 @@ typedef struct {
} v4_mesh_window;
typedef struct {
uint64_t tick; /* the node's heartbeat cycles (v3's tick_count): by execution, as v3 */
uint32_t check_counter; /* executions since the last cycle: v3's, tokens and words run */
v4_cell tokens_seen; /* (TOKENS) when last added in */
uint32_t cycle_every; /* V4_MESH_CHECK_FREQUENCY */
uint64_t tick; /* the ONE adaptive heartbeat's tick (the mesh's `tick`), the same on every
* node: every node advances one tick on each of its ticks, active or not
* (Captain Bob, 2026-11-17; plan 2026-11-17-one-adaptive-heartbeat) */
uint8_t ticking; /* not 0: the node's physics is set up, and it runs its cycle on each tick */
uint64_t decay_slope_q48;
uint8_t l3_decay; /* L8's gate on Loop #3 */
uint8_t l2_window; /* L8's gate on Loop #2 */
@@ -225,7 +225,6 @@ typedef struct {
uint64_t last_inference_tick;
uint8_t inference_early_exited;
uint64_t inference_runs, inference_early_exits;
uint64_t tick_target_ns; /* v3's tick_target_ns: HEARTBEAT_TICK_NS, a quarter to four times it */
/* the opcodes' physics (ruling 7): their records, the one before, their decay slope, their inference */
v4_mesh_opcode op[V4_MESH_OPCODES];
uint32_t prev_op; /* V4_MESH_NO_WORD: none yet */
@@ -275,8 +274,10 @@ struct v4_mesh {
v4_mesh_account *accounts;
unsigned char *is_word;
v4_mesh_physics *physics; /* `capacity` of them: each node's (#189, Phase 7) */
/* Loop #7 on Hera: the kernel's heartbeat period, re-armed (v3: heartbeat_set_adaptive_period_ns; may be 0) */
void (*heartrate)(void *self, uint64_t kernel_period_ns);
/* THE ONE ADAPTIVE HEARTBEAT's tick, as the owner has it (the kernel: its heartbeat's ticks since POST ended --
* held, 0, until then); 0: no heartbeat, the tick never moves. Read at every fabric step; each new tick is
* delivered to every node. The heartbeat paces itself (kernel/src/heartbeat.c): nothing here paces it. */
uint64_t (*clock)(void *self);
/* memory for a word's transition counters, zeroed, and given back (pipelining; may be 0: none recorded) */
void *(*alloc)(void *self, unsigned long bytes);
void (*release)(void *self, void *p);
@@ -287,6 +288,7 @@ struct v4_mesh {
/* ---- the mesh's own ---- */
v4_fabric f;
v4_manage m;
uint64_t tick; /* the last of the heartbeat's ticks delivered to every node */
unsigned hera_place;
v4_cell cells[V4_MESH_NUCLEUS_CELLS]; /* the nucleus as a capsule of F18 cells */
unsigned cell_count, given; /* how many; how many given to Hera */
@@ -323,7 +325,7 @@ const v4_mesh_account *v4_mesh_account_at(const v4_mesh *ms, unsigned place, v4_
* it choose again from there. */
void v4_mesh_l8_force(v4_mesh *ms, unsigned place, unsigned card, int hold);
/* Every node's tick set to `tick` (for tests: a node's tick is its own count of heartbeat cycles). */
/* The tick, and so every node's, set to `tick`, no cycle run (for tests). */
void v4_mesh_set_tick(v4_mesh *ms, uint64_t tick);
/* A word's state flags (V4_MESH_STATE_*), or 0 if xt is not a word's. */
+37 -34
View File
@@ -641,22 +641,15 @@ static void inference_tick(unsigned place, v4_mesh_physics *p)
#if OPCODE_PHYSICS
opcodes_inference(p);
#endif
/* Loop #7, the adaptive heartrate: stable, 25% slower; else 20% faster -- within 1/4 to 4 times the nominal */
{
uint64_t cur = p->tick_target_ns, n;
if (p->inference.early_exited) { n = (cur * 125u) / 100u; if (n > HEARTBEAT_TICK_NS * 4u) n = HEARTBEAT_TICK_NS * 4u; }
else { n = (cur * 80u) / 100u; if (n < HEARTBEAT_TICK_NS / 4u) n = HEARTBEAT_TICK_NS / 4u; }
p->tick_target_ns = n;
if (place == the->hera_place && the->heartrate) /* Hera's re-arms the kernel's (10 ms base) */
the->heartrate(the->self, (p->tick_target_ns * 10000000ULL) / HEARTBEAT_TICK_NS);
}
/* No Loop #7 here: the one adaptive heartbeat paces itself, on its own RWOT and slope provider, from the
* Stadium's resident heat alone (kernel/src/heartbeat.c; Captain Bob, 2026-11-17). A node paces nothing. */
}
/* a node's heartbeat cycle, in v3's order (vm_heartbeat_run_cycle): its tick (and inference, every 1000);
* background decay; the window's service; L8's update; the snapshot */
static void heartbeat_cycle(unsigned place, v4_mesh_physics *p)
{
p->tick++;
p->tick = the->tick; /* the one heartbeat's: every node the same */
if (p->tick - p->last_inference_tick >= V4_MESH_INFERENCE_EVERY) inference_tick(place, p);
background_decay(place, p);
window_service(&p->win);
@@ -684,14 +677,6 @@ static void on_call(void *ctx, v4_node *n, v4_cell target)
v4_mesh_account *a;
const v4_image *im = the->im;
int from_code, dispatched;
if (the->physics) { /* the tokens INTERPRET has taken since: each counts, as v3's */
v4_mesh_physics *pp = &the->physics[place];
v4_cell t = n->mem[im->tokens];
if (t != pp->tokens_seen) {
pp->check_counter += (uint32_t)(t - pp->tokens_seen);
pp->tokens_seen = t;
}
}
/* a word run, as v3 counts it: called from code defined at run time, or by INTERPRET or EXECUTE -- not the
* system's own calls among its words (v3's are C) */
from_code = (ret >= im->dict_lo && ret < im->dict_hi) || ret == im->exec + 1;
@@ -717,14 +702,7 @@ static void on_call(void *ctx, v4_node *n, v4_cell target)
if (p->l1_cache && a->heat > V4_MESH_HOT_HEAT && !hot_has(place, target)) promote(place, target);
#endif
p->prev_id = (uint32_t)id;
/* the heartbeat, by execution (v3: every HEARTBEAT_CHECK_FREQUENCY executions -- its interpreter's tokens and
* the words its definitions run; Captain Bob, 2026-11-13: "By execution, as v3"); a word INTERPRET dispatched
* was counted as its token */
if (from_code) p->check_counter++;
while (p->check_counter >= p->cycle_every) {
p->check_counter -= p->cycle_every;
heartbeat_cycle(place, p);
}
/* the tick is not counted here: it is the one heartbeat's (Captain Bob, 2026-11-17) */
}
a->calls++;
a->since++;
@@ -734,6 +712,7 @@ void v4_mesh_set_tick(v4_mesh *ms, uint64_t tick)
{
unsigned k;
if (!ms->physics) return;
ms->tick = tick;
for (k = 0; k < ms->capacity; k++) ms->physics[k].tick = tick;
}
@@ -774,13 +753,12 @@ static void words_attach(unsigned place, v4_fabric_node *x)
}
if (the->physics) { /* the node's physics, as v3's VM starts */
v4_mesh_physics *p = &the->physics[place];
uint64_t tick = 0; /* its own count of cycles, from none */
uint64_t tick = the->tick; /* the one heartbeat's, as every other node's */
unsigned char *z = (unsigned char *)p;
unsigned long i;
for (i = 0; i < sizeof *p; i++) z[i] = 0;
p->tick = tick;
p->cycle_every = V4_MESH_CHECK_FREQUENCY;
p->tokens_seen = x->n.mem[the->im->tokens];
p->ticking = 1; /* from now it runs its cycle on every tick */
p->decay_slope_q48 = V4_MESH_INITIAL_DECAY_SLOPE_Q48;
p->win.effective_window_size = V4_MESH_WINDOW;
p->opwin.effective_window_size = V4_MESH_WINDOW;
@@ -791,7 +769,6 @@ static void words_attach(unsigned place, v4_fabric_node *x)
* applies its card */
l8_seed(&p->l8);
p->last_inference_tick = 0; /* as v3's */
p->tick_target_ns = HEARTBEAT_TICK_NS;
}
x->es.on_call = on_call;
x->es.on_call_ctx = &the->kernel[place];
@@ -1074,6 +1051,7 @@ static void gone_cb(void *self, unsigned place, v4_fabric_node *was)
{
(void)self;
if (place < MAX_PLACES) { the->reading_nucleus[place] = 0; reads[place].p = reads[place].end = 0; }
if (the->physics && place < the->capacity) the->physics[place].ticking = 0; /* it marches no more */
if (the->accounts && place < the->capacity) { /* its words' records go with it */
unsigned k;
for (k = 0; k < WORD_BITS_BYTES; k++) bits_of(place)[k] = 0;
@@ -1137,12 +1115,36 @@ static int takes(v4_mesh *ms, v4_cell *ended_from, v4_cell *ended_how, unsigned
return took;
}
/* ONE ADAPTIVE HEARTBEAT (Captain Bob, 2026-11-17). At every fabric step the owner's clock is read; each tick
* of the heartbeat not yet delivered is delivered, one by one: every node present whose physics is set up runs its
* heartbeat cycle on it, in place order -- active, idle or blocked alike: lockstep. */
static void heart(v4_mesh *ms)
{
uint64_t t;
unsigned k;
if (!ms->clock) return;
t = ms->clock(ms->self);
while (ms->tick < t) {
ms->tick++;
if (ms->physics)
for (k = 0; k < ms->capacity; k++)
if (v4_fabric_node_at(&ms->f, k) && ms->physics[k].ticking) heartbeat_cycle(k, &ms->physics[k]);
}
}
static unsigned fabric_step(v4_mesh *ms)
{
unsigned did = v4_fabric_step(&ms->f);
heart(ms);
return did;
}
unsigned v4_mesh_step(v4_mesh *ms)
{
v4_cell f = -1, h = -1;
unsigned e = 0, did;
the = ms;
did = v4_fabric_step(&ms->f);
did = fabric_step(ms);
(void)takes(ms, &f, &h, &e);
return did;
}
@@ -1163,7 +1165,7 @@ int v4_mesh_tell(v4_mesh *ms, v4_cell node, const char *text, unsigned len)
if (v4_fabric_device_put(&ms->f, ms->hera_place, V4_MESH_CONSOLE, msg.word, msg.word + V4_MSG_HEADER) != V4_WIRE_DONE)
return V4_BOOT_LINE_REFUSED;
while (steps++ < STEP_LIMIT) {
unsigned did = v4_fabric_step(&ms->f);
unsigned did = fabric_step(ms);
int took = takes(ms, &ended_from, &ended_how, &ended);
int running;
if (h && h->n.stopped) return V4_BOOT_LINE_STOPPED;
@@ -1265,7 +1267,8 @@ static int boot(v4_mesh *ms)
(void)v4_capsule_write(&ms->nucleus->n, ms->im->idle, put_cell, ms);
if (ms->cell_count == 0 || ms->cell_count >= V4_MESH_NUCLEUS_CELLS) { say("V4: the nucleus did not fit\n"); return 0; }
/* 2. the fabric, and Hera born empty at place 0: the kernel on port 0, the console on port 1 */
/* 2. the fabric, and Hera born empty at place 0: the kernel on port 0, the console on port 1; no tick yet */
ms->tick = 0;
v4_fabric_init(&ms->f, ms->places, ms->capacity);
v4_fabric_queues(&ms->f, ms->queues, ms->queue_count);
v4_fabric_gone_error(&ms->f, V4_ERROR_NO_ONE);
@@ -1280,7 +1283,7 @@ static int boot(v4_mesh *ms)
return 0;
}
while (!(h->n.doing && h->n.do_op == 8 && ms->given == ms->cell_count)) { /* she takes it in, and sleeps */
(void)v4_fabric_step(&ms->f);
(void)fabric_step(ms);
if (h->n.stopped || ++steps > STEP_LIMIT) { say("V4: Hera did not take in the nucleus\n"); return 0; }
}
+58 -41
View File
@@ -37,10 +37,13 @@ static v4_mesh ms;
static v4_mesh_account accounts[PLACES * V4_MESH_WORD_IDS]; /* the words' records (#189, Phase 2) */
static unsigned char is_word[PLACES * (V4_NODE_WORDS / 8u)];
static v4_mesh_physics physics[PLACES];
static unsigned forgotten, heartrates;
static uint64_t heartrate_ns;
static void heartrate(void *self, uint64_t ns) { (void)self; heartrates++; heartrate_ns = ns; }
static unsigned forgotten;
static v4_cell forgotten_id = -1;
/* the one adaptive heartbeat's tick, as the owner reads it to the mesh (the kernel's heartbeat_ticks() after POST;
* here the test's own): Captain Bob, 2026-11-17 -- every VM ticks on it, active or not */
static uint64_t heart;
static uint64_t clock_now(void *self) { (void)self; return heart; }
static void set_tick(uint64_t t);
static void forgot(void *self, unsigned place, v4_cell id) { (void)self; (void)place; forgotten++; forgotten_id = id; }
static v4_uheat_t charged[V4_MESH_WORD_IDS];
static void charge(void *ctx, v4_cell id, v4_uheat_t calls) { (void)ctx; charged[id] += calls; }
@@ -96,6 +99,9 @@ static const char *line(v4_cell node, const char *text, int *how)
return said;
}
/* the tick set for a check (v4_mesh_set_tick), and the heartbeat's clock with it, so no catch-up follows */
static void set_tick(uint64_t t) { v4_mesh_set_tick(&ms, t); heart = t; }
int main(void)
{
int how;
@@ -113,7 +119,7 @@ int main(void)
ms.out = out; ms.key = key; ms.words = words; ms.word_count = 1; ms.serve = serve;
ms.capsules = capsules; ms.capsule_count = 3; ms.im = &im; ms.self = 0;
ms.accounts = accounts; ms.is_word = is_word; ms.forgot = forgot;
ms.physics = physics; ms.alloc = alloc; ms.release = release; ms.heartrate = heartrate;
ms.physics = physics; ms.alloc = alloc; ms.release = release; ms.clock = clock_now;
/* ---- the boot ---- */
CHECK(v4_mesh_boot(&ms) == 1, "the boot: %s", said);
@@ -150,6 +156,30 @@ int main(void)
CHECK(v4_mesh_node(&ms, 11) != 0, "node 11 is in the fabric");
r = line(11, "6 7 * .", &how);
CHECK(how == V4_TEXT_COMPLETED && strcmp(r, "42 ") == 0, "node 11 answers a line of its own: \"%s\" (%d)", r, how);
/* ---- ONE ADAPTIVE HEARTBEAT (Captain Bob, 2026-11-17; plan 2026-11-17-one-adaptive-heartbeat): every node's
* tick is the heartbeat's -- the owner's clock -- and on each tick every node present runs its cycle, active or
* idle, in lockstep. Nothing in a VM paces it. ---- */
{
unsigned k, p11 = PLACES;
uint64_t c0, c11;
for (k = 0; k < PLACES; k++) if (v4_fabric_node_at(&ms.f, k) == v4_mesh_node(&ms, 11)) p11 = k;
CHECK(p11 < PLACES, "node 11 has a place");
CHECK(ms.tick == 0 && ms.physics[0].tick == 0 && p11 < PLACES && ms.physics[p11].tick == 0,
"held: through the boot and POST the heartbeat gave no tick, and no node ticked (%lu)", (unsigned long)ms.tick);
c0 = ms.physics[0].decay_cycles; c11 = p11 < PLACES ? ms.physics[p11].decay_cycles : 0;
heart = 5;
r = line(V4_MESH_HERA, "3 4 + .", &how);
CHECK(ms.tick == 5 && ms.physics[0].tick == 5 && p11 < PLACES && ms.physics[p11].tick == 5,
"five ticks: Hera and node 11, idle, both at tick 5 -- one clock (%lu)", (unsigned long)ms.tick);
CHECK(ms.physics[0].decay_cycles - c0 == 5 && p11 < PLACES && ms.physics[p11].decay_cycles - c11 == 5,
"each tick delivered, one by one, to every node: five cycles each, idle node 11's too");
CHECK(p11 < PLACES && ms.physics[p11].snapshot.tick == 5, "node 11's last cycle was tick 5");
heart = 8;
(void)v4_mesh_step(&ms);
CHECK(ms.tick == 8 && p11 < PLACES && ms.physics[p11].tick == 8 && ms.physics[p11].decay_cycles - c11 == 8,
"between lines too: three more ticks, three more cycles, none lost (%lu)", (unsigned long)ms.tick);
}
r = line(V4_MESH_HERA, "S\" 6 7 * .\" 11 SEND 11 AWAIT .", &how);
CHECK(how == V4_TEXT_COMPLETED && strstr(r, "42 ") && strstr(r, "1 "),
"and through Hera, as the prompt reaches it: she sends node 11 a line and awaits it: \"%s\" (%d)", r, how);
@@ -228,22 +258,14 @@ int main(void)
r = line(V4_MESH_HERA, "FORGET L8T", &how);
}
/* ---- the tick as v3's (Captain Bob, 2026-11-14, "v3"; "we can always change it late"): one a token the
* interpreter takes, one a word run from code defined at run time; the system's own internal calls, none ---- */
/* ---- the words run, as v3 counts them on their records: one a word run from code defined at run time, or
* dispatched by INTERPRET or EXECUTE; the system's own internal calls, none. (The tick no longer counts them:
* it is the one heartbeat's, Captain Bob 2026-11-17 -- the "tick as v3's" checks of 11-14 are withdrawn.) ---- */
{
v4_mesh_physics *p = &ms.physics[0];
uint64_t c0, c1;
const v4_mesh_account *wd;
c0 = p->tick * p->cycle_every + p->check_counter;
r = line(V4_MESH_HERA, "3 4 + .", &how);
c1 = p->tick * p->cycle_every + p->check_counter;
CHECK(strcmp(r, "7 ") == 0 && c1 - c0 == 4u, "3 4 + . counts 4, as v3: its four tokens (%lu)", (unsigned long)(c1 - c0));
r = line(V4_MESH_HERA, ": TSQ DUP * ; : TQ TSQ TSQ ;", &how);
c0 = p->tick * p->cycle_every + p->check_counter;
r = line(V4_MESH_HERA, "2 TQ .", &how);
c1 = p->tick * p->cycle_every + p->check_counter;
CHECK(strcmp(r, "16 ") == 0 && c1 - c0 >= 5u && c1 - c0 <= 9u,
"2 TQ . counts its 3 tokens and the words TQ runs, as v3 (%lu)", (unsigned long)(c1 - c0));
CHECK(strcmp(r, "16 ") == 0, "2 TQ . runs: %s", r);
r = line(V4_MESH_HERA, "' TSQ .", &how);
wd = v4_mesh_account_at(&ms, 0, (v4_cell)strtol(r, 0, 10));
CHECK(wd && wd->calls == 2, "TSQ, called twice from TQ, has 2 calls on its record (%lu)", wd ? (unsigned long)wd->calls : 0ul);
@@ -349,19 +371,16 @@ int main(void)
r = line(V4_MESH_HERA, "FORGET OPS", &how);
}
/* ---- inference every 1000 ticks, and Loop #7 (#189 Phase 7, Task 3) ---- */
/* ---- inference every 1000 ticks (#189 Phase 7, Task 3) -- on the one heartbeat's ticks (2026-11-17) ---- */
{
v4_mesh_physics *p = &ms.physics[0];
uint64_t t0 = p->tick, runs0 = p->inference_runs;
r = line(V4_MESH_HERA, ": IW ; : LIW 30 0 DO 10000 0 DO IW LOOP LOOP ; LIW", &how); /* 300000 calls: over 1000 ticks */
r = line(V4_MESH_HERA, ": IW ; : LIW 30 0 DO 10000 0 DO IW LOOP LOOP ; LIW", &how); /* 300000 calls */
heart += 1100u; (void)v4_mesh_step(&ms); /* and the one heartbeat ticks 1100 times (its ticks, not the calls') */
CHECK(how == V4_TEXT_COMPLETED && p->tick - t0 > 1000u && p->win.is_warm, "a long run: over 1000 ticks (%lu), the window warm",
(unsigned long)(p->tick - t0));
CHECK(p->inference_runs > runs0, "inference ran (%lu times)", (unsigned long)p->inference_runs);
CHECK(p->tick_target_ns != HEARTBEAT_TICK_NS && p->tick_target_ns >= HEARTBEAT_TICK_NS / 4u
&& p->tick_target_ns <= HEARTBEAT_TICK_NS * 4u, "Loop #7 moved the heartrate, within its bounds: %lu ns",
(unsigned long)p->tick_target_ns);
CHECK(heartrates > 0 && heartrate_ns == (p->tick_target_ns * 10000000ULL) / HEARTBEAT_TICK_NS,
"and on Hera re-armed the kernel's heartbeat: %lu ns", (unsigned long)heartrate_ns);
/* Loop #7 is the heartbeat's own now (kernel/tests/test_heartbeat.c): a node paces nothing */
CHECK(!p->inference.early_exited ? p->last_inference_tick > 0 : 1, "a full run marks its tick");
CHECK(p->snapshot.tick == p->tick && p->snapshot.window_width == p->win.effective_window_size
&& p->snapshot.decay_slope_q48 == p->decay_slope_q48 && p->snapshot.fill == V4_MESH_WINDOW
@@ -399,20 +418,16 @@ int main(void)
v4_mesh_physics *p = &ms.physics[0];
const v4_mesh_account *a;
uint64_t total0;
uint32_t every = p->cycle_every;
uint64_t slope = p->decay_slope_q48;
p->decay_slope_q48 = 21845u; /* v3's initial, for decay's arithmetic seen exactly */
r = line(V4_MESH_HERA, ": P7 DUP * ; ' P7 .", &how);
a = v4_mesh_account_at(&ms, 0, (v4_cell)strtol(r, 0, 10));
/* the tick, by execution (Captain Bob, 2026-11-13: "By execution, as v3"): every 256 word calls a
* node's heartbeat cycle runs, and its tick is the count of them -- held still here, so decay's
* arithmetic is seen exactly, and seen moving below */
CHECK(every == 256u, "a node's heartbeat cycle comes every 256 word calls, as v3's HEARTBEAT_CHECK_FREQUENCY");
p->cycle_every = 0xFFFFFFFFu;
/* the tick is the one heartbeat's (Captain Bob, 2026-11-17): set by hand here, and the clock with it,
* so decay's arithmetic is seen exactly */
v4_mesh_l8_force(&ms, 0, 24u, 1); /* L8 held on card 24: L2 and L3 (and L7) -- the window and decay */
CHECK(p->l2_window && p->l3_decay && !p->l4_pipelining && !p->l1_cache && p->l7_adaptive_heartrate,
"card 24's gates: the window, decay, and L7, which is always on");
v4_mesh_set_tick(&ms, 100);
set_tick(100);
total0 = p->win.total_executions;
r = line(V4_MESH_HERA, "2 P7 3 P7 4 P7 + + .", &how);
CHECK(strcmp(r, "29 ") == 0 && a && a->heat == 3 && a->last_decay_tick == 100,
@@ -420,33 +435,33 @@ int main(void)
CHECK(p->win.total_executions >= total0 + 3 && p->win.history[(p->win.window_pos + V4_MESH_WINDOW - 1u) % V4_MESH_WINDOW]
!= (uint32_t)-1, "the rolling window took them (%lu)", (unsigned long)(p->win.total_executions - total0));
CHECK(a && a->temperature_q8 > 0, "and the temperature rose: %u", a ? a->temperature_q8 : 0u);
v4_mesh_set_tick(&ms, 106); /* six ticks at 21845 (1/3 a tick, Q48.16): 1 heat */
set_tick(106); /* six ticks at 21845 (1/3 a tick, Q48.16): 1 heat */
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 3 && a->last_decay_tick == 106, "six ticks on: one heat decayed, one added: %lu",
a ? (unsigned long)a->heat : 0ul);
v4_mesh_set_tick(&ms, 109); /* three ticks: 65535 >> 16 = 0, as v3 */
set_tick(109); /* three ticks: 65535 >> 16 = 0, as v3 */
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 4, "three ticks decay nothing, as v3's arithmetic: %lu", a ? (unsigned long)a->heat : 0ul);
((v4_mesh_account *)a)->state_flags |= V4_MESH_STATE_FROZEN;
v4_mesh_set_tick(&ms, 409);
set_tick(409);
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 5, "a frozen word does not decay: %lu", a ? (unsigned long)a->heat : 0ul);
((v4_mesh_account *)a)->state_flags &= (uint8_t)~V4_MESH_STATE_FROZEN;
p->l3_decay = 0;
v4_mesh_set_tick(&ms, 709);
set_tick(709);
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 6, "nor any word while L8 has Loop #3 off: %lu", a ? (unsigned long)a->heat : 0ul);
p->l3_decay = 1;
v4_mesh_set_tick(&ms, 1009);
set_tick(1009);
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 1, "and with it on, 300 ticks take all six, then one: %lu", a ? (unsigned long)a->heat : 0ul);
v4_mesh_set_tick(&ms, 0);
p->cycle_every = every;
set_tick(0);
{
uint64_t t0 = p->tick;
heart += 2u; /* the heartbeat ticks twice while the line runs */
r = line(V4_MESH_HERA, ": LP7 300 0 DO 2 P7 DROP LOOP ; LP7", &how);
CHECK(p->tick >= t0 + 2,
"300 calls of P7, and the many the line's compiling makes: the tick moves, a cycle per 256 (%lu)",
CHECK(p->tick >= t0 + 2 && p->tick == ms.tick,
"300 calls of P7 while the heartbeat ticks twice: Hera's tick is the heartbeat's (%lu)",
(unsigned long)(p->tick - t0));
}
/* the cycle's loops (Task 3): background decay, 64 words a cycle from a cursor down the dictionary,
@@ -458,14 +473,16 @@ int main(void)
uint64_t c0 = p->decay_cycles;
p->last_inference_tick = p->tick; /* no inference in this check's 1000 ticks: v3's slope stays */
p->decay_slope_q48 = 21845u;
r = line(V4_MESH_HERA, ": Q7 ; : LQ7 300 0 DO Q7 LOOP ; LQ7 ' Q7 .", &how); /* over 256: a cycle at least */
heart += 1u; /* a tick of the heartbeat, at least, while it runs */
r = line(V4_MESH_HERA, ": Q7 ; : LQ7 300 0 DO Q7 LOOP ; LQ7 ' Q7 .", &how);
q7 = (v4_cell)strtol(r, 0, 10);
qa = v4_mesh_account_at(&ms, 0, q7);
#define Q7_HOT 90u /* under card 24 (no L4): no speculation to set its heat to 51 */
CHECK(qa && qa->heat >= Q7_HOT && p->decay_cycles > c0, "Q7 hot after 300 calls (%lu), and the cycles decay in the background",
qa ? (unsigned long)qa->heat : 0ul);
q7_heat = qa ? qa->heat : 0;
r = line(V4_MESH_HERA, ": NOP ; : LZ 20000 0 DO NOP LOOP ; LZ", &how); /* many cycles of calls, none to Q7 */
heart += 300u; /* many ticks of the heartbeat, no call to Q7 */
r = line(V4_MESH_HERA, ": NOP ; : LZ 20000 0 DO NOP LOOP ; LZ", &how);
CHECK(qa && qa->heat < q7_heat && qa->last_decay_tick > 0, "Q7, never called again, has cooled in the background: %lu",
qa ? (unsigned long)qa->heat : 0ul);
CHECK(p->win.diversity_checks > 0 && p->win.effective_window_size >= 256u && p->win.effective_window_size <= V4_MESH_WINDOW,