xcl run: the crash report places every register in the title's memory #3628

Open
Royalflamejlh wants to merge 2 commits from upstream-pr/3628 into main
Royalflamejlh commented 2026-12-02 01:06:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T01:06:04Z.


(Edited: head 4cff929d4, rebased with #3627's commit on main 395405e4c; this commit unchanged.)

(Edited: head 095fdc694: crash_part reads XCL_WINDOW_STATS without a first read that could wait (second review), on #3627's fixes. On main 38ad22da.)

Stacked on #3627 (d3d12x/window-stats); only the top commit belongs here.

An unhandled exception logged the page events at the pages the registers point into, and only where there were some. A crash where a register held an address in a memory window with no page events (memory the title corrupted in a coherent window, say) said nothing about where that address lay. Now each register that points into a memory window (sparse, coherent, view), a view of a pair or a graphics reservation gets one line: the region, the 64 KiB page, its page events, and what XCL_WINDOW_STATS counted for its window when that is on. Other registers keep the line they had. Locks are only tried on this path, never waited for.

Related, not the same: #1186 names the Windows memory state and UMA window of the faulting address; #3027 dumps the memory around readable pointers. This one places every register in XCL's own regions.

What is in it

  • eh.rs: register_lines, the lines for the registers, with the region, page events and counters passed in, so it is tested without a crash; title_region.
  • hle/kernelx.rs: crash_region (graphics reservations) and mirrors::view_of (which view of a pair), both with try_lock.
  • hle/d3d12x/window_stats.rs: crash_part, the window's counters so far.

Tested

  • At 095fdc694: cargo check with and without --tests, no errors; Under Wine on Mesa's CPU Vulkan driver, release, 1 run: cargo test --lib -- window_stats file_reads write_log shader_mem console_heap eh:: at the top of the stack (#3642, f1ae90ebb): 62 passed, 0 failed.
  • RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, debug, at the top of this stack (#3642, head 5653fd69, with an earlier version of this PR's commit, before the second review's fixes): cargo test --workspace -- --test-threads=4, 2,931 passed, 0 failed, 51 ignored, 1 run; 28 SKIPPED lines (wave64 tests: no wave64 on this card; heap-window tests without XCL_HEAP_WINDOWS=1; no D3D12 debug layer). The stack's GPU tests (gpu_mem_stats_*, the writer and geometry-pass tests) ran and passed.
  • RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, Rust 1.98.0, x86_64-pc-windows-gnu, release. Tests under Wine on Mesa's CPU Vulkan driver (no card: the card was running a title).
  • cargo check -p xcl --release --target x86_64-pc-windows-gnu, with and without --tests: no errors, no new warnings.
  • cargo test -p xcl --release --target x86_64-pc-windows-gnu --lib -- --test-threads=8 window_stats eh:: kernelx: 89 passed, 0 failed, 1 ignored in 1 of 3 runs; 88 passed and 1 failed in the other 2. Over all runs here, one of three kernelx tests that share process-wide state (an_address_keeps_the_page_the_title_mapped_there_last, a_page_whose_move_fails_stays_mapped_where_it_was, gpu_visible_fallback_memory_is_write_watched) failed in some runs and passed in others; the same tests failed the same way on the branch below this one, which does not touch kernelx. The new test, registers_into_title_memory_get_a_line_each_page, checks the lines for registers in a window, in a view of a pair, outside with page events, and repeated or small values.
  • 2 title runs on our development tree with this in (705 s and 1,501 s) had no unhandled exception, so the new lines have not yet been seen at a real crash.

Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by scripts/smoke.ps1, the same retail title for 60 s each.

main:

xcl-smoke v1
commit: 395405e4c0ed814afde0610a724dc96a3af329de
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1522 (PresentX 1522)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16017 MB

this PR's head:

xcl-smoke v1
commit: 4cff929d4e14af9a60b4cf16997046913e805a7e
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1391 (PresentX 1391)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15532 MB

Not tested

  • AMD, a real crash with the new lines.

AI use

  • Claude Code, Claude Opus 5.5: wrote the change, its test and this description, and ported it to main.
<!-- greyfinch-sync:ivall/xcl:issue:5597693142 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T01:06:04Z. --- (Edited: head `4cff929d4`, rebased with #3627's commit on `main` 395405e4c; this commit unchanged.) (Edited: head `095fdc694`: `crash_part` reads `XCL_WINDOW_STATS` without a first read that could wait (second review), on #3627's fixes. On `main` 38ad22da.) Stacked on #3627 (`d3d12x/window-stats`); only the top commit belongs here. An unhandled exception logged the page events at the pages the registers point into, and only where there were some. A crash where a register held an address in a memory window with no page events (memory the title corrupted in a coherent window, say) said nothing about where that address lay. Now each register that points into a memory window (sparse, coherent, view), a view of a pair or a graphics reservation gets one line: the region, the 64 KiB page, its page events, and what `XCL_WINDOW_STATS` counted for its window when that is on. Other registers keep the line they had. Locks are only tried on this path, never waited for. Related, not the same: #1186 names the Windows memory state and UMA window of the faulting address; #3027 dumps the memory around readable pointers. This one places every register in XCL's own regions. **What is in it** - `eh.rs`: `register_lines`, the lines for the registers, with the region, page events and counters passed in, so it is tested without a crash; `title_region`. - `hle/kernelx.rs`: `crash_region` (graphics reservations) and `mirrors::view_of` (which view of a pair), both with `try_lock`. - `hle/d3d12x/window_stats.rs`: `crash_part`, the window's counters so far. **Tested** - At `095fdc694`: `cargo check` with and without `--tests`, no errors; Under Wine on Mesa's CPU Vulkan driver, release, 1 run: `cargo test --lib -- window_stats file_reads write_log shader_mem console_heap eh::` at the top of the stack (#3642, `f1ae90ebb`): 62 passed, 0 failed. - RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, debug, at the top of this stack (#3642, head `5653fd69`, with an earlier version of this PR's commit, before the second review's fixes): `cargo test --workspace -- --test-threads=4`, 2,931 passed, 0 failed, 51 ignored, 1 run; 28 `SKIPPED` lines (wave64 tests: no wave64 on this card; heap-window tests without `XCL_HEAP_WINDOWS=1`; no D3D12 debug layer). The stack's GPU tests (`gpu_mem_stats_*`, the writer and geometry-pass tests) ran and passed. - RTX 4060 Ti 16 GB, NVIDIA 615.71.09, AMD Ryzen 9 9950X3D, Linux, Wine 11.21 Staging, Rust 1.98.0, `x86_64-pc-windows-gnu`, release. Tests under Wine on Mesa's CPU Vulkan driver (no card: the card was running a title). - `cargo check -p xcl --release --target x86_64-pc-windows-gnu`, with and without `--tests`: no errors, no new warnings. - `cargo test -p xcl --release --target x86_64-pc-windows-gnu --lib -- --test-threads=8 window_stats eh:: kernelx`: 89 passed, 0 failed, 1 ignored in 1 of 3 runs; 88 passed and 1 failed in the other 2. Over all runs here, one of three `kernelx` tests that share process-wide state (`an_address_keeps_the_page_the_title_mapped_there_last`, `a_page_whose_move_fails_stays_mapped_where_it_was`, `gpu_visible_fallback_memory_is_write_watched`) failed in some runs and passed in others; the same tests failed the same way on the branch below this one, which does not touch `kernelx`. The new test, `registers_into_title_memory_get_a_line_each_page`, checks the lines for registers in a window, in a view of a pair, outside with page events, and repeated or small values. - 2 title runs on our development tree with this in (705 s and 1,501 s) had no unhandled exception, so the new lines have not yet been seen at a real crash. **Regression run** RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by `scripts/smoke.ps1`, the same retail title for 60 s each. `main`: ``` xcl-smoke v1 commit: 395405e4c0ed814afde0610a724dc96a3af329de gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 1522 (PresentX 1522) presents per 2 s (last 3): 60 60 61 device removals: 0 crashes: 0 peak commit: 16017 MB ``` this PR's head: ``` xcl-smoke v1 commit: 4cff929d4e14af9a60b4cf16997046913e805a7e gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 1391 (PresentX 1391) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15532 MB ``` **Not tested** - AMD, a real crash with the new lines. **AI use** - Claude Code, Claude Opus 5.5: wrote the change, its test and this description, and ported it to `main`.
Foniass commented 2026-12-02 01:12:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T01:12:07Z.


Review (head 0a876d26, diff read, not a merge-check; draft, checks red):

No problems found in the diff. Read the top commit 0a876d26 only (register_lines, title_region in eh.rs, kernelx::crash_region, mirrors::view_of, window_stats::crash_part / totals_part) against gpu::uma's window lookup, the mirrors state layout and pagelog; the exception-filter path takes no blocking lock (try_lock only, window_of / window / kind are lock-free), view_of reads the (size, cpu) tuple the way source does, and the old page of line stays for registers outside title memory. The stack on #3627 is declared. Still owed: the xcl-smoke blocks (the reason PR description is red) and a whole-suite run on a GPU; the tests ran filtered under Wine only.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7331429175 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#issuecomment-7331429175). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T01:12:07Z. --- Review (head 0a876d26, diff read, not a merge-check; draft, checks red): No problems found in the diff. Read the top commit `0a876d26` only (`register_lines`, `title_region` in `eh.rs`, `kernelx::crash_region`, `mirrors::view_of`, `window_stats::crash_part` / `totals_part`) against `gpu::uma`'s window lookup, the `mirrors` state layout and `pagelog`; the exception-filter path takes no blocking lock (`try_lock` only, `window_of` / `window` / `kind` are lock-free), `view_of` reads the `(size, cpu)` tuple the way `source` does, and the old `page of` line stays for registers outside title memory. The stack on #3627 is declared. Still owed: the `xcl-smoke` blocks (the reason `PR description` is red) and a whole-suite run on a GPU; the tests ran filtered under Wine only. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-02 03:00:33 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T03:00:33Z.


Follow-up review (head bc55ba1f, since 0a876d26, diff read, not a merge-check):

  • No problems found earlier: still holds; the commit's own lines are unchanged in bc55ba1f, only the hunk context in window_stats.rs moved with #3627's given_in. The xcl-smoke blocks are now in (1669 vs 1620 frames, peak commit 110 %) and PR description passes; the whole suite has still not run on a GPU.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7333428823 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#issuecomment-7333428823). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T03:00:33Z. --- Follow-up review (head bc55ba1f, since 0a876d26, diff read, not a merge-check): - **No problems found earlier:** still holds; the commit's own lines are unchanged in `bc55ba1f`, only the hunk context in `window_stats.rs` moved with #3627's `given_in`. The `xcl-smoke` blocks are now in (1669 vs 1620 frames, peak commit 110 %) and `PR description` passes; the whole suite has still not run on a GPU. New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-02 13:47:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T13:47:09Z.


Follow-up review (head 67ac04a2, since bc55ba1f, diff read, not a merge-check; checks red):

  • Earlier points: unchanged. git range-diff shows the own commit identical to the previous one; this push only rebases the stack onto the current main.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7347455518 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#issuecomment-7347455518). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T13:47:09Z. --- Follow-up review (head 67ac04a2, since bc55ba1f, diff read, not a merge-check; checks red): - **Earlier points:** unchanged. `git range-diff` shows the own commit identical to the previous one; this push only rebases the stack onto the current `main`. New: none. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-02 16:34:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:34:18Z.

Code review location: crates/xcl/src/hle/d3d12x/window_stats.rs; line 216

@@ -0,0 +1,321 @@
+//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window
+//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and
+//! was filled since the line before; and a line for the addresses the title gave the GPU that lie
+//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by
+//! default: each counter is then one branch.
+
+use std::collections::BTreeMap;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::OnceLock;
+use std::time::Duration;
+
+use super::view_want::{Path, NAMES, PATHS};
+use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS};
+
+fn seconds() -> Option<u64> {
+    static N: OnceLock<Option<u64>> = OnceLock::new();
+    *N.get_or_init(|| {
+        let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1);
+        crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s");
+        Some(n)
+    })
+}
+
+#[inline]
+pub(super) fn enabled() -> bool {
+    seconds().is_some()
+}
+
+#[derive(Clone, Copy)]
+pub(super) enum Traffic {
+    /// bytes copied up from the CPU
+    Up,
+    /// pages the write watch found written
+    Written,
+    /// bytes copied back to the CPU
+    Back,
+    /// GPU-view tiles given video memory and filled from the CPU view
+    Filled,
+}
+
+const TRAFFIC: usize = 4;
+/// the windows', and last what lies in none
+const SLOTS: usize = MAX_HEAP_WINDOWS + 1;
+/// addresses outside every window logged for each path
+const FIRST: u64 = 8;
+
+#[allow(clippy::declare_interior_mutable_const)]
+const ZERO: AtomicU64 = AtomicU64::new(0);
+#[allow(clippy::declare_interior_mutable_const)]
+const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC];
+static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS];
+static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS];
+
+fn on() -> Option<&'static Uma> {
+    if enabled() {
+        crate::gpu::uma::get()
+    } else {
+        None
+    }
+}
+
+fn add(u: &Uma, va: usize, what: Traffic, n: u64) {
+    COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed);
+}
+
+#[inline]
+pub(super) fn count(va: usize, what: Traffic, n: u64) {
+    if let Some(u) = on() {
+        add(u, va, what, n);
+    }
+}
+
+/// The copies of a submitted upload (window address, CPU address, bytes).
+#[inline]
+pub(super) fn uploaded(copies: &[(usize, usize, usize)]) {
+    if let Some(u) = on() {
+        for &(a, _, n) in copies {
+            add(u, a, Traffic::Up, n as u64);
+        }
+    }
+}
+
+#[inline]
+pub(super) fn written(pages: &[usize]) {
+    if let Some(u) = on() {
+        for &p in pages {
+            add(u, p, Traffic::Written, 1);
+        }
+    }
+}
+
+/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and
+/// the first `FIRST` of each path logged.
+#[inline]
+pub(super) fn given(path: Path, va: u64, len: u64) {
+    if va == 0 {
+        return;
+    }
+    if let Some(u) = on() {
+        given_in(u, path, va, len);
+    }
+}
+
+fn given_in(u: &Uma, path: Path, va: u64, len: u64) {
+    if place(u, va as usize).is_some() {
+        return;
+    }
+    if OUTSIDE[path as usize].fetch_add(1, Ordering::Relaxed) < FIRST {
+        crate::xlog_info!("{}", outside_address(path, va, len, region(va as usize)));
+    }
+}
+
+/// What the counters know of the window of `va`, for a crash report (empty: nothing counted).
+pub fn crash_part(va: usize) -> String {
+    let Some(k) = crate::gpu::uma::existing().and_then(|u| u.window_of(va)).filter(|_| enabled()) else { return String::new() };
+    totals_part(std::array::from_fn(|i| COUNTS[k][i].load(Ordering::Relaxed)))
+}
+
+fn totals_part(t: [u64; TRAFFIC]) -> String {
+    format!(
+        "; its window so far {} KB up, {} pages written, {} KB read back, {} tiles filled",
+        t[Traffic::Up as usize] >> 10,
+        t[Traffic::Written as usize],
+        t[Traffic::Back as usize] >> 10,
+        t[Traffic::Filled as usize]
+    )
+}
+
+/// What the title has at `va`, an address in no window.
+fn region(va: usize) -> &'static str {
+    if crate::hle::kernelx::mirrors::source(va).is_some() {
+        "a GPU view of the title's memory"
+    } else if crate::hle::kernelx::in_graphics_reservation(va) {
+        "a graphics reservation of the title's"
+    } else if crate::gpu::shader::readable(va, 1) {
+        "the title's plain memory"
+    } else {
+        "no memory committed"
+    }
+}
+
+fn outside_address(path: Path, va: u64, len: u64, region: &str) -> String {
+    format!("D3D12.X: XCL_WINDOW_STATS: {} at {va:#x} ({len} bytes) lies in no memory window: {region}", NAMES[path as usize])
+}
+
+/// Window `k` of `u`: its kind, or None when the layout has no window there.
+pub fn kind(u: &Uma, k: usize) -> Option<&'static str> {
+    match () {
+        _ if u.is_sparse_window(k) => Some("sparse"),
+        _ if u.is_committed_window(k) => Some("coherent"),
+        _ if u.is_view_window(k) => Some("view"),
+        _ => None,
+    }
+}
+
+/// The window `va` lies in and its kind (None: no window).
+fn place(u: &Uma, va: usize) -> Option<(usize, &'static str)> {
+    let k = u.window_of(va)?;
+    Some((k, kind(u, k)?))
+}
+
+#[derive(Clone, Copy)]
+struct Totals {
+    counts: [[u64; TRAFFIC]; SLOTS],
+    outside: [u64; PATHS],
+}
+
+fn totals() -> Totals {
+    Totals {
+        counts: std::array::from_fn(|k| std::array::from_fn(|i| COUNTS[k][i].load(Ordering::Relaxed))),
+        outside: std::array::from_fn(|i| OUTSIDE[i].load(Ordering::Relaxed)),
+    }
+}
+
+fn delta(now: &[u64; TRAFFIC], before: &[u64; TRAFFIC]) -> [u64; TRAFFIC] {
+    std::array::from_fn(|i| now[i].wrapping_sub(before[i]))
+}
+
+fn window_line(k: usize, kind: &str, (start, len): (usize, usize), mapped: u64, t: [u64; TRAFFIC]) -> String {
+    format!(
+        "D3D12.X: window {k} ({kind}, {start:#x}..{:#x}): {} MB mapped; since the last line {} KB up, {} pages written, {} KB read back, {} tiles filled",
+        start + len,
+        mapped >> 20,
+        t[Traffic::Up as usize] >> 10,
+        t[Traffic::Written as usize],
+        t[Traffic::Back as usize] >> 10,
+        t[Traffic::Filled as usize]
+    )
+}
+
+fn outside_line(outside: &[u64; PATHS], written: u64) -> String {
+    let parts: Vec<String> = (0..PATHS).filter(|&i| outside[i] != 0).map(|i| format!("{} {}", outside[i], NAMES[i])).collect();
+    let total: u64 = outside.iter().sum();
+    let by_path = if parts.is_empty() { String::new() } else { format!(" ({})", parts.join(", ")) };
+    format!("D3D12.X: outside every window: since the last line {total} addresses given to the GPU{by_path}, {written} pages written")
+}
+
+fn lines(u: &Uma, mapped: &BTreeMap<usize, u64>, now: &Totals, before: &Totals) -> Vec<String> {
+    let mut out = Vec::new();
+    for k in 0..MAX_HEAP_WINDOWS {
+        let Some(kind) = kind(u, k) else { continue };
+        let (start, len) = u.window(k);
+        let bytes = if u.is_committed_window(k) { len as u64 } else { mapped.get(&start).copied().unwrap_or(0) };
+        let t = delta(&now.counts[k], &before.counts[k]);
+        if bytes != 0 || t.iter().any(|&n| n != 0) {
+            out.push(window_line(k, kind, (start, len), bytes, t));
+        }
+    }
+    let outside: [u64; PATHS] = std::array::from_fn(|i| now.outside[i].wrapping_sub(before.outside[i]));
+    let written = delta(&now.counts[MAX_HEAP_WINDOWS], &before.counts[MAX_HEAP_WINDOWS])[Traffic::Written as usize];
+    out.push(outside_line(&outside, written));
+    out
+}
+
+fn log(now: &Totals, before: &Totals) {
+    let Some(u) = crate::gpu::uma::get() else { return };

Medium: log() (and on() at ~56) call crate::gpu::uma::get(), which creates the UMA region on first call, instead of uma::existing(), whose comment says "Observability must not allocate it." window_stats::start() runs in host_main before preparation::before_guest, so with XCL_WINDOW_STATS=1 the stats thread wakes after 1 s while shader preparation is still running (which can take minutes) and calls uma::get(). That reserves the aperture and commits the coherent window (up to GBs of resident memory) on the stats thread long before the title would have, so a debug switch changes when and on which thread the title's memory is made. This comes from the stacked XCL_WINDOW_STATS commit. Note also that XCL_WINDOW_STATS=0 turns it on at 1 s (.max(1)) rather than off. Using existing() in log() and on() would fix it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772851788 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#discussion_r4772851788). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:34:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/window_stats.rs`; line 216 ~~~~diff @@ -0,0 +1,321 @@ +//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window +//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and +//! was filled since the line before; and a line for the addresses the title gave the GPU that lie +//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by +//! default: each counter is then one branch. + +use std::collections::BTreeMap; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::OnceLock; +use std::time::Duration; + +use super::view_want::{Path, NAMES, PATHS}; +use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS}; + +fn seconds() -> Option<u64> { + static N: OnceLock<Option<u64>> = OnceLock::new(); + *N.get_or_init(|| { + let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1); + crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s"); + Some(n) + }) +} + +#[inline] +pub(super) fn enabled() -> bool { + seconds().is_some() +} + +#[derive(Clone, Copy)] +pub(super) enum Traffic { + /// bytes copied up from the CPU + Up, + /// pages the write watch found written + Written, + /// bytes copied back to the CPU + Back, + /// GPU-view tiles given video memory and filled from the CPU view + Filled, +} + +const TRAFFIC: usize = 4; +/// the windows', and last what lies in none +const SLOTS: usize = MAX_HEAP_WINDOWS + 1; +/// addresses outside every window logged for each path +const FIRST: u64 = 8; + +#[allow(clippy::declare_interior_mutable_const)] +const ZERO: AtomicU64 = AtomicU64::new(0); +#[allow(clippy::declare_interior_mutable_const)] +const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC]; +static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS]; +static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS]; + +fn on() -> Option<&'static Uma> { + if enabled() { + crate::gpu::uma::get() + } else { + None + } +} + +fn add(u: &Uma, va: usize, what: Traffic, n: u64) { + COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed); +} + +#[inline] +pub(super) fn count(va: usize, what: Traffic, n: u64) { + if let Some(u) = on() { + add(u, va, what, n); + } +} + +/// The copies of a submitted upload (window address, CPU address, bytes). +#[inline] +pub(super) fn uploaded(copies: &[(usize, usize, usize)]) { + if let Some(u) = on() { + for &(a, _, n) in copies { + add(u, a, Traffic::Up, n as u64); + } + } +} + +#[inline] +pub(super) fn written(pages: &[usize]) { + if let Some(u) = on() { + for &p in pages { + add(u, p, Traffic::Written, 1); + } + } +} + +/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and +/// the first `FIRST` of each path logged. +#[inline] +pub(super) fn given(path: Path, va: u64, len: u64) { + if va == 0 { + return; + } + if let Some(u) = on() { + given_in(u, path, va, len); + } +} + +fn given_in(u: &Uma, path: Path, va: u64, len: u64) { + if place(u, va as usize).is_some() { + return; + } + if OUTSIDE[path as usize].fetch_add(1, Ordering::Relaxed) < FIRST { + crate::xlog_info!("{}", outside_address(path, va, len, region(va as usize))); + } +} + +/// What the counters know of the window of `va`, for a crash report (empty: nothing counted). +pub fn crash_part(va: usize) -> String { + let Some(k) = crate::gpu::uma::existing().and_then(|u| u.window_of(va)).filter(|_| enabled()) else { return String::new() }; + totals_part(std::array::from_fn(|i| COUNTS[k][i].load(Ordering::Relaxed))) +} + +fn totals_part(t: [u64; TRAFFIC]) -> String { + format!( + "; its window so far {} KB up, {} pages written, {} KB read back, {} tiles filled", + t[Traffic::Up as usize] >> 10, + t[Traffic::Written as usize], + t[Traffic::Back as usize] >> 10, + t[Traffic::Filled as usize] + ) +} + +/// What the title has at `va`, an address in no window. +fn region(va: usize) -> &'static str { + if crate::hle::kernelx::mirrors::source(va).is_some() { + "a GPU view of the title's memory" + } else if crate::hle::kernelx::in_graphics_reservation(va) { + "a graphics reservation of the title's" + } else if crate::gpu::shader::readable(va, 1) { + "the title's plain memory" + } else { + "no memory committed" + } +} + +fn outside_address(path: Path, va: u64, len: u64, region: &str) -> String { + format!("D3D12.X: XCL_WINDOW_STATS: {} at {va:#x} ({len} bytes) lies in no memory window: {region}", NAMES[path as usize]) +} + +/// Window `k` of `u`: its kind, or None when the layout has no window there. +pub fn kind(u: &Uma, k: usize) -> Option<&'static str> { + match () { + _ if u.is_sparse_window(k) => Some("sparse"), + _ if u.is_committed_window(k) => Some("coherent"), + _ if u.is_view_window(k) => Some("view"), + _ => None, + } +} + +/// The window `va` lies in and its kind (None: no window). +fn place(u: &Uma, va: usize) -> Option<(usize, &'static str)> { + let k = u.window_of(va)?; + Some((k, kind(u, k)?)) +} + +#[derive(Clone, Copy)] +struct Totals { + counts: [[u64; TRAFFIC]; SLOTS], + outside: [u64; PATHS], +} + +fn totals() -> Totals { + Totals { + counts: std::array::from_fn(|k| std::array::from_fn(|i| COUNTS[k][i].load(Ordering::Relaxed))), + outside: std::array::from_fn(|i| OUTSIDE[i].load(Ordering::Relaxed)), + } +} + +fn delta(now: &[u64; TRAFFIC], before: &[u64; TRAFFIC]) -> [u64; TRAFFIC] { + std::array::from_fn(|i| now[i].wrapping_sub(before[i])) +} + +fn window_line(k: usize, kind: &str, (start, len): (usize, usize), mapped: u64, t: [u64; TRAFFIC]) -> String { + format!( + "D3D12.X: window {k} ({kind}, {start:#x}..{:#x}): {} MB mapped; since the last line {} KB up, {} pages written, {} KB read back, {} tiles filled", + start + len, + mapped >> 20, + t[Traffic::Up as usize] >> 10, + t[Traffic::Written as usize], + t[Traffic::Back as usize] >> 10, + t[Traffic::Filled as usize] + ) +} + +fn outside_line(outside: &[u64; PATHS], written: u64) -> String { + let parts: Vec<String> = (0..PATHS).filter(|&i| outside[i] != 0).map(|i| format!("{} {}", outside[i], NAMES[i])).collect(); + let total: u64 = outside.iter().sum(); + let by_path = if parts.is_empty() { String::new() } else { format!(" ({})", parts.join(", ")) }; + format!("D3D12.X: outside every window: since the last line {total} addresses given to the GPU{by_path}, {written} pages written") +} + +fn lines(u: &Uma, mapped: &BTreeMap<usize, u64>, now: &Totals, before: &Totals) -> Vec<String> { + let mut out = Vec::new(); + for k in 0..MAX_HEAP_WINDOWS { + let Some(kind) = kind(u, k) else { continue }; + let (start, len) = u.window(k); + let bytes = if u.is_committed_window(k) { len as u64 } else { mapped.get(&start).copied().unwrap_or(0) }; + let t = delta(&now.counts[k], &before.counts[k]); + if bytes != 0 || t.iter().any(|&n| n != 0) { + out.push(window_line(k, kind, (start, len), bytes, t)); + } + } + let outside: [u64; PATHS] = std::array::from_fn(|i| now.outside[i].wrapping_sub(before.outside[i])); + let written = delta(&now.counts[MAX_HEAP_WINDOWS], &before.counts[MAX_HEAP_WINDOWS])[Traffic::Written as usize]; + out.push(outside_line(&outside, written)); + out +} + +fn log(now: &Totals, before: &Totals) { + let Some(u) = crate::gpu::uma::get() else { return }; ~~~~ --- **Medium**: `log()` (and `on()` at ~56) call `crate::gpu::uma::get()`, which creates the UMA region on first call, instead of `uma::existing()`, whose comment says "Observability must not allocate it." `window_stats::start()` runs in `host_main` before `preparation::before_guest`, so with XCL_WINDOW_STATS=1 the stats thread wakes after 1 s while shader preparation is still running (which can take minutes) and calls `uma::get()`. That reserves the aperture and commits the coherent window (up to GBs of resident memory) on the stats thread long before the title would have, so a debug switch changes when and on which thread the title's memory is made. This comes from the stacked XCL_WINDOW_STATS commit. Note also that XCL_WINDOW_STATS=0 turns it on at 1 s (`.max(1)`) rather than off. Using `existing()` in `log()` and `on()` would fix it.
bmjask commented 2026-12-02 16:34:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:34:18Z.

Code review location: crates/xcl/src/hle/d3d12x/window_stats.rs; line 114

@@ -0,0 +1,321 @@
+//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window
+//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and
+//! was filled since the line before; and a line for the addresses the title gave the GPU that lie
+//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by
+//! default: each counter is then one branch.
+
+use std::collections::BTreeMap;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::OnceLock;
+use std::time::Duration;
+
+use super::view_want::{Path, NAMES, PATHS};
+use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS};
+
+fn seconds() -> Option<u64> {
+    static N: OnceLock<Option<u64>> = OnceLock::new();
+    *N.get_or_init(|| {
+        let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1);
+        crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s");
+        Some(n)
+    })
+}
+
+#[inline]
+pub(super) fn enabled() -> bool {
+    seconds().is_some()
+}
+
+#[derive(Clone, Copy)]
+pub(super) enum Traffic {
+    /// bytes copied up from the CPU
+    Up,
+    /// pages the write watch found written
+    Written,
+    /// bytes copied back to the CPU
+    Back,
+    /// GPU-view tiles given video memory and filled from the CPU view
+    Filled,
+}
+
+const TRAFFIC: usize = 4;
+/// the windows', and last what lies in none
+const SLOTS: usize = MAX_HEAP_WINDOWS + 1;
+/// addresses outside every window logged for each path
+const FIRST: u64 = 8;
+
+#[allow(clippy::declare_interior_mutable_const)]
+const ZERO: AtomicU64 = AtomicU64::new(0);
+#[allow(clippy::declare_interior_mutable_const)]
+const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC];
+static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS];
+static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS];
+
+fn on() -> Option<&'static Uma> {
+    if enabled() {
+        crate::gpu::uma::get()
+    } else {
+        None
+    }
+}
+
+fn add(u: &Uma, va: usize, what: Traffic, n: u64) {
+    COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed);
+}
+
+#[inline]
+pub(super) fn count(va: usize, what: Traffic, n: u64) {
+    if let Some(u) = on() {
+        add(u, va, what, n);
+    }
+}
+
+/// The copies of a submitted upload (window address, CPU address, bytes).
+#[inline]
+pub(super) fn uploaded(copies: &[(usize, usize, usize)]) {
+    if let Some(u) = on() {
+        for &(a, _, n) in copies {
+            add(u, a, Traffic::Up, n as u64);
+        }
+    }
+}
+
+#[inline]
+pub(super) fn written(pages: &[usize]) {
+    if let Some(u) = on() {
+        for &p in pages {
+            add(u, p, Traffic::Written, 1);
+        }
+    }
+}
+
+/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and
+/// the first `FIRST` of each path logged.
+#[inline]
+pub(super) fn given(path: Path, va: u64, len: u64) {
+    if va == 0 {
+        return;
+    }
+    if let Some(u) = on() {
+        given_in(u, path, va, len);
+    }
+}
+
+fn given_in(u: &Uma, path: Path, va: u64, len: u64) {
+    if place(u, va as usize).is_some() {
+        return;
+    }
+    if OUTSIDE[path as usize].fetch_add(1, Ordering::Relaxed) < FIRST {
+        crate::xlog_info!("{}", outside_address(path, va, len, region(va as usize)));
+    }
+}
+
+/// What the counters know of the window of `va`, for a crash report (empty: nothing counted).
+pub fn crash_part(va: usize) -> String {

Medium: Not certain about this one: crash_part runs from the unhandled-exception filter and calls enabled() -> seconds() -> OnceLock::get_or_init. If that OnceLock was never set, it reads the environment and calls xlog_info! inside the crash path, and it can block on a concurrent initializer, against the PR's "locks are only tried, never waited for". In an early crash, or a process that installed the filter but skips host_main's start(), the first enabled() runs inside the filter, and if another thread is inside get_or_init at that moment the crashing thread waits on it, so the report may never be written. Using OnceLock::get() there would avoid it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4772851807 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#discussion_r4772851807). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:34:18Z. **Code review location:** `crates/xcl/src/hle/d3d12x/window_stats.rs`; line 114 ~~~~diff @@ -0,0 +1,321 @@ +//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window +//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and +//! was filled since the line before; and a line for the addresses the title gave the GPU that lie +//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by +//! default: each counter is then one branch. + +use std::collections::BTreeMap; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::OnceLock; +use std::time::Duration; + +use super::view_want::{Path, NAMES, PATHS}; +use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS}; + +fn seconds() -> Option<u64> { + static N: OnceLock<Option<u64>> = OnceLock::new(); + *N.get_or_init(|| { + let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1); + crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s"); + Some(n) + }) +} + +#[inline] +pub(super) fn enabled() -> bool { + seconds().is_some() +} + +#[derive(Clone, Copy)] +pub(super) enum Traffic { + /// bytes copied up from the CPU + Up, + /// pages the write watch found written + Written, + /// bytes copied back to the CPU + Back, + /// GPU-view tiles given video memory and filled from the CPU view + Filled, +} + +const TRAFFIC: usize = 4; +/// the windows', and last what lies in none +const SLOTS: usize = MAX_HEAP_WINDOWS + 1; +/// addresses outside every window logged for each path +const FIRST: u64 = 8; + +#[allow(clippy::declare_interior_mutable_const)] +const ZERO: AtomicU64 = AtomicU64::new(0); +#[allow(clippy::declare_interior_mutable_const)] +const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC]; +static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS]; +static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS]; + +fn on() -> Option<&'static Uma> { + if enabled() { + crate::gpu::uma::get() + } else { + None + } +} + +fn add(u: &Uma, va: usize, what: Traffic, n: u64) { + COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed); +} + +#[inline] +pub(super) fn count(va: usize, what: Traffic, n: u64) { + if let Some(u) = on() { + add(u, va, what, n); + } +} + +/// The copies of a submitted upload (window address, CPU address, bytes). +#[inline] +pub(super) fn uploaded(copies: &[(usize, usize, usize)]) { + if let Some(u) = on() { + for &(a, _, n) in copies { + add(u, a, Traffic::Up, n as u64); + } + } +} + +#[inline] +pub(super) fn written(pages: &[usize]) { + if let Some(u) = on() { + for &p in pages { + add(u, p, Traffic::Written, 1); + } + } +} + +/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and +/// the first `FIRST` of each path logged. +#[inline] +pub(super) fn given(path: Path, va: u64, len: u64) { + if va == 0 { + return; + } + if let Some(u) = on() { + given_in(u, path, va, len); + } +} + +fn given_in(u: &Uma, path: Path, va: u64, len: u64) { + if place(u, va as usize).is_some() { + return; + } + if OUTSIDE[path as usize].fetch_add(1, Ordering::Relaxed) < FIRST { + crate::xlog_info!("{}", outside_address(path, va, len, region(va as usize))); + } +} + +/// What the counters know of the window of `va`, for a crash report (empty: nothing counted). +pub fn crash_part(va: usize) -> String { ~~~~ --- **Medium**: Not certain about this one: `crash_part` runs from the unhandled-exception filter and calls `enabled()` -> `seconds()` -> `OnceLock::get_or_init`. If that OnceLock was never set, it reads the environment and calls `xlog_info!` inside the crash path, and it can block on a concurrent initializer, against the PR's "locks are only tried, never waited for". In an early crash, or a process that installed the filter but skips `host_main`'s `start()`, the first `enabled()` runs inside the filter, and if another thread is inside `get_or_init` at that moment the crashing thread waits on it, so the report may never be written. Using `OnceLock::get()` there would avoid it.
bmjask commented 2026-12-02 16:34:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:34:18Z.

Review: COMMENTED


Review of 67ac04a2: 2 finding(s) (2 medium), most severe first.

  1. Medium crates/xcl/src/hle/d3d12x/window_stats.rs:216: log() (and on() at ~56) call crate::gpu::uma::get(), which creates the UMA region on first call, instead of uma::existing(), whose comment says "Observability must not allocate it." window_stats::start() runs in host_main bef.... (inline)
  2. Medium crates/xcl/src/hle/d3d12x/window_stats.rs:114: Not certain about this one: crash_part runs from the unhandled-exception filter and calls enabled() -> seconds() -> OnceLock::get_or_init. (inline)

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6154997830 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#pullrequestreview-6154997830). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:34:18Z. **Review:** COMMENTED --- Review of `67ac04a2`: 2 finding(s) (2 medium), most severe first. 1. **Medium** `crates/xcl/src/hle/d3d12x/window_stats.rs:216`: `log()` (and `on()` at ~56) call `crate::gpu::uma::get()`, which creates the UMA region on first call, instead of `uma::existing()`, whose comment says "Observability must not allocate it." `window_stats::start()` runs in `host_main` bef.... (inline) 2. **Medium** `crates/xcl/src/hle/d3d12x/window_stats.rs:114`: Not certain about this one: `crash_part` runs from the unhandled-exception filter and calls `enabled()` -> `seconds()` -> `OnceLock::get_or_init`. (inline) --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-02 16:34:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T16:34:20Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7352141396 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#issuecomment-7352141396). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T16:34:20Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Royalflamejlh commented 2026-12-02 20:47:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:47:03Z.

Code review location: crates/xcl/src/hle/d3d12x/window_stats.rs; line 216

@@ -0,0 +1,321 @@
+//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window
+//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and
+//! was filled since the line before; and a line for the addresses the title gave the GPU that lie
+//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by
+//! default: each counter is then one branch.
+
+use std::collections::BTreeMap;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::OnceLock;
+use std::time::Duration;
+
+use super::view_want::{Path, NAMES, PATHS};
+use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS};
+
+fn seconds() -> Option<u64> {
+    static N: OnceLock<Option<u64>> = OnceLock::new();
+    *N.get_or_init(|| {
+        let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1);
+        crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s");
+        Some(n)
+    })
+}
+
+#[inline]
+pub(super) fn enabled() -> bool {
+    seconds().is_some()
+}
+
+#[derive(Clone, Copy)]
+pub(super) enum Traffic {
+    /// bytes copied up from the CPU
+    Up,
+    /// pages the write watch found written
+    Written,
+    /// bytes copied back to the CPU
+    Back,
+    /// GPU-view tiles given video memory and filled from the CPU view
+    Filled,
+}
+
+const TRAFFIC: usize = 4;
+/// the windows', and last what lies in none
+const SLOTS: usize = MAX_HEAP_WINDOWS + 1;
+/// addresses outside every window logged for each path
+const FIRST: u64 = 8;
+
+#[allow(clippy::declare_interior_mutable_const)]
+const ZERO: AtomicU64 = AtomicU64::new(0);
+#[allow(clippy::declare_interior_mutable_const)]
+const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC];
+static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS];
+static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS];
+
+fn on() -> Option<&'static Uma> {
+    if enabled() {
+        crate::gpu::uma::get()
+    } else {
+        None
+    }
+}
+
+fn add(u: &Uma, va: usize, what: Traffic, n: u64) {
+    COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed);
+}
+
+#[inline]
+pub(super) fn count(va: usize, what: Traffic, n: u64) {
+    if let Some(u) = on() {
+        add(u, va, what, n);
+    }
+}
+
+/// The copies of a submitted upload (window address, CPU address, bytes).
+#[inline]
+pub(super) fn uploaded(copies: &[(usize, usize, usize)]) {
+    if let Some(u) = on() {
+        for &(a, _, n) in copies {
+            add(u, a, Traffic::Up, n as u64);
+        }
+    }
+}
+
+#[inline]
+pub(super) fn written(pages: &[usize]) {
+    if let Some(u) = on() {
+        for &p in pages {
+            add(u, p, Traffic::Written, 1);
+        }
+    }
+}
+
+/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and
+/// the first `FIRST` of each path logged.
+#[inline]
+pub(super) fn given(path: Path, va: u64, len: u64) {
+    if va == 0 {
+        return;
+    }
+    if let Some(u) = on() {
+        given_in(u, path, va, len);
+    }
+}
+
+fn given_in(u: &Uma, path: Path, va: u64, len: u64) {
+    if place(u, va as usize).is_some() {
+        return;
+    }
+    if OUTSIDE[path as usize].fetch_add(1, Ordering::Relaxed) < FIRST {
+        crate::xlog_info!("{}", outside_address(path, va, len, region(va as usize)));
+    }
+}
+
+/// What the counters know of the window of `va`, for a crash report (empty: nothing counted).
+pub fn crash_part(va: usize) -> String {
+    let Some(k) = crate::gpu::uma::existing().and_then(|u| u.window_of(va)).filter(|_| enabled()) else { return String::new() };
+    totals_part(std::array::from_fn(|i| COUNTS[k][i].load(Ordering::Relaxed)))
+}
+
+fn totals_part(t: [u64; TRAFFIC]) -> String {
+    format!(
+        "; its window so far {} KB up, {} pages written, {} KB read back, {} tiles filled",
+        t[Traffic::Up as usize] >> 10,
+        t[Traffic::Written as usize],
+        t[Traffic::Back as usize] >> 10,
+        t[Traffic::Filled as usize]
+    )
+}
+
+/// What the title has at `va`, an address in no window.
+fn region(va: usize) -> &'static str {
+    if crate::hle::kernelx::mirrors::source(va).is_some() {
+        "a GPU view of the title's memory"
+    } else if crate::hle::kernelx::in_graphics_reservation(va) {
+        "a graphics reservation of the title's"
+    } else if crate::gpu::shader::readable(va, 1) {
+        "the title's plain memory"
+    } else {
+        "no memory committed"
+    }
+}
+
+fn outside_address(path: Path, va: u64, len: u64, region: &str) -> String {
+    format!("D3D12.X: XCL_WINDOW_STATS: {} at {va:#x} ({len} bytes) lies in no memory window: {region}", NAMES[path as usize])
+}
+
+/// Window `k` of `u`: its kind, or None when the layout has no window there.
+pub fn kind(u: &Uma, k: usize) -> Option<&'static str> {
+    match () {
+        _ if u.is_sparse_window(k) => Some("sparse"),
+        _ if u.is_committed_window(k) => Some("coherent"),
+        _ if u.is_view_window(k) => Some("view"),
+        _ => None,
+    }
+}
+
+/// The window `va` lies in and its kind (None: no window).
+fn place(u: &Uma, va: usize) -> Option<(usize, &'static str)> {
+    let k = u.window_of(va)?;
+    Some((k, kind(u, k)?))
+}
+
+#[derive(Clone, Copy)]
+struct Totals {
+    counts: [[u64; TRAFFIC]; SLOTS],
+    outside: [u64; PATHS],
+}
+
+fn totals() -> Totals {
+    Totals {
+        counts: std::array::from_fn(|k| std::array::from_fn(|i| COUNTS[k][i].load(Ordering::Relaxed))),
+        outside: std::array::from_fn(|i| OUTSIDE[i].load(Ordering::Relaxed)),
+    }
+}
+
+fn delta(now: &[u64; TRAFFIC], before: &[u64; TRAFFIC]) -> [u64; TRAFFIC] {
+    std::array::from_fn(|i| now[i].wrapping_sub(before[i]))
+}
+
+fn window_line(k: usize, kind: &str, (start, len): (usize, usize), mapped: u64, t: [u64; TRAFFIC]) -> String {
+    format!(
+        "D3D12.X: window {k} ({kind}, {start:#x}..{:#x}): {} MB mapped; since the last line {} KB up, {} pages written, {} KB read back, {} tiles filled",
+        start + len,
+        mapped >> 20,
+        t[Traffic::Up as usize] >> 10,
+        t[Traffic::Written as usize],
+        t[Traffic::Back as usize] >> 10,
+        t[Traffic::Filled as usize]
+    )
+}
+
+fn outside_line(outside: &[u64; PATHS], written: u64) -> String {
+    let parts: Vec<String> = (0..PATHS).filter(|&i| outside[i] != 0).map(|i| format!("{} {}", outside[i], NAMES[i])).collect();
+    let total: u64 = outside.iter().sum();
+    let by_path = if parts.is_empty() { String::new() } else { format!(" ({})", parts.join(", ")) };
+    format!("D3D12.X: outside every window: since the last line {total} addresses given to the GPU{by_path}, {written} pages written")
+}
+
+fn lines(u: &Uma, mapped: &BTreeMap<usize, u64>, now: &Totals, before: &Totals) -> Vec<String> {
+    let mut out = Vec::new();
+    for k in 0..MAX_HEAP_WINDOWS {
+        let Some(kind) = kind(u, k) else { continue };
+        let (start, len) = u.window(k);
+        let bytes = if u.is_committed_window(k) { len as u64 } else { mapped.get(&start).copied().unwrap_or(0) };
+        let t = delta(&now.counts[k], &before.counts[k]);
+        if bytes != 0 || t.iter().any(|&n| n != 0) {
+            out.push(window_line(k, kind, (start, len), bytes, t));
+        }
+    }
+    let outside: [u64; PATHS] = std::array::from_fn(|i| now.outside[i].wrapping_sub(before.outside[i]));
+    let written = delta(&now.counts[MAX_HEAP_WINDOWS], &before.counts[MAX_HEAP_WINDOWS])[Traffic::Written as usize];
+    out.push(outside_line(&outside, written));
+    out
+}
+
+fn log(now: &Totals, before: &Totals) {
+    let Some(u) = crate::gpu::uma::get() else { return };

Right on both. log() and on() now take uma::existing(), so the stats thread never makes the UMA region, and XCL_WINDOW_STATS=0 is off (every in window_stats.rs; zero_seconds_is_off failed without it). The code is #3627's, so the fix is in its commit, 2580976a; this PR's head is 371b0fe2. The existing() change has no test: whether the region exists is process-wide, and the test process has already made it.

AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775811869 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#discussion_r4775811869). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:47:03Z. **Code review location:** `crates/xcl/src/hle/d3d12x/window_stats.rs`; line 216 ~~~~diff @@ -0,0 +1,321 @@ +//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window +//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and +//! was filled since the line before; and a line for the addresses the title gave the GPU that lie +//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by +//! default: each counter is then one branch. + +use std::collections::BTreeMap; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::OnceLock; +use std::time::Duration; + +use super::view_want::{Path, NAMES, PATHS}; +use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS}; + +fn seconds() -> Option<u64> { + static N: OnceLock<Option<u64>> = OnceLock::new(); + *N.get_or_init(|| { + let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1); + crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s"); + Some(n) + }) +} + +#[inline] +pub(super) fn enabled() -> bool { + seconds().is_some() +} + +#[derive(Clone, Copy)] +pub(super) enum Traffic { + /// bytes copied up from the CPU + Up, + /// pages the write watch found written + Written, + /// bytes copied back to the CPU + Back, + /// GPU-view tiles given video memory and filled from the CPU view + Filled, +} + +const TRAFFIC: usize = 4; +/// the windows', and last what lies in none +const SLOTS: usize = MAX_HEAP_WINDOWS + 1; +/// addresses outside every window logged for each path +const FIRST: u64 = 8; + +#[allow(clippy::declare_interior_mutable_const)] +const ZERO: AtomicU64 = AtomicU64::new(0); +#[allow(clippy::declare_interior_mutable_const)] +const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC]; +static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS]; +static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS]; + +fn on() -> Option<&'static Uma> { + if enabled() { + crate::gpu::uma::get() + } else { + None + } +} + +fn add(u: &Uma, va: usize, what: Traffic, n: u64) { + COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed); +} + +#[inline] +pub(super) fn count(va: usize, what: Traffic, n: u64) { + if let Some(u) = on() { + add(u, va, what, n); + } +} + +/// The copies of a submitted upload (window address, CPU address, bytes). +#[inline] +pub(super) fn uploaded(copies: &[(usize, usize, usize)]) { + if let Some(u) = on() { + for &(a, _, n) in copies { + add(u, a, Traffic::Up, n as u64); + } + } +} + +#[inline] +pub(super) fn written(pages: &[usize]) { + if let Some(u) = on() { + for &p in pages { + add(u, p, Traffic::Written, 1); + } + } +} + +/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and +/// the first `FIRST` of each path logged. +#[inline] +pub(super) fn given(path: Path, va: u64, len: u64) { + if va == 0 { + return; + } + if let Some(u) = on() { + given_in(u, path, va, len); + } +} + +fn given_in(u: &Uma, path: Path, va: u64, len: u64) { + if place(u, va as usize).is_some() { + return; + } + if OUTSIDE[path as usize].fetch_add(1, Ordering::Relaxed) < FIRST { + crate::xlog_info!("{}", outside_address(path, va, len, region(va as usize))); + } +} + +/// What the counters know of the window of `va`, for a crash report (empty: nothing counted). +pub fn crash_part(va: usize) -> String { + let Some(k) = crate::gpu::uma::existing().and_then(|u| u.window_of(va)).filter(|_| enabled()) else { return String::new() }; + totals_part(std::array::from_fn(|i| COUNTS[k][i].load(Ordering::Relaxed))) +} + +fn totals_part(t: [u64; TRAFFIC]) -> String { + format!( + "; its window so far {} KB up, {} pages written, {} KB read back, {} tiles filled", + t[Traffic::Up as usize] >> 10, + t[Traffic::Written as usize], + t[Traffic::Back as usize] >> 10, + t[Traffic::Filled as usize] + ) +} + +/// What the title has at `va`, an address in no window. +fn region(va: usize) -> &'static str { + if crate::hle::kernelx::mirrors::source(va).is_some() { + "a GPU view of the title's memory" + } else if crate::hle::kernelx::in_graphics_reservation(va) { + "a graphics reservation of the title's" + } else if crate::gpu::shader::readable(va, 1) { + "the title's plain memory" + } else { + "no memory committed" + } +} + +fn outside_address(path: Path, va: u64, len: u64, region: &str) -> String { + format!("D3D12.X: XCL_WINDOW_STATS: {} at {va:#x} ({len} bytes) lies in no memory window: {region}", NAMES[path as usize]) +} + +/// Window `k` of `u`: its kind, or None when the layout has no window there. +pub fn kind(u: &Uma, k: usize) -> Option<&'static str> { + match () { + _ if u.is_sparse_window(k) => Some("sparse"), + _ if u.is_committed_window(k) => Some("coherent"), + _ if u.is_view_window(k) => Some("view"), + _ => None, + } +} + +/// The window `va` lies in and its kind (None: no window). +fn place(u: &Uma, va: usize) -> Option<(usize, &'static str)> { + let k = u.window_of(va)?; + Some((k, kind(u, k)?)) +} + +#[derive(Clone, Copy)] +struct Totals { + counts: [[u64; TRAFFIC]; SLOTS], + outside: [u64; PATHS], +} + +fn totals() -> Totals { + Totals { + counts: std::array::from_fn(|k| std::array::from_fn(|i| COUNTS[k][i].load(Ordering::Relaxed))), + outside: std::array::from_fn(|i| OUTSIDE[i].load(Ordering::Relaxed)), + } +} + +fn delta(now: &[u64; TRAFFIC], before: &[u64; TRAFFIC]) -> [u64; TRAFFIC] { + std::array::from_fn(|i| now[i].wrapping_sub(before[i])) +} + +fn window_line(k: usize, kind: &str, (start, len): (usize, usize), mapped: u64, t: [u64; TRAFFIC]) -> String { + format!( + "D3D12.X: window {k} ({kind}, {start:#x}..{:#x}): {} MB mapped; since the last line {} KB up, {} pages written, {} KB read back, {} tiles filled", + start + len, + mapped >> 20, + t[Traffic::Up as usize] >> 10, + t[Traffic::Written as usize], + t[Traffic::Back as usize] >> 10, + t[Traffic::Filled as usize] + ) +} + +fn outside_line(outside: &[u64; PATHS], written: u64) -> String { + let parts: Vec<String> = (0..PATHS).filter(|&i| outside[i] != 0).map(|i| format!("{} {}", outside[i], NAMES[i])).collect(); + let total: u64 = outside.iter().sum(); + let by_path = if parts.is_empty() { String::new() } else { format!(" ({})", parts.join(", ")) }; + format!("D3D12.X: outside every window: since the last line {total} addresses given to the GPU{by_path}, {written} pages written") +} + +fn lines(u: &Uma, mapped: &BTreeMap<usize, u64>, now: &Totals, before: &Totals) -> Vec<String> { + let mut out = Vec::new(); + for k in 0..MAX_HEAP_WINDOWS { + let Some(kind) = kind(u, k) else { continue }; + let (start, len) = u.window(k); + let bytes = if u.is_committed_window(k) { len as u64 } else { mapped.get(&start).copied().unwrap_or(0) }; + let t = delta(&now.counts[k], &before.counts[k]); + if bytes != 0 || t.iter().any(|&n| n != 0) { + out.push(window_line(k, kind, (start, len), bytes, t)); + } + } + let outside: [u64; PATHS] = std::array::from_fn(|i| now.outside[i].wrapping_sub(before.outside[i])); + let written = delta(&now.counts[MAX_HEAP_WINDOWS], &before.counts[MAX_HEAP_WINDOWS])[Traffic::Written as usize]; + out.push(outside_line(&outside, written)); + out +} + +fn log(now: &Totals, before: &Totals) { + let Some(u) = crate::gpu::uma::get() else { return }; ~~~~ --- Right on both. `log()` and `on()` now take `uma::existing()`, so the stats thread never makes the UMA region, and `XCL_WINDOW_STATS=0` is off (`every` in `window_stats.rs`; `zero_seconds_is_off` failed without it). The code is #3627's, so the fix is in its commit, `2580976a`; this PR's head is `371b0fe2`. The `existing()` change has no test: whether the region exists is process-wide, and the test process has already made it. AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.
Royalflamejlh commented 2026-12-02 20:47:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T20:47:06Z.

Code review location: crates/xcl/src/hle/d3d12x/window_stats.rs; line 114

@@ -0,0 +1,321 @@
+//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window
+//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and
+//! was filled since the line before; and a line for the addresses the title gave the GPU that lie
+//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by
+//! default: each counter is then one branch.
+
+use std::collections::BTreeMap;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::OnceLock;
+use std::time::Duration;
+
+use super::view_want::{Path, NAMES, PATHS};
+use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS};
+
+fn seconds() -> Option<u64> {
+    static N: OnceLock<Option<u64>> = OnceLock::new();
+    *N.get_or_init(|| {
+        let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1);
+        crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s");
+        Some(n)
+    })
+}
+
+#[inline]
+pub(super) fn enabled() -> bool {
+    seconds().is_some()
+}
+
+#[derive(Clone, Copy)]
+pub(super) enum Traffic {
+    /// bytes copied up from the CPU
+    Up,
+    /// pages the write watch found written
+    Written,
+    /// bytes copied back to the CPU
+    Back,
+    /// GPU-view tiles given video memory and filled from the CPU view
+    Filled,
+}
+
+const TRAFFIC: usize = 4;
+/// the windows', and last what lies in none
+const SLOTS: usize = MAX_HEAP_WINDOWS + 1;
+/// addresses outside every window logged for each path
+const FIRST: u64 = 8;
+
+#[allow(clippy::declare_interior_mutable_const)]
+const ZERO: AtomicU64 = AtomicU64::new(0);
+#[allow(clippy::declare_interior_mutable_const)]
+const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC];
+static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS];
+static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS];
+
+fn on() -> Option<&'static Uma> {
+    if enabled() {
+        crate::gpu::uma::get()
+    } else {
+        None
+    }
+}
+
+fn add(u: &Uma, va: usize, what: Traffic, n: u64) {
+    COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed);
+}
+
+#[inline]
+pub(super) fn count(va: usize, what: Traffic, n: u64) {
+    if let Some(u) = on() {
+        add(u, va, what, n);
+    }
+}
+
+/// The copies of a submitted upload (window address, CPU address, bytes).
+#[inline]
+pub(super) fn uploaded(copies: &[(usize, usize, usize)]) {
+    if let Some(u) = on() {
+        for &(a, _, n) in copies {
+            add(u, a, Traffic::Up, n as u64);
+        }
+    }
+}
+
+#[inline]
+pub(super) fn written(pages: &[usize]) {
+    if let Some(u) = on() {
+        for &p in pages {
+            add(u, p, Traffic::Written, 1);
+        }
+    }
+}
+
+/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and
+/// the first `FIRST` of each path logged.
+#[inline]
+pub(super) fn given(path: Path, va: u64, len: u64) {
+    if va == 0 {
+        return;
+    }
+    if let Some(u) = on() {
+        given_in(u, path, va, len);
+    }
+}
+
+fn given_in(u: &Uma, path: Path, va: u64, len: u64) {
+    if place(u, va as usize).is_some() {
+        return;
+    }
+    if OUTSIDE[path as usize].fetch_add(1, Ordering::Relaxed) < FIRST {
+        crate::xlog_info!("{}", outside_address(path, va, len, region(va as usize)));
+    }
+}
+
+/// What the counters know of the window of `va`, for a crash report (empty: nothing counted).
+pub fn crash_part(va: usize) -> String {

Right: nothing made sure seconds() had been read before the filter ran. crash_part now reads the OnceLock with get() (SECONDS in window_stats.rs), so it neither initialises it nor waits on it; head 371b0fe2. In #3630, crash_part also no longer calls shader_mem::enabled() (another OnceLock): page_part already returns nothing while the buffer pointer is null. No test: one test cannot arrange a OnceLock that no other test has read.

AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.

<!-- greyfinch-sync:ivall/xcl:review-comment:4775812456 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#discussion_r4775812456). Originally posted by [Royalflamejlh](https://github.com/Royalflamejlh) on 2026-12-02T20:47:06Z. **Code review location:** `crates/xcl/src/hle/d3d12x/window_stats.rs`; line 114 ~~~~diff @@ -0,0 +1,321 @@ +//! `XCL_WINDOW_STATS=<seconds>`: every that many seconds a line for each memory window +//! (`gpu::uma`): what of it has memory on the GPU and what went up, was written, came back and +//! was filled since the line before; and a line for the addresses the title gave the GPU that lie +//! in no window, by path (`view_want::Path`), the first few of each logged where they are. Off by +//! default: each counter is then one branch. + +use std::collections::BTreeMap; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::OnceLock; +use std::time::Duration; + +use super::view_want::{Path, NAMES, PATHS}; +use crate::gpu::uma::{Uma, MAX_HEAP_WINDOWS}; + +fn seconds() -> Option<u64> { + static N: OnceLock<Option<u64>> = OnceLock::new(); + *N.get_or_init(|| { + let n = std::env::var("XCL_WINDOW_STATS").ok()?.trim().parse::<u64>().ok()?.max(1); + crate::xlog_info!("D3D12.X: XCL_WINDOW_STATS={n} - each memory window's traffic, and the addresses given outside every window, every {n} s"); + Some(n) + }) +} + +#[inline] +pub(super) fn enabled() -> bool { + seconds().is_some() +} + +#[derive(Clone, Copy)] +pub(super) enum Traffic { + /// bytes copied up from the CPU + Up, + /// pages the write watch found written + Written, + /// bytes copied back to the CPU + Back, + /// GPU-view tiles given video memory and filled from the CPU view + Filled, +} + +const TRAFFIC: usize = 4; +/// the windows', and last what lies in none +const SLOTS: usize = MAX_HEAP_WINDOWS + 1; +/// addresses outside every window logged for each path +const FIRST: u64 = 8; + +#[allow(clippy::declare_interior_mutable_const)] +const ZERO: AtomicU64 = AtomicU64::new(0); +#[allow(clippy::declare_interior_mutable_const)] +const ZEROS: [AtomicU64; TRAFFIC] = [ZERO; TRAFFIC]; +static COUNTS: [[AtomicU64; TRAFFIC]; SLOTS] = [ZEROS; SLOTS]; +static OUTSIDE: [AtomicU64; PATHS] = [ZERO; PATHS]; + +fn on() -> Option<&'static Uma> { + if enabled() { + crate::gpu::uma::get() + } else { + None + } +} + +fn add(u: &Uma, va: usize, what: Traffic, n: u64) { + COUNTS[u.window_of(va).unwrap_or(MAX_HEAP_WINDOWS)][what as usize].fetch_add(n, Ordering::Relaxed); +} + +#[inline] +pub(super) fn count(va: usize, what: Traffic, n: u64) { + if let Some(u) = on() { + add(u, va, what, n); + } +} + +/// The copies of a submitted upload (window address, CPU address, bytes). +#[inline] +pub(super) fn uploaded(copies: &[(usize, usize, usize)]) { + if let Some(u) = on() { + for &(a, _, n) in copies { + add(u, a, Traffic::Up, n as u64); + } + } +} + +#[inline] +pub(super) fn written(pages: &[usize]) { + if let Some(u) = on() { + for &p in pages { + add(u, p, Traffic::Written, 1); + } + } +} + +/// The title gave the GPU `[va, va + len)` on `path`: counted when it lies in no window, and +/// the first `FIRST` of each path logged. +#[inline] +pub(super) fn given(path: Path, va: u64, len: u64) { + if va == 0 { + return; + } + if let Some(u) = on() { + given_in(u, path, va, len); + } +} + +fn given_in(u: &Uma, path: Path, va: u64, len: u64) { + if place(u, va as usize).is_some() { + return; + } + if OUTSIDE[path as usize].fetch_add(1, Ordering::Relaxed) < FIRST { + crate::xlog_info!("{}", outside_address(path, va, len, region(va as usize))); + } +} + +/// What the counters know of the window of `va`, for a crash report (empty: nothing counted). +pub fn crash_part(va: usize) -> String { ~~~~ --- Right: nothing made sure `seconds()` had been read before the filter ran. `crash_part` now reads the `OnceLock` with `get()` (`SECONDS` in `window_stats.rs`), so it neither initialises it nor waits on it; head `371b0fe2`. In #3630, `crash_part` also no longer calls `shader_mem::enabled()` (another `OnceLock`): `page_part` already returns nothing while the buffer pointer is null. No test: one test cannot arrange a `OnceLock` that no other test has read. AI use: Claude Code (Claude Opus 5.5) made the fix and wrote this reply.
Foniass commented 2026-12-02 21:04:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:04:38Z.


Follow-up review of 371b0fe2, since 67ac04a2 (code reading only, not a merge-check; PR description red) · no new findings

In short: Since 67ac04a2 the PR's own commit has one change: crash_part reads XCL_WINDOW_STATS through SECONDS.get() and no longer calls enabled(), which could run the OnceLock initialiser inside the exception filter, wait on it and log from it. The rest of the push is #3627's commit underneath. The earlier reviews found nothing, and the new code adds no problem. The xcl-smoke block still names 67ac04a2, not this head (PR description is red), and the whole-suite GPU run is from an earlier head.

Checked and fine
  • The earlier reviews had no findings to fix.
  • crash_part (window_stats.rs ~123): SECONDS.get().is_some_and(Option::is_some) never starts the first read of the variable. If nothing has read it yet, the line gets no counters, which is right, since nothing was counted.
  • SECONDS moved from a local static to a module static. seconds() still sets it once and logs once.
  • The filter's path takes no lock it has to wait for. uma::existing() is GLOBAL.get(). mirrors::view_of, kernelx::crash_region and pagelog::describe use try_lock.
  • register_lines keeps the old page of line for registers outside title memory, and skips values below 0x1_0000 and repeated 64 KiB pages. registers_into_title_memory_get_a_line_each_page covers each case.
  • The stack on #3627 is declared, and this PR's first commit is #3627's head.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7358755665 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#issuecomment-7358755665). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T21:04:38Z. --- **Follow-up review** of `371b0fe2`, since `67ac04a2` (code reading only, not a merge-check; `PR description` red) · no new findings **In short:** Since `67ac04a2` the PR's own commit has one change: `crash_part` reads `XCL_WINDOW_STATS` through `SECONDS.get()` and no longer calls `enabled()`, which could run the `OnceLock` initialiser inside the exception filter, wait on it and log from it. The rest of the push is #3627's commit underneath. The earlier reviews found nothing, and the new code adds no problem. The `xcl-smoke` block still names `67ac04a2`, not this head (`PR description` is red), and the whole-suite GPU run is from an earlier head. <details><summary>Checked and fine</summary> - The earlier reviews had no findings to fix. - `crash_part` (`window_stats.rs` ~123): `SECONDS.get().is_some_and(Option::is_some)` never starts the first read of the variable. If nothing has read it yet, the line gets no counters, which is right, since nothing was counted. - `SECONDS` moved from a local `static` to a module `static`. `seconds()` still sets it once and logs once. - The filter's path takes no lock it has to wait for. `uma::existing()` is `GLOBAL.get()`. `mirrors::view_of`, `kernelx::crash_region` and `pagelog::describe` use `try_lock`. - `register_lines` keeps the old `page of` line for registers outside title memory, and skips values below `0x1_0000` and repeated 64 KiB pages. `registers_into_title_memory_get_a_line_each_page` covers each case. - The stack on #3627 is declared, and this PR's first commit is #3627's head. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Foniass commented 2026-12-02 21:33:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T21:33:49Z.


Follow-up review of 095fdc69, since 371b0fe2 (code reading only, not a merge-check; PR description red) · no new findings

In short: This push only rebases onto #3627's new commit. This PR's own commit is the same apart from context (git range-diff). Nothing new. The smoke block names 371b0fe2 (PR description is red).

Checked and fine
  • The earlier reviews found no problems, and the own commit is unchanged.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7359457071 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#issuecomment-7359457071). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T21:33:49Z. --- **Follow-up review** of `095fdc69`, since `371b0fe2` (code reading only, not a merge-check; `PR description` red) · no new findings **In short:** This push only rebases onto #3627's new commit. This PR's own commit is the same apart from context (`git range-diff`). Nothing new. The smoke block names `371b0fe2` (`PR description` is red). <details><summary>Checked and fine</summary> - The earlier reviews found no problems, and the own commit is unchanged. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Foniass commented 2026-12-03 02:34:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T02:34:15Z.


Follow-up review of 4cff929d, since 095fdc69 (code reading only, not a merge-check) · no new findings

In short: This push only rebases the stack onto main. This PR's own commit is identical (git range-diff); the only change underneath is #3627 following main's new UploadCopy jobs. Nothing new, and nothing blocks it.

Checked and fine
  • The own commit is unchanged since the last review.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7365612733 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3628#issuecomment-7365612733). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T02:34:15Z. --- **Follow-up review** of `4cff929d`, since `095fdc69` (code reading only, not a merge-check) · no new findings **In short:** This push only rebases the stack onto `main`. This PR's own commit is identical (`git range-diff`); the only change underneath is #3627 following `main`'s new `UploadCopy` jobs. Nothing new, and nothing blocks it. <details><summary>Checked and fine</summary> - The own commit is unchanged since the last review. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3628:upstream-pr/3628'
git switch 'upstream-pr/3628'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3628'
git switch 'upstream-pr/3628'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3628'
git switch 'upstream-pr/3628'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3628'
git switch 'main'
git merge --squash 'upstream-pr/3628'
git switch 'main'
git merge --ff-only 'upstream-pr/3628'
git switch 'main'
git merge 'upstream-pr/3628'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3628
No description provided.