In-place check: a store failure fails every class's pass; compares read in wide loads

With the dma-buf class's pages imported on the Iris Xe (the commit before), two things showed,
both from one cause: ANV maps its exported memory uncached for the CPU, whatever the memory type
(job 7706: types 1 and 2 alike), so each byte the check reads there is a bus read of about 80 ns.

1. A flaky pass. The check's writer reads each byte before it rewrites it, sweep after sweep,
   while the GPU stores; a sweep of a 101x51@512 window there takes about 2.7 ms, against a store
   step of 0.1 to 0.8 ms, so it revisits a row's last line about 40 us apart instead of under a
   microsecond, and rarely lands a write between the GPU's read of the line and its write-back.
   The storage-write rounds of rows that end inside lines saw the padding change in 3 of 18
   dma-buf rounds against 10 and 14 of 18 of the pointer and fresh-pages classes (job 7706), and
   the dma-buf class passed storage writes inside lines in one fresh check of three (job 7688),
   where its pass would have put a kernel's writes in place over kept padding on a guest's pages.
   In that run every round agreed (none saw a change).

   carried_store_failures: a class's failure of an access whose rounds store (renders: the pass's
   clear and store, and the draw; storage writes and buffer writes: the kernel's stores), where
   that class's reads of those row ends passed (so the failure is the stores', not the first
   move's), fails the other classes' passes of that access and row ends. The line write-back
   belongs to the store path every class's images share; how often a class's rounds see it does
   not. A reads failure (whether the GPU sees the CPU's bytes depends on the class's mapping and
   import), an unchecked verdict and a class whose pages could not be made carry nowhere. Each
   carried failure is noted. To change no verdict a texture already took, the check now gives
   its verdicts together once every class is done, not per class.

2. A 19 s check. Bytes::matches compared the window byte by byte: 2.7 s for each round of the
   3840x2160 surface over the dma-buf pages (the fill took 4 ms). It now compares each period
   whole first (slice equality, in wide loads) and looks for the byte only where one differs; a
   cleared row's texels likewise, a chunk of zeros at a time.

CHECK_VERSION stays 9 (the commit before, not yet released).

Docs: the module's verdicts paragraph and run's, API.md's in-place check paragraph.

Test: a_store_failure_fails_the_other_classes_passes_and_nothing_else_carries (tests/in_place.rs),
the Iris's verdicts of the flaky run: the dma-buf class's pass of storage writes inside lines
alone fails, as the pointer class's failure; a failure of the dma-buf class's own carries to the
others; reads failures, an unchecked verdict and a store failure of a class whose reads failed
carry nowhere.

