feat(gpu): GPU TIMES gives behind_us, the part of a command buffer's wait to start that the GPU still ran earlier work, so the rest is the host's way to the GPU
This commit is contained in:
1 parent
f0bcdb3b1e
commit
4e95bb2049
2 files changed
+60
-4
No files matched your search
@@ -792,8 +792,9 @@ pub(in crate::engine) fn report_calls(tsc_hz: u64) {
|
||||
));
|
||||
}
|
||||
}
|
||||
// Which part of that latency was waiting for the GPU to start, the GPU's
|
||||
// own time, and waiting for the look after it finished.
|
||||
// Which part of that latency was waiting for the GPU to start (behind
|
||||
// earlier work, or on the host's way to the GPU), the GPU's own time,
|
||||
// and waiting for the look after it finished.
|
||||
for service in shared().iter() {
|
||||
let Some(times) = service.gpu_times() else {
|
||||
continue;
|
||||
@@ -804,7 +805,7 @@ pub(in crate::engine) fn report_calls(tsc_hz: u64) {
|
||||
let average = |total: u64, count: u64| total.checked_div(count).unwrap_or(0);
|
||||
output::arguments(format_args!(
|
||||
"GPU TIMES timed={} busy_us={} average_us={} longest_us={}@{}:{} idle_us={} \
|
||||
overlap_us={} placed={} queued_us={}/{} noticed_us={}/{} waiting={} \
|
||||
overlap_us={} placed={} queued_us={}/{} behind_us={} noticed_us={}/{} waiting={} \
|
||||
span_us={}@{}:{}/{}:{} longest_submits={}\n",
|
||||
times.timed,
|
||||
times.busy_ns / 1000,
|
||||
@@ -817,6 +818,7 @@ pub(in crate::engine) fn report_calls(tsc_hz: u64) {
|
||||
times.placed,
|
||||
micros(average(times.queued_ticks, times.placed)),
|
||||
micros(times.longest_queued_ticks),
|
||||
micros(average(times.behind_ticks, times.placed)),
|
||||
micros(average(times.noticed_ticks, times.placed)),
|
||||
micros(times.longest_noticed_ticks),
|
||||
times.waiting,
|
||||
|
||||
@@ -30,6 +30,10 @@ pub struct GpuTimes {
|
||||
pub placed: u64,
|
||||
pub queued_ticks: u64,
|
||||
pub longest_queued_ticks: u64,
|
||||
/// Of `queued_ticks`, the ticks the GPU still ran earlier command
|
||||
/// buffers: the rest is the host's way to the GPU (the submit thread,
|
||||
/// the boot processor's pump, the driver's scheduler).
|
||||
pub behind_ticks: u64,
|
||||
pub noticed_ticks: u64,
|
||||
pub longest_noticed_ticks: u64,
|
||||
/// Committed command buffers that wait on an event.
|
||||
@@ -170,7 +174,8 @@ impl GpuClock {
|
||||
times.longest_entries = names(entries());
|
||||
times.longest_submits = submits;
|
||||
}
|
||||
if let Some(previous) = self.previous_end {
|
||||
let earlier = self.previous_end;
|
||||
if let Some(previous) = earlier {
|
||||
if start >= previous {
|
||||
times.idle_ns += start - previous;
|
||||
} else {
|
||||
@@ -181,10 +186,14 @@ impl GpuClock {
|
||||
let (Some(started), Some(ended)) = (self.ticks_at(start), self.ticks_at(end)) else {
|
||||
return;
|
||||
};
|
||||
let behind = earlier
|
||||
.and_then(|earlier| self.ticks_at(earlier))
|
||||
.map_or(0, |earlier| earlier.min(started).saturating_sub(committed));
|
||||
let times = &mut self.times;
|
||||
let queued = started.saturating_sub(committed);
|
||||
let noticed = seen.saturating_sub(ended);
|
||||
times.placed += 1;
|
||||
times.behind_ticks += behind.min(queued);
|
||||
times.queued_ticks += queued;
|
||||
times.longest_queued_ticks = times.longest_queued_ticks.max(queued);
|
||||
times.noticed_ticks += noticed;
|
||||
@@ -250,6 +259,51 @@ mod tests {
|
||||
assert_eq!(clock.take(), GpuTimes::default());
|
||||
}
|
||||
|
||||
/// A command buffer committed while an earlier one still ran waits for
|
||||
/// the GPU first: only what follows that one's end is the host's.
|
||||
#[test]
|
||||
fn splits_the_queue_into_earlier_work_and_the_hosts_way() {
|
||||
let mut clock = GpuClock::default();
|
||||
// One tick per GPU nanosecond, from GPU time 0 at tick 1000.
|
||||
clock.calibrate(1_000, 1_000, 0);
|
||||
clock.calibrate(200_001_000, 200_001_000, 200_000_000);
|
||||
// The first ends at GPU 200_000_100 (tick 200_001_100).
|
||||
clock.retire(
|
||||
1,
|
||||
1,
|
||||
200_000_900,
|
||||
200_001_200,
|
||||
[200_000_000, 200_000_100],
|
||||
Vec::new,
|
||||
core::iter::empty(),
|
||||
);
|
||||
// The second, committed at tick 200_001_040 while the first ran,
|
||||
// starts 30 ticks after its end.
|
||||
clock.retire(
|
||||
2,
|
||||
1,
|
||||
200_001_040,
|
||||
200_001_300,
|
||||
[200_000_130, 200_000_200],
|
||||
Vec::new,
|
||||
core::iter::empty(),
|
||||
);
|
||||
// A third, committed after both ended, waits on the host alone.
|
||||
clock.retire(
|
||||
3,
|
||||
1,
|
||||
200_001_250,
|
||||
200_001_400,
|
||||
[200_000_300, 200_000_310],
|
||||
Vec::new,
|
||||
core::iter::empty(),
|
||||
);
|
||||
let times = clock.take();
|
||||
assert_eq!(times.placed, 3);
|
||||
assert_eq!(times.queued_ticks, 100 + 90 + 50);
|
||||
assert_eq!(times.behind_ticks, 60, "the second waited 60 for the first");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn counts_gaps_and_overlaps_between_command_buffers() {
|
||||
let mut clock = GpuClock::default();
|
||||
|
||||
Reference in new issue
Block a user