From 2a1b4b449325a3678ce188ff683c25fbd6e54e24 Mon Sep 17 00:00:00 2001 From: japabu Date: Thu, 5 Nov 2026 11:35:18 +0100 Subject: [PATCH 1/2] sdk: the lane proof reads the last refusal after the join, not after is_finished a_lane_gives_its_reader_every_record_in_order_or_counts_it_refused ended its read loop on JoinHandle::is_finished and compared the refusals it had read with the writer's own count. JoinHandle::join documents that the thread's completion synchronizes with its return; is_finished documents no ordering, and is `Arc::strong_count(&self.packet) == 1`, a Relaxed load (std's thread/lifecycle.rs, alloc's sync.rs). So seeing the writer finished orders none of its pushes before the reader's next read, and on a weak-ordered host the last read can miss the writer's last refusal: the one red issues/a-lane-reader-counted-one-refusal-fewer-than-its-writer-made.md recorded, 49999 read against 50000 refused at a load average of 44, was one short at the end. The reader now reads while the writer runs, joins it, and reads once more: the join orders every push before that read. The ring test beside it already waited on a Release/Acquire flag stored after its joins. Not reproduced: the unchanged test ran green 2400 times, twelve loops of 200 at once on an aarch64 macOS host. The fix rests on join's documented ordering. Co-Authored-By: Claude Opus 5.5 --- ...-one-refusal-fewer-than-its-writer-made.md | 30 ------------------- sdk/toyos/src/log/proof.rs | 12 ++++---- 2 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 issues/a-lane-reader-counted-one-refusal-fewer-than-its-writer-made.md diff --git a/issues/a-lane-reader-counted-one-refusal-fewer-than-its-writer-made.md b/issues/a-lane-reader-counted-one-refusal-fewer-than-its-writer-made.md deleted file mode 100644 index ce986c6a254..00000000000 --- a/issues/a-lane-reader-counted-one-refusal-fewer-than-its-writer-made.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -status: open -kind: defect -opened: 2026-10-10 ---- - -# A lane's reader counted one refusal fewer than its writer made - -`sdk/toyos/src/log/proof.rs`'s -`a_lane_gives_its_reader_every_record_in_order_or_counts_it_refused` went red -once in `cargo run -- --ci host`'s `the toyos SDK` step, on the branch -that brings up the GICv3 ITS, which touches nothing under `sdk/toyos/`: - -``` -panicked at toyos/src/log/proof.rs:161:5: -assertion `left == right` failed - left: 49999 - right: 50000 -``` - -The reader's `Reader::refused` total was one short of the refusals the -writer thread counted from `push_lane`. The host's load average was 44.31 -on 14 cores when it was read; the same step was green an hour earlier on -a tree whose `sdk/toyos/` was the same. Either the lane loses a refusal between -the writer's count and the reader's last read after `writer.is_finished()`, -or the test reads the count before the last refusal is published: which one -is not determined. - -**Exit**: the cause is named, and the test reds on it without load, or the -lane's refusal count is fixed and the test holds under the load above. diff --git a/sdk/toyos/src/log/proof.rs b/sdk/toyos/src/log/proof.rs index eeaef169893..10f251c19b6 100644 --- a/sdk/toyos/src/log/proof.rs +++ b/sdk/toyos/src/log/proof.rs @@ -146,17 +146,19 @@ fn a_lane_gives_its_reader_every_record_in_order_or_counts_it_refused() { let mut reader = Reader::new(); let mut got = Vec::new(); let mut counted = 0; - loop { - let finished = writer.is_finished(); + let mut read = || { while let Some((_, seq)) = reader.next_lane(&*lane) { got.push(seq); } counted += reader.refused(&*lane); - if finished { - break; - } + }; + while !writer.is_finished() { + read(); } + // The join orders the writer's last push before the last read; + // `is_finished` orders nothing. let refused = writer.join().unwrap() as u64; + read(); assert_eq!(counted, refused); assert_eq!(got.len() as u64 + counted, EACH); assert!(got.windows(2).all(|w| w[0] < w[1]), "a lane reordered its records"); From 7d79229de5e359e486b6435085fdf2b2ba0aa238 Mon Sep 17 00:00:00 2001 From: japabu Date: Thu, 5 Nov 2026 12:05:32 +0100 Subject: [PATCH 2/2] build: the guest-CPU queue's fairness test runs alone in a process buildlock's a_narrow_guest_does_not_overtake_a_wide_one_waiting reads the wide guest as queued once a probe finds the queue lock held, and only then starts the narrow one (issues/a-narrow-guest-test-reads-any-queue-holder-as-the-wide-waiter.md). A flock belongs to the open file description, and a sibling test's fork shares every description this process has open until the child execs: if one forks while the first guest holds the queue, the queue stays held after that guest's handle is dropped, the probe reads the wide guest as queued before it has asked, and the narrow guest that follows takes the free CPU first. Its guest threads then outlive the failed test, write lock files into its removed scratch, and the process's last TempDir finds its root not empty: the second red that run reported against whichever test dropped last (sysroot's the_primary_s_fork_checkout_is_moved_to_its_pin, buildlock's a_clean_cannot_land_inside_a_build). Measured on the dev host (aarch64 macOS), the lib test binary filtered to `buildlock::`: in a whole `cargo run -- --ci host`, the two reds above; in loops of the filtered binary, 3 of 15 and 2 of 60 red; the one red read whole was this test, its leftover root holding only this test's `locks/guest-cpus/cpu-*`. A/B in one session, the two binaries interleaved 150 runs each: the base 9 red, this change 0. The scenario is now an #[ignore]d test the real one runs alone through `rerun`, as the module's other process-level scenarios are: no sibling forks in that process, and its threads end with it. There the queue's only holders are the guests and the probe, and the first guest's handle is closed before it reports, so a failed probe is the wide guest holding the queue, which is what the record's exit asked for, and the record goes. Co-Authored-By: Claude Opus 5.5 --- build/buildlock.rs | 12 +++++++++++ ...ads-any-queue-holder-as-the-wide-waiter.md | 21 ------------------- 2 files changed, 12 insertions(+), 21 deletions(-) delete mode 100644 issues/a-narrow-guest-test-reads-any-queue-holder-as-the-wide-waiter.md diff --git a/build/buildlock.rs b/build/buildlock.rs index e6f8e179ad5..bcd99e2fd5f 100644 --- a/build/buildlock.rs +++ b/build/buildlock.rs @@ -910,8 +910,20 @@ pub(crate) mod tests { one.send(()).unwrap(); } + /// Alone in a process ([`rerun`]): a sibling test's fork holds every lock + /// description this process has locked until it execs, so a queue left + /// held by the first guest's dropped handle would read as the wide one + /// queued. #[test] fn a_narrow_guest_does_not_overtake_a_wide_one_waiting() { + let out = rerun("buildlock::tests::a_narrow_guest_behind_a_wide_one").output().expect("run the scenario alone"); + let said = String::from_utf8_lossy(&out.stdout).into_owned() + &String::from_utf8_lossy(&out.stderr); + assert!(out.status.success() && said.contains("test result: ok. 1 passed"), "{said}"); + } + + #[test] + #[ignore = "the scenario of the test above, alone in its process; never runs on its own"] + fn a_narrow_guest_behind_a_wide_one() { let store = scratch("guest-cpus-queue"); let (tx, done) = std::sync::mpsc::channel(); let first = guest(&store, 3, 4, "first", tx.clone()); diff --git a/issues/a-narrow-guest-test-reads-any-queue-holder-as-the-wide-waiter.md b/issues/a-narrow-guest-test-reads-any-queue-holder-as-the-wide-waiter.md deleted file mode 100644 index d1bd67a84c4..00000000000 --- a/issues/a-narrow-guest-test-reads-any-queue-holder-as-the-wide-waiter.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -status: open -kind: tooling -opened: 2026-11-04 ---- - -# `a_narrow_guest_does_not_overtake_a_wide_one_waiting` reads any holder of the queue as the wide guest waiting - -`build/buildlock.rs`'s test starts the wide guest, then polls `guest-cpus/queue` -and starts the narrow guest once a `try_lock` of it fails, taking that as the -wide guest holding the queue while it waits. Under host load it failed with -`a narrow guest took the CPU a queued wide one waits for`. Its log shows both -guests *waiting for* the queue, the narrow one acquiring it first and the wide -one after, so the probe's failed `try_lock` was not the wide guest queued. -The run was `cargo run -- --ci host` at `2d29d98db` (#1173, a change that does not -touch `buildlock.rs`), host load average 22 to 28; the test passed alone three -times on the same tree: evidence `pr-1173/r1/r1-host-ci.log` and -`isolated-*.log` at ToyOSOrg/evidence `067de8d244ac7e8c517cf1039ec692f5241c097f`. - -**Exit**: the test starts the narrow guest only once the wide guest itself -reports that it holds the queue, and stays green under load.