Skip to content
Closed
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
26 changes: 24 additions & 2 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ const GPU_WAIT_WATCHDOG_TIMEOUT: Duration = Duration::from_millis(5000);
/// Cap on tracked per-list written UMA ranges (for same-list write-then-wait detection).
const MAX_WRITTEN_RANGES: usize = 256;

/// `GPU_WAIT_WATCHDOG_TIMEOUT`, or `XCL_GPU_WAIT_RELEASE_MS` (a value above 0). A release on the
/// CPU lets the waiting queue go on before its producer has written the value: when the producer
/// is only late (its list held while a pipeline is built), the consumer reads what was not
/// written yet.
fn gpu_wait_watchdog_timeout() -> Duration {
static T: OnceLock<Duration> = OnceLock::new();
*T.get_or_init(|| release_after(std::env::var("XCL_GPU_WAIT_RELEASE_MS").ok().as_deref()))
}

fn release_after(ms: Option<&str>) -> Duration {
ms.and_then(|v| v.trim().parse::<u64>().ok()).filter(|&ms| ms > 0).map_or(GPU_WAIT_WATCHDOG_TIMEOUT, Duration::from_millis)
}

fn wait_timeout() -> Duration {
static T: OnceLock<Duration> = OnceLock::new();
*T.get_or_init(|| {
Expand Down Expand Up @@ -1388,7 +1401,7 @@ fn wake_sync_watchdog() {
let mut waiter_ty = -1i32;
let before = cell.armed_waits.len();
cell.armed_waits.retain(|aw| {
if aw.armed_at.elapsed() >= GPU_WAIT_WATCHDOG_TIMEOUT {
if aw.armed_at.elapsed() >= gpu_wait_watchdog_timeout() {
if aw.val >= max_exp {
max_exp = aw.val;
waiter_q = aw.waiting_queue;
Expand Down Expand Up @@ -1438,7 +1451,7 @@ fn wake_sync_watchdog() {
let pq = prod_q.map(queue_id);
crate::xlog_warn!(
"D3D12.X: GPU queue.Wait at {va:#x} >= {val:#x} did not complete within {} ms (waiter=q{wq}/ty{waiter_ty}, prod=q{pq:?}/ty{prod_ty:?}, recorded={rec:#x}, submitted={sub:#x}, completed={done:#x}) – released on CPU to prevent GPU hang",
GPU_WAIT_WATCHDOG_TIMEOUT.as_millis()
gpu_wait_watchdog_timeout().as_millis()
);
}
if had_expired {
Expand Down Expand Up @@ -3844,6 +3857,15 @@ mod tests {
use super::*;
use std::sync::Arc;

#[test]
fn a_gpu_wait_is_released_after_xcl_gpu_wait_release_ms_or_the_default() {
assert_eq!(release_after(None), GPU_WAIT_WATCHDOG_TIMEOUT);
assert_eq!(release_after(Some("180000")), Duration::from_secs(180));
assert_eq!(release_after(Some(" 750 ")), Duration::from_millis(750));
assert_eq!(release_after(Some("0")), GPU_WAIT_WATCHDOG_TIMEOUT, "0 keeps the default");
assert_eq!(release_after(Some("soon")), GPU_WAIT_WATCHDOG_TIMEOUT);
}

static RESET_TEST_HR: AtomicU32 = AtomicU32::new(0);
static RESET_TEST_REPLACEMENT_VT: AtomicU64 = AtomicU64::new(0);

Expand Down
Loading