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" } )); }