Skip to content
Draft
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
58 changes: 49 additions & 9 deletions crates/xcl/src/hle/d3d12x/build_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,28 @@ impl Inner {
}

fn promote(&self, id: JobId, priority: Priority) -> bool {
// Stop admission at the authoritative transition, then wake the accepted work before
// publishing timing. Reporting must never delay a worker that can now take the job.
let admission = crate::stall::deferred_span();
let mut state = self.state.lock().unwrap_or_else(|e| e.into_inner());
let Some(job) = state.jobs.get_mut(&id) else { return false };
let Some(job) = state.jobs.get_mut(&id) else {
let admission = admission.map(crate::stall::DeferredSpan::stop);
drop(state);
if let Some(admission) = admission {
admission.finish(crate::stall::StallKind::PipelineQueueAdmission);
}
return false;
};
if priority <= job.priority {
let admission = admission.map(crate::stall::DeferredSpan::stop);
drop(state);
if let Some(admission) = admission {
admission.finish(crate::stall::StallKind::PipelineQueueAdmission);
}
return true;
}
let ranked_preload = job.priority == Priority::Preload && job.preload_rank.is_some();
if queue_stall_kind(job.priority) != queue_stall_kind(priority) {
job.previous_queue_wait = job.queue_wait.take().map(crate::stall::DeferredSpan::stop);
job.queue_wait = crate::stall::deferred_span();
}
let cross_band = queue_stall_kind(job.priority) != queue_stall_kind(priority);
job.priority = priority;
job.generation += 1;
let ticket = Ticket { id, generation: job.generation };
Expand All @@ -269,7 +281,21 @@ impl Inner {
if ranked_preload {
self.ranked_preloads.promoted.fetch_add(1, Ordering::Relaxed);
}
if cross_band {
let job = state.jobs.get_mut(&id).unwrap();
// Admission legitimately overlaps the old band's residence until this promotion is
// accepted. The new band's residence starts only after admission itself has stopped.
job.previous_queue_wait = job.queue_wait.take().map(crate::stall::DeferredSpan::stop);
}
let admission = admission.map(crate::stall::DeferredSpan::stop);
if cross_band {
state.jobs.get_mut(&id).unwrap().queue_wait = crate::stall::deferred_span();
}
drop(state);
self.wake(priority);
if let Some(admission) = admission {
admission.finish(crate::stall::StallKind::PipelineQueueAdmission);
}
true
}

Expand Down Expand Up @@ -400,13 +426,22 @@ impl BuildQueue {

/// Add work, optionally ordered by an earlier-run rank within the Preload band only.
///
/// Queue latency measures accepted priority-band residence: it starts at insertion after the
/// state mutex is acquired, so admission mutex wait is excluded. A cross-band promotion ends
/// the speculative interval when that promotion is accepted while holding the same mutex.
/// Queue latency measures accepted priority-band residence: it starts at the handoff after
/// queue insertion, immediately before the state mutex is released, so admission is excluded.
/// A cross-band promotion ends the old interval when that promotion is accepted while holding
/// the same mutex and starts the new interval after promotion admission stops.
pub(super) fn submit_ranked(&self, priority: Priority, preload_rank: Option<usize>, work: Work) -> Option<JobHandle> {
let completion = Arc::new(Completion::new());
// Accepted queue residence deliberately excludes admission synchronization. Stop that
// interval at the handoff, start residence, unlock, wake, then publish admission timing.
let admission = crate::stall::deferred_span();
let mut state = self.inner.state.lock().unwrap_or_else(|e| e.into_inner());
if state.stopped {
let admission = admission.map(crate::stall::DeferredSpan::stop);
drop(state);
if let Some(admission) = admission {
admission.finish(crate::stall::StallKind::PipelineQueueAdmission);
}
return None;
}
state.next_id = state.next_id.checked_add(1).expect("build queue job ID overflow");
Expand All @@ -418,16 +453,21 @@ impl BuildQueue {
preload_rank,
generation,
previous_queue_wait: None,
queue_wait: crate::stall::deferred_span(),
queue_wait: None,
work,
completion: completion.clone(),
});
state.push(priority, Ticket { id, generation }, preload_rank);
if preload_rank.is_some() {
self.inner.ranked_preloads.submissions.fetch_add(1, Ordering::Relaxed);
}
let admission = admission.map(crate::stall::DeferredSpan::stop);
state.jobs.get_mut(&id).unwrap().queue_wait = crate::stall::deferred_span();
drop(state);
self.inner.wake(priority);
if let Some(admission) = admission {
admission.finish(crate::stall::StallKind::PipelineQueueAdmission);
}
Some(JobHandle { id, queue: Arc::downgrade(&self.inner), completion })
}

Expand Down
2 changes: 2 additions & 0 deletions crates/xcl/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn stall_kind_name(kind: crate::stall::StallKind) -> &'static str {
StallKind::ShaderTranslation => "shader_translation",
StallKind::DxcQueue => "dxc_queue",
StallKind::DxcCompile => "dxc_compile",
StallKind::PipelineQueueAdmission => "pipeline_queue_admission",
StallKind::PipelineQueueSpeculative => "pipeline_queue_speculative",
StallKind::PipelineQueueDemand => "pipeline_queue_demand",
StallKind::PipelineWait => "pipeline_wait",
Expand Down Expand Up @@ -422,6 +423,7 @@ mod tests {

#[test]
fn pipeline_queue_stall_names_are_stable() {
assert_eq!(stall_kind_name(crate::stall::StallKind::PipelineQueueAdmission), "pipeline_queue_admission");
assert_eq!(stall_kind_name(crate::stall::StallKind::PipelineQueueSpeculative), "pipeline_queue_speculative");
assert_eq!(stall_kind_name(crate::stall::StallKind::PipelineQueueDemand), "pipeline_queue_demand");
}
Expand Down
4 changes: 3 additions & 1 deletion crates/xcl/src/stall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum StallKind {
ShaderTranslation,
DxcQueue,
DxcCompile,
PipelineQueueAdmission,
PipelineQueueSpeculative,
PipelineQueueDemand,
PipelineWait,
Expand All @@ -42,10 +43,11 @@ pub enum StallKind {
}

impl StallKind {
pub const ALL: [Self; 23] = [
pub const ALL: [Self; 24] = [
Self::ShaderTranslation,
Self::DxcQueue,
Self::DxcCompile,
Self::PipelineQueueAdmission,
Self::PipelineQueueSpeculative,
Self::PipelineQueueDemand,
Self::PipelineWait,
Expand Down
Loading