feat(v4): Phase 7 Task 2b -- pipelining and the hot-words cache, built, off as v3 (#189)

Rulings, Captain Bob 2026-11-13: "Build a hot-words cache"; then, v3 being found to have both off
(ENABLE_PIPELINING, ENABLE_HOTWORDS_CACHE: n in Kconfig.physics and kernel/Makefile), "Built, off as v3".

- The kernel, at every call (mesh.c): v3's hit check, the transition, the likeliest next word (kept as each
  count rises; v3 scans 1024 a call -- the same word but in a tie v3's Q48.16 rounding makes), speculation
  at v3's thresholds into the node's cache; a word past heat 50 promoted at its call (v3 promotes at a
  lookup; v4's heat is the kernel's). Counters from the owner's heap, given back when a word goes.
- The node (dict.f18): (LOOKUP) tries (HOT)'s xts first, in F18, calling only C@; the kernel keeps it true
  (entries that go, or whose name is defined again, taken out). Empty unless the build has the cache.
- Tests: test_mesh_boot.c as built (57 checks) and with both on (mesh-boot-on, 65). v4 test: all pass.
- Reported, v3's own: when full, its promote takes the next slot without looking for the word there (a few
  hot words churn all 32 slots); its prefetch misses are never counted. Both reproduced.
- amd64 boots, RESULT: PASS, but 174 s and 181 s against 2a's 146 s, while on the host the mesh boot is no
  slower: being measured. Not pushed (held to the Phase 7 boundary).

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-13 21:52:01 +00:00
parent b880a6eaed
commit 3a70e824a2
19 changed files with 473 additions and 145 deletions
+6
View File
@@ -71,6 +71,11 @@ typedef struct {
* and when entries go, or 0 (dict.f18); a kernel that keeps records puts its own there */
v4_cell word_defined, word_forgotten;
/* (HOT): the hot-words cache (#189, Phase 7; Captain Bob, 2026-11-13): its count, the slot the kernel
* takes next when it is full, the lookup's index, then V4_IMAGE_HOT_SIZE xts, which (LOOKUP) tries before
* the dictionary. The kernel fills it, when its build has ENABLE_HOTWORDS_CACHE; otherwise it is empty. */
v4_cell hot;
/* the block window: the word address of the slots the kernel copies
* blocks into (v4/blocks.h) */
v4_cell block_window;
@@ -90,6 +95,7 @@ typedef struct {
/* The memory map's description of the system (the generated file defines
* it): what is known of it before it is built. */
extern const v4_image v4_map_image;
#define V4_IMAGE_HOT_SIZE 32 /* v3's HOTWORDS_CACHE_SIZE */
/* What only the assembled system knows, read from the image record of the
* node `n` that holds it into `im`, which the map's description is in.
+34
View File
@@ -61,6 +61,13 @@ typedef struct {
uint64_t last_decay_tick; /* the node's tick when decay was last applied: the only clock decay reads */
uint16_t temperature_q8; /* the heat, smoothed (an EMA), in Q8 */
uint8_t state_flags; /* the kernel's own: V4_MESH_STATE_PINNED, _FROZEN */
/* pipelining (Loop #4; v3's WordTransitionMetrics), when ENABLE_PIPELINING: how often each word ID came
* next -- V4_MESH_WORD_IDS counters from the owner's alloc, on the first transition -- and the likeliest */
uint64_t *transitions;
uint64_t total_transitions;
uint64_t most_likely_count;
uint32_t most_likely_next;
uint64_t prefetch_attempts, prefetch_hits;
} v4_mesh_account;
/* A word's state flags, as v3's (PHYSICS_STATE_*): immediate and hidden are the node's (its header's
@@ -73,6 +80,23 @@ typedef struct {
/* Each node's physics (v3's VM fields): its heartbeat's tick, the decay slope (Q48.16 heat a tick;
* v3's INITIAL_DECAY_SLOPE_Q48, which the inference engine tunes), and L8's gate on Loop #3. */
#define V4_MESH_INITIAL_DECAY_SLOPE_Q48 21845u
/* Pipelining and the hot-words cache: built, and off unless the build turns them on, as v3's
* (Kconfig.physics; Captain Bob, 2026-11-13: "Built, off as v3"). v3's thresholds. */
#ifndef ENABLE_PIPELINING
#define ENABLE_PIPELINING 0
#endif
#ifndef ENABLE_HOTWORDS_CACHE
#define ENABLE_HOTWORDS_CACHE 0
#endif
#ifndef SPECULATION_THRESHOLD_Q48
#define SPECULATION_THRESHOLD_Q48 0x8000 /* a probability of 1/2, Q48.16 */
#endif
#ifndef MIN_SAMPLES_FOR_SPECULATION
#define MIN_SAMPLES_FOR_SPECULATION 10
#endif
#define V4_MESH_HOT_HEAT 50u /* v3's HOTWORDS_EXECUTION_HEAT_THRESHOLD */
#define V4_MESH_NO_WORD 0xFFFFFFFFu
#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 */
@@ -89,6 +113,13 @@ typedef struct {
uint32_t adaptive_check_accumulator;
uint8_t is_warm;
uint8_t adaptive_pending; /* the heartbeat should check the window's diversity */
/* pipelining (Loop #4): the word called before, L8's gate, and the node's counts */
uint32_t prev_id; /* V4_MESH_NO_WORD: none yet */
uint8_t l4_pipelining;
uint64_t prefetch_attempts, prefetch_hits;
/* the hot-words cache (the node's (HOT), v4/image.h): L8's gate (v3's L1_heat_tracking), and its counts */
uint8_t l1_cache;
uint64_t hot_promotions, hot_evictions;
} v4_mesh_physics;
typedef struct v4_mesh v4_mesh;
@@ -126,6 +157,9 @@ struct v4_mesh {
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);
/* a word has gone, its ID free for the next: the owner forgets what it keeps by it (may be 0) */
void (*forgot)(void *self, unsigned place, v4_cell id);
void *self;