From cd9efbb714e8e6583c9972d8a31afcf5c3cb7042 Mon Sep 17 00:00:00 2001 From: japabu Date: Wed, 11 Nov 2026 14:25:53 +0200 Subject: [PATCH 1/2] logkeeper: the UART's carrier starts within a bound, whatever the rounds have read The console UART's carrier starts where the rounds have read past the records the kernel put on the UART itself. Nothing bounded that: a kernel answer naming a position its ring never reaches (a shard of a CPU that never started, fixed at its cause by #1207) left the carrier waiting in `Hub::wire_start` and the UART silent for the machine's life, with no line saying why. A round with no lines never said the start either. The loop owns the awaited event, so the bound is the loop's: the hand-over (`Handover`) carries what the kernel spoke, what the rounds so far owe the UART and a deadline `WIRE_START` (5 s) after it. Every round, with lines or without, says the start once the rounds have read past the kernel's positions, or at the deadline wherever they have read to, with a warning that names both sets of positions. The carrier then starts from there with what the rounds before owe; the kernel's records read later repeat on the UART, which beats a silent one. The loop wakes at least every `POLL_SLOW`, so the carrier's wait on the hub ends within the bound plus one cadence. Closes issues/logkeepers-uart-carrier-waits-for-its-start-with-no-bound-and-no-report.md. Co-Authored-By: Claude Fable 5.2 --- ...r-its-start-with-no-bound-and-no-report.md | 26 ------ system/logkeeper/src/carrier.rs | 5 +- system/logkeeper/src/main.rs | 91 +++++++++++++++---- system/logkeeper/src/serve.rs | 4 +- 4 files changed, 79 insertions(+), 47 deletions(-) delete mode 100644 issues/logkeepers-uart-carrier-waits-for-its-start-with-no-bound-and-no-report.md diff --git a/issues/logkeepers-uart-carrier-waits-for-its-start-with-no-bound-and-no-report.md b/issues/logkeepers-uart-carrier-waits-for-its-start-with-no-bound-and-no-report.md deleted file mode 100644 index 0e35d8787cc..00000000000 --- a/issues/logkeepers-uart-carrier-waits-for-its-start-with-no-bound-and-no-report.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -status: open -kind: defect -severity: [hang] -opened: 2026-11-11 ---- - -# logkeeper's UART carrier waits for its start with no bound and no report - -The console UART's carrier is fed from where the kernel left the UART, which -`logkeeper` says once its read positions reach what the kernel says the -console spoke (`system/logkeeper/src/main.rs`, `set_wire_from`). Until then -the carrier's feed waits in `Hub::wire_start` -(`system/logkeeper/src/serve.rs`), on a condition with no timeout, and says -nothing. - -If the start is never said, the UART carries nothing for the machine's life -and no line anywhere says why. That is what a kernel answer that could not -be reached did on a machine with a CPU that never started, until the answer -was made reachable: the cause went, this wait stayed. - -**Exit**: the wait has a bound; past it `logkeeper` says so and starts the -carrier anyway, from the hand-over with what the rounds before it owe. Lines -the kernel already put on the UART may then repeat, which the port's `STALL` -already holds is better than a silent UART. A host test of the carrier's -start holds the expiry. diff --git a/system/logkeeper/src/carrier.rs b/system/logkeeper/src/carrier.rs index 2686f8c2a4d..cb61056a958 100644 --- a/system/logkeeper/src/carrier.rs +++ b/system/logkeeper/src/carrier.rs @@ -16,8 +16,9 @@ //! **The port's carrier is handed the boot from its first line, and the //! UART's from where the UART's last carrier left off, or else from the //! hand-over with every line before it but the records the kernel put on the -//! UART itself** ([`Hub::wire_start`]). A slow channel is never let go. What a -//! channel has taken is told the kernel as the read positions of the rounds it +//! UART itself** ([`Hub::wire_start`]); the rounds say where that is within a +//! bound, read past those records or not. A slow channel is never let go. What +//! a channel has taken is told the kernel as the read positions of the rounds it //! has taken whole (`toyos::log::spoken`), so a fatal path and the stop put on //! the UART exactly the kernel's records no channel has delivered; a channel //! handed a gap in the replay speaks for nothing after it. diff --git a/system/logkeeper/src/main.rs b/system/logkeeper/src/main.rs index 59f03b29ee3..dabe8c6c3ca 100644 --- a/system/logkeeper/src/main.rs +++ b/system/logkeeper/src/main.rs @@ -193,6 +193,7 @@ fn main() { let shards = words - toyos_abi::log::CURSOR_HEAD_WORDS; let spoken = toyos::log::spoken(&cap, &vec![0; shards]).unwrap_or_else(|e| panic!("logkeeper: SYS_LOG_SPOKEN refused ({e:?})")); + let handover = Handover { spoken, owed: String::new(), by: Instant::now() + WIRE_START }; let (port, wire) = (endow::acceptor(CARRIER), endow::acceptor(WIRE)); let carriers = (port.is_some() || wire.is_some()).then(|| Carriers::serve(port, wire, Arc::clone(&hub), Arc::clone(&cap))); @@ -203,8 +204,7 @@ fn main() { from_supervisor, supervisor_rx: ipc::FrameRx::new(), carriers, - spoken: Some(spoken), - owed_wire: String::new(), + handover: Some(handover), origins: Vec::new(), tail, records: vec![Record::EMPTY; BATCH], @@ -227,12 +227,8 @@ struct Log { from_supervisor: Connection, supervisor_rx: ipc::FrameRx<{ 4 + MAX_TAG }>, carriers: Option>, - /// What the kernel put on the UART itself, a read position per shard, - /// until the rounds have read past it and said where the UART's carrier - /// starts. - spoken: Option>, - /// Those rounds' lines but the kernel's records the UART carried. - owed_wire: String, + /// Until the rounds have said where the UART's carrier starts. + handover: Option, origins: Vec, tail: LogTail>, records: Vec, @@ -254,6 +250,39 @@ struct Log { stopping: Option, } +/// What the kernel put on the UART itself, which the rounds read past before +/// the UART's carrier starts. +struct Handover { + /// A read position per shard. + spoken: Vec, + /// The rounds' lines so far but the kernel's records the UART carried. + owed: String, + /// When the carrier starts wherever the rounds have read to. + by: Instant, +} + +/// How long the UART's carrier waits for the rounds to read past what the +/// kernel put on the UART. Those records are in the kernel's ring before the +/// first round, which reads the ring whole, so only a kernel answer its ring +/// never reaches outlasts a round. Policy, short because the costs are +/// lopsided: a false expiry repeats lines on the UART, and a missed one +/// leaves it silent. +const WIRE_START: Duration = Duration::from_secs(5); + +impl Handover { + /// Whether the rounds, written `through`, have read past what the kernel + /// put on the UART. + fn read_past(&self, through: &[u64]) -> bool { + through.iter().zip(&self.spoken).all(|(read, spoken)| read >= spoken) + } + + /// Whether the UART's carrier starts at `now`: the rounds have read past + /// what the kernel put on the UART, or [`WIRE_START`] is up. + fn over(&self, through: &[u64], now: Instant) -> bool { + self.read_past(through) || now >= self.by + } +} + /// The file's text held back after a flush, the lines past the bound, and /// whether the flush wrote the stop mark. struct Stopping { @@ -496,7 +525,8 @@ impl Log { lines.into_iter().partition(|line| all || line.at_ns <= cut); let through = written_through(self.tail.positions(), &later); self.waiting = later; - self.write(now, all, through); + self.write(now, all, Arc::clone(&through)); + self.start_wire(&through); oldest } @@ -553,7 +583,7 @@ impl Log { match &line.kind { Kind::Kernel(record) => { let text = format!("{}\n", record.dated(&stamp(self.boot_secs, record.at_ns()))); - if !self.spoken.as_ref().is_some_and(|spoken| on_the_uart(record, spoken)) { + if !self.handover.as_ref().is_some_and(|handover| on_the_uart(record, &handover.spoken)) { wire.push_str(&text); } file.push_str(&text); @@ -595,16 +625,29 @@ impl Log { // only what /log already holds, whenever the machine stops between the // two. A part refused or catching up takes this text from the replay. self.to_volume(file.as_bytes(), !flushing); - self.hub.append(file.as_bytes(), Some(Arc::clone(&through))); - if let Some(spoken) = &self.spoken { - self.owed_wire.push_str(&wire); - if through.iter().zip(spoken).all(|(read, spoken)| read >= spoken) { - self.hub.set_wire_from(self.hub.end(), std::mem::take(&mut self.owed_wire).into_bytes()); - self.spoken = None; - } + self.hub.append(file.as_bytes(), Some(through)); + if let Some(handover) = &mut self.handover { + handover.owed.push_str(&wire); } } + /// Say where the UART's carrier starts once the rounds, written + /// `through`, have read past what the kernel put on the UART, or by + /// [`WIRE_START`] wherever they have read to, which is said. + fn start_wire(&mut self, through: &[u64]) { + let now = Instant::now(); + let Some(handover) = self.handover.take_if(|handover| handover.over(through, now)) else { return }; + if !handover.read_past(through) { + toyos::warn!( + "logkeeper: the kernel's records are read through {through:?} and not the {:?} it put on the UART \ + after {} s; the UART's carrier starts here, and what is read of them later repeats on the UART", + handover.spoken, + WIRE_START.as_secs() + ); + } + self.hub.set_wire_from(self.hub.end(), handover.owed.into_bytes()); + } + /// Write a round to the volume, and make it durable unless it is one of a /// flush's rounds, which `flushed` makes durable together: a stop's flush /// is bounded by the supervisor, and a sync per round of it is what outruns that. @@ -951,6 +994,20 @@ mod tests { assert_eq!(&*super::written_through(&[5, 12], &[]), &[5, 12]); } + /// **The UART's carrier starts once the rounds have read past what the + /// kernel put on the UART, or at the bound wherever they have read to**: + /// a position the rounds never reach delays the start and never ends it. + #[test] + fn the_wire_starts_at_its_bound_whatever_the_rounds_have_read() { + let began = std::time::Instant::now(); + let by = began + super::WIRE_START; + let handover = super::Handover { spoken: vec![4, 2], owed: String::new(), by }; + assert!(!handover.over(&[4, 1], began)); + assert!(!handover.over(&[9, 1], by - std::time::Duration::from_nanos(1)), "one shard short is not read past"); + assert!(handover.over(&[4, 1], by) && !handover.read_past(&[4, 1]), "started unread at the bound"); + assert!(handover.over(&[4, 2], began) && handover.read_past(&[4, 2])); + } + /// The kernel's records the UART carried before the hand-over are those /// before the position it spoke through in their shard, whatever their /// stamps say. diff --git a/system/logkeeper/src/serve.rs b/system/logkeeper/src/serve.rs index b8d08cb831c..2be0559ecf4 100644 --- a/system/logkeeper/src/serve.rs +++ b/system/logkeeper/src/serve.rs @@ -130,8 +130,8 @@ impl Hub { held.rounds.iter().rev().find(|(end, _)| *end <= at).map(|(_, positions)| Arc::clone(positions)) } - /// The console UART's carrier starts at `at`, past every kernel record the - /// kernel put on the UART itself, owing `owed` of the rounds before. Once. + /// The console UART's carrier starts at `at`, owing `owed` of the rounds + /// before. Once. pub fn set_wire_from(&self, at: u64, owed: Vec) { let mut held = self.lock(); assert!(held.wire_from.is_none(), "logkeeper: where the UART's carrier starts is said twice"); From 3713400e759c7cf9b401998afd91d3a36e59be7b Mon Sep 17 00:00:00 2001 From: japabu Date: Wed, 11 Nov 2026 17:39:27 +0200 Subject: [PATCH 2/2] logkeeper: the wire-start test takes its instant a nanosecond short by a checked subtraction Clippy's adopted `unchecked_time_subtraction` names the bare `Instant - Duration` in the new test. Co-Authored-By: Claude Opus 5.5 --- system/logkeeper/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/logkeeper/src/main.rs b/system/logkeeper/src/main.rs index dabe8c6c3ca..72197c9a77f 100644 --- a/system/logkeeper/src/main.rs +++ b/system/logkeeper/src/main.rs @@ -1003,7 +1003,8 @@ mod tests { let by = began + super::WIRE_START; let handover = super::Handover { spoken: vec![4, 2], owed: String::new(), by }; assert!(!handover.over(&[4, 1], began)); - assert!(!handover.over(&[9, 1], by - std::time::Duration::from_nanos(1)), "one shard short is not read past"); + let short = by.checked_sub(std::time::Duration::from_nanos(1)).expect("a nanosecond after `began`"); + assert!(!handover.over(&[9, 1], short), "one shard short is not read past"); assert!(handover.over(&[4, 1], by) && !handover.read_past(&[4, 1]), "started unread at the bound"); assert!(handover.over(&[4, 2], began) && handover.read_past(&[4, 2])); }