rt tests: the event chain sets its held link's value only once the submit thread holds it
The chain test set the shared event's value for its last link (a wait no submitted signal promises) as soon as the links had completed, and then asserted one hold in Metrics::event_holds. The submit thread counts a hold only for a segment it found not ready on a pass with nothing left to stage (WorkState::mark_holds), and counts it when it stages that segment. Its first pass after the link's commit decides, and nothing orders that pass before the host's set. On a loaded host the thread can still be waiting to run when the floor is raised. Its first look then finds the wait met and stages the link at once, with nothing held, and the test read 0 (msi-laptop lavapipe, the full rt suite, job m3-max-62988; the test alone passed, m3-max-62993). Both orders are correct Metal behaviour, and the counter is true in both: the assertion assumed an order the runtime does not promise. The test now parks the submit thread in a scheduled handler of a command buffer with nothing for the GPU, committed on the other queue just before the last link, so every run commits the link, opens the busy work and completes the links before the thread first looks at it. It then releases the thread, waits until the thread holds the link (Work::holding, a device-test accessor beside Work::pending, reading the FIFO's held_since against its head), and only then sets the value. No product behaviour changes.
This commit is contained in:
1 parent
eb77b326a0
commit
6800559b22
2 files changed
+46
-4
No files matched your search
@@ -1020,6 +1020,21 @@ impl Work {
|
||||
(state.region.as_ref()).map_or_else(Vec::new, |region| region.ring.live())
|
||||
}
|
||||
|
||||
/// For the device tests: the queues whose head's next segment the submit thread holds for an
|
||||
/// event's value ([`WorkState::mark_holds`]).
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
pub(crate) fn holding(&self) -> usize {
|
||||
let state = self.lock();
|
||||
(state.fifos.iter())
|
||||
.filter(|fifo| {
|
||||
(fifo.head()).is_some_and(|pending| {
|
||||
(fifo.held_since)
|
||||
.is_some_and(|(seq, next, _)| (seq, next) == (pending.seq, pending.next))
|
||||
})
|
||||
})
|
||||
.count()
|
||||
}
|
||||
|
||||
/// Records the zero fill of `offset..end` of `block` into the upload ([`fill`](Self::fill)).
|
||||
///
|
||||
/// Err: as [`fill`](Self::fill).
|
||||
|
||||
@@ -1110,8 +1110,11 @@ pub(crate) mod on_device {
|
||||
/// submitted for a link: once the busy work ends, the links complete in order, and each holds
|
||||
/// the words of every link before it and its own, as the barrier ending each link's commands
|
||||
/// orders the next link's after them on the device's one queue. A link waiting for a value no
|
||||
/// submitted signal promises is held, at `Committed`, until the host sets it, and counted in
|
||||
/// `Metrics::event_holds` as it goes.
|
||||
/// submitted signal promises, committed while the submit thread is parked in a scheduled
|
||||
/// handler, stays `Committed` while the links complete; once released, the thread holds it,
|
||||
/// and the host sets the value only then: the hold is counted in `Metrics::event_holds` as it
|
||||
/// goes. A value set before the thread first looks would meet the wait there, with nothing
|
||||
/// held.
|
||||
#[test]
|
||||
fn every_device_submits_a_shared_event_chain_across_two_queues_before_its_first_link_runs() {
|
||||
const LINKS: u32 = 5;
|
||||
@@ -1187,6 +1190,20 @@ pub(crate) mod on_device {
|
||||
"{name}: no link has run, the busy work holding the device"
|
||||
);
|
||||
assert_eq!(holds(), before, "{name}: no link held for a value");
|
||||
// The submit thread parked in a scheduled handler: it first looks at the link committed
|
||||
// next only once the test releases it, after the links have completed, as a loaded
|
||||
// host may run it late.
|
||||
let park = Arc::new(std::sync::Barrier::new(2));
|
||||
let parker = queues[1].command_buffer().expect("a command buffer");
|
||||
let parked = Arc::clone(&park);
|
||||
(parker.add_scheduled_handler(move |_| {
|
||||
parked.wait();
|
||||
parked.wait();
|
||||
}))
|
||||
.expect("a handler");
|
||||
parker.commit().expect("a commit");
|
||||
park.wait();
|
||||
let mut release = Release::of(&park);
|
||||
// A link waiting for a value no submitted signal promises: held until the host sets
|
||||
// it.
|
||||
let last = queues[0].command_buffer().expect("a command buffer");
|
||||
@@ -1207,10 +1224,18 @@ pub(crate) mod on_device {
|
||||
assert_eq!(
|
||||
last.status(),
|
||||
CommandBufferStatus::Committed,
|
||||
"{name}: the link held for a value nothing promises"
|
||||
"{name}: the link waiting for a value nothing promises, not yet looked at"
|
||||
);
|
||||
// The host sets the value only once the submit thread, released, holds the link for
|
||||
// it: set before the thread has looked, it meets the wait at that first look, and
|
||||
// nothing is held.
|
||||
release.now();
|
||||
within(&format!("{name}: the link held for its value"), || {
|
||||
device.core().work.holding() == 1
|
||||
});
|
||||
chain.set_signaled_value(value);
|
||||
finished(name, &last);
|
||||
finished(name, &parker);
|
||||
let held: Vec<u64> = (holds().iter().zip(&before))
|
||||
.map(|(now, was)| now - was)
|
||||
.collect();
|
||||
@@ -1233,7 +1258,9 @@ pub(crate) mod on_device {
|
||||
"{name}: link {at}'s words: every link's before it, then its own"
|
||||
);
|
||||
}
|
||||
drop((last, links, busy, buffers, arena, chain, queues, device));
|
||||
drop((
|
||||
last, parker, links, busy, buffers, arena, chain, queues, device,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user