starkernel: item 3.5 -- admission and eviction
Punch list §25 item 3.5 complete. stadium_admit(candidate) places into an unused cell if one exists (no comparison needed), otherwise finds the least-dense resident -- skipping pinned and contains-gated patrons, which are never eviction candidates -- and evicts it only if the candidate is strictly denser, per §19.3. stadium_evict(cell_index) dispatches the departing patron's behaviour before clearing its slot, per §17.2. Caught a real bug before it ran: the first draft used contains == 0 to mean "holds nothing," but cell index 0 is a valid index (Hera, item 3.6). Fixed with a proper sentinel, STADIUM_CONTAINS_NONE (UINT32_MAX). A second-pass review found mass was not accounted for: both functions handled exactly one cell regardless of the candidate's stated mass, which leaks cells on eviction of any mass > 1 patron and breaks capacity conservation. Fixed by refusing any candidate with mass != 1 -- multi-cell patrons need the per-VM free lists item 3.2 already deferred (§22.3), not built here. Documented, not fixed: the discriminator bitmap can't distinguish free from continuation cells, so the free-cell scan reads continuation-cell payload bytes under the header layout -- latent since nothing creates continuation cells yet, and the mass != 1 refusal keeps it provably latent. Superseded by the free list when it exists. Unexercised at runtime: nothing calls either function yet (no real patron kind is wired to the Stadium). No self-test added -- filling ~74,000+ cells to reach the eviction-on-full branch was judged impractical, following item 2.2's own precedent for its unexercised fleet-full path. Verified: three-architecture boot (amd64, aarch64, riscv64), all reaching ok> with identical dict_hash=0x3d4e1daf289da94f matching the item-3.4 baseline. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
0b47c256fc
commit
f8a50561b0
@@ -2796,8 +2796,65 @@ document and committing that amendment as its own item.*
|
||||
> `dict_hash=0x3d4e1daf289da94f`, matching the item-3.3 baseline — amd64
|
||||
> (`logs/20260804-171332`), aarch64 (`logs/20260804-171414`), riscv64
|
||||
> (`logs/20260804-171513`).
|
||||
- [ ] **3.5 — Admission and eviction.** Admit if denser than the least dense resident.
|
||||
- [x] **3.5 — Admission and eviction.** Admit if denser than the least dense resident.
|
||||
*Refs:* §19.3.
|
||||
|
||||
> **DONE 2026-08-04.** `stadium_admit(candidate)` and `stadium_evict(cell_index)` in
|
||||
> `stadium.c`. Admission scans for an unused cell first (bitmap bit clear, `mass == 0`) and
|
||||
> places there directly, no comparison needed — §19.3's density rule only governs the full
|
||||
> case. Otherwise finds the least-dense resident, skipping pinned patrons (`flags` bit 0,
|
||||
> §3) and `contains`-gated ones (item 1.1: a patron holding another cannot be reaped), and
|
||||
> evicts it only if the candidate is strictly denser ("denser than," not "at least as dense
|
||||
> as," per §19.3's own wording). Eviction dispatches the departing patron's behaviour
|
||||
> (§18.3) before clearing its slot, per §17.2 ("reap means leaves the floor, not
|
||||
> destroyed").
|
||||
>
|
||||
> **A real bug caught before this ever ran:** the first draft used `contains == 0` to mean
|
||||
> "holds nothing." Cell index 0 is a valid index — Hera, item 3.6's patron zero — so that
|
||||
> conflated "contains Hera" with "contains nothing." Fixed with a proper sentinel,
|
||||
> `STADIUM_CONTAINS_NONE` (`UINT32_MAX`), distinct from every valid index. Caught by
|
||||
> re-reading before compiling, not by any test.
|
||||
>
|
||||
> **A second-pass review (before the boot run) found one blocking gap, fixed, and two
|
||||
> non-blocking ones, recorded rather than fixed:**
|
||||
>
|
||||
> - **Blocking, fixed:** neither function accounted for `mass`. Admission placed exactly
|
||||
> one cell and set exactly one bit regardless of the candidate's stated mass; eviction
|
||||
> symmetrically freed one cell and orphaned the rest. For `mass > 1` (§23.3: a 1024-byte
|
||||
> block is mass 19) this breaks capacity conservation — cells leak on every eviction of a
|
||||
> multi-cell patron, and the "Stadium is full" test becomes wrong since occupancy was
|
||||
> never correctly accounted. The fix is refusal, not implementation:
|
||||
> **`stadium_admit()` now refuses any candidate with `mass != 1`.** A multi-cell patron
|
||||
> needs its continuation chain allocated through the per-VM free lists (§22.3) —
|
||||
> item 3.2's own DONE note already deferred those as out of scope, granted only when Hera
|
||||
> assigns a VM its quota. This item does not build them; it refuses what it can't yet do
|
||||
> correctly rather than doing it wrong.
|
||||
> - **Not fixed, documented as a live latent gap:** the discriminator bitmap can only say
|
||||
> header-vs-not-header, not free-vs-continuation. The free-cell scan
|
||||
> (`!bitmap_get(i) && mass == 0`) reads offsets 28–29 of whatever cell is actually there
|
||||
> under the *header* struct layout; for a real continuation cell those offsets are
|
||||
> payload bytes, and if they happen to read as zero the scan would treat a live
|
||||
> continuation cell as free and overwrite it. Latent, not live: nothing creates
|
||||
> continuation cells yet, and the `mass != 1` refusal above keeps this provably latent
|
||||
> for as long as that refusal stands. The real fix is the free list itself — a cell is
|
||||
> free iff it is on one, no union-punning needed — which supersedes this scan when built.
|
||||
> - **Not fixed, minor:** `stadium_admit()`'s two full-array scans are O(N) each, and
|
||||
> `candidate_density` duplicates `stadium_density()`'s arithmetic inline because the
|
||||
> candidate is not yet in the array to call it on. Both go away with the free list; not
|
||||
> worth a workaround for code with no caller yet.
|
||||
>
|
||||
> **Unexercised at runtime, stated plainly rather than implied by a passing boot:** nothing
|
||||
> calls `stadium_admit()` or `stadium_evict()` yet (no real patron kind is wired to the
|
||||
> Stadium — Phase 4 migration work). No self-test was added: filling ~74,000+ cells to
|
||||
> actually reach the eviction-on-full branch in a boot run was judged impractical for the
|
||||
> value it would add, following the same honesty precedent item 2.2 recorded for its own
|
||||
> unexercised fleet-full path. The free-cell placement branch, the pin/contains skip
|
||||
> logic, and the density-comparison branch have never executed against real data.
|
||||
>
|
||||
> **Regression: clean.** All three architectures boot to `ok>` with identical
|
||||
> `dict_hash=0x3d4e1daf289da94f`, matching the item-3.4 baseline — amd64
|
||||
> (`logs/20260804-172516`), aarch64 (`logs/20260804-172556`), riscv64
|
||||
> (`logs/20260804-172651`).
|
||||
- [ ] **3.6 — Hera as patron zero, pinned.** Assert at the eviction site; selecting Hera is
|
||||
a panic, not a filtered candidate. *Refs:* §20.5 #3.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Capsule Block Manifest — Auto-generated
|
||||
<!-- Generated by mkcapsule --manifest 2026-08-04T21:14:57Z -->
|
||||
<!-- Generated by mkcapsule --manifest 2026-08-04T21:26:36Z -->
|
||||
<!-- DO NOT EDIT — re-run mkcapsule --manifest to refresh. -->
|
||||
<!-- Hand-written justifications and immutability notes live -->
|
||||
<!-- in MANIFEST.md alongside this auto-generated index. -->
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
tick_number,elapsed_ns,tick_interval_ns,cache_hits_delta,bucket_hits_delta,word_executions_delta,hot_word_count,avg_word_heat_q48,window_width,actual_window_size,predicted_label_hits,jitter_bits,apic_ticks,time_trust_q48,variance_q48,vm_call_depth_max,hera_heat_q48,hermes_heat_q48,artemis_heat_q48
|
||||
1,10000,10000,0,0,183,4,45,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
2,20000,10000,0,0,173,5,44,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
3,30000,10000,0,0,184,6,60,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
4,40000,10000,0,0,174,8,71,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
5,50000,10000,0,0,150,9,78,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
6,60000,10000,0,0,159,11,73,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
7,70000,10000,0,0,188,15,71,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
8,80000,10000,0,0,214,16,83,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
9,90000,10000,0,0,216,19,82,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
10,100000,10000,0,0,222,21,84,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
11,110000,10000,0,0,207,23,86,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
12,120000,10000,0,0,189,26,83,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
13,130000,10000,0,0,221,28,80,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
14,140000,10000,0,0,204,29,83,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
15,150000,10000,0,0,203,30,82,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
16,160000,10000,0,0,201,32,83,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
17,170000,10000,0,0,190,34,86,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
18,180000,10000,0,0,170,35,73,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
19,190000,10000,0,0,154,28,44,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
20,200000,10000,0,0,154,28,41,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
21,210000,10000,0,0,153,32,39,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
22,220000,10000,0,0,167,35,42,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
23,230000,10000,0,0,176,37,41,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
24,240000,10000,0,0,175,37,39,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
25,250000,10000,0,0,196,38,37,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
26,260000,10000,0,0,192,41,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
27,270000,10000,0,0,158,40,38,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
28,280000,10000,0,0,158,40,35,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
29,290000,10000,0,0,164,41,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
30,300000,10000,0,0,154,43,39,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
31,310000,10000,0,0,172,46,35,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
32,320000,10000,0,0,180,49,34,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
33,330000,10000,0,0,145,51,35,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
34,340000,10000,0,0,203,53,37,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
35,350000,10000,0,0,154,55,39,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
36,360000,10000,0,0,144,57,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
37,370000,10000,0,0,144,57,35,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
38,380000,10000,0,0,132,57,34,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
39,390000,10000,0,0,180,57,32,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
40,400000,10000,0,0,220,63,29,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
41,410000,10000,0,0,215,64,28,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
42,420000,10000,0,0,208,68,29,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
43,430000,10000,0,0,177,72,27,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
44,440000,10000,0,0,199,77,28,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
45,450000,10000,0,0,223,82,26,4096,30,0,0,0,65536,0,0,65536,0,0
|
||||
46,460000,10000,0,0,202,85,24,4096,67,0,0,0,65536,0,0,65536,0,0
|
||||
47,470000,10000,0,0,218,91,25,4096,198,0,0,0,65536,0,0,65536,0,0
|
||||
48,480000,10000,0,0,221,92,26,4096,350,0,0,0,65536,0,0,65536,0,0
|
||||
49,490000,10000,0,0,225,97,26,4096,528,0,0,0,65536,0,0,65536,0,0
|
||||
50,500000,10000,0,0,214,100,27,4096,694,0,0,0,65536,0,0,65536,0,0
|
||||
51,510000,10000,0,0,227,102,28,4096,883,0,0,0,65536,0,0,65536,0,0
|
||||
52,520000,10000,0,0,208,102,29,4096,1043,0,0,0,65536,0,0,65536,0,0
|
||||
53,530000,10000,0,0,207,102,30,4096,1202,0,0,0,65536,0,0,65536,0,0
|
||||
54,540000,10000,0,0,200,102,31,4096,1319,0,0,0,65536,0,0,65536,0,0
|
||||
55,550000,10000,0,0,205,103,32,4096,1464,0,0,0,65536,0,0,65536,0,0
|
||||
56,560000,10000,0,0,211,103,32,4096,1620,0,0,0,65536,0,0,65536,0,0
|
||||
57,570000,10000,0,0,193,110,33,4096,1712,0,0,0,65536,0,0,65536,0,0
|
||||
58,580000,10000,0,0,190,5,67,4096,1775,0,0,0,65536,0,0,65536,0,0
|
||||
|
@@ -0,0 +1,59 @@
|
||||
tick_number,elapsed_ns,tick_interval_ns,cache_hits_delta,bucket_hits_delta,word_executions_delta,hot_word_count,avg_word_heat_q48,window_width,actual_window_size,predicted_label_hits,jitter_bits,apic_ticks,time_trust_q48,variance_q48,vm_call_depth_max,hera_heat_q48,hermes_heat_q48,artemis_heat_q48
|
||||
1,10000,10000,0,0,183,4,45,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
2,20000,10000,0,0,173,5,44,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
3,30000,10000,0,0,184,6,60,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
4,40000,10000,0,0,174,8,71,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
5,50000,10000,0,0,150,9,78,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
6,60000,10000,0,0,159,11,73,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
7,70000,10000,0,0,188,15,71,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
8,80000,10000,0,0,214,16,83,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
9,90000,10000,0,0,216,19,82,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
10,100000,10000,0,0,222,21,84,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
11,110000,10000,0,0,207,23,86,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
12,120000,10000,0,0,189,26,83,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
13,130000,10000,0,0,221,28,80,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
14,140000,10000,0,0,204,29,83,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
15,150000,10000,0,0,203,30,82,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
16,160000,10000,0,0,201,32,83,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
17,170000,10000,0,0,190,34,86,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
18,180000,10000,0,0,170,35,73,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
19,190000,10000,0,0,154,28,44,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
20,200000,10000,0,0,154,28,41,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
21,210000,10000,0,0,153,32,39,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
22,220000,10000,0,0,167,35,42,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
23,230000,10000,0,0,176,37,41,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
24,240000,10000,0,0,175,37,39,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
25,250000,10000,0,0,196,38,37,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
26,260000,10000,0,0,192,41,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
27,270000,10000,0,0,158,40,38,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
28,280000,10000,0,0,158,40,35,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
29,290000,10000,0,0,164,41,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
30,300000,10000,0,0,154,43,39,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
31,310000,10000,0,0,172,46,35,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
32,320000,10000,0,0,180,49,34,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
33,330000,10000,0,0,145,51,35,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
34,340000,10000,0,0,203,53,37,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
35,350000,10000,0,0,154,55,39,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
36,360000,10000,0,0,144,57,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
37,370000,10000,0,0,144,57,35,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
38,380000,10000,0,0,132,57,34,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
39,390000,10000,0,0,180,57,32,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
40,400000,10000,0,0,220,63,29,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
41,410000,10000,0,0,215,64,28,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
42,420000,10000,0,0,208,68,29,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
43,430000,10000,0,0,177,72,27,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
44,440000,10000,0,0,199,77,28,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
45,450000,10000,0,0,223,82,26,4096,30,0,0,0,65536,0,0,65536,0,0
|
||||
46,460000,10000,0,0,202,85,24,4096,67,0,0,0,65536,0,0,65536,0,0
|
||||
47,470000,10000,0,0,218,91,25,4096,198,0,0,0,65536,0,0,65536,0,0
|
||||
48,480000,10000,0,0,221,92,26,4096,350,0,0,0,65536,0,0,65536,0,0
|
||||
49,490000,10000,0,0,225,97,26,4096,528,0,0,0,65536,0,0,65536,0,0
|
||||
50,500000,10000,0,0,214,100,27,4096,694,0,0,0,65536,0,0,65536,0,0
|
||||
51,510000,10000,0,0,227,102,28,4096,883,0,0,0,65536,0,0,65536,0,0
|
||||
52,520000,10000,0,0,208,102,29,4096,1043,0,0,0,65536,0,0,65536,0,0
|
||||
53,530000,10000,0,0,207,102,30,4096,1202,0,0,0,65536,0,0,65536,0,0
|
||||
54,540000,10000,0,0,200,102,31,4096,1319,0,0,0,65536,0,0,65536,0,0
|
||||
55,550000,10000,0,0,205,103,32,4096,1464,0,0,0,65536,0,0,65536,0,0
|
||||
56,560000,10000,0,0,211,103,32,4096,1620,0,0,0,65536,0,0,65536,0,0
|
||||
57,570000,10000,0,0,193,110,33,4096,1712,0,0,0,65536,0,0,65536,0,0
|
||||
58,580000,10000,0,0,190,5,67,4096,1775,0,0,0,65536,0,0,65536,0,0
|
||||
|
@@ -0,0 +1,59 @@
|
||||
tick_number,elapsed_ns,tick_interval_ns,cache_hits_delta,bucket_hits_delta,word_executions_delta,hot_word_count,avg_word_heat_q48,window_width,actual_window_size,predicted_label_hits,jitter_bits,apic_ticks,time_trust_q48,variance_q48,vm_call_depth_max,hera_heat_q48,hermes_heat_q48,artemis_heat_q48
|
||||
1,10000,10000,0,0,183,4,45,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
2,20000,10000,0,0,173,5,44,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
3,30000,10000,0,0,184,6,60,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
4,40000,10000,0,0,174,8,71,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
5,50000,10000,0,0,150,9,78,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
6,60000,10000,0,0,159,11,73,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
7,70000,10000,0,0,188,15,71,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
8,80000,10000,0,0,214,16,83,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
9,90000,10000,0,0,216,19,82,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
10,100000,10000,0,0,222,21,84,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
11,110000,10000,0,0,207,23,86,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
12,120000,10000,0,0,189,26,83,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
13,130000,10000,0,0,221,28,80,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
14,140000,10000,0,0,204,29,83,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
15,150000,10000,0,0,203,30,82,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
16,160000,10000,0,0,201,32,83,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
17,170000,10000,0,0,190,34,86,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
18,180000,10000,0,0,170,35,73,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
19,190000,10000,0,0,154,28,44,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
20,200000,10000,0,0,154,28,41,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
21,210000,10000,0,0,153,32,39,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
22,220000,10000,0,0,167,35,42,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
23,230000,10000,0,0,176,37,41,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
24,240000,10000,0,0,175,37,39,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
25,250000,10000,0,0,196,38,37,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
26,260000,10000,0,0,192,41,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
27,270000,10000,0,0,158,40,38,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
28,280000,10000,0,0,158,40,35,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
29,290000,10000,0,0,164,41,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
30,300000,10000,0,0,154,43,39,685,685,0,0,0,65536,0,0,65536,0,0
|
||||
31,310000,10000,0,0,172,46,35,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
32,320000,10000,0,0,180,49,34,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
33,330000,10000,0,0,145,51,35,567,567,0,0,0,65536,0,0,65536,0,0
|
||||
34,340000,10000,0,0,203,53,37,582,582,0,0,0,65536,0,0,65536,0,0
|
||||
35,350000,10000,0,0,154,55,39,731,731,0,0,0,65536,0,0,65536,0,0
|
||||
36,360000,10000,0,0,144,57,37,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
37,370000,10000,0,0,144,57,35,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
38,380000,10000,0,0,132,57,34,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
39,390000,10000,0,0,180,57,32,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
40,400000,10000,0,0,220,63,29,4096,0,0,0,0,65536,0,0,65536,0,0
|
||||
41,410000,10000,0,0,215,64,28,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
42,420000,10000,0,0,208,68,29,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
43,430000,10000,0,0,177,72,27,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
44,440000,10000,0,0,199,77,28,4096,24,0,0,0,65536,0,0,65536,0,0
|
||||
45,450000,10000,0,0,223,82,26,4096,30,0,0,0,65536,0,0,65536,0,0
|
||||
46,460000,10000,0,0,202,85,24,4096,67,0,0,0,65536,0,0,65536,0,0
|
||||
47,470000,10000,0,0,218,91,25,4096,198,0,0,0,65536,0,0,65536,0,0
|
||||
48,480000,10000,0,0,221,92,26,4096,350,0,0,0,65536,0,0,65536,0,0
|
||||
49,490000,10000,0,0,225,97,26,4096,528,0,0,0,65536,0,0,65536,0,0
|
||||
50,500000,10000,0,0,214,100,27,4096,694,0,0,0,65536,0,0,65536,0,0
|
||||
51,510000,10000,0,0,227,102,28,4096,883,0,0,0,65536,0,0,65536,0,0
|
||||
52,520000,10000,0,0,208,102,29,4096,1043,0,0,0,65536,0,0,65536,0,0
|
||||
53,530000,10000,0,0,207,102,30,4096,1202,0,0,0,65536,0,0,65536,0,0
|
||||
54,540000,10000,0,0,200,102,31,4096,1319,0,0,0,65536,0,0,65536,0,0
|
||||
55,550000,10000,0,0,205,103,32,4096,1464,0,0,0,65536,0,0,65536,0,0
|
||||
56,560000,10000,0,0,211,103,32,4096,1620,0,0,0,65536,0,0,65536,0,0
|
||||
57,570000,10000,0,0,193,110,33,4096,1712,0,0,0,65536,0,0,65536,0,0
|
||||
58,580000,10000,0,0,190,5,67,4096,1775,0,0,0,65536,0,0,65536,0,0
|
||||
|
@@ -40,6 +40,11 @@
|
||||
|
||||
#define STADIUM_CELL_BYTES 64
|
||||
|
||||
/* Sentinel for `contains` meaning "holds no patron." Not 0 -- cell index 0 is
|
||||
* a valid index (Hera, item 3.6), so 0 cannot double as "none" without
|
||||
* conflating "contains Hera" with "contains nothing." */
|
||||
#define STADIUM_CONTAINS_NONE ((uint32_t)-1)
|
||||
|
||||
/*
|
||||
* StadiumPatronHeader - one member of the closed two-valued cell union
|
||||
* (FABRIC.md §3). Nine wires: identity, heat, TTL, pin (a bit in `flags`),
|
||||
@@ -58,9 +63,12 @@ typedef struct {
|
||||
uint64_t heat; /* offset 8 -- Q48.16, conserved share of 1.0 (§19.1) */
|
||||
uint32_t ttl; /* offset 16 -- remaining lifetime; messages and ACLs only (§17.1) */
|
||||
uint32_t link; /* offset 20 -- index into the Stadium, not a pointer */
|
||||
uint32_t contains; /* offset 24 -- index of the patron held inside this one, or none (item 1.1).
|
||||
* Chains up to STADIUM_CONTAINS_DEPTH_MAX deep; reap-gating
|
||||
* enforcement of that bound is item 3.5's scope, not this one's. */
|
||||
uint32_t contains; /* offset 24 -- index of the patron held inside this one, or
|
||||
* STADIUM_CONTAINS_NONE (item 1.1). Cell index 0 is a valid
|
||||
* index (Hera, item 3.6) so 0 cannot mean "none" -- item 3.5
|
||||
* caught this and picked UINT32_MAX instead. Chains up to
|
||||
* STADIUM_CONTAINS_DEPTH_MAX deep; reap-gating enforcement of
|
||||
* that bound is item 3.5's scope. */
|
||||
uint16_t mass; /* offset 28 -- cells this patron occupies (§19.2) */
|
||||
uint8_t flags; /* offset 30 -- bit 0 = pin; remaining bits reserved */
|
||||
uint8_t behaviour; /* offset 31 -- code field. Valid values are StadiumBehaviour (§18.3)
|
||||
@@ -201,6 +209,67 @@ void stadium_dispatch(size_t cell_index, StadiumBehaviour behaviour);
|
||||
*/
|
||||
uint64_t stadium_density(size_t cell_index);
|
||||
|
||||
/* Sentinel returned by stadium_admit() on refusal -- no cell index is this large. */
|
||||
#define STADIUM_CELL_NONE ((size_t)-1)
|
||||
|
||||
/*
|
||||
* stadium_evict - Reap the patron header at cell_index (FABRIC.md §17.2:
|
||||
* "reap means leaves the floor, not destroyed"). Dispatches its behaviour
|
||||
* (§18.3), clears its item-3.1 discriminator bit, zeroes its header.
|
||||
*
|
||||
* Refuses if the header is pinned (`flags` bit 0, §3's invariance wire) or
|
||||
* has a non-none `contains` (item 1.1: a patron holding another cannot be
|
||||
* reaped, full stop). Also refuses for an out-of-range index or a cell whose
|
||||
* discriminator bit is not set (nothing resident there to reap).
|
||||
*
|
||||
* @param cell_index Index of the patron header to reap.
|
||||
* @return 0 on success, -1 if refused.
|
||||
*/
|
||||
int stadium_evict(size_t cell_index);
|
||||
|
||||
/*
|
||||
* stadium_admit - Place a candidate patron header into the Stadium (FABRIC.md
|
||||
* §19.3).
|
||||
*
|
||||
* First scans for an unused cell (discriminator bit clear and mass == 0) and
|
||||
* places the candidate there directly -- §19.3's density comparison only
|
||||
* governs the full case, not this one. If none is free, finds the
|
||||
* least-dense resident (discriminator bit set, mass > 0, not pinned, not
|
||||
* `contains`-gated -- pinned and gated residents are never eviction
|
||||
* candidates, per §3 and item 1.1) and evicts it via stadium_evict() only if
|
||||
* the candidate is strictly denser (§19.3: "denser than," not "at least as
|
||||
* dense as"). Otherwise refuses.
|
||||
*
|
||||
* Does not itself assert anything about which resident this turns out to be
|
||||
* -- the item-3.6 rule that patron zero (Hera) must never actually be
|
||||
* selected is a separate, later check at the eviction site.
|
||||
*
|
||||
* REFUSES any candidate with mass != 1. A multi-cell patron (mass > 1, e.g.
|
||||
* §23.3's 1024-byte block at mass 19) needs its continuation chain allocated
|
||||
* too, which needs the per-VM free lists §22.3 describes -- item 3.2's DONE
|
||||
* note already deferred those (not this item's scope, they are granted when
|
||||
* Hera assigns a VM its quota). Admitting only the header and leaking the
|
||||
* rest would break capacity conservation, so this refuses rather than doing
|
||||
* that. Revisit when the free lists exist.
|
||||
*
|
||||
* REQUIRES candidate->contains to be either STADIUM_CONTAINS_NONE or a valid
|
||||
* index (< the current cell count) -- refuses otherwise. This does NOT catch
|
||||
* a zero-initialized candidate that was meant to contain nothing: 0 is a
|
||||
* valid index (Hera), so a caller that forgets to set `contains` explicitly
|
||||
* to STADIUM_CONTAINS_NONE will admit a patron that reads as "contains
|
||||
* Hera" and is therefore permanently un-evictable. There is no way to tell
|
||||
* "meant to be 0" from "forgot to set it" from inside this function --
|
||||
* callers must set every field, `contains` included.
|
||||
*
|
||||
* @param candidate Header to admit. Copied into the winning cell as-is;
|
||||
* caller fills in every field including mass and heat.
|
||||
* @return The cell index admitted into, or STADIUM_CELL_NONE if refused
|
||||
* (mass != 1, invalid contains, Stadium full and candidate not
|
||||
* denser than the least-dense evictable resident, or no evictable
|
||||
* resident exists at all).
|
||||
*/
|
||||
size_t stadium_admit(const StadiumPatronHeader *candidate);
|
||||
|
||||
#endif /* __STARKERNEL__ */
|
||||
|
||||
#endif /* STARKERNEL_VM_STADIUM_H */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -169,4 +169,111 @@ uint64_t stadium_density(size_t cell_index) {
|
||||
return header->heat / (uint64_t)header->mass;
|
||||
}
|
||||
|
||||
#define STADIUM_FLAG_PIN 0x01u
|
||||
|
||||
static int bitmap_get(size_t cell_index) {
|
||||
return (stadium_bitmap[cell_index / 8u] >> (cell_index % 8u)) & 1u;
|
||||
}
|
||||
|
||||
static void bitmap_set(size_t cell_index) {
|
||||
stadium_bitmap[cell_index / 8u] |= (uint8_t)(1u << (cell_index % 8u));
|
||||
}
|
||||
|
||||
static void bitmap_clear(size_t cell_index) {
|
||||
stadium_bitmap[cell_index / 8u] &= (uint8_t)~(1u << (cell_index % 8u));
|
||||
}
|
||||
|
||||
/*
|
||||
* FABRIC.md §17.2: reap means leaves the floor, not destroyed. Refuses a
|
||||
* pinned header (§3) or one with a non-none `contains` (item 1.1: a patron
|
||||
* holding another cannot be reaped). Refuses an out-of-range index or a cell
|
||||
* whose discriminator bit is not set -- nothing resident there to reap.
|
||||
*/
|
||||
int stadium_evict(size_t cell_index) {
|
||||
StadiumPatronHeader *header;
|
||||
|
||||
if (cell_index >= stadium_ncells) return -1;
|
||||
if (!bitmap_get(cell_index)) return -1;
|
||||
|
||||
header = &stadium_cell_array[cell_index].header;
|
||||
if (header->flags & STADIUM_FLAG_PIN) return -1;
|
||||
if (header->contains != STADIUM_CONTAINS_NONE) return -1;
|
||||
|
||||
stadium_dispatch(cell_index, (StadiumBehaviour)header->behaviour);
|
||||
bitmap_clear(cell_index);
|
||||
|
||||
{
|
||||
uint8_t *raw = (uint8_t *)header;
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(*header); i++) raw[i] = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* FABRIC.md §19.3: admit if denser than the least-dense resident. Free-cell
|
||||
* placement first (no comparison needed -- §19.3 only governs the full
|
||||
* case); otherwise finds the least-dense evictable resident (pinned and
|
||||
* contains-gated residents are skipped, never eviction candidates) and
|
||||
* evicts it only if the candidate is strictly denser.
|
||||
*/
|
||||
size_t stadium_admit(const StadiumPatronHeader *candidate) {
|
||||
size_t i;
|
||||
size_t least_dense_index = STADIUM_CELL_NONE;
|
||||
uint64_t least_dense_value = 0;
|
||||
uint64_t candidate_density;
|
||||
|
||||
if (!stadium_initialized || !candidate) return STADIUM_CELL_NONE;
|
||||
|
||||
/* Multi-cell patrons need their continuation chain allocated too, which
|
||||
* needs the per-VM free lists item 3.2 deferred (§22.3) -- not this
|
||||
* item's scope. Refuse rather than admit only the header and leak the
|
||||
* rest, which would break capacity conservation. */
|
||||
if (candidate->mass != 1) return STADIUM_CELL_NONE;
|
||||
|
||||
/* contains must be a real "none" or a real index -- catches garbage/
|
||||
* uninitialized values, though not a zero-initialized candidate that
|
||||
* meant "none": 0 is Hera's valid index, so that case is a caller
|
||||
* contract issue this function cannot detect (see the header doc). */
|
||||
if (candidate->contains != STADIUM_CONTAINS_NONE &&
|
||||
candidate->contains >= stadium_ncells) return STADIUM_CELL_NONE;
|
||||
|
||||
for (i = 0; i < stadium_ncells; i++) {
|
||||
if (!bitmap_get(i) && stadium_cell_array[i].header.mass == 0) {
|
||||
stadium_cell_array[i].header = *candidate;
|
||||
bitmap_set(i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < stadium_ncells; i++) {
|
||||
StadiumPatronHeader *h;
|
||||
|
||||
if (!bitmap_get(i)) continue;
|
||||
h = &stadium_cell_array[i].header;
|
||||
if (h->flags & STADIUM_FLAG_PIN) continue;
|
||||
if (h->contains != STADIUM_CONTAINS_NONE) continue;
|
||||
|
||||
{
|
||||
uint64_t d = stadium_density(i);
|
||||
if (least_dense_index == STADIUM_CELL_NONE || d < least_dense_value) {
|
||||
least_dense_index = i;
|
||||
least_dense_value = d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (least_dense_index == STADIUM_CELL_NONE) return STADIUM_CELL_NONE;
|
||||
|
||||
candidate_density = candidate->mass ? (candidate->heat / (uint64_t)candidate->mass) : 0;
|
||||
if (candidate_density <= least_dense_value) return STADIUM_CELL_NONE;
|
||||
|
||||
if (stadium_evict(least_dense_index) != 0) return STADIUM_CELL_NONE;
|
||||
|
||||
stadium_cell_array[least_dense_index].header = *candidate;
|
||||
bitmap_set(least_dense_index);
|
||||
return least_dense_index;
|
||||
}
|
||||
|
||||
#endif /* __STARKERNEL__ */
|
||||
Reference in New Issue
Block a user