rt: count the pipeline cache's replacements past its bound and the blob writes skipped past it
The reaper bounds the device's VkPipelineCache at 32 MiB (cache.rs, PIPELINE_CACHE_BOUND). When a look finds the cache past the bound, look_alone replaces it with a fresh, empty cache, and the pipelines the old one held then compile again wherever they are made again. write() skips data past the bound, which happens at the teardown's write of a cache that grew past the bound after the reaper's last look; the blob then keeps what it held. Today neither event leaves a trace: the replacement only sets the PipelineCacheBytes gauge, and the skip only returns. So a walk cannot tell a recompile storm caused by the bound from any other. Two metrics, counted where the events happen: - Metrics::pipeline_caches_replaced: at look_alone's replacement. - Metrics::pipeline_cache_writes_skipped: at write()'s early return past the bound. Both are fields of Metrics, whose type has no Metal counterpart, and each doc says Metal has none. The bound's shape is unchanged. Test: every_device_replaces_its_pipeline_cache_past_its_bound (tests/translate.rs), extended. The lowered bound (set_bound) makes its one replacement, and pipeline_caches_replaced reads 1. After the fresh cache's write, a creation is held open (cache::creation) so the reaper does not look again before the teardown. A fourth kernel (ob1_storage_buffer) grows the cache, and the bound is set to 1 byte. The device's teardown, run while a clone of its core holds the core, stops the reaper with no look made. The skip count reads 0 until the core's drop, whose close() writes the grown cache; then it reads 1, and the blob still holds the fresh cache's data (24 bytes plus the size written at the last look). README: the cache directory's paragraph on the bound names both counters; so does the counters line. The signatures table gains both fields (scripts/api-signatures/signatures.py --bless). Verified at 76be5d46aa, on development9f3ff1aa75(this tree): - compile job m3-max-66719: signatures check, refusal-surface check, fmt, clippy plain / --cfg m2v_gpu / --cfg m2v_cpu_icd, workspace Rustdoc -D warnings, api-docs, all exit 0. The rt suite on lavapipe: 642 passed, 3 skipped. The cache test passed on lavapipe, but the job's filter dropped its printed line, so whether its body ran there is not shown. - From the m2v_gpu archive m3-max-66721, the extended cache test printed "replacements 1, writes skipped at the teardown 1" on each card: - RX 550 (RADV POLARIS12, Mesa 26.2.6), job m3-max-66731: 1752 bytes past a bound of 1751, replaced by 36, grown to 1584. Full rt suite 644 passed, 3 skipped; peak 874 MiB. - Iris Xe (RPL-P, Mesa 26.2.6), job m3-max-66773: 6704 past 6703, replaced by 36, grown to 6580. Full rt suite 644 passed, 3 skipped; peak 4.6 GiB. Its 4 GiB leg m3-max-66732 printed the same lines, then went over its memory limit in the suite. - RTX 3090 (NVIDIA 620.70.06), job m3-max-66733: 11732 past 11731, replaced by 36, grown to 12441. Full rt suite 644 passed (1 slow), 3 skipped; peak 2.6 GiB. On each card, the exported_overs test still printed "1 1 1 0" and "[1, 0, 0, 0], then out: [0, 1, 1]; blocks addressed 0, then 1". A note onbe1b2cfe46(an exported block's textures owe their copy for an address write only once its address went out). The test fails without that bound: m3-max-66711 at probe 312091e824 (wrote() on leans.unbound alone): no address of the block out; left: [1, 1, 1, 1], right: [1, 0, 0, 0].
This commit is contained in:
1 parent
a9c1a7d012
commit
015ece4929
5 files changed
+76
-13
No files matched your search
@@ -206,7 +206,9 @@ timestamps of their own (`runtime_command_buffer_gpu_nanos`);
|
||||
the copies of textures over a buffer that no linear image holds are split by cause
|
||||
(`over_copies_pitch` and the rest, in Textures below); the exported blocks a public call handed
|
||||
out a device address of, each counted at the first (`exported_blocks_addressed`, the exported
|
||||
block's rule in Textures below), 0 where none went out;
|
||||
block's rule in Textures below), 0 where none went out; the pipeline cache's replacements past its
|
||||
bound and its blob writes skipped past it (`pipeline_caches_replaced`,
|
||||
`pipeline_cache_writes_skipped`, The cache directory below);
|
||||
`gauges()` are live counts per kind of resource, every one zero after teardown, and
|
||||
`handles_out`, 1 while a handle of the device is out (Teardown). They are relaxed atomics, always
|
||||
on. What an encoder's commands count arrives when the encoder ends.
|
||||
@@ -2775,10 +2777,13 @@ loses only the pipelines made since the last; no creation waits for a write.
|
||||
|
||||
The cache holds at most 32 MiB when the reaper looks (about five times the 6.25 MB of pipeline data
|
||||
a long recorded session made): one past it is replaced by a fresh, empty cache that creations take
|
||||
from then on, and is destroyed once no creation holds it. The next write replaces the blob with
|
||||
the fresh cache's data, so the blob holds at most 32 MiB too, with no second file and no
|
||||
generations. `Gauges::pipeline_cache_bytes` is the cache's size at the reaper's last look, and is
|
||||
zero once the device is torn down. With no directory the cache is the same, made empty, and
|
||||
from then on, and is destroyed once no creation holds it, each replacement counted in
|
||||
`Metrics::pipeline_caches_replaced`. The next write replaces the blob with the fresh cache's data,
|
||||
so the blob holds at most 32 MiB too, with no second file and no generations. A write of data past
|
||||
32 MiB, the teardown's of a cache that grew past it after the reaper's last look, is skipped and
|
||||
counted in `Metrics::pipeline_cache_writes_skipped`; the blob keeps what it held.
|
||||
`Gauges::pipeline_cache_bytes` is the cache's size at the reaper's last look, and is zero once the
|
||||
device is torn down. With no directory the cache is the same, made empty, and
|
||||
nothing is written.
|
||||
|
||||
**The lowerings** live in two generations, `g<N>/` (young) and `g<N-1>/` (old), each holding at most
|
||||
|
||||
@@ -38,9 +38,11 @@
|
||||
//!
|
||||
//! The cache holds at most [`PIPELINE_CACHE_BOUND`]: a cache past it when the reaper looks is
|
||||
//! replaced by a fresh, empty one that creations take from then on, and destroyed once no creation
|
||||
//! holds it; the next write replaces the blob with the fresh cache's data, so the blob holds at
|
||||
//! most the bound too, with no second file. [`Gauges::pipeline_cache_bytes`] is the cache's size
|
||||
//! at the reaper's last look. Without a directory the cache is the same, and nothing is on disk.
|
||||
//! holds it (counted in `Metrics::pipeline_caches_replaced`); the next write replaces the blob with
|
||||
//! the fresh cache's data, so the blob holds at most the bound too, with no second file. A write
|
||||
//! of data past the bound, the teardown's of a cache that grew past it after the last look, is
|
||||
//! skipped (`Metrics::pipeline_cache_writes_skipped`). [`Gauges::pipeline_cache_bytes`] is the
|
||||
//! cache's size at the reaper's last look. Without a directory the cache is the same, and nothing is on disk.
|
||||
//!
|
||||
//! **The lowerings.** The store keeps one file per lowered function (a kernel, or a render
|
||||
//! pipeline's vertex or fragment function) under `translations/`, named by the hex of its
|
||||
@@ -1673,6 +1675,7 @@ impl Caches {
|
||||
pipelines.written = fresh_size;
|
||||
drop(pipelines);
|
||||
counters.set(Gauge::PipelineCacheBytes, fresh_size);
|
||||
counters.count(Metric::PipelineCachesReplaced);
|
||||
return None;
|
||||
}
|
||||
let written = lock(&self.pipelines).written;
|
||||
@@ -1709,10 +1712,11 @@ impl Caches {
|
||||
}
|
||||
|
||||
/// Writes `data`, the cache's data the driver gave at size `size`, over the device's blob at
|
||||
/// `path`, where it is within the bound.
|
||||
/// `path`, where it is within the bound; past it, the write is skipped and counted.
|
||||
fn write(&self, path: &Path, data: &[u8], size: u64, counters: &Counters) {
|
||||
let len = data.len() as u64;
|
||||
if len > self.bound.load(Relaxed) {
|
||||
counters.count(Metric::PipelineCacheWritesSkipped);
|
||||
return;
|
||||
}
|
||||
if write_whole(path, &[&frame(data), data]).is_ok() {
|
||||
|
||||
@@ -228,6 +228,10 @@ pub(crate) enum Metric {
|
||||
CreationsBeforeSeed,
|
||||
/// [`Metrics::cache_writes_dropped`].
|
||||
CacheWritesDropped,
|
||||
/// [`Metrics::pipeline_caches_replaced`].
|
||||
PipelineCachesReplaced,
|
||||
/// [`Metrics::pipeline_cache_writes_skipped`].
|
||||
PipelineCacheWritesSkipped,
|
||||
/// [`Metrics::ring_writes`].
|
||||
RingWrites,
|
||||
/// [`Metrics::pushes`].
|
||||
@@ -304,6 +308,8 @@ const METRIC_ORDER: [Metric; METRICS] = [
|
||||
Metric::RenderRecordsStale,
|
||||
Metric::CreationsBeforeSeed,
|
||||
Metric::CacheWritesDropped,
|
||||
Metric::PipelineCachesReplaced,
|
||||
Metric::PipelineCacheWritesSkipped,
|
||||
Metric::RingWrites,
|
||||
Metric::Pushes,
|
||||
Metric::PushesHeld,
|
||||
@@ -652,6 +658,8 @@ struct Atomics {
|
||||
pipeline_cache_lock_wait_nanos: AtomicU64,
|
||||
pipeline_cache_lock_wait_max_nanos: AtomicU64,
|
||||
cache_writes_dropped: AtomicU64,
|
||||
pipeline_caches_replaced: AtomicU64,
|
||||
pipeline_cache_writes_skipped: AtomicU64,
|
||||
ring_writes: AtomicU64,
|
||||
pushes: AtomicU64,
|
||||
pushes_held: AtomicU64,
|
||||
@@ -832,6 +840,8 @@ impl Counters {
|
||||
Metric::RenderRecordsStale => &a.render_records_stale,
|
||||
Metric::CreationsBeforeSeed => &a.creations_before_seed,
|
||||
Metric::CacheWritesDropped => &a.cache_writes_dropped,
|
||||
Metric::PipelineCachesReplaced => &a.pipeline_caches_replaced,
|
||||
Metric::PipelineCacheWritesSkipped => &a.pipeline_cache_writes_skipped,
|
||||
Metric::RingWrites => &a.ring_writes,
|
||||
Metric::Pushes => &a.pushes,
|
||||
Metric::PushesHeld => &a.pushes_held,
|
||||
@@ -1651,6 +1661,8 @@ impl Counters {
|
||||
pipeline_cache_lock_wait_nanos: a.pipeline_cache_lock_wait_nanos.load(Relaxed),
|
||||
pipeline_cache_lock_wait_max_nanos: a.pipeline_cache_lock_wait_max_nanos.load(Relaxed),
|
||||
cache_writes_dropped: a.cache_writes_dropped.load(Relaxed),
|
||||
pipeline_caches_replaced: a.pipeline_caches_replaced.load(Relaxed),
|
||||
pipeline_cache_writes_skipped: a.pipeline_cache_writes_skipped.load(Relaxed),
|
||||
cache_bytes_written: a.cache_bytes_written.load(Relaxed),
|
||||
ring_writes: a.ring_writes.load(Relaxed),
|
||||
pushes: a.pushes.load(Relaxed),
|
||||
@@ -2260,6 +2272,16 @@ pub struct Metrics {
|
||||
/// 8 MiB alone is kept where none waits). A later device lowers it again. Metal has no
|
||||
/// counterpart: Metal's compiler service keeps its own cache.
|
||||
pub cache_writes_dropped: u64,
|
||||
/// The reaper's replacements of the device's `VkPipelineCache` by a fresh, empty one, at a
|
||||
/// look that found the cache past its bound of 32 MiB: creations take the fresh one from then
|
||||
/// on, so the pipelines the old one held compile again where made again. Metal has no
|
||||
/// counterpart: Metal's compiler service keeps its own cache.
|
||||
pub pipeline_caches_replaced: u64,
|
||||
/// Writes of the pipeline cache's data over the device's blob skipped because the data was
|
||||
/// past the bound of 32 MiB, as at the device's teardown where the cache grew past it after
|
||||
/// the reaper's last look: 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
|
||||
/// quiet where the cache grew by more than an eighth since the last write, and at the
|
||||
|
||||
@@ -1995,13 +1995,18 @@ mod on_device {
|
||||
/// The pipeline cache filled past its bound: at the look after a creation takes it past, the
|
||||
/// reaper replaces it with a fresh one, which the gauge falls to, keeps the old one while it is
|
||||
/// held, and destroys it at the first look after it is let go; creations go on through the
|
||||
/// fresh cache, and the next write replaces the blob with the fresh cache's data alone.
|
||||
/// fresh cache, and the next write replaces the blob with the fresh cache's data alone. The
|
||||
/// replacement counts once in `Metrics::pipeline_caches_replaced`. Then a creation grows the
|
||||
/// cache while another holds creation open, so no look comes before the teardown, and with
|
||||
/// the bound lowered past the cache the teardown's write is skipped, counted once in
|
||||
/// `Metrics::pipeline_cache_writes_skipped`, and the blob keeps the fresh cache's data.
|
||||
#[test]
|
||||
fn every_device_replaces_its_pipeline_cache_past_its_bound() {
|
||||
let (Some(first), Some(second), Some(third)) = (
|
||||
let (Some(first), Some(second), Some(third), Some(fourth)) = (
|
||||
descriptor("a1_bool_from_float"),
|
||||
descriptor("a1_sign_and_division"),
|
||||
descriptor("a1_sign_and_division_precise"),
|
||||
descriptor("ob1_storage_buffer"),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
@@ -2044,6 +2049,8 @@ mod on_device {
|
||||
first_blob,
|
||||
"{name}: no write at the replacement"
|
||||
);
|
||||
let replaced = counters.metrics().pipeline_caches_replaced;
|
||||
assert_eq!(replaced, 1, "{name}: one replacement counted");
|
||||
drop(held);
|
||||
caches.set_bound(crate::cache::PIPELINE_CACHE_BOUND);
|
||||
let c = state_and_look(name, &device, &third);
|
||||
@@ -2059,12 +2066,35 @@ mod on_device {
|
||||
24 + now,
|
||||
"{name}: the blob holds the fresh cache"
|
||||
);
|
||||
drop((a, b, c));
|
||||
// Creation held open keeps the reaper from looking until the teardown stops it.
|
||||
let core = std::sync::Arc::clone(device.core());
|
||||
let blob = caches.blob().expect("a cache directory").to_path_buf();
|
||||
let open = crate::cache::creation(&core);
|
||||
let pipelines = counters.metrics().pipelines_created;
|
||||
let d = state(name, &device, &fourth);
|
||||
assert!(
|
||||
counters.metrics().pipelines_created > pipelines,
|
||||
"{name}: the fourth state made its VkPipeline"
|
||||
);
|
||||
caches.set_bound(1);
|
||||
drop((a, b, c, d));
|
||||
drop(device);
|
||||
drop(open);
|
||||
assert_eq!(
|
||||
counters.metrics().pipeline_cache_writes_skipped,
|
||||
0,
|
||||
"{name}"
|
||||
);
|
||||
drop(core);
|
||||
let skipped = counters.metrics().pipeline_cache_writes_skipped;
|
||||
assert_eq!(skipped, 1, "{name}: the teardown's write skipped");
|
||||
let kept = std::fs::metadata(&blob).map_or(0, |meta| meta.len());
|
||||
assert_eq!(kept, 24 + now, "{name}: the blob keeps the fresh cache");
|
||||
within("the teardown", || counters.gauges() == Gauges::default());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
println!(
|
||||
"{name}: {full} bytes past a bound of {}, replaced by {fresh}, grown to {now}",
|
||||
"{name}: {full} bytes past a bound of {}, replaced by {fresh}, grown to {now}; \
|
||||
replacements {replaced}, writes skipped at the teardown {skipped}",
|
||||
full - 1
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1572,6 +1572,8 @@ field metal2vulkan-runtime::Metrics.pipeline_cache_lock_wait_max_nanos pub pipel
|
||||
field metal2vulkan-runtime::Metrics.pipeline_cache_lock_wait_nanos pub pipeline_cache_lock_wait_nanos: u64
|
||||
field metal2vulkan-runtime::Metrics.pipeline_cache_lock_waits pub pipeline_cache_lock_waits: u64
|
||||
field metal2vulkan-runtime::Metrics.pipeline_cache_looks_skipped pub pipeline_cache_looks_skipped: u64
|
||||
field metal2vulkan-runtime::Metrics.pipeline_cache_writes_skipped pub pipeline_cache_writes_skipped: u64
|
||||
field metal2vulkan-runtime::Metrics.pipeline_caches_replaced pub pipeline_caches_replaced: u64
|
||||
field metal2vulkan-runtime::Metrics.pipeline_creation_nanos pub pipeline_creation_nanos: u64
|
||||
field metal2vulkan-runtime::Metrics.pipelines_created pub pipelines_created: u64
|
||||
field metal2vulkan-runtime::Metrics.pipelines_from_stage_fills pub pipelines_from_stage_fills: u64
|
||||
|
||||
|
Can't render this file because it is too large.
|
Reference in new issue
Block a user