Verified: pending (the unit test with and without the rule, the Iris check time and verdicts in
release, the device test repeated, the 780M and lavapipe verdicts against development's).

(cherry picked from commit f2f0e284c2b62980bbc3f1e1881e01b2c8ce9227)
This commit is contained in:
Anees Iqbal committed 2026-11-08 01:56:14 -08:00
1 parent aafecf768a
commit aadc115900
3 files changed
+190 -18

No files matched your search

+113 -14
View File
@@ -92,9 +92,12 @@
//! On the Iris Xe, whose clear and store, and draws, write back the line that holds a row's last
//! texels whole, the first fail and the second pass. Of [`SHAPES`] at 64-byte lines, the five
//! whose rows lie one after another, the 20x9 one at a 512-byte pitch and the 3840x2160 surface
//! share none, and the other six share one. Each is the device's as it is known, so a class,
//! access and row ends that passed take textures in place while the next is checked. Counted
//! (`WorkCounts::in_place_checks_*`).
//! share none, and the other six share one. A failure under the GPU's stores (renders,
//! storage writes, buffer writes) whose class's reads of those row ends passed fails that
//! access and row ends in every class whose rounds passed them ([`carried_store_failures`]):
//! the line write-back belongs to the store path every class shares, and a class whose pages
//! the CPU maps uncached sees it less often. So the verdicts are the device's once every class
//! is done, all at once. Counted (`WorkCounts::in_place_checks_*`).
//! - **Kept.** Once every class answered, the verdicts are written as one record in the shader
//! cache's content directory (`shader_cache/store.rs`), named by the driver's identity (its
//! version and the device's UUID among it) and the check's version ([`record_name`]), not the
@@ -441,13 +444,15 @@ fn step_aside(device: &Device) {
}
}
/// The check's thread: each class in turn, each of its accesses, each verdict given as it is
/// known, then the record.
/// The check's thread: each class in turn, each of its accesses; then every verdict given at
/// once, store failures carried across classes ([`carried_store_failures`]), and the record.
fn run(weak: crate::device::WeakDevice) {
mark_checking();
crate::step_aside::mark_a_check_s_thread(crate::step_aside::Counted::AsTheDevice);
let started = Instant::now();
let mut stopped = false;
// This run's verdicts, given once every class is done.
let mut found: Vec<Found> = Vec::new();
for class in PagesClass::ALL {
for access in Access::ALL {
// The accesses this one's rounds answer: none of an access with no rounds of its own.
@@ -468,7 +473,7 @@ fn run(weak: crate::device::WeakDevice) {
if stopped || word_overwritten(&device) {
stopped = true;
for (access, rows) in each() {
checks.set(class, access, rows, Verdict::Unchecked);
found.push((class, access, rows, Verdict::Unchecked));
}
continue;
}
@@ -478,19 +483,50 @@ fn run(weak: crate::device::WeakDevice) {
};
for (&access, verdicts) in answered.iter().zip(verdicts) {
for rows in RowEnds::ALL {
let verdict = verdicts[rows.index()];
checks.set(class, access, rows, verdict);
device.shared().counts.in_place_check_ran(verdict);
found.push((class, access, rows, verdicts[rows.index()]));
}
}
// Shadows made before their verdicts that know them now may move in place.
device.in_place_verdicts_given();
}
}
let Some(device) = weak.hold() else {
return;
};
let checks = &device.shared().in_place;
// Every verdict, those known before the check ran among them, of which a store failure
// carries to the passes of this run's other classes.
let known: Vec<Found> = (PagesClass::ALL.into_iter())
.flat_map(|class| Access::ALL.map(move |access| (class, access)))
.flat_map(|(class, access)| RowEnds::ALL.map(move |rows| (class, access, rows)))
.filter(|&(class, access, rows)| {
!found
.iter()
.any(|f| (f.0, f.1, f.2) == (class, access, rows))
})
.map(|(class, access, rows)| (class, access, rows, checks.verdict(class, access, rows)))
.filter(|known| known.3 != Verdict::Pending)
.chain(found.iter().copied())
.collect();
let carried = carried_store_failures(&known);
for (class, access, rows, verdict) in found {
let from = (carried.iter()).find(|c| (c.0, c.1, c.2) == (class, access, rows));
let verdict = match from {
Some(&(_, _, _, from)) => {
let lines = match rows {
RowEnds::InLines => "",
RowEnds::OnLines => ", rows on lines",
};
checks.note(format!(
"{class:?} {}{lines}: failed as {from:?}'s did, a change under the GPU's \
stores, which every class's images share",
access.words()
));
Verdict::Failed
}
None => verdict,
};
checks.set(class, access, rows, verdict);
device.shared().counts.in_place_check_ran(verdict);
}
let verdicts = checks.verdicts();
let stopped = stopped || word_overwritten(&device);
if stopped {
@@ -659,6 +695,56 @@ fn check_class(device: &Device, class: PagesClass, access: Access) -> Option<Vec
Some(tally.verdicts(access, None, forced))
}
/// One verdict of the check: its class, access, row ends and answer.
pub(crate) type Found = (PagesClass, Access, RowEnds, Verdict);
/// The passes of `found` a store failure fails, each with the class whose failure it is: a
/// class's pass of an access whose rounds store (renders: a pass's clear and store, and a draw;
/// storage writes and buffer writes: a kernel's stores) for texels whose rows end as another
/// class's failure of that access did, where that class's reads of those row ends passed, so
/// that its failure was the stores' and not the first move's.
///
/// Such a failure is a byte beside the texels changed under the GPU's stores: a line of its
/// cache that holds a row's last texels written back whole, with what it read beside them. The
/// write-back belongs to the store path, which every class's images share, while how often a
/// class's rounds see it does not: the CPU's write must land between the GPU's read of the line
/// and its write-back, and a class whose pages the CPU maps uncached sweeps them far slower. On
/// the Iris Xe, ANV maps its exported memory so (the dma-buf class's: each byte's read about
/// 80 ns), and the storage-write rounds of shapes whose rows end inside lines saw the padding
/// change in 3 of 18 rounds there, against 10 and 14 of 18 of the pointer and fresh-pages
/// classes, so that the dma-buf class passed one fresh check in three.
///
/// Nothing else carries: a reads failure (whether the GPU sees the CPU's bytes depends on the
/// class's mapping and import), an unchecked verdict, or a class whose pages could not be made.
pub(crate) fn carried_store_failures(
found: &[Found],
) -> Vec<(PagesClass, Access, RowEnds, PagesClass)> {
let stores = |access| {
matches!(
access,
Access::Renders | Access::Writes | Access::BufferWrites
)
};
let of = |class, access, rows| {
(found.iter())
.find(|f| (f.0, f.1, f.2) == (class, access, rows))
.map(|f| f.3)
};
let by_stores = |&(class, access, rows, verdict): &Found| {
verdict == Verdict::Failed
&& stores(access)
&& of(class, Access::Reads, rows) == Some(Verdict::Passed)
};
(found.iter())
.filter(|f| f.3 == Verdict::Passed && stores(f.1))
.filter_map(|&(class, access, rows, _)| {
(found.iter())
.find(|f| f.0 != class && (f.1, f.2) == (access, rows) && by_stores(f))
.map(|f| (class, access, rows, f.0))
})
.collect()
}
/// A class's rounds for an access so far (`check_class`): those that kept every byte, by row ends
/// ([`RowEnds::ALL`]'s order); those that changed no byte but of their shape's free padding
/// ([`Shape::padding`]) or none at all, by row ends; and the row ends of the first round that
@@ -1111,6 +1197,9 @@ const STRIDE: u64 = 1_000_003;
/// pitch, page or texel, and a byte copied from another row or page reads wrong.
const PERIOD: usize = 4099;
/// Zeros a row's cleared texels are compared against, a chunk at a time (`Bytes::compare`).
static ZEROS: [u8; 4096] = [0; 4096];
/// A round's pattern: [`PERIOD`] bytes of a hash of their place and the round, repeated over the
/// window. A byte the writer wrote holds it changed by its last sweep's [`mark`].
pub(crate) struct Pattern {
@@ -1384,7 +1473,12 @@ impl Bytes {
// SAFETY: as above; the row's texels lie in the window.
let read =
unsafe { std::slice::from_raw_parts(self.byte(start), row_bytes as usize) };
let at = read.iter().position(|&read| read != 0);
// Compared in wide loads first, as in `matches`.
let zero =
(read.chunks(ZEROS.len())).all(|chunk| chunk == &ZEROS[..chunk.len()]);
let at = (!zero)
.then(|| read.iter().position(|&read| read != 0))
.flatten();
at.map(|at| (start + at as u64, 0, read[at]))
}
Due::Stored => self.matches(&pattern.stored, start, start + row_bytes),
@@ -1421,8 +1515,13 @@ impl Bytes {
// SAFETY: as in `compare`; nothing writes the bytes while the slice is read.
let read = unsafe { std::slice::from_raw_parts(self.byte(offset), count) };
let due = &period[phase..phase + count];
if let Some(at) = read.iter().zip(due).position(|(read, due)| read != due) {
return Some((offset + at as u64, due[at], read[at]));
// Compared whole first: slice equality reads in wide loads, where a read of each byte
// of pages the CPU maps uncached is a bus read of its own (the dma-buf class's on the
// Iris Xe: 2.7 s for a 3840x2160 surface's window byte by byte).
if read != due {
if let Some(at) = read.iter().zip(due).position(|(read, due)| read != due) {
return Some((offset + at as u64, due[at], read[at]));
}
}
offset += count as u64;
}
@@ -37,8 +37,8 @@ use crate::in_place::{
NARROW_TEXEL_BYTES, STORED_TEXEL_BYTES, VERDICTS,
};
use crate::in_place_check::{
verdicts, Bytes, Due, Pattern, Round, Shape, Tally, Written, NARROW_STORE_SHAPES, SHAPES,
STORE_SHAPES,
carried_store_failures, verdicts, Bytes, Due, Found, Pattern, Round, Shape, Tally, Written,
NARROW_STORE_SHAPES, SHAPES, STORE_SHAPES,
};
use crate::linear_plan::BufferLayout;
use metal2vulkan::device::HostPageTexturePolicy;
@@ -605,6 +605,74 @@ fn a_change_beside_texels_that_share_no_line_fails_both_row_ends() {
assert_eq!(verdicts([9, 0], None, false), [Passed, Unchecked]);
}
/// The Iris Xe's verdicts of one fresh check in three (ms01, job 7688): the dma-buf class's
/// storage-write rounds of rows that end inside lines saw no change where the pointer and
/// fresh-pages classes' did. A store failure of a class whose reads of those row ends passed
/// fails the others' passes of that access and row ends; a reads failure, an unchecked verdict,
/// and a store failure of a class whose reads failed carry nowhere.
#[test]
fn a_store_failure_fails_the_other_classes_passes_and_nothing_else_carries() {
use Access::{BufferWrites, Reads, Renders, Writes};
use PagesClass::{DmaBuf, Fresh, Pointer};
use RowEnds::{InLines, OnLines};
use Verdict::{Failed, Passed, Unchecked};
let mut found: Vec<Found> = Vec::new();
for class in [Pointer, Fresh, DmaBuf] {
for rows in [InLines, OnLines] {
for access in [Reads, Renders, Writes, BufferWrites] {
found.push((class, access, rows, Passed));
}
}
}
fn set(
found: &mut [Found],
class: PagesClass,
access: Access,
rows: RowEnds,
verdict: Verdict,
) {
let at = (found.iter()).position(|f| (f.0, f.1, f.2) == (class, access, rows));
found[at.unwrap()].3 = verdict;
}
// The Iris Xe: renders and storage writes of rows that end inside lines fail in the pointer
// and fresh-pages classes; the dma-buf class's storage writes passed in that check.
for class in [Pointer, Fresh] {
set(&mut found, class, Renders, InLines, Failed);
set(&mut found, class, Writes, InLines, Failed);
}
set(&mut found, DmaBuf, Renders, InLines, Failed);
// The dma-buf class's buffer writes of rows on lines: unchecked (no dispatch made).
set(&mut found, DmaBuf, BufferWrites, OnLines, Unchecked);
// The fresh-pages class's reads of rows on lines failed, and so did its buffer writes there:
// the first move's, which says nothing of the other classes.
set(&mut found, Fresh, Reads, OnLines, Failed);
set(&mut found, Fresh, BufferWrites, OnLines, Failed);
assert_eq!(
carried_store_failures(&found),
[(DmaBuf, Writes, InLines, Pointer)],
"the dma-buf class's pass of storage writes inside lines alone fails, as the pointer \
class's failure"
);
// A failure the dma-buf class's own rounds found carries to the others' passes too.
set(&mut found, Pointer, Writes, InLines, Passed);
set(&mut found, Fresh, Writes, InLines, Passed);
set(&mut found, DmaBuf, Writes, InLines, Failed);
assert_eq!(
carried_store_failures(&found),
[
(Pointer, Writes, InLines, DmaBuf),
(Fresh, Writes, InLines, DmaBuf)
]
);
// No store failure: nothing carries, whatever reads did.
set(&mut found, DmaBuf, Writes, InLines, Passed);
for class in [Pointer, Fresh, DmaBuf] {
set(&mut found, class, Renders, InLines, Passed);
set(&mut found, class, Reads, InLines, Failed);
}
assert!(carried_store_failures(&found).is_empty());
}
#[test]
fn rows_padding_is_free_over_a_buffer_s_own_rows_that_end_on_lines() {
let (kept, free) = (Padding::Kept, Padding::Free);
+7 -2
View File
@@ -363,8 +363,13 @@ buffer's rows (no IOSurface plane's) whose rows, each to its pitch, start and en
buffer holding the last row to its pitch, may change the rows' padding (section 10, **Kernels**):
the same rounds give a second verdict for such textures, which a round that changed only bytes of
its rows' padding passes, so the Iris Xe's written textures over a buffer take the image in place
whatever their rows' ends. It runs
on a thread of its own, which the first such texture starts; a texture made before its kind of
whatever their rows' ends. A byte beside the texels changed under the GPU's stores (a render
round's clear, store or draw, or a kernel's stores) in one kind of pages, whose reads of those row
ends passed, fails that access and row ends for every kind: the line written back belongs to the
GPU's store path, which every kind's images share, while a kind whose pages the CPU maps uncached
(ANV maps the dma-buf kind's so) sees it in fewer rounds. Reads, and verdicts a kind could not
check, carry to no other kind. So the verdicts are given together once every kind is checked. It
runs on a thread of its own, which the first such texture starts; a texture made before its kind of
pages and access has its verdict is a shadow, made without waiting for the check
(`WorkCounts::host_texture_shadows_check_pending`), and moves in place, with no copy, at a quiet
commit once its kind's verdicts pass (`WorkCounts::host_textures_moved_in_place`; docs/HOWTO.md