diff --git a/.crumb b/.crumb index a5ac3e68..b40be82e 100644 --- a/.crumb +++ b/.crumb @@ -22,38 +22,38 @@ "children": [ { "digest": "505f0368767022d22d0d58e4911c9f5d32b0db78af9176aacf5ce52ce1801f25", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "crates", "purpose": "Directory crates. Purpose not yet described by a human." }, { "digest": "203bf6275590e6a8f0179d1c7904673f576265db144ebf6f1c7b0306a1d67304", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { - "digest": "dc0c8a2262594253b77df2dc74efed04ade1145396308cdab8f78e9a3ddd5955", - "last_commit": "621c9e6f", + "digest": "ad0b540d1236966d9319033c32838fa527a13fd6307c515df4c80cfa5f081dd7", + "last_commit": "5291a4a5", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { - "digest": "0794e1ad2bcb73135f89ff006231c855c3d8aec44b90e10b4e9f252bed562f2b", - "last_commit": "621c9e6f", + "digest": "32aaad6e964ad6c1c00c770d113053dfe55fea96d5cc00cb48b98e4835f9ae9c", + "last_commit": "9e48cf84", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:14b5a4b7f16c441c86bcdaa081ed05d7ee67f9685b7058e9ca2476ca9797f655", - "compiled_at": "2026-10-24T04:15:32Z", + "children_root": "sha256:d789de698ad393f6558e47400bd41d72e67542bc1d3f58ecdefbf2d6099ee763", + "compiled_at": "2026-10-24T17:40:38Z", "compiler": "crumb-compile/1", - "digest": "sha256:6939c94ff0f2ae45579a426c2b2698f561f14bbbc4dcca5f17f29d2d76f221b6", - "evidence_files": 211, - "evidence_root": "sha256:3a8f56415109a697e4beb6048c85805c50c9c6c4089629057f4e8b3e76863981", - "files": 3491, - "generated_at_commit": "621c9e6fe430ee689836bee3ee2689d7d32e0f7d", - "source_tree": "sha256:a346c4206d136936b51181566e826e4567df47a2504dea8be8c4951f1dcd7ebc" + "digest": "sha256:278ef0122f9e31e1c41323fcb1d34b065248145c2fa0f82c4a02eabefd20878b", + "evidence_files": 216, + "evidence_root": "sha256:88ba864f439c06750b936b281f5958c12cbfb47f3c0cc8024c2f58e442dfeb24", + "files": 3496, + "generated_at_commit": "ad77d8134db082bc013cfde92835cef8d43ddc80", + "source_tree": "sha256:eee69fabc2c93b81b5e29428c53a9d073f3ec6bdd8862177facdfede040e30d8" }, "owner_lane": "", "provenance": { diff --git a/evidence/timer_window_starvation_2026-10-19/README.md b/evidence/timer_window_starvation_2026-10-19/README.md new file mode 100644 index 00000000..977cbedb --- /dev/null +++ b/evidence/timer_window_starvation_2026-10-19/README.md @@ -0,0 +1,31 @@ +# M1 timer window starvation (aienos#434 gate AIENOS-CK-QEMU-GATES, rc_nonzero), 2026-10-19 + +## Symptom +Judge run of aienos#434 head 49e6f6a: `AIENOS-CK-QEMU-GATES` FAIL rc_nonzero. The failing child was the +Allen gate (`[allen] exit 1`), whose M1 checks (`scripts/lib_ck_m1_checks.sh`) rejected the timer window: +"timer IRQ delivered fewer than five ticks" or "tick statistics out of range". The same head passes +when the Spark is quiet (5/5 `qemu_ck_allen_test.sh` runs PASS), so the code under test was not at fault. + +## Cause +`ck_timer_window` is wall-clock (200 ms). QEMU TCG shares the Spark with the whole hive (load 20 to 67). +A starved vCPU runs fewer than five 10 ms ticks inside the 200 ms window, and `ck_timer_tick` read the +counter a second time after re-arming, so a host stall between the two reads made one interval long and the +next one short (min_us as low as 9 against a 10000 us period). + +## Fix (native/kernel/arch/timer.c, scripts/ck_gates.sh) +1. An interval runs from IRQ entry to IRQ entry, the same counter value the next deadline is built from, so + it is never shorter than the period. +2. The window keeps counting, up to 5 s, until five ticks have arrived. A dead timer still reports 0 ticks. +3. A failing child's own FAIL lines are now copied into the gate's evidence blob (the child log lives in a + temp folder that is removed at exit, which is why the first failure could not be read afterwards). + +## Measurement (Spark, 20 boots of `scripts/qemu_ck_boot_test.sh` per arm, pinned to CPU 3 with 5 busy loops +on the same CPU at the same nice level; `pinned-stress.sh`) +| arm | pass | fail | +|---|---|---| +| before the fix (origin/main 18e2765) | 2 | 18 | +| after the fix (fix/timer-window-starvation) | 20 | 0 | + +Red: `red-before-fix-fails.txt`, `red-before-fix-stats.txt`. Green: `green-after-fix-stats.txt`. +Quiet machine, 5 runs of the Allen gate before the fix: 5/5 PASS (so the fix changes nothing when idle). +Also run after the fix: `scripts/ck_gates.sh --self-test` PASS, `make -C native/kernel test` PASS (CK_CORE_HOST). diff --git a/evidence/timer_window_starvation_2026-10-19/green-after-fix-stats.txt b/evidence/timer_window_starvation_2026-10-19/green-after-fix-stats.txt new file mode 100644 index 00000000..7b050800 --- /dev/null +++ b/evidence/timer_window_starvation_2026-10-19/green-after-fix-stats.txt @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/evidence/timer_window_starvation_2026-10-19/pinned-stress.sh b/evidence/timer_window_starvation_2026-10-19/pinned-stress.sh new file mode 100644 index 00000000..0dded3dd --- /dev/null +++ b/evidence/timer_window_starvation_2026-10-19/pinned-stress.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# usage: pinned-stress.sh WORKTREE N HOGS TAG : N boot tests pinned to CPU 3 with HOGS busy loops on CPU 3 (same nice), counts FAILs +cd "$1" || exit 1 +D=$HOME/workspace/hermes-desk/allen-logs/$4; mkdir -p "$D"; : > "$D/fails.txt" +for i in $(seq 1 "$3"); do timeout 1200 taskset -c 3 nice -n 19 sh -c 'while :; do :; done' & done +pass=0; fail=0 +for i in $(seq 1 "$2"); do + taskset -c 3 nice -n 19 bash scripts/qemu_ck_boot_test.sh > "$D/run-$i.txt" 2>&1 + rc=$? + if [ $rc = 0 ]; then pass=$((pass+1)); else fail=$((fail+1)); echo "run $i rc=$rc" >> "$D/fails.txt"; grep -h "^FAIL" "$D/run-$i.txt" >> "$D/fails.txt"; fi + grep -h "timer_irq\|timer_stats" "$D/run-$i.txt" | tr '\n' ' ' >> "$D/stats.txt"; echo >> "$D/stats.txt" +done +echo "$4 pass=$pass fail=$fail" >> $HOME/workspace/hermes-desk/allen-logs/summary.txt +kill $(jobs -p) 2>/dev/null diff --git a/evidence/timer_window_starvation_2026-10-19/red-before-fix-fails.txt b/evidence/timer_window_starvation_2026-10-19/red-before-fix-fails.txt new file mode 100644 index 00000000..e04b0407 --- /dev/null +++ b/evidence/timer_window_starvation_2026-10-19/red-before-fix-fails.txt @@ -0,0 +1,38 @@ +run 1 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 2 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 3 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 4 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 5 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 6 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 7 rc=1 +FAIL timer IRQ delivered fewer than five ticks +FAIL tick statistics out of range: timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=0 avg_us=0 max_us=0 +run 10 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 11 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 12 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 13 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 14 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 15 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 16 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 17 rc=1 +FAIL timer IRQ delivered fewer than five ticks +FAIL tick statistics out of range: timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=0 avg_us=0 max_us=0 +run 18 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 19 rc=1 +FAIL timer IRQ delivered fewer than five ticks +run 20 rc=1 +FAIL timer IRQ delivered fewer than five ticks diff --git a/evidence/timer_window_starvation_2026-10-19/red-before-fix-stats.txt b/evidence/timer_window_starvation_2026-10-19/red-before-fix-stats.txt new file mode 100644 index 00000000..8e1b3f15 --- /dev/null +++ b/evidence/timer_window_starvation_2026-10-19/red-before-fix-stats.txt @@ -0,0 +1,20 @@ +timer_irq: 3 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=22261 avg_us=63425 max_us=127049 +timer_irq: 2 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=22671 avg_us=99331 max_us=175990 +timer_irq: 1 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=189039 avg_us=189039 max_us=189039 +timer_irq: 1 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=251606 avg_us=251606 max_us=251606 +timer_irq: 2 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=28106 avg_us=127561 max_us=227016 +timer_irq: 2 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=18965 avg_us=65979 max_us=112993 +FAIL tick statistics out of range: timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=0 avg_us=0 max_us=0 timer_irq: 0 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=0 avg_us=0 max_us=0 + + +timer_irq: 1 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=64112 avg_us=64112 max_us=64112 +timer_irq: 1 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=234449 avg_us=234449 max_us=234449 +timer_irq: 1 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=128576 avg_us=128576 max_us=128576 +timer_irq: 3 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=18093 avg_us=67359 max_us=120038 +timer_irq: 3 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=61419 avg_us=83425 max_us=126006 +timer_irq: 2 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=63812 avg_us=125928 max_us=188044 +timer_irq: 2 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=120501 avg_us=124589 max_us=128677 +FAIL tick statistics out of range: timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=0 avg_us=0 max_us=0 timer_irq: 0 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=0 avg_us=0 max_us=0 +timer_irq: 2 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=62871 avg_us=125027 max_us=187183 +timer_irq: 2 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=63837 avg_us=125671 max_us=187505 +timer_irq: 1 ticks in 200 ms timer_stats: intid=30 freq_hz=62500000 period_us=10000 min_us=62338 avg_us=62338 max_us=62338 diff --git a/native/.crumb b/native/.crumb index 7c06e124..6c84d922 100644 --- a/native/.crumb +++ b/native/.crumb @@ -50,74 +50,74 @@ "children": [ { "digest": "9a550a7209350cc658a55708701504f70b54c461e672243bebf48d50c52c1c70", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "argus", "purpose": "Directory native/argus. Purpose not yet described by a human." }, { "digest": "62678ee88494d4f5fab2a67d68edded631793eecbe46bc470db7941e220cba04", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "boot", "purpose": "Directory native/boot. Purpose not yet described by a human." }, { "digest": "1b5414c184e37d4d943e7979db3d82f1441d6004bb9b5c379a4e4e39381fe7fd", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "capability", "purpose": "Directory native/capability. Purpose not yet described by a human." }, { "digest": "5ee5fb66726b423c9a8a15d6b6f8c2ac08092727f386c32015f3fb14fe258079", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "crypto", "purpose": "Directory native/crypto. Purpose not yet described by a human." }, { "digest": "c4ce5c38d99a4f4fbbaf8f829817511aa6ba94d92318ba4f638eddd485341eb0", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "disk", "purpose": "Directory native/disk. Purpose not yet described by a human." }, { - "digest": "f951cbac83635abdd46bd86bd9b0d6374fc8e578c73b4eab3661ec87e673445f", - "last_commit": "621c9e6f", + "digest": "77047afc7d4f7c70b090d9b6717eb21cb2f6031ed386a5750a15f0cd88a33425", + "last_commit": "5291a4a5", "name": "kernel", "purpose": "Directory native/kernel. Purpose not yet described by a human." }, { "digest": "257e53b395e1f417a61838914d73ebbf408361083e9e40ca3b56011e1f9754c4", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "m5", "purpose": "Directory native/m5. Purpose not yet described by a human." }, { "digest": "f9c2453f4a79f6f4f27e6761cc2cdfc0431fb698be73a7f8869b5d6580e96d9d", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "net", "purpose": "Directory native/net. Purpose not yet described by a human." }, { "digest": "e89066d6aa5c09de6f67671846971d09cf733e4620f713983ff29fae60321c9e", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "sig", "purpose": "Directory native/sig. Purpose not yet described by a human." }, { "digest": "325fec79752c7be76550de52f400c5cc35d4641de8dc45290cff10ddc526fa3b", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "store", "purpose": "Directory native/store. Purpose not yet described by a human." } ], - "children_root": "sha256:d75d511db1dd85271720d1ab237b4be4f9c7c6a2c81c73c0712402165452b0f1", - "compiled_at": "2026-10-24T04:15:32Z", + "children_root": "sha256:04fc6765a8f988da93b5e2ebd1023727a42445137c157cf55a07111c91ae9959", + "compiled_at": "2026-10-24T17:40:38Z", "compiler": "crumb-compile/1", - "digest": "sha256:dc0c8a2262594253b77df2dc74efed04ade1145396308cdab8f78e9a3ddd5955", + "digest": "sha256:ad0b540d1236966d9319033c32838fa527a13fd6307c515df4c80cfa5f081dd7", "evidence_files": 4, "evidence_root": "sha256:e410b845507e00568e15b51a5797af32a97e0e4b8ab4e8487bb7c98e7e0cf335", "files": 606, - "generated_at_commit": "621c9e6fe430ee689836bee3ee2689d7d32e0f7d", - "source_tree": "sha256:2129937e2c82b7365b920dbe8c917aee97b0c792286d253235244a129c385e54" + "generated_at_commit": "ad77d8134db082bc013cfde92835cef8d43ddc80", + "source_tree": "sha256:ca85e5af268234f69c6641628f904b05f1e0e44ef25f9ea1d8581ab4dcb5ed3b" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/.crumb b/native/kernel/.crumb index 890c738c..8d38d53c 100644 --- a/native/kernel/.crumb +++ b/native/kernel/.crumb @@ -45,69 +45,69 @@ "generated": { "children": [ { - "digest": "7fbcf8cfb77799807b2a55611e2a3f6563d9c2403aac467868dfa685ce46cfe2", - "last_commit": "621c9e6f", + "digest": "aa16ee3dab6c71bf912686eef4e763743d26883addadc7ca4371eb8545b513aa", + "last_commit": "9e48cf84", "name": "arch", "purpose": "Directory native/kernel/arch. Purpose not yet described by a human." }, { "digest": "de009659b554bfb75b093c0b62567ed58238731e3ce4c457008fcc2be1488b89", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "artifact", "purpose": "Directory native/kernel/artifact. Purpose not yet described by a human." }, { "digest": "260dd9252422aaa6f636c8665c2b403126dc7a48e8177968be612420fd278add", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "core", "purpose": "Directory native/kernel/core. Purpose not yet described by a human." }, { "digest": "eb3146a026248b54faa150003192fcc43ab2bd9b01d3c0d0c120c2d5bbe2b453", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "dev", "purpose": "Directory native/kernel/dev. Purpose not yet described by a human." }, { "digest": "54cee35b405dc1c90f62d4d227ed172142abfd4917e720708ba0b83b94b9376e", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "include", "purpose": "Directory native/kernel/include. Purpose not yet described by a human." }, { "digest": "c7dc6acbe30f21ef0d3983d31b212f89ff23ae6e56862a2718d98fd28c76649a", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "mm", "purpose": "Directory native/kernel/mm. Purpose not yet described by a human." }, { "digest": "7d1c2af30b802a41a46b1b70250cdaa855ba8c579ce5c870de452980e161cbfb", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "svc", "purpose": "Directory native/kernel/svc. Purpose not yet described by a human." }, { "digest": "8d2fb81be11b693b4924e441d5365371d48d868c78e38ab2d146d68739aade36", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "tests", "purpose": "Directory native/kernel/tests. Purpose not yet described by a human." }, { "digest": "161f0b797ac718a09d619e04330a1b55aced4690cb59727bbd566a9b86aaad77", - "last_commit": "621c9e6f", + "last_commit": "f45d00ad", "name": "tools", "purpose": "Hosted (Linux-built) checkers for the native kernel, run by `make -C native/kernel test`; nothin" } ], - "children_root": "sha256:2891cf6ca7116bff9ce212b37abfde7d22d78073138c80071b867f2af4dca60c", - "compiled_at": "2026-10-24T04:15:32Z", + "children_root": "sha256:864aeea48738a256559f15de154300386742e590a5d4a48572a438475fa891fd", + "compiled_at": "2026-10-24T17:40:38Z", "compiler": "crumb-compile/1", - "digest": "sha256:f951cbac83635abdd46bd86bd9b0d6374fc8e578c73b4eab3661ec87e673445f", + "digest": "sha256:77047afc7d4f7c70b090d9b6717eb21cb2f6031ed386a5750a15f0cd88a33425", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 421, - "generated_at_commit": "621c9e6fe430ee689836bee3ee2689d7d32e0f7d", - "source_tree": "sha256:117f6c2cb335c6f1e79b58e8a5b6f819c10456bca62b74bc1498f8dae72168d6" + "generated_at_commit": "ad77d8134db082bc013cfde92835cef8d43ddc80", + "source_tree": "sha256:f53f5939706589c4897125cd09afd46018f0814c6f59f7f3b0e3b6da6bd3a960" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/README.md b/native/kernel/README.md index 9b30cc2f..e044fcbd 100644 --- a/native/kernel/README.md +++ b/native/kernel/README.md @@ -494,7 +494,7 @@ a FAIL to report, not to retry. 3. `ck_enter_el1`: EL2 -> EL1h with the MMU already on our tables. 4. EL1: `mmu: enabled`, `mmu_switch: ...` read back from the registers, heap check, guard-page self test, GICv3 from the MADT, 200 ms timer window - (INTID 30, 10 ms period), `kernel: alive`, `kernel_el: EL1h`. + (INTID 30, 10 ms period; on a starved emulator the window keeps counting up to 5 s until five ticks arrived, and each interval is measured from IRQ entry, so a host stall cannot produce a short interval), `kernel: alive`, `kernel_el: EL1h`. 5. Stages, in order, if linked: `ck_stage_devices`, `ck_stage_security`, `ck_stage_store`. Each prints `stage : ok`, `stage : FAIL rc=` or `stage : not linked`. diff --git a/native/kernel/arch/.crumb b/native/kernel/arch/.crumb index 83ad2c0a..6cf54407 100644 --- a/native/kernel/arch/.crumb +++ b/native/kernel/arch/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-24T04:15:32Z", + "compiled_at": "2026-10-24T17:40:38Z", "compiler": "crumb-compile/1", - "digest": "sha256:7fbcf8cfb77799807b2a55611e2a3f6563d9c2403aac467868dfa685ce46cfe2", + "digest": "sha256:aa16ee3dab6c71bf912686eef4e763743d26883addadc7ca4371eb8545b513aa", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 8, - "generated_at_commit": "621c9e6fe430ee689836bee3ee2689d7d32e0f7d", - "source_tree": "sha256:28b738e67cff45a3e75fde530c200f001dc2fe196045f1e842e331d541caee6e" + "generated_at_commit": "ad77d8134db082bc013cfde92835cef8d43ddc80", + "source_tree": "sha256:dca3ea13b3bbcc2c4c07510716f4f7d8ada85602a71b8805734c48b7e77a0e22" }, "owner_lane": "", "provenance": { diff --git a/native/kernel/arch/timer.c b/native/kernel/arch/timer.c index 24f8d7aa..6f01dabe 100644 --- a/native/kernel/arch/timer.c +++ b/native/kernel/arch/timer.c @@ -17,12 +17,23 @@ /* timer.c -- EL1 physical generic timer (CNTP, PPI INTID 30) and the * monotonic time services. Tick semantics match the Rust kernel: the IRQ * re-arms CNTP_CVAL 10 ms after "now", then records the interval since the - * previous tick (the first interval is measured from arming). */ + * previous tick (the first interval is measured from arming). + * + * Both ends of an interval are the counter value read at IRQ ENTRY, the same + * value the next deadline is built from. An interval is therefore never + * shorter than the period, whatever the host does: the old code read the + * counter again AFTER re-arming, so a host stall between the two reads (QEMU + * TCG on a loaded machine) made one interval long and the next one short, and + * the M1 "no interval shorter than half a period" check failed (an interrupt + * storm or a missing EOI still shows: the next IRQ arrives at once). */ #include "arch.h" #include "ck_internal.h" static volatile uint64_t ticks, last, tmin, tmax; +#define CK_TIMER_MIN_TICKS 5 /* the M1 gate wants at least five ticks */ +#define CK_TIMER_GRACE_MS 5000 /* longest extra wait for them */ + static uint64_t counter(void) { ck_isb(); @@ -58,9 +69,8 @@ void ck_timer_tick(void) ck_wr(cntp_ctl_el0, 1); ck_isb(); ticks++; - uint64_t t = counter(); - uint64_t interval = t - last; - last = t; + uint64_t interval = now - last; + last = now; if (interval < tmin) tmin = interval; if (interval > tmax) @@ -82,15 +92,21 @@ int ck_timer_window(uint32_t ms, struct ck_timer_window *w) ck_isb(); ck_irq_on(); ck_isb(); + /* The window is wall-clock. A starved vCPU (QEMU TCG on a loaded host) may + * see fewer than CK_TIMER_MIN_TICKS ticks in it, which says nothing about + * the timer. Keep counting past the window until that many ticks arrived, + * giving up after CK_TIMER_GRACE_MS: a dead timer still reports 0 ticks. */ uint64_t window = hz / 1000 * ms; - while (counter() - start < window) + uint64_t grace = hz / 1000 * CK_TIMER_GRACE_MS; + uint64_t t; + while ((t = counter()) - start < window || (ticks < CK_TIMER_MIN_TICKS && t - start < grace)) ; ck_irq_off(); ck_isb(); ck_wr(cntp_ctl_el0, 0); ck_isb(); w->ticks = ticks; - w->ms = ms; + w->ms = (t - start) / (hz / 1000); w->freq_hz = hz; w->min_interval = ticks ? tmin : 0; w->max_interval = tmax; diff --git a/scripts/.crumb b/scripts/.crumb index 926b87ee..c17f1d8a 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-24T04:15:32Z", + "compiled_at": "2026-10-24T17:40:38Z", "compiler": "crumb-compile/1", - "digest": "sha256:0794e1ad2bcb73135f89ff006231c855c3d8aec44b90e10b4e9f252bed562f2b", + "digest": "sha256:32aaad6e964ad6c1c00c770d113053dfe55fea96d5cc00cb48b98e4835f9ae9c", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 119, - "generated_at_commit": "621c9e6fe430ee689836bee3ee2689d7d32e0f7d", - "source_tree": "sha256:c1950abfc89f1dfee5bceba57e7bd74ed699f27c905ce3a7c0dad2f95bbba218" + "generated_at_commit": "ad77d8134db082bc013cfde92835cef8d43ddc80", + "source_tree": "sha256:761d46f111d59bf708dd2461cb29d052a9c79d8f4748f51183210dc7014d8df6" }, "owner_lane": "", "provenance": { diff --git a/scripts/ck_gates.sh b/scripts/ck_gates.sh index 133d0261..73544149 100755 --- a/scripts/ck_gates.sh +++ b/scripts/ck_gates.sh @@ -242,6 +242,12 @@ run_children() { child_log_sha[${c}]="$(sha_of <"${log}")" child_lines[${c}]="$(wc -l <"${log}")" echo "--- [${c}] exit ${child_rc[${c}]} after ${child_secs[${c}]} s" >&2 + # A failing child's own FAIL lines go to stderr (the evidence blob), so a red gate can be read + # without rerunning it: the child log itself lives in a temp folder that is removed at exit. + if [[ "${child_rc[${c}]}" != 0 ]]; then + { grep -aE '^(FAIL|ALLEN: |CONTINUITY: )' "${log}" | tail -n 40 | sed "s/^/ [${c}] /" >&2; } || true + { tail -n 5 "${log}" | sed "s/^/ [${c}] tail: /" >&2; } || true + fi done }