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:
+4
-1
@@ -63,7 +63,9 @@
|
||||
#define HBUF_W (SVARS - 16) /* the hold buffer: 16 cells = 64 bytes */
|
||||
#define HEND ((HBUF_W + 16) * 4)
|
||||
#define XVARS (HBUF_W - 4) /* (X): words.f18, 4 cells */
|
||||
#define QBASE (XVARS - 40) /* the Q words' and DUMP's scratch cells, 39 in all */
|
||||
#define HOTVARS (XVARS - 35) /* (HOT): the hot-words cache (#189 Phase 7): its count, the kernel's next slot to take when it is full, the lookup's index, then 32 xts */
|
||||
#define HOT_SIZE 32
|
||||
#define QBASE (HOTVARS - 40) /* the Q words' and DUMP's scratch cells, 39 in all */
|
||||
#define BVARS (QBASE - 16) /* blocks.f18: 6 cells not used now, then SCR BLK (SRC) (SRC-HOOK) */
|
||||
#define SCR (BVARS + 6)
|
||||
#define BLK (BVARS + 7)
|
||||
@@ -286,6 +288,7 @@ static unsigned host_branch_slots(void)
|
||||
X("(S)", SVARS) \
|
||||
X("(W)", WVARS) \
|
||||
X("(X)", XVARS) \
|
||||
X("(HOT)", HOTVARS) \
|
||||
X("(BOOT)", BOOT_CELLS) \
|
||||
X("(NEXT-ID)", NEXT_ID) \
|
||||
X("(BOOT-ID)", BOOT_ID) \
|
||||
|
||||
@@ -41,6 +41,26 @@ static v4_cell forgotten_id = -1;
|
||||
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; }
|
||||
#define TABLES 1024u /* every word with a successor has one, as on the kernel's heap */
|
||||
static uint64_t tables[TABLES][V4_MESH_WORD_IDS]; /* transition counters, given out in turn */
|
||||
static int table_used[TABLES];
|
||||
static void *alloc(void *self, unsigned long bytes)
|
||||
{
|
||||
unsigned k; (void)self;
|
||||
if (bytes > sizeof tables[0]) return 0;
|
||||
for (k = 0; k < TABLES; k++) if (!table_used[k]) { table_used[k] = 1; memset(tables[k], 0, sizeof tables[k]); return tables[k]; }
|
||||
return 0;
|
||||
}
|
||||
static void release(void *self, void *p) { (void)self; table_used[(uint64_t (*)[V4_MESH_WORD_IDS])p - tables] = 0; }
|
||||
#if ENABLE_HOTWORDS_CACHE
|
||||
static int hot_holds(v4_cell xt)
|
||||
{
|
||||
v4_fabric_node *h = v4_mesh_node(&ms, V4_MESH_HERA);
|
||||
v4_cell i;
|
||||
for (i = 0; i < h->n.mem[im.hot]; i++) if (h->n.mem[im.hot + 3 + i] == xt) return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int no_room; /* the owner has no room to give */
|
||||
static v4_fabric_node *room(void *self) { unsigned k; (void)self; if (no_room) return 0; for (k = 0; k < PLACES; k++) if (!used[k]) { used[k] = 1; roomed++; return &pool[k]; } return 0; }
|
||||
@@ -90,7 +110,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 = 2; ms.im = &im; ms.self = 0;
|
||||
ms.accounts = accounts; ms.is_word = is_word; ms.forgot = forgot;
|
||||
ms.physics = physics;
|
||||
ms.physics = physics; ms.alloc = alloc; ms.release = release;
|
||||
|
||||
/* ---- the boot ---- */
|
||||
CHECK(v4_mesh_boot(&ms) == 1, "the boot: %s", said);
|
||||
@@ -285,6 +305,57 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_PIPELINING && ENABLE_HOTWORDS_CACHE
|
||||
/* ---- pipelining and the hot-words cache, on (built off as v3; Captain Bob, 2026-11-13) ---- */
|
||||
{
|
||||
v4_cell pa, pb, pb2, hw;
|
||||
const v4_mesh_account *aa;
|
||||
v4_mesh_physics *p = &ms.physics[0];
|
||||
r = line(V4_MESH_HERA, ": PA 1 ; : PB 2 ; ' PA .", &how);
|
||||
pa = (v4_cell)strtol(r, 0, 10);
|
||||
r = line(V4_MESH_HERA, "' PB .", &how); pb = (v4_cell)strtol(r, 0, 10);
|
||||
r = line(V4_MESH_HERA, ": PAT PA PB PA PB PA PB PA PB PA PB PA PB PA PB PA PB PA PB PA PB PA PB PA PB ; PAT", &how);
|
||||
aa = v4_mesh_account_at(&ms, 0, pa);
|
||||
CHECK(how == V4_TEXT_COMPLETED && aa && aa->total_transitions == 12 && aa->transitions
|
||||
&& aa->most_likely_next == (uint32_t)v4_mesh_node(&ms, V4_MESH_HERA)->n.mem[pb - 4],
|
||||
"PA's transitions: 12, every one to PB, its likeliest next (%lu)", aa ? (unsigned long)aa->total_transitions : 0ul);
|
||||
CHECK(aa && aa->prefetch_attempts > 0 && hot_holds(pb) && p->hot_promotions > 0,
|
||||
"after 10, speculation on PB: it is put in the node's cache (%lu attempts)", aa ? (unsigned long)aa->prefetch_attempts : 0ul);
|
||||
CHECK(aa && aa->prefetch_hits > 0 && p->prefetch_hits > 0, "and PB coming next counts as hits (%lu)", aa ? (unsigned long)aa->prefetch_hits : 0ul);
|
||||
r = line(V4_MESH_HERA, "PB .", &how);
|
||||
CHECK(strcmp(r, "2 ") == 0, "a cached word is found by its name: \"%s\"", r);
|
||||
r = line(V4_MESH_HERA, ": PB 3 ; PB .", &how);
|
||||
CHECK(strcmp(r, "3 ") == 0 && !hot_holds(pb), "PB defined again: the old one is out of the cache, the new one found: \"%s\"", r);
|
||||
r = line(V4_MESH_HERA, "' PB .", &how); pb2 = (v4_cell)strtol(r, 0, 10);
|
||||
/* v3's promote, when the cache is full, takes the next slot in turn without looking for the word
|
||||
* already there: a few hot words then churn through all 32 slots (reproduced, as v3; reported). So
|
||||
* the heat promotion is seen on a cache emptied first. */
|
||||
CHECK(v4_mesh_node(&ms, V4_MESH_HERA)->n.mem[im.hot] == V4_IMAGE_HOT_SIZE && p->hot_evictions > 0,
|
||||
"by now the cache is full, and taking slots in turn, as v3's");
|
||||
v4_mesh_node(&ms, V4_MESH_HERA)->n.mem[im.hot] = 0;
|
||||
v4_mesh_node(&ms, V4_MESH_HERA)->n.mem[im.hot + 1] = 0;
|
||||
r = line(V4_MESH_HERA, ": HW ; : LH 60 0 DO HW LOOP ; LH ' HW .", &how);
|
||||
hw = (v4_cell)strtol(r, 0, 10);
|
||||
CHECK(hot_holds(hw), "a word called past heat 50 goes into the cache");
|
||||
r = line(V4_MESH_HERA, "FORGET PA", &how);
|
||||
CHECK(!hot_holds(hw) && !hot_holds(pb2) && v4_mesh_account_at(&ms, 0, pa) == 0,
|
||||
"FORGET takes everything from PA on out of the cache, and PA's counters back");
|
||||
r = line(V4_MESH_HERA, "3 4 + .", &how);
|
||||
CHECK(strcmp(r, "7 ") == 0, "and lookups go on as before: \"%s\"", r);
|
||||
}
|
||||
#else
|
||||
{
|
||||
const v4_mesh_account *aa;
|
||||
v4_cell pa;
|
||||
r = line(V4_MESH_HERA, ": PA 1 ; : PB 2 ; : PAT PA PB PA PB PA PB PA PB PA PB PA PB PA PB ; PAT ' PA .", &how);
|
||||
pa = (v4_cell)strtol(r, 0, 10);
|
||||
aa = v4_mesh_account_at(&ms, 0, pa);
|
||||
CHECK(aa && aa->total_transitions == 0 && !aa->transitions && v4_mesh_node(&ms, V4_MESH_HERA)->n.mem[im.hot] == 0,
|
||||
"built off, as v3: no transitions recorded, nothing in the cache");
|
||||
r = line(V4_MESH_HERA, "FORGET PA", &how);
|
||||
}
|
||||
#endif
|
||||
|
||||
printf(" %d checks, %d failures\n", checks, failures);
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user