From 95ecbb0f956eb490c380ee7d4df677d1663e2001 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 30 Aug 2026 23:58:48 +0300 Subject: [PATCH] observe: the store's destination and the presented plane's pages were both known and never emitted beside each other Component: reims-vgpu Vulkan engine (outstanding-write ledger) and the scanout present witness. Pathway: x86 macOS / Linux Vulkan, rail macos-15. Observation only; no guest-visible behaviour changes and no execution path altered. Session 10b established, at n=3, that the flat-white desktop field is neither of the two readings six sessions were spent choosing between: the guest composites into the presented plane at 14-195 draws per heartbeat for the entire white interval, and 409 stores publish into it, while its guest pages stay uniform 0xff. What it asked for next was one comparison -- the guest-physical pages the Store wrote against the pages the present sampled. Both numbers were already inside this device and neither was emitted beside the other. `present_field_witness` gains `write_reach=` and the presented mapping's page count, first and last page. The witness reads guest pages without settling, and that is deliberate: settling there would make the instrument cause the visibility it is trying to observe. But it also means a uniform field has been three findings wearing one number. Overlap a writeback is in flight into these very pages, so the bytes read are pre-write bytes and the field says nothing about what the guest composited. The question moves to whether whatever presents this plane settles before reading it. Disjoint nothing outstanding lands here, so the stores this boot records are landing in another page set entirely, and publish and present disagree about which pages the plane is. Unnamed the ledger overflowed or raced and cannot say -- counted apart so it cannot be read as Disjoint. Three different repairs, and no record separated them. `store_destination` is the other half, emitted from `record_guest_write_footprint_debt` -- the function that arms the ledger -- so the destination named and the destination armed cannot drift. It reports on a change of allocation identity rather than per store: this rail records hundreds of stores a second into a handful of surfaces, so a per-store line would be a flood repeating one fact, and the destination is what the question is about. Identity is `same_allocation` (Arc pointer equality), which is the key the ledger already deduplicates on, not the page values. A recycled page list describes a later allocation, so equal addresses would suppress a real destination change -- the one thing this record must not do. `runs` and `page_size` travel with it because a scattered destination and a contiguous one of the same length are not the same footprint. Test: a_recycled_page_list_is_a_new_destination_and_a_retained_one_is_not pins all four arms -- a retained clone is the same destination, an identical page list rebuilt is not, a different page set is not, and the first store of a process has nothing to be the same as. The suppression rule is split into `store_destination_changed` so it is stated as a test rather than inferred from the shape of a log. Verified: cargo fmt --all and --check; all three clippy arms with -D warnings (aarch64-apple-darwin/backend-metal, host Vulkan, x86_64-unknown-linux-gnu Vulkan); full backend-vulkan,host-window suite serially, 2407 passing, 0 failures. Not verified: no boot carries either record yet, so no white-interval reach and no store destination has been measured. Metal tests were not run; this host is not Apple. No conformance battery was run -- the change emits OFF records and alters no execution path. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/backend/vulkan/engine/mod.rs | 93 +++++++++++++++++++ crates/reims-vgpu/src/runtime/scanout/mod.rs | 40 +++++++- 2 files changed, 131 insertions(+), 2 deletions(-) diff --git a/crates/reims-vgpu/src/backend/vulkan/engine/mod.rs b/crates/reims-vgpu/src/backend/vulkan/engine/mod.rs index f323030ec..8953b5d63 100644 --- a/crates/reims-vgpu/src/backend/vulkan/engine/mod.rs +++ b/crates/reims-vgpu/src/backend/vulkan/engine/mod.rs @@ -3752,10 +3752,103 @@ pub(super) fn record_guest_write_footprint_debt( footprint: &crate::runtime::guest_ram::GuestPageFootprint, ) { pools.note_guest_write_recorded(GuestWriteSource::ResidentTarget(identity)); + note_store_destination(footprint); arm_guest_write_footprint(footprint); GUEST_WRITE_DEBT.store(true, std::sync::atomic::Ordering::Release); } +/// The destination a resident store publishes into, reported when it changes. +/// +/// The counterpart to `present_field_witness`'s page span, and the two exist to +/// be read against each other. A boot in which the presented plane's field is +/// uniform while stores keep publishing has two candidate readings -- the +/// content stored is itself uniform, or the store and the present disagree about +/// which guest pages the plane is -- and the second is settled by comparing the +/// page set a store lands in with the page set the present reads. Both numbers +/// were already inside this device and neither was emitted beside the other. +/// +/// Reported on change rather than per store because it is the destination that +/// is the question, and it moves rarely: this rail records hundreds of stores +/// per second into a handful of surfaces, so a per-store line would be a flood +/// that says the same thing. Recorded here, in the function that arms the +/// ledger, so the destination named and the destination armed cannot drift. +/// Whether this store publishes into a different allocation than the last one +/// reported. +/// +/// Allocation identity, not page values: a page list can be recycled, so equal +/// addresses do not mean the same surface, and `same_allocation` is the identity +/// the outstanding-write ledger already deduplicates on. Split out from the +/// emitter so the suppression rule can be stated as a test rather than inferred +/// from the shape of a log. +fn store_destination_changed( + last: Option<&crate::runtime::guest_ram::GuestPageFootprint>, + now: &crate::runtime::guest_ram::GuestPageFootprint, +) -> bool { + !matches!(last, Some(l) if l.same_allocation(now)) +} + +#[cfg(test)] +mod store_destination_tests { + use super::*; + use crate::runtime::guest_ram::GuestPageFootprint; + + fn fp(pages: &[u64]) -> GuestPageFootprint { + GuestPageFootprint::new(pages.into(), 0x1000).expect("valid footprint") + } + + #[test] + fn a_recycled_page_list_is_a_new_destination_and_a_retained_one_is_not() { + let first = fp(&[0x1000, 0x2000]); + // The same retained allocation, cloned the way the resident hands it to + // the ledger. Reporting this again would be the flood the suppression + // exists to stop. + assert!( + !store_destination_changed(Some(&first), &first.clone()), + "a retained allocation is the same destination" + ); + // The same page addresses, built again: a recycled list describing a + // later allocation. Suppressing this would hide a destination change + // behind equal numbers, which is the one thing this record must not do. + assert!( + store_destination_changed(Some(&first), &fp(&[0x1000, 0x2000])), + "equal page addresses are not allocation identity" + ); + assert!( + store_destination_changed(Some(&first), &fp(&[0x9000])), + "a different page set is a different destination" + ); + assert!( + store_destination_changed(None, &first), + "the first store of a process has nothing to be the same as" + ); + } +} + +fn note_store_destination(footprint: &crate::runtime::guest_ram::GuestPageFootprint) { + static LAST: std::sync::Mutex> = + std::sync::Mutex::new(None); + let Ok(mut last) = LAST.lock() else { + return; + }; + if !store_destination_changed(last.as_ref(), footprint) { + return; + } + *last = Some(footprint.clone()); + drop(last); + let pages = footprint.pages(); + let Some(&first) = pages.first() else { + return; + }; + crate::observe::off(format!( + "store_destination pages={} first={:#x} last={:#x} runs={} page_size={:#x}", + pages.len(), + first, + pages.last().copied().unwrap_or(first), + footprint.runs().len(), + footprint.page_size(), + )); +} + /// Report the exact binding equation for one live packed guest surface. /// /// This remains an observation entry point; resident creation consumes the diff --git a/crates/reims-vgpu/src/runtime/scanout/mod.rs b/crates/reims-vgpu/src/runtime/scanout/mod.rs index b5a55b29d..757aa50dc 100644 --- a/crates/reims-vgpu/src/runtime/scanout/mod.rs +++ b/crates/reims-vgpu/src/runtime/scanout/mod.rs @@ -1566,10 +1566,46 @@ pub fn note_present_field_witness( // the Metal arm, so the field is simply absent there rather than empty. #[cfg(not(feature = "backend-vulkan"))] let ring = String::new(); + // What the outstanding-write ledger says about the very pages just read. + // + // This witness reads guest pages without settling, which is deliberate -- + // settling here would make the instrument cause the visibility it is trying + // to observe. But that also means a uniform field is two different findings + // wearing one number, and the whole blank-field investigation turns on which + // one it is: + // + // * `Overlap` -- a writeback is in flight into these pages. The bytes read + // are then simply pre-write bytes, and the field being uniform says + // nothing about what the guest composited. The question moves to whether + // whatever presents this plane settles before it reads. + // * `Disjoint` -- nothing outstanding lands here at all. The stores this + // boot records are landing in some other page set, so the plane being + // published and the plane being presented are not the same pages. + // * `Unnamed` -- the ledger overflowed or raced and cannot say. Not evidence + // either way, and counted separately so it cannot be read as `Disjoint`. + // + // Those three have different repairs, and no record on this rail separated + // them: a plane that reads uniform white with 409 stores publishing into it + // is consistent with all three. + #[cfg(feature = "backend-vulkan")] + let reach = format!( + " write_reach={:?}", + crate::backend::vulkan::engine::guest_writes_reaching(&gpas) + ); + #[cfg(not(feature = "backend-vulkan"))] + let reach = String::new(); + // The page span, so a store record naming its destination and this record + // naming the presented plane can be compared without either having to know + // about the other. First and last of the mapping's own order, not of the + // sorted set: that is the order the window's offsets index. + let span = match (gpas.first(), gpas.last()) { + (Some(f), Some(l)) => format!(" pages={} first={f:#x} last={l:#x}", gpas.len()), + _ => String::new(), + }; crate::observe::off(format!( "present_field_witness mid={mapping_id} {width}x{height} map_gen={map_gen} \ - epoch={epoch} seq={seq} why={} unpainted={blank}/4 patches=[{report}]{ring} \ - (guest pages, no settle)", + epoch={epoch} seq={seq} why={} unpainted={blank}/4 patches=[{report}]{ring}\ + {reach}{span} (guest pages, no settle)", if changed { "changed" } else { "heartbeat" } )); }