feat(v4): Phase 7 Task 3, first step -- each node's tick by execution, as v3 (#189)
Captain Bob, 2026-11-13: "By execution, as v3". v3's kernel runs a VM's heartbeat cycle every 256 word executions (HEARTBEAT_CHECK_FREQUENCY, vm_core.c:912 and :1210), and its tick_count is the count of cycles. Task 2a had used the kernel's timer heartbeat as the decay clock: corrected. Each node counts its word calls; every 256th runs its heartbeat cycle at the call; the cycle's loops follow. The kernel no longer gives the mesh its timer. Test first: test_mesh_boot.c, 59 checks (67 with pipelining and the cache on). Not pushed (held to the end of Phase 7). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
@@ -100,8 +100,11 @@ typedef struct {
|
||||
#define V4_MESH_WINDOW 4096u /* v3's ROLLING_WINDOW_SIZE */
|
||||
#define V4_MESH_WINDOW_WARM 1024u /* executions before the window is warm, as v3 */
|
||||
#define V4_MESH_ADAPTIVE_CHECK 512u /* v3's ADAPTIVE_CHECK_FREQUENCY: executions between diversity checks */
|
||||
#define V4_MESH_CHECK_FREQUENCY 256u /* v3's HEARTBEAT_CHECK_FREQUENCY: word calls a heartbeat cycle */
|
||||
typedef struct {
|
||||
uint64_t tick;
|
||||
uint64_t tick; /* the node's heartbeat cycles (v3's tick_count): by execution, as v3 */
|
||||
uint32_t check_counter; /* word calls since the last cycle */
|
||||
uint32_t cycle_every; /* V4_MESH_CHECK_FREQUENCY */
|
||||
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 */
|
||||
@@ -156,7 +159,6 @@ struct v4_mesh {
|
||||
v4_mesh_account *accounts;
|
||||
unsigned char *is_word;
|
||||
v4_mesh_physics *physics; /* `capacity` of them: each node's (#189, Phase 7) */
|
||||
uint64_t (*ticks)(void); /* the heartbeat's tick count, read at each call (0: v4_mesh_set_tick's) */
|
||||
/* 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);
|
||||
@@ -199,7 +201,7 @@ int v4_mesh_busy(const v4_mesh *ms);
|
||||
/* A word's record on the node in `place`, by its xt: 0 if that is not a word's xt. */
|
||||
const v4_mesh_account *v4_mesh_account_at(const v4_mesh *ms, unsigned place, v4_cell xt);
|
||||
|
||||
/* The heartbeat's tick, for every node (v3's vm->heartbeat.tick_count): what decay is measured by. */
|
||||
/* Every node's tick set to `tick` (for tests: a node's tick is its own count of heartbeat cycles). */
|
||||
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. */
|
||||
|
||||
+15
-2
@@ -340,6 +340,13 @@ static void pipeline(unsigned place, v4_mesh_physics *p, uint32_t id)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* a node's heartbeat cycle (v3's vm_heartbeat_run_cycle): its tick; the per-tick loops follow (Task 3) */
|
||||
static void heartbeat_cycle(unsigned place, v4_mesh_physics *p)
|
||||
{
|
||||
(void)place;
|
||||
p->tick++;
|
||||
}
|
||||
|
||||
/* at `call` (exec.h), on a word -- any other target, nothing -- in v3's order (physics_pre_execute,
|
||||
* V3-PARITY.md 2.1; Captain Bob, 2026-11-13: "Every call, as v3"): decay by the ticks since, heat +1,
|
||||
* the count the Stadium is charged by, the temperature, the rolling window */
|
||||
@@ -354,7 +361,6 @@ static void on_call(void *ctx, v4_node *n, v4_cell target)
|
||||
a = &accounts_of(place)[id];
|
||||
if (the->physics) {
|
||||
v4_mesh_physics *p = &the->physics[place];
|
||||
if (the->ticks) p->tick = the->ticks();
|
||||
decay(a, p, p->tick - a->last_decay_tick);
|
||||
a->last_decay_tick = p->tick;
|
||||
a->heat++;
|
||||
@@ -370,6 +376,12 @@ 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 words its VM executes;
|
||||
* Captain Bob, 2026-11-13: "By execution, as v3") */
|
||||
if (++p->check_counter >= p->cycle_every) {
|
||||
p->check_counter = 0;
|
||||
heartbeat_cycle(place, p);
|
||||
}
|
||||
}
|
||||
a->calls++;
|
||||
a->since++;
|
||||
@@ -419,11 +431,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 = p->tick; /* the heartbeat's, which goes on */
|
||||
uint64_t tick = 0; /* its own count of cycles, from none */
|
||||
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->decay_slope_q48 = V4_MESH_INITIAL_DECAY_SLOPE_Q48;
|
||||
p->l3_decay = 1;
|
||||
p->l2_window = 1; /* v3: "No config yet: recorded" */
|
||||
|
||||
@@ -225,8 +225,14 @@ int main(void)
|
||||
v4_mesh_physics *p = &ms.physics[0];
|
||||
const v4_mesh_account *a;
|
||||
uint64_t total0;
|
||||
uint32_t every = p->cycle_every;
|
||||
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;
|
||||
v4_mesh_set_tick(&ms, 100);
|
||||
total0 = p->total_executions;
|
||||
r = line(V4_MESH_HERA, "2 P7 3 P7 4 P7 + + .", &how);
|
||||
@@ -256,6 +262,14 @@ int main(void)
|
||||
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;
|
||||
{
|
||||
uint64_t t0 = p->tick;
|
||||
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)",
|
||||
(unsigned long)(p->tick - t0));
|
||||
}
|
||||
r = line(V4_MESH_HERA, "FORGET P7", &how);
|
||||
}
|
||||
r = line(V4_MESH_HERA, "3 SQ .", &how);
|
||||
|
||||
Reference in New Issue
Block a user