rt: a quiesce begins no last blob write past its deadline

What: Caches::last_write, the reaper's last write at a quiesce, checks the quiesce's deadline
before each try for the creations lock and again before it reads the cache's data to write: past
the deadline it writes nothing and counts the skip in Metrics::pipeline_cache_writes_skipped. A
write begun before the deadline still runs to its end. Past the deadline before the lock, the size
is not read, so the skip is counted whether or not the cache changed; the doc says so. At the
device's teardown, with no deadline, nothing changes.

Why: the audit lane's finding. The deadline was checked only while a creation held the lock, and
halt() asks the reaper to stop after the submit, block-maker and completion stages, which may use
the whole timeout; so with no creation running a write of up to 128 MiB could begin past the
deadline, quiesce answering false while it ran on, against the quiesce doc.

Docs: Device::quiesce, Metrics::pipeline_cache_writes_skipped, Caches::last_write, the runtime
README's Quiesce and exit.

Verified: red on the RTX 5080 Laptop (NVIDIA 615.71.09) with the runtime sources of the test's
commit, m3-max-78990: the new test timed out waiting for the skip (61.7 s; the last write took the
lock and wrote). Green in the same job at this code: the five blob tests passed, 902 skipped;
"quiesce late: the last write past a passed deadline skipped, the drop wrote the blob"; the
doubling test 5 writes of 286050 bytes for a 108159-byte blob. At this tree (dd0a40d8c6, the same
tree): clippy -D warnings plain, under m2v_cpu_icd and under m2v_gpu, and rustdoc -D warnings, all
exit 0; the runtime's suite on lavapipe 902 passed, 3 skipped (m3-max-78987). lavapipe keeps no
blob, so the blob tests pass there without one.
This commit is contained in:
Anees Iqbal committed 2026-12-02 08:57:41 -08:00
1 parent 5b1acd0aa9
commit 8dd00ec58c
4 files changed
+30 -18

No files matched your search

