From 1928d53b6bc8be54a0ad54c645a3d5a70ce3a155 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 01:21:36 +0000 Subject: [PATCH] kernel: v4 waits for a key in arch_halt(), not a spin (#151) An idle StarshipOS kept a CPU core 100% busy: sk_v4_readline(), with nothing typed, and sk_v4_identity_wait(), headless until Zuse, waited in arch_relax(). Both now halt until the next interrupt (hlt; wfi on aarch64 and riscv64): the heartbeat's timer, ISR-driven on all three, wakes them at 100 Hz, so a key is still seen within a tick. Idle at the prompt, QEMU's CPU: 100% -> 1% of a core on amd64, 1% on aarch64 and riscv64. Acceptance passes: amd64 logs/20261108-005539, aarch64 -005753, riscv64 -010136 (POST 538/538, one dict_hash, 7 ok), the stick loaded high, test-32 (39 programs, 0 failures). FABRIC-3 XLVIII.5. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01GE3SDvQn5EoxdGufk84zz2 --- docs/fabric/FABRIC-3.md | 16 ++++++++++++++++ .../runs/doe-aarch64-20261108-005753.csv | 0 .../runs/doe-aarch64-20261108-011029.csv | 0 .../runs/doe-aarch64-20261108-011614.csv | 0 .../runs/doe-amd64-20261108-005539.csv | 0 .../runs/doe-amd64-20261108-010323.csv | 0 .../runs/doe-riscv64-20261108-010136.csv | 0 .../runs/doe-riscv64-20261108-011931.csv | 0 kernel/src/v4/sk_v4.c | 6 +++++- kernel/src/v4/sk_v4_identity.c | 2 +- .../amd64/qemu-amd64-20261108-005539.log | 3 +++ .../aarch64/qemu-aarch64-20261108-005753.log | 3 +++ .../riscv64/qemu-riscv64-20261108-010136.log | 3 +++ .../amd64/qemu-amd64-20261108-010323.log | 3 +++ .../aarch64/qemu-aarch64-20261108-011029.log | 0 .../aarch64/qemu-aarch64-20261108-011614.log | 3 +++ .../riscv64/qemu-riscv64-20261108-011931.log | 3 +++ 17 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 experiments/bare_metal/runs/doe-aarch64-20261108-005753.csv create mode 100644 experiments/bare_metal/runs/doe-aarch64-20261108-011029.csv create mode 100644 experiments/bare_metal/runs/doe-aarch64-20261108-011614.csv create mode 100644 experiments/bare_metal/runs/doe-amd64-20261108-005539.csv create mode 100644 experiments/bare_metal/runs/doe-amd64-20261108-010323.csv create mode 100644 experiments/bare_metal/runs/doe-riscv64-20261108-010136.csv create mode 100644 experiments/bare_metal/runs/doe-riscv64-20261108-011931.csv create mode 100644 logs/20261108-005539/amd64/qemu-amd64-20261108-005539.log create mode 100644 logs/20261108-005753/aarch64/qemu-aarch64-20261108-005753.log create mode 100644 logs/20261108-010136/riscv64/qemu-riscv64-20261108-010136.log create mode 100644 logs/20261108-010323/amd64/qemu-amd64-20261108-010323.log create mode 100644 logs/20261108-011029/aarch64/qemu-aarch64-20261108-011029.log create mode 100644 logs/20261108-011614/aarch64/qemu-aarch64-20261108-011614.log create mode 100644 logs/20261108-011931/riscv64/qemu-riscv64-20261108-011931.log diff --git a/docs/fabric/FABRIC-3.md b/docs/fabric/FABRIC-3.md index 034dd1d4..e56d479b 100644 --- a/docs/fabric/FABRIC-3.md +++ b/docs/fabric/FABRIC-3.md @@ -6263,3 +6263,19 @@ Found on the way: - **Try it in the .com's navigation** (#117): "Try it" added to the canvas's Home and Inquiries artboards, the .com rebuilt from them (`site/com`) and installed. Checked as a visitor: the home page, the "Try it" link, the Try it page in 1.1 s, its framed console Ready. + +### 5. #151: the idle loop halts (2026-11-08) + +Ruled (Captain Bob): "Fix the kernel problem." The v4 system waited for a key -- `sk_v4_readline()` +with nothing typed, and `sk_v4_identity_wait()` headless until Zuse -- in `arch_relax()`, a spin. +Both now wait in `arch_halt()` (`hlt` on amd64, `wfi` on aarch64 and riscv64) until the next +interrupt: the heartbeat's timer, which is ISR-driven on all three (`heartbeat_tick()`), wakes them +at 100 Hz, so a key is seen within a tick, as the cursor's blink and the identity beat already +were. v3's REPL (`repl.c`) still spins; v3 is not in acceptance. + +Verified: idle at Zuse's prompt for 20 s, QEMU's CPU **100% -> 1%** of a core on amd64 (the demo +machine), and **1%** on aarch64 and riscv64 (`logs/20261108-011614`, `-011931`); the acceptance +protocol passes -- amd64 `logs/20261108-005539`, aarch64 `-005753`, riscv64 `-010136`, POST +538/538, `dict_hash 0xfec8c47cfc6f437f` on all three, `7 ok` typed and answered; the stick loaded +high; `test-32` (39 programs, 0 failures). The demo's CPU cap (`CPUQuota=100%`) can be relaxed +once this reaches the server. diff --git a/experiments/bare_metal/runs/doe-aarch64-20261108-005753.csv b/experiments/bare_metal/runs/doe-aarch64-20261108-005753.csv new file mode 100644 index 00000000..e69de29b diff --git a/experiments/bare_metal/runs/doe-aarch64-20261108-011029.csv b/experiments/bare_metal/runs/doe-aarch64-20261108-011029.csv new file mode 100644 index 00000000..e69de29b diff --git a/experiments/bare_metal/runs/doe-aarch64-20261108-011614.csv b/experiments/bare_metal/runs/doe-aarch64-20261108-011614.csv new file mode 100644 index 00000000..e69de29b diff --git a/experiments/bare_metal/runs/doe-amd64-20261108-005539.csv b/experiments/bare_metal/runs/doe-amd64-20261108-005539.csv new file mode 100644 index 00000000..e69de29b diff --git a/experiments/bare_metal/runs/doe-amd64-20261108-010323.csv b/experiments/bare_metal/runs/doe-amd64-20261108-010323.csv new file mode 100644 index 00000000..e69de29b diff --git a/experiments/bare_metal/runs/doe-riscv64-20261108-010136.csv b/experiments/bare_metal/runs/doe-riscv64-20261108-010136.csv new file mode 100644 index 00000000..e69de29b diff --git a/experiments/bare_metal/runs/doe-riscv64-20261108-011931.csv b/experiments/bare_metal/runs/doe-riscv64-20261108-011931.csv new file mode 100644 index 00000000..e69de29b diff --git a/kernel/src/v4/sk_v4.c b/kernel/src/v4/sk_v4.c index b0ba43a6..0f6f7fbd 100644 --- a/kernel/src/v4/sk_v4.c +++ b/kernel/src/v4/sk_v4.c @@ -113,7 +113,11 @@ static int sk_v4_readline(void) } else { heartbeat_service(); } - arch_relax(); + /* Nothing typed: wait for the next interrupt, not in a spin (#151 -- the spin kept a + * CPU core 100% busy at the prompt, and the demo's host with it). The heartbeat's + * timer wakes it at 100 Hz, so a key is seen within a tick, as the blink and the + * identity beat are. */ + arch_halt(); continue; } if (c == '\r' || c == '\n') { diff --git a/kernel/src/v4/sk_v4_identity.c b/kernel/src/v4/sk_v4_identity.c index e7c8d1ed..95282e77 100644 --- a/kernel/src/v4/sk_v4_identity.c +++ b/kernel/src/v4/sk_v4_identity.c @@ -331,7 +331,7 @@ void sk_v4_identity_wait(void) while (!g_zuse_session) { sk_v4_discard_input(); sk_v4_identity_beat(); - arch_relax(); + arch_halt(); /* headless, until Zuse: wait for the next tick, not a spin (#151) */ } sk_v4_discard_input(); } diff --git a/logs/20261108-005539/amd64/qemu-amd64-20261108-005539.log b/logs/20261108-005539/amd64/qemu-amd64-20261108-005539.log new file mode 100644 index 00000000..a15926e2 --- /dev/null +++ b/logs/20261108-005539/amd64/qemu-amd64-20261108-005539.log @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eaa65c2724ccd2279473f94884df0d853611ba08d8d0bdb9b14f44b59be16ab1 +size 6637 diff --git a/logs/20261108-005753/aarch64/qemu-aarch64-20261108-005753.log b/logs/20261108-005753/aarch64/qemu-aarch64-20261108-005753.log new file mode 100644 index 00000000..b965509c --- /dev/null +++ b/logs/20261108-005753/aarch64/qemu-aarch64-20261108-005753.log @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac20bd2d786f2d5b810d729cf3758c22378ce5a42b286d115a2c9cef41e479fe +size 5602 diff --git a/logs/20261108-010136/riscv64/qemu-riscv64-20261108-010136.log b/logs/20261108-010136/riscv64/qemu-riscv64-20261108-010136.log new file mode 100644 index 00000000..5b30ae83 --- /dev/null +++ b/logs/20261108-010136/riscv64/qemu-riscv64-20261108-010136.log @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2565b08cf1053d506e46e1318542c890818b5c6b2477c4bc304198756be58188 +size 7993 diff --git a/logs/20261108-010323/amd64/qemu-amd64-20261108-010323.log b/logs/20261108-010323/amd64/qemu-amd64-20261108-010323.log new file mode 100644 index 00000000..0518b538 --- /dev/null +++ b/logs/20261108-010323/amd64/qemu-amd64-20261108-010323.log @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c03601e006a4c119cc4fc4ea5cfc0c8e68dbc8c0d5816d92b4165a788efeb60a +size 6708 diff --git a/logs/20261108-011029/aarch64/qemu-aarch64-20261108-011029.log b/logs/20261108-011029/aarch64/qemu-aarch64-20261108-011029.log new file mode 100644 index 00000000..e69de29b diff --git a/logs/20261108-011614/aarch64/qemu-aarch64-20261108-011614.log b/logs/20261108-011614/aarch64/qemu-aarch64-20261108-011614.log new file mode 100644 index 00000000..82c2ed34 --- /dev/null +++ b/logs/20261108-011614/aarch64/qemu-aarch64-20261108-011614.log @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e777a51aa2058567fd55b03914776f4a609ccf5d7338682f77fdc6feafc57b7 +size 5491 diff --git a/logs/20261108-011931/riscv64/qemu-riscv64-20261108-011931.log b/logs/20261108-011931/riscv64/qemu-riscv64-20261108-011931.log new file mode 100644 index 00000000..967016c4 --- /dev/null +++ b/logs/20261108-011931/riscv64/qemu-riscv64-20261108-011931.log @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aab2cce11d2b9b3f0bf8a6b2258f13254e36e2134e881dacad5616c27f32d4f2 +size 7882