Count the shared-event waits whose cost the hold moved
The steps this packet landed as, in order: - Re-pin the runtime sources at the landing tip Content: the tree of `development` at ce0298fc5a, unchanged.
This commit is contained in:
1 parent
0f374bc9ec
commit
fdf3f414b6
7 files changed
+112
-1
No files matched your search
@@ -1628,6 +1628,7 @@ impl Gpu for Runtime {
|
||||
("slot_waits", c.slot_waits),
|
||||
("slot_wait_nanos", c.slot_wait_nanos),
|
||||
("event_waits_met", c.event_waits_met),
|
||||
("shared_event_waits_held", c.shared_event_waits_held),
|
||||
("bare_starts", c.bare_starts),
|
||||
("prefixed_starts", c.prefixed_starts),
|
||||
("command_barriers", c.command_barriers),
|
||||
|
||||
@@ -194,6 +194,12 @@ impl EventShared {
|
||||
lock(&self.state).timeline.wait(value)
|
||||
}
|
||||
|
||||
/// Whether a wait for `value` is held on the host where a Vulkan wait for a submitted GPU
|
||||
/// signal's index would have served (`event_timeline.rs`).
|
||||
pub(super) fn held_for_the_host(&self, value: u64) -> bool {
|
||||
lock(&self.state).timeline.held_for_the_host(value)
|
||||
}
|
||||
|
||||
/// What a signal of `value` by a batch submitted now on `VkQueue` `queue` becomes.
|
||||
pub(super) fn signal(&self, value: u64, queue: usize) -> Signal {
|
||||
lock(&self.state).timeline.signal(value, queue)
|
||||
|
||||
@@ -165,6 +165,17 @@ impl<Q: Copy + Eq> EventTimeline<Q> {
|
||||
.map(|pending| WaitFor::Index(pending.index))
|
||||
}
|
||||
|
||||
/// Whether a wait for `value` is held on the host where a Vulkan wait for a submitted GPU
|
||||
/// signal's index would have served: the host may set the value, it is not reached, and a
|
||||
/// signal submitted before the waiting batch reaches it. Exactly the waits that chained on
|
||||
/// the `VkQueue` before, which cost a hold and a `vkQueueSubmit` now
|
||||
/// (`WorkCounts::shared_event_waits_held`).
|
||||
pub(super) fn held_for_the_host(&self, value: u64) -> bool {
|
||||
self.settable
|
||||
&& value > self.value()
|
||||
&& (self.pending.iter()).any(|pending| pending.value >= value)
|
||||
}
|
||||
|
||||
/// What a GPU signal of `value` by a batch submitted now on `queue` becomes. Nothing changes
|
||||
/// until [`EventTimeline::keep`].
|
||||
pub(super) fn signal(&self, value: u64, queue: Q) -> Signal {
|
||||
|
||||
@@ -490,6 +490,9 @@ struct Held {
|
||||
/// The makings of the pipelines its host step records were raised to a queue's first held
|
||||
/// batch's ([`hasten_heads`]).
|
||||
hastened: bool,
|
||||
/// Its waits held on the host where a Vulkan wait would have served were counted
|
||||
/// ([`count_waits_held`]): once per batch.
|
||||
counted_held: bool,
|
||||
}
|
||||
|
||||
/// What a batch's host step waits for (`CommandBufferShared::step_waits`).
|
||||
@@ -1034,6 +1037,7 @@ fn take_in(state: &mut State, commits: &mut Vec<Committed>, spent: &mut Spent) {
|
||||
gate: None,
|
||||
checked: batch.checked,
|
||||
hastened: false,
|
||||
counted_held: false,
|
||||
});
|
||||
order.push(queue, held);
|
||||
spent.push(buffer);
|
||||
@@ -1638,6 +1642,7 @@ fn check_heads(state: &mut State, behind: &[u64], left: &mut Left<Work>, awaits:
|
||||
}
|
||||
return true;
|
||||
}
|
||||
count_waits_held(held);
|
||||
if !held.checked || !otherwise_ready || !due {
|
||||
return !due && goes(held);
|
||||
}
|
||||
@@ -1659,6 +1664,24 @@ fn check_heads(state: &mut State, behind: &[u64], left: &mut Left<Work>, awaits:
|
||||
landing
|
||||
}
|
||||
|
||||
/// The waits of `held`, a line's head, for a shared event's value that a submitted GPU signal
|
||||
/// reaches: each chained on the `VkQueue` before and is held on the host now, so each cost moved
|
||||
/// (`WorkCounts::shared_event_waits_held`, `event_timeline.rs`). Counted once per batch, at the
|
||||
/// pass that first finds it leading its line: a batch behind another waits for that one, not for
|
||||
/// its own events.
|
||||
fn count_waits_held(held: &mut Held) {
|
||||
if held.counted_held {
|
||||
return;
|
||||
}
|
||||
let held_for_the_host = (held.waits.iter())
|
||||
.filter(|(event, value)| event.held_for_the_host(*value))
|
||||
.count();
|
||||
if held_for_the_host > 0 {
|
||||
held.counted_held = true;
|
||||
(held.buffer.device().shared().counts).shared_event_waits_held(held_for_the_host);
|
||||
}
|
||||
}
|
||||
|
||||
/// Raise the makings of the pipelines each command queue's first held batch's host step records
|
||||
/// to a head's (`budget::Urgency::Head`), once per batch, whatever else it waits for: every batch
|
||||
/// committed after it on its queue waits behind it, and once a queue's command buffers are all
|
||||
|
||||
@@ -98,3 +98,51 @@ fn the_signals_of_either_kind_take_the_same_indices() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The waits whose cost moved are exactly the ones a plain event would have chained on the
|
||||
/// `VkQueue`: `held_for_the_host` answers for a shared event's timeline exactly where the same
|
||||
/// state of a plain one answers `WaitFor::Index` (`WorkCounts::shared_event_waits_held`).
|
||||
#[test]
|
||||
fn the_waits_counted_as_held_are_the_ones_that_chained_on_the_vk_queue() {
|
||||
let mut shared: EventTimeline<usize> = EventTimeline::new(true);
|
||||
let mut plain: EventTimeline<usize> = EventTimeline::new(false);
|
||||
let steps: [(u64, Option<u64>, Option<u64>); 5] = [
|
||||
// (a GPU signal submitted, an index observed, a host set)
|
||||
(3, None, None),
|
||||
(8, None, None),
|
||||
(0, None, Some(2)),
|
||||
(0, Some(1), None),
|
||||
(12, None, Some(9)),
|
||||
];
|
||||
for (signal, observe, set) in steps {
|
||||
for timeline in [&mut shared, &mut plain] {
|
||||
if signal > 0 {
|
||||
submit(timeline, signal, 0);
|
||||
}
|
||||
if let Some(index) = observe {
|
||||
timeline.observe(index);
|
||||
}
|
||||
}
|
||||
// Only a shared event's value is ever set; the plain one's floor stands in for it, so
|
||||
// both timelines hold the same signals, indices and values throughout.
|
||||
if let Some(value) = set {
|
||||
assert!(shared.set(value));
|
||||
assert!(plain.set(value));
|
||||
}
|
||||
assert_eq!(shared.value(), plain.value());
|
||||
for value in 0..16 {
|
||||
let chained = matches!(plain.wait(value), Some(WaitFor::Index(_)));
|
||||
assert_eq!(
|
||||
shared.held_for_the_host(value),
|
||||
chained,
|
||||
"value {value} at {steps:?} up to ({signal}, {observe:?}, {set:?})"
|
||||
);
|
||||
// A wait counted as held is one the shared event does not hand to Vulkan, and one
|
||||
// it answers for needs no wait at all.
|
||||
assert_eq!(
|
||||
shared.wait(value).is_none(),
|
||||
chained || plain.wait(value).is_none()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,6 +185,7 @@ pub(crate) struct Counters {
|
||||
slot_wait_nanos: AtomicU64,
|
||||
completed_waits: AtomicU64,
|
||||
event_waits_met: AtomicU64,
|
||||
shared_event_waits_held: AtomicU64,
|
||||
bare_starts: AtomicU64,
|
||||
prefixed_starts: AtomicU64,
|
||||
command_barriers: AtomicU64,
|
||||
@@ -1330,6 +1331,14 @@ impl Counters {
|
||||
.fetch_add(waits as u64, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// A batch became a line's head holding `waits` of its event waits for values the host may
|
||||
/// set that a submitted GPU signal reaches: each one chained on the `VkQueue` before, and
|
||||
/// costs a hold and a `vkQueueSubmit` now (`scheduler/mod.rs`). Counted once per batch.
|
||||
pub(crate) fn shared_event_waits_held(&self, waits: usize) {
|
||||
self.shared_event_waits_held
|
||||
.fetch_add(waits as u64, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// A batch with work was submitted with no command buffer of barriers before its first
|
||||
/// encoder.
|
||||
pub(crate) fn bare_start(&self) {
|
||||
@@ -3230,6 +3239,18 @@ pub struct WorkCounts {
|
||||
/// (`CompletionPolicy::Grouped`) as a batch with no wait does; the others' waits make it lead
|
||||
/// one or go alone (`group_ends_wait`).
|
||||
pub event_waits_met: u64,
|
||||
/// Event waits (`encode_wait_for_event`) for a shared event's value (`MTLSharedEvent`, whose
|
||||
/// value the host may set) that a GPU signal submitted before the batch reaches, held on the
|
||||
/// host as their batch led its line rather than handed to its `VkQueue`: Metal's
|
||||
/// `setSignaledValue:` releases such a wait as soon as the value is reached, and a Vulkan wait
|
||||
/// a batch was submitted with cannot be released by the host, so the batch waits for the value
|
||||
/// to be reached and goes with no Vulkan wait (`event_timeline.rs`). Each one chained on the
|
||||
/// `VkQueue` before and costs a hold and a `vkQueueSubmit` now: these are the waits whose cost
|
||||
/// moved, apart from the `event_waits_met` that were always free. Counted once per batch,
|
||||
/// whatever reaches the value (the host's set, or a completion turn seeing the GPU signal).
|
||||
/// A plain event's wait (`MTLEvent`, which no host call signals) is never among them: it
|
||||
/// chains on the `VkQueue`, where that is exact.
|
||||
pub shared_event_waits_held: u64,
|
||||
/// Batches with work submitted with no command buffer of barriers before their first
|
||||
/// encoder: nothing planned before it, and no start timestamp to write there (none, or one
|
||||
/// its first encoder wrote, `WorkCounts::prefixed_starts`).
|
||||
@@ -4464,6 +4485,7 @@ impl Device {
|
||||
queues_sharing_a_vk_queue: counters.queues_sharing_a_vk_queue.load(Ordering::Relaxed),
|
||||
completed_waits: counters.completed_waits.load(Ordering::Relaxed),
|
||||
event_waits_met: counters.event_waits_met.load(Ordering::Relaxed),
|
||||
shared_event_waits_held: counters.shared_event_waits_held.load(Ordering::Relaxed),
|
||||
bare_starts: counters.bare_starts.load(Ordering::Relaxed),
|
||||
prefixed_starts: counters.prefixed_starts.load(Ordering::Relaxed),
|
||||
command_barriers: counters.command_barriers.load(Ordering::Relaxed),
|
||||
|
||||
@@ -1 +1 @@
|
||||
63f1125d13968869a9fa988be48e6263d6e6a42506a996ebeba25f6657a66457
|
||||
4a225dd40b17c9141505490b955fee25d80f7e444d0158194e16b323408cdccb
|
||||
Reference in new issue
Block a user