+3 -2
View File
@@ -2599,8 +2599,9 @@ held work ends `NotRun`) and the block-maker, waits for the GPU to complete what
completion thread retire it and end, lets the reaper write the pipeline cache's blob where the
cache changed since its last write and end, and then runs `BlockMappings::unmap` on the calling
thread for every allocation still mapped. The reaper's write waits for a pipeline creation still
running until the same deadline, and past it is skipped (`Metrics::pipeline_cache_writes_skipped`);
a write begun before the deadline runs to its end, and where it ends past it quiesce answers false. It frees nothing: every block's memory and mapping stays valid until
running until the same deadline, and no write begins past it, whether a creation or quiesce's
earlier waits took the time: it is skipped (`Metrics::pipeline_cache_writes_skipped`). A write
begun before the deadline runs to its end, and where it ends past it quiesce answers false. It frees nothing: every block's memory and mapping stays valid until
the process ends. After it, no runtime thread touches a block; later calls that need a thread
return `Error::Quiesced`. It answers true once the GPU went idle and every thread ended in time,
and false at once in a handler or a listener, whose thread cannot wait for itself. A second call
+15 -8
View File
@@ -1810,10 +1810,12 @@ impl Caches {
/// At the reaper's end, a quiesce's or the device's teardown: writes the blob where the
/// cache's size changed since the last write, so a process that ends after a quiesce, with no
/// drop, keeps what it made. A creation still running holds it: it tries for
/// [`Caches::creations`] each [`LAST_WRITE_STEP`] until `until`, past which the write is
/// skipped and counted (`Metrics::pipeline_cache_writes_skipped`), and with no `until` until
/// the creation ends. It waits for no GPU work: a creation compiles on the CPU, and reading a
/// cache's data waits for nothing the GPU does.
/// [`Caches::creations`] each [`LAST_WRITE_STEP`] until `until`, and with no `until` until the
/// creation ends. It begins no write past `until`: where `until` has passed before it takes
/// the lock, or before it reads the cache's data, the write is skipped and counted
/// (`Metrics::pipeline_cache_writes_skipped`), the cache's size unread before the lock; a
/// write begun runs to its end. It waits for no GPU work: a creation compiles on the CPU, and
/// reading a cache's data waits for nothing the GPU does.
///
/// # Safety
///
@@ -1827,14 +1829,15 @@ impl Caches {
let Some(path) = self.blob_to_write() else {
return;
};
let past = || until.is_some_and(|until| Instant::now() >= until);
let alone = loop {
if let Some(alone) = self.alone() {
break alone;
}
if until.is_some_and(|until| Instant::now() >= until) {
if past() {
counters.count(Metric::PipelineCacheWritesSkipped);
return;
}
if let Some(alone) = self.alone() {
break alone;
}
std::thread::sleep(LAST_WRITE_STEP);
};
let (current, written) = {
@@ -1849,6 +1852,10 @@ impl Caches {
if size == written {
return;
}
if past() {
counters.count(Metric::PipelineCacheWritesSkipped);
return;
}
// SAFETY: as above.
let data = unsafe { device.get_pipeline_cache_data(current.0) };
drop(alone);
+6 -3
View File
@@ -3005,9 +3005,12 @@ pub struct Metrics {
pub kernel_makes_dropped: u64,
/// Writes of the pipeline cache's data over the device's blob skipped: because the data was
/// past the bound of 128 MiB, as at the device's teardown where the cache grew past it after
/// the reaper's last look, or because a creation still ran at a quiesce's deadline, which the
/// reaper's last write waits until ([`Device::quiesce`](crate::Device::quiesce)). The blob
/// keeps what it held, and a later device seeds from that. Metal has no counterpart.
/// the reaper's last look, or because a quiesce's deadline passed before the reaper's last
/// write began: a creation still ran, which that write waits for until the deadline, or the
/// quiesce's earlier waits took the time ([`Device::quiesce`](crate::Device::quiesce)). Past the
/// deadline before it takes the pipeline cache's lock, the write is counted without the
/// cache's size read, so whether or not the cache changed. The blob keeps what it held, and a
/// later device seeds from that. Metal has no counterpart.
pub pipeline_cache_writes_skipped: u64,
/// Bytes written to the cache directory ([`DeviceOptions::pipeline_cache_dir`]): lowered
/// kernels, and the device's pipeline cache blob each time it is written: once creation is
+6 -5
View File
@@ -1226,11 +1226,12 @@ impl Device {
/// block-maker thread ends; the GPU completes everything submitted; the completion thread
/// retires it, runs the completed handlers, and ends; the reaper thread writes the pipeline
/// cache's blob ([`DeviceOptions::pipeline_cache_dir`]) where the cache changed since its last
/// write, waiting for a pipeline creation still running until the same deadline, past which it
/// skips the write (`Metrics::pipeline_cache_writes_skipped`), and ends; then
/// [`BlockMappings::unmap`] runs on this thread for every allocation still mapped. A write
/// begun before the deadline runs to its end, and where it ends past it the call answers
/// false; cut short by the process's end, it leaves the blob as it was. After it, no runtime thread touches a block,
/// write, waiting for a pipeline creation still running until the same deadline, and ends; it
/// begins no write past the deadline, which it skips (`Metrics::pipeline_cache_writes_skipped`)
/// whether a creation or the waits before it took the time; then [`BlockMappings::unmap`] runs
/// on this thread for every allocation still mapped. A write begun before the deadline runs to
/// its end, and where it ends past it the call answers false; cut short by the process's end,
/// it leaves the blob as it was. After it, no runtime thread touches a block,
/// unless the call answered false. A thread past the timeout ends alone: the completion
/// thread once the GPU completed what was submitted and it retired that, running its
/// completed handlers, so what the work held goes then. Such a thread is not joined here; the device's last handle joins