Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/victory-gpu/src/copystat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = std::sync::OnceLock::new();
Expand Down
37 changes: 37 additions & 0 deletions crates/victory-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| {
Expand Down Expand Up @@ -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(&copy, 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(&copy, 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.
Expand Down