diff --git a/crates/victory-gpu/src/copystat.rs b/crates/victory-gpu/src/copystat.rs index 4dc27c50b..50e80b99a 100644 --- a/crates/victory-gpu/src/copystat.rs +++ b/crates/victory-gpu/src/copystat.rs @@ -126,6 +126,12 @@ pub(crate) fn add(c: C, n: u64) { COUNT[c as usize].fetch_add(n, Relaxed); } +/// A counter's count so far, for the tests. +#[cfg(test)] +pub(crate) fn count(c: C) -> u64 { + COUNT[c as usize].load(Relaxed) +} + /// How copies run: 0 guarded (as always), 1 plain, 2 not at all. pub(crate) fn mode() -> u8 { static MODE: std::sync::OnceLock = std::sync::OnceLock::new(); diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index 13571489e..2e65156d8 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -3439,6 +3439,13 @@ impl Batch { let have = self.current.get(&key).map_or(&empty, |(_, have)| have); let mut todo = have.missing(address, end).peekable(); if todo.peek().is_none() { + // Already current: what a later list asked again, and what + // #259 keeps current across its moves. + #[cfg(feature = "diagnostics")] + { + crate::copystat::add(crate::copystat::C::Skipped, 1); + crate::copystat::add(crate::copystat::C::SkippedBytes, (end - address) as u64); + } return; } let i = *self.pending.entry(key).or_insert_with(|| { @@ -5047,6 +5054,36 @@ mod batch { crate::watch::tests::free(p); } + /// A list asking again for what the submission already brought up to + /// date copies nothing, and the copystat line says so: the skipped + /// bytes are what staying current saved the later lists. + #[test] + #[cfg(feature = "diagnostics")] + fn a_still_current_ask_is_counted_skipped() { + let Some((p, copy)) = plain(2) else { + return; + }; + let len = 2 * PAGE; + let mut batch = Batch::default(); + batch.add(©, p, len); + assert!(batch.flush() > 0, "all of it at first"); + let (skips, bytes) = ( + crate::copystat::count(crate::copystat::C::Skipped), + crate::copystat::count(crate::copystat::C::SkippedBytes), + ); + batch.add(©, p, len); + assert_eq!(batch.flush(), 0, "nothing again in the submission"); + assert!( + crate::copystat::count(crate::copystat::C::Skipped) > skips, + "the ask counted" + ); + assert!( + crate::copystat::count(crate::copystat::C::SkippedBytes) >= bytes + len as u64, + "its bytes" + ); + done(p, Some(copy)); + } + /// A copy of `pages` pages of plain private memory, which is not the /// runtime's: untracked, copied whole whatever was asked for. None /// without a host GPU.