Skip to content
Merged
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
45 changes: 36 additions & 9 deletions d3d12/crates/leonida-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,21 +836,15 @@ pub(crate) fn removal_context() -> String {
use std::fmt::Write;
let now = now_us();
let ms = |at: u64| now.saturating_sub(at) as f64 / 1000.0;
let phase = match SUBMITTING[0].load(Ordering::Relaxed) {
0 => "between submissions (nothing of ours was running on the card)",
1 => "preparing a submission (nothing of ours was running on the card)",
2 => "waiting for the card to run a submission",
_ => "copying back what a submission wrote (nothing of ours was running on the card)",
};
let (started, finished) = (STARTED.load(Ordering::Relaxed), FINISHED.load(Ordering::Relaxed));
let phase = submitting_phase(SUBMITTING[0].load(Ordering::Relaxed), started.saturating_sub(finished));
let mut text = format!(
"the submitting thread was {phase}, of {} lists, for {:.1} ms; {}; objects let go at once {} and after a running submission {}; submissions started {} finished {}",
"the submitting thread was {phase}, of {} lists, for {:.1} ms; {}; objects let go at once {} and after a running submission {}; submissions started {started} finished {finished}",
SUBMITTING[1].load(Ordering::Relaxed),
ms(SUBMITTING[2].load(Ordering::Relaxed)),
crate::pipeline::library_removal_note(),
RETIREMENTS[0].load(Ordering::Relaxed),
RETIREMENTS[1].load(Ordering::Relaxed),
STARTED.load(Ordering::Relaxed),
FINISHED.load(Ordering::Relaxed),
);
let trail = TRAIL.lock().unwrap_or_else(|e| e.into_inner());
let _ = write!(text, "; the last {} things done, newest last:", trail.len());
Expand All @@ -860,6 +854,26 @@ pub(crate) fn removal_context() -> String {
text
}

/// What the submitting thread was doing ([`SUBMITTING`]), and how many submissions of ours were started
/// and not yet seen finished (`in_air`: [`STARTED`] less [`FINISHED`]). With submissions sent ahead the
/// submitting thread can be preparing the next one while earlier ones may still run, so a device lost
/// then is told as idle only when that number is 0. (`STARTED` counts a submission from the start of
/// its preparation, so the one being prepared is among them; and one not yet seen finished may have
/// finished already: the count is of what was not observed complete.)
fn submitting_phase(phase: u64, in_air: u64) -> String {
let doing = match phase {
0 => "between submissions",
1 => "preparing a submission",
2 => return "waiting for the card to run a submission".to_owned(),
_ => "copying back what a submission wrote",
};
match in_air {
0 => format!("{doing} (nothing of ours was running on the card)"),
1 => format!("{doing} (1 submission of ours started and not yet seen finished)"),
n => format!("{doing} ({n} submissions of ours started and not yet seen finished)"),
}
}

/// Says [`removal_context`] in the log, once: called by whoever finds the
/// host device removed.
pub(crate) fn log_removal_context() {
Expand Down Expand Up @@ -13818,6 +13832,19 @@ mod trail {
assert!(text.contains(&format!("thing {} done", super::TRAIL_MOST + 4)));
assert!(!text.contains("thing 4 done"), "the oldest entries are dropped");
}

/// A device lost while the submitting thread is between submissions or preparing the next one is
/// told as idle only when none of ours was started and not yet seen finished: with submissions sent
/// ahead some can still be on the card then.
#[test]
fn the_removal_phase_names_submissions_not_yet_seen_finished() {
use super::submitting_phase;
assert_eq!(submitting_phase(1, 0), "preparing a submission (nothing of ours was running on the card)");
assert_eq!(submitting_phase(1, 1), "preparing a submission (1 submission of ours started and not yet seen finished)");
assert_eq!(submitting_phase(0, 3), "between submissions (3 submissions of ours started and not yet seen finished)");
assert_eq!(submitting_phase(2, 5), "waiting for the card to run a submission");
assert_eq!(submitting_phase(3, 0), "copying back what a submission wrote (nothing of ours was running on the card)");
}
}

#[cfg(test)]
Expand Down