starkernel: item 4.1 -- hot words onto the Stadium, density-ranked eviction
Punch list §25 item 4.1 complete. Replaces the round-robin hotwords cache with Stadium density-ranked admission/eviction on the kernel side, via the §17.7 reservoir mechanism and a kernel-side word_id -> cell_index map (no DictEntry change, dict_hash untouched). Adds stadium_birth_hera() to close the cell-0 panic hazard, STADIUM_WORD_HEAT_QUANTUM/STADIUM_WORD_COOL_RATE_Q48 Kconfig knobs (flagged untuned), and a stadium_word_forget() FORGET coherence hook to close a recycled-word_id aliasing gap. Verified: all five hotwords_cache_* call sites in dictionary_management.c bypassed under __STARKERNEL__; word dispatch feeds the Stadium at all three vm_core.c physics_execution_heat_increment() sites; hosted make unaffected; all three architectures booted to ok> with matching dict_hash (0x3d4e1daf289da94f) and matching conservation stats (promotions=354 evictions=0, resident_sum=65536 reservoir=0 sum=65536). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
bd92c57834
commit
3d0b9351bd
@@ -55,6 +55,10 @@
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#ifdef __STARKERNEL__
|
||||
#include "starkernel/vm/stadium_words.h" /* item 4.1: FORGET coherence hook */
|
||||
#include "starkernel/vm_uuid.h" /* vm_uuid_hera() */
|
||||
#endif
|
||||
/* LIKELY/UNLIKELY macros are defined in vm.h */
|
||||
|
||||
#ifndef SF_FC_BUCKETS
|
||||
@@ -112,14 +116,28 @@ void vm_dictionary_untrack_entry(VM *vm, DictEntry *entry) {
|
||||
|
||||
/* Cache coherence: the entry is about to be removed (FORGET frees it) —
|
||||
* a stale pointer left in the hot-words ring would be a use-after-free,
|
||||
* and an older same-named word may become visible again. */
|
||||
* and an older same-named word may become visible again.
|
||||
* §17.3 (item 4.1): retired under __STARKERNEL__ -- the kernel word
|
||||
* layer stays inert to this mechanism entirely, so there is nothing to
|
||||
* keep coherent here on the kernel side. Hosted is unaffected. */
|
||||
#ifndef __STARKERNEL__
|
||||
hotwords_cache_evict_entry(vm->hotwords_cache, entry);
|
||||
#endif
|
||||
|
||||
uint32_t word_id = entry->word_id;
|
||||
if (word_id == WORD_ID_INVALID || word_id >= DICTIONARY_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef __STARKERNEL__
|
||||
/* item 4.1 coherence hook: if this word_id is resident on the Stadium,
|
||||
* reclaim its cell (crediting heat back to the reservoir) BEFORE the id
|
||||
* is recycled below -- otherwise the next word assigned this same id
|
||||
* would alias onto the forgotten word's stale cell (same failure class
|
||||
* as the 2026-08-02 block_words.c aliasing bug). */
|
||||
stadium_word_forget(word_id);
|
||||
#endif
|
||||
|
||||
if (vm->word_id_map[word_id] == entry) {
|
||||
vm->word_id_map[word_id] = NULL;
|
||||
}
|
||||
@@ -316,12 +334,18 @@ DictEntry *vm_find_word(VM *vm, const char *name, size_t len) {
|
||||
|
||||
/* Use hot-words cache for physics-driven frequency-based acceleration.
|
||||
* The cache's bucket fallback resolves via vm_dict_resolve_in_bucket(),
|
||||
* so a non-NULL result already honors newest-first shadowing. */
|
||||
* so a non-NULL result already honors newest-first shadowing.
|
||||
* §17.3 (item 4.1): bypassed under __STARKERNEL__ -- the kernel side
|
||||
* feeds the Stadium instead (vm_core.c's dispatch sites), and this
|
||||
* lookup fast path is retired in favor of the ordinary bucket scan
|
||||
* below. Hosted is unaffected. */
|
||||
#ifndef __STARKERNEL__
|
||||
DictEntry *found = hotwords_cache_lookup(vm, vm->hotwords_cache, bucket, n, name, len);
|
||||
if (found) {
|
||||
sf_mutex_unlock(&vm->dict_lock);
|
||||
return found;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Phase 2: Choose lookup strategy based on pattern diversity */
|
||||
if (vm->lookup_strategy == 1) {
|
||||
@@ -431,8 +455,12 @@ DictEntry *vm_create_word(VM *vm, const char *name, size_t len, word_func_t func
|
||||
|
||||
/* Cache coherence: this definition may shadow an older word of the same
|
||||
* name that the hot-words cache is still serving. Evict the name so the
|
||||
* next lookup re-resolves through the arbitrated bucket scan. */
|
||||
* next lookup re-resolves through the arbitrated bucket scan.
|
||||
* §17.3 (item 4.1): retired under __STARKERNEL__, same as the other
|
||||
* hotwords_cache_* call sites in this file. */
|
||||
#ifndef __STARKERNEL__
|
||||
hotwords_cache_evict_name(vm->hotwords_cache, name, len);
|
||||
#endif
|
||||
|
||||
log_message(LOG_DEBUG, "vm_create_word: '%.*s' len=%zu total=%zu @%p",
|
||||
(int) len, name, len, total, (void *) entry);
|
||||
@@ -492,9 +520,12 @@ void vm_hide_word(VM *vm) {
|
||||
if (vm && vm->latest) {
|
||||
vm->latest->flags |= WORD_HIDDEN;
|
||||
physics_metadata_refresh_state(vm->latest);
|
||||
/* Visibility changed: this name may now resolve to an older entry */
|
||||
/* Visibility changed: this name may now resolve to an older entry.
|
||||
* §17.3 (item 4.1): retired under __STARKERNEL__. */
|
||||
#ifndef __STARKERNEL__
|
||||
hotwords_cache_evict_name(vm->hotwords_cache,
|
||||
vm->latest->name, vm->latest->name_len);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,9 +539,12 @@ void vm_smudge_word(VM *vm) {
|
||||
}
|
||||
vm->latest->flags ^= WORD_SMUDGED;
|
||||
physics_metadata_refresh_state(vm->latest);
|
||||
/* Visibility changed in either direction: force re-resolution */
|
||||
/* Visibility changed in either direction: force re-resolution.
|
||||
* §17.3 (item 4.1): retired under __STARKERNEL__. */
|
||||
#ifndef __STARKERNEL__
|
||||
hotwords_cache_evict_name(vm->hotwords_cache,
|
||||
vm->latest->name, vm->latest->name_len);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vm_pin_execution_heat(VM *vm) {
|
||||
|
||||
Reference in New Issue
Block a user