rt cache: a state's lowering is written to the store by the reaper, through a bounded queue, never on the creating thread
The cold-creation split (probe a3318b088f, m3-max-45806/45807/45809/45810) showed rt writing each new lowering to the store inside the guest's creation call: 57-119 us on Linux and 434-446 us on the UHD 630 under Windows (NTFS), per creation. The old runtime hands its writes to a thread, at 3-7 us. The planner ruled the write off the creating thread. Now a state serializes its lowering, or the translator's refusal of a variant, and hands it to the reaper: cache::keep_translation pushes it onto a queue of at most 8 MiB of bytes (PENDING_BYTES, about the 9.16 MB a long recorded session's 282 lowerings fill) and pokes the reaper. The reaper writes queued files after its jobs and before anything else it does, so a teardown writes every lowering handed over before the reaper ends. A file that would take the queue past its bound is dropped and counted in the new Metrics::cache_writes_dropped, never waited for: a lowering is only a cache, and a later device lowers it again. Store::put's state-file lock and the temporary file's rename leave the creating thread with the write. The warm read stays where it was. Tests: - host the_write_queue_refuses_a_file_past_its_bound: a file past the bound is refused and nothing is queued; files come out in order; each one taken makes room; - device every_device_writes_its_lowerings_off_the_creating_thread_and_drops_them_past_its_queue: with the reaper's writes held (a test-only stall), a creation returns with nothing written; with the queue full, the next state's lowering is dropped and counted; let go, the reaper writes what was queued, and a device after it reads the first kernel's lowering and lowers the second again. Docs: the cache and reaper module docs, the rt README's lowerings paragraph, the metric's doc, the api_signatures row. Verified: nothing yet; the check and device legs of this commit are reported with its sha.
This commit is contained in:
1 parent
e5ede9dee6
commit
7e6064be83
8 files changed
+245
-49
No files matched your search
@@ -974,18 +974,21 @@ generations. `Gauges::pipeline_cache_bytes` is the cache's size at the reaper's
|
||||
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 half of `DeviceOptions::pipeline_cache_cap` (128 MiB where it is `None`: half of it is about
|
||||
seven times the 9.16 MB a long recorded session's 282 lowerings fill). A lookup tries young, then
|
||||
old, and a hit in old moves the file into young by a rename. A new file goes into young. The write
|
||||
that takes young past half the cap starts the next generation: young becomes old, and the old one
|
||||
is removed whole, by a thread the store starts for it. So a file stays for at least half the cap,
|
||||
and at most the whole cap, of files written or moved after its last use. Half the cap is what the
|
||||
store is sure to keep: a set of functions used over and over that is larger than half the cap is
|
||||
partly removed at each new generation and lowered again. On disk the lowerings take at most the
|
||||
cap, and while a removal runs, also what is left of the generation it removes; the blobs are
|
||||
beside them. A file larger than half the cap is not kept. `Metrics::cache_bytes_written` counts
|
||||
the bytes the device wrote there, lowerings and blobs.
|
||||
**The lowerings** live in two generations, `g<N>/` (young) and `g<N-1>/` (old), each holding at most
|
||||
half of `DeviceOptions::pipeline_cache_cap` (128 MiB where it is `None`: half of it is about seven
|
||||
times the 9.16 MB a long recorded session's 282 lowerings fill). A lookup tries young, then old, and
|
||||
a hit in old moves the file into young by a rename. A new file goes into young, written by the
|
||||
reaper off every guest thread: a state hands its lowering over and returns, and where the lowerings
|
||||
waiting for the reaper hold 8 MiB it is dropped and counted (`Metrics::cache_writes_dropped`), never
|
||||
waited for, and lowered again by a later device. The write that takes young past half the cap starts
|
||||
the next generation: young becomes old, and the old one is removed whole, by a thread the store
|
||||
starts for it. So a file stays for at least half the cap, and at most the whole cap, of files
|
||||
written or moved after its last use. Half the cap is what the store is sure to keep: a set of
|
||||
functions used over and over that is larger than half the cap is partly removed at each new
|
||||
generation and lowered again. On disk the lowerings take at most the cap, and while a removal runs,
|
||||
also what is left of the generation it removes; the blobs are beside them. A file larger than half
|
||||
the cap is not kept. `Metrics::cache_bytes_written` counts the bytes the device wrote there,
|
||||
lowerings and blobs.
|
||||
|
||||
The bytes young holds are counted in `state`, a file of 24 bytes beside the generations, read and
|
||||
written under its lock, so devices open on one directory, in one process or several, share its
|
||||
|
||||
@@ -39,23 +39,24 @@
|
||||
//! self-checking encoding (`CompiledFunction::to_bytes`), and bytes that do not decode for the key
|
||||
//! are a miss. A partial-threadgroups variant the translator refused is kept too, as a marker.
|
||||
//!
|
||||
//! The files live in two generations, `g<N>/` (young) and `g<N-1>/` (old), which the consumer's
|
||||
//! cap ([`DeviceOptions::pipeline_cache_cap`]) bounds at half of it each. A lookup tries young,
|
||||
//! then old; a hit in old is renamed into young, which is its mark of use. Generations start at
|
||||
//! 1, and the first has no old: a lookup there tries young alone. A write goes into young. The
|
||||
//! bytes young holds are counted in `state`, 24 bytes beside the generations: young's number,
|
||||
//! its bytes and a checksum of both, read and written under a lock on the file, which every store
|
||||
//! on the directory, in this process or another, holds open for its life. The write that takes
|
||||
//! young past half the cap makes the next generation young: young becomes old, and the old one is
|
||||
//! dead. A store keeps young's number as it last read or wrote the state, so a lookup reads no
|
||||
//! state: a move another store made is seen at this store's next write, and until then its
|
||||
//! lookups try the generations it knew, a miss at worst. A thread of the store's own removes the
|
||||
//! dead generation and ends, so no thread that submits, waits for or completes work removes
|
||||
//! files. So a file stays at least half the cap and at most the cap of other writes and moves
|
||||
//! after its last use, opening reads one file whatever the store holds, and nothing per file is
|
||||
//! kept in memory. The same thread removes the `pipelines/` directories under young and old in
|
||||
//! which an earlier version kept one file of pipeline data per `VkPipeline`; their bytes stay
|
||||
//! counted in young until it moves on.
|
||||
//! The files live in two generations, `g<N>/` (young) and `g<N-1>/` (old), which the consumer's cap
|
||||
//! ([`DeviceOptions::pipeline_cache_cap`]) bounds at half of it each. A lookup tries young, then
|
||||
//! old; a hit in old is renamed into young, which is its mark of use. Generations start at 1, and
|
||||
//! the first has no old: a lookup there tries young alone. A write goes into young, made by the
|
||||
//! reaper: a state hands its lowering over ([`keep_translation`]) and returns, and a lowering that
|
||||
//! would take the ones waiting past [`PENDING_BYTES`] is dropped and counted, never waited for. The
|
||||
//! bytes young holds are counted in `state`, 24 bytes beside the generations: young's number, its
|
||||
//! bytes and a checksum of both, read and written under a lock on the file, which every store on
|
||||
//! the directory, in this process or another, holds open for its life. The write that takes young
|
||||
//! past half the cap makes the next generation young: young becomes old, and the old one is dead. A
|
||||
//! store keeps young's number as it last read or wrote the state, so a lookup reads no state: a
|
||||
//! move another store made is seen at this store's next write, and until then its lookups try the
|
||||
//! generations it knew, a miss at worst. A thread of the store's own removes the dead generation
|
||||
//! and ends, so no thread that submits, waits for or completes work removes files. So a file stays
|
||||
//! at least half the cap and at most the cap of other writes and moves after its last use, opening
|
||||
//! reads one file whatever the store holds, and nothing per file is kept in memory. The same thread
|
||||
//! removes the `pipelines/` directories under young and old in which an earlier version kept one
|
||||
//! file of pipeline data per `VkPipeline`; their bytes stay counted in young until it moves on.
|
||||
//!
|
||||
//! Every write is a temporary file renamed over its name, counted before it is written and given
|
||||
//! back where it fails, so the count is never below what young holds. Every file checks itself
|
||||
@@ -75,6 +76,7 @@ use crate::device::{lock, Core};
|
||||
use crate::memory::QUIET_NANOS;
|
||||
use crate::times::host_time;
|
||||
use ash::vk;
|
||||
use std::collections::VecDeque;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, ErrorKind, Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -97,6 +99,9 @@ const MAGIC: &[u8; 8] = b"m2vblob1";
|
||||
const BLOB: &str = "pipelines";
|
||||
/// The most blobs a cache directory keeps: four kinds of device or driver versions.
|
||||
pub(crate) const BLOBS_KEPT: usize = 4;
|
||||
/// The most bytes of lowerings waiting for the reaper to write them: about the 9.16 MB a long
|
||||
/// recorded session's 282 lowerings fill. A lowering past it is not kept.
|
||||
pub(crate) const PENDING_BYTES: u64 = 8 << 20;
|
||||
/// What a translation file holds where the translator refused the lowering: bytes no lowering
|
||||
/// encodes to, and that a file cut short is not.
|
||||
const REFUSED: &[u8] = b"m2v-refused";
|
||||
@@ -651,6 +656,11 @@ pub(crate) struct Caches {
|
||||
grown: AtomicBool,
|
||||
/// [`PIPELINE_CACHE_BOUND`], lower in a test.
|
||||
bound: AtomicU64,
|
||||
/// The lowerings and refusals waiting for the reaper to write them.
|
||||
pending: Mutex<Pending>,
|
||||
/// Whether the reaper's writes wait, for a test.
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
writes_stalled: AtomicBool,
|
||||
/// Whether the reaper has seeded the cache from the blob, or found none to take.
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
seeded: AtomicBool,
|
||||
@@ -681,6 +691,64 @@ struct Pipelines {
|
||||
/// A `VkPipelineCache` of the device's, held by each creation through it.
|
||||
pub(crate) struct PipelineCache(vk::PipelineCache);
|
||||
|
||||
/// Hands the bytes of a lowered function of key digest `key` to the reaper, which writes them to
|
||||
/// the store, off every guest thread. Where the lowerings waiting for it hold [`PENDING_BYTES`]
|
||||
/// already, they are dropped and counted (`Metrics::cache_writes_dropped`), never waited for: a
|
||||
/// lowering is only a cache, and a later state lowers it again.
|
||||
pub(crate) fn keep_translation(core: &Core, key: &[u8], bytes: Vec<u8>) {
|
||||
if core.caches.store.is_none() {
|
||||
return;
|
||||
}
|
||||
let queued = lock(&core.caches.pending).push(Caches::translation_file(key), bytes);
|
||||
match queued {
|
||||
true => core.reaper.poke(),
|
||||
false => core.counters.count(Metric::CacheWritesDropped),
|
||||
}
|
||||
}
|
||||
|
||||
/// Hands the translator's refusal of the lowering of key digest `key` to the reaper, as
|
||||
/// [`keep_translation`] does a lowering.
|
||||
pub(crate) fn keep_refusal(core: &Core, key: &[u8]) {
|
||||
keep_translation(core, key, REFUSED.to_vec());
|
||||
}
|
||||
|
||||
/// The files waiting for the reaper to write them, in order, at most `bound` bytes of them.
|
||||
pub(crate) struct Pending {
|
||||
files: VecDeque<(String, Vec<u8>)>,
|
||||
bytes: u64,
|
||||
bound: u64,
|
||||
}
|
||||
|
||||
impl Pending {
|
||||
/// An empty queue of at most `bound` bytes.
|
||||
pub(crate) fn new(bound: u64) -> Pending {
|
||||
Pending {
|
||||
files: VecDeque::new(),
|
||||
bytes: 0,
|
||||
bound,
|
||||
}
|
||||
}
|
||||
|
||||
/// Queues `bytes` under `file`; false, queuing nothing, where they would take the queue past
|
||||
/// its bound.
|
||||
pub(crate) fn push(&mut self, file: String, bytes: Vec<u8>) -> bool {
|
||||
let len = bytes.len() as u64;
|
||||
if self.bytes.saturating_add(len) > self.bound {
|
||||
return false;
|
||||
}
|
||||
self.bytes += len;
|
||||
self.files.push_back((file, bytes));
|
||||
true
|
||||
}
|
||||
|
||||
/// The first file queued, taken off the queue.
|
||||
pub(crate) fn pop(&mut self) -> Option<(String, Vec<u8>)> {
|
||||
let (file, bytes) = self.files.pop_front()?;
|
||||
self.bytes -= bytes.len() as u64;
|
||||
Some((file, bytes))
|
||||
}
|
||||
}
|
||||
|
||||
/// A creation through the device's `VkPipelineCache`, from [`creation`] until it is dropped.
|
||||
pub(crate) struct Creation<'a> {
|
||||
core: &'a Core,
|
||||
@@ -779,6 +847,9 @@ impl Caches {
|
||||
created: AtomicU64::new(0),
|
||||
grown: AtomicBool::new(false),
|
||||
bound: AtomicU64::new(PIPELINE_CACHE_BOUND),
|
||||
pending: Mutex::new(Pending::new(PENDING_BYTES)),
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
writes_stalled: AtomicBool::new(false),
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
seeded: AtomicBool::new(false),
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
@@ -794,6 +865,20 @@ impl Caches {
|
||||
self.blob.get().map(PathBuf::as_path)
|
||||
}
|
||||
|
||||
/// Makes the reaper's writes of lowerings wait, or go on, for a test.
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
pub(crate) fn stall_writes(&self, stalled: bool) {
|
||||
(self.writes_stalled).store(stalled, std::sync::atomic::Ordering::Release);
|
||||
}
|
||||
|
||||
/// Sets the bound of the lowerings waiting to be written, for a test; the bytes waiting.
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
pub(crate) fn set_pending_bound(&self, bytes: u64) -> u64 {
|
||||
let mut pending = lock(&self.pending);
|
||||
pending.bound = bytes;
|
||||
pending.bytes
|
||||
}
|
||||
|
||||
/// Sets the cache's bound for a test.
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
pub(crate) fn set_bound(&self, bytes: u64) {
|
||||
@@ -846,10 +931,23 @@ impl Caches {
|
||||
kept.flatten()
|
||||
}
|
||||
|
||||
/// Keeps the bytes of a lowered kernel of key digest `key`.
|
||||
pub(crate) fn keep_translation(&self, key: &[u8], bytes: &[u8], counters: &Counters) {
|
||||
/// The next lowering or refusal waiting for the reaper to write it.
|
||||
pub(crate) fn next_write(&self) -> Option<(String, Vec<u8>)> {
|
||||
lock(&self.pending).pop()
|
||||
}
|
||||
|
||||
/// On the reaper: writes `bytes` under `file` in the store, as [`keep_translation`] queued
|
||||
/// them.
|
||||
pub(crate) fn write_kept(&self, file: &str, bytes: &[u8], counters: &Counters) {
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
while self
|
||||
.writes_stalled
|
||||
.load(std::sync::atomic::Ordering::Acquire)
|
||||
{
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
if let Some(store) = &self.store {
|
||||
if store.put(&Caches::translation_file(key), bytes) {
|
||||
if store.put(file, bytes) {
|
||||
counters.cache_written(bytes.len() as u64);
|
||||
}
|
||||
}
|
||||
@@ -862,11 +960,6 @@ impl Caches {
|
||||
.is_some_and(|store| store.holds(&Caches::translation_file(key), REFUSED))
|
||||
}
|
||||
|
||||
/// Keeps the translator's refusal of the lowering of key digest `key`.
|
||||
pub(crate) fn keep_refusal(&self, key: &[u8], counters: &Counters) {
|
||||
self.keep_translation(key, REFUSED, counters);
|
||||
}
|
||||
|
||||
/// On the reaper, first: makes the device's `VkPipelineCache` empty, which creations waiting
|
||||
/// for a cache take at once; then, where the device has a blob that checks, whose data begins
|
||||
/// with the header the device's driver writes and that the driver takes, makes a cache from
|
||||
|
||||
@@ -27,6 +27,8 @@ pub(crate) enum Metric {
|
||||
TranslationsLoaded,
|
||||
/// [`Metrics::creations_before_seed`].
|
||||
CreationsBeforeSeed,
|
||||
/// [`Metrics::cache_writes_dropped`].
|
||||
CacheWritesDropped,
|
||||
/// [`Metrics::ring_writes`].
|
||||
RingWrites,
|
||||
/// [`Metrics::upload_waits`].
|
||||
@@ -136,6 +138,7 @@ struct Atomics {
|
||||
translations: AtomicU64,
|
||||
translations_loaded: AtomicU64,
|
||||
creations_before_seed: AtomicU64,
|
||||
cache_writes_dropped: AtomicU64,
|
||||
ring_writes: AtomicU64,
|
||||
upload_waits: AtomicU64,
|
||||
synchronizations: AtomicU64,
|
||||
@@ -206,6 +209,7 @@ impl Counters {
|
||||
Metric::Translations => &a.translations,
|
||||
Metric::TranslationsLoaded => &a.translations_loaded,
|
||||
Metric::CreationsBeforeSeed => &a.creations_before_seed,
|
||||
Metric::CacheWritesDropped => &a.cache_writes_dropped,
|
||||
Metric::RingWrites => &a.ring_writes,
|
||||
Metric::UploadWaits => &a.upload_waits,
|
||||
Metric::Synchronizations => &a.synchronizations,
|
||||
@@ -412,6 +416,7 @@ impl Counters {
|
||||
translations: a.translations.load(Relaxed),
|
||||
translations_loaded: a.translations_loaded.load(Relaxed),
|
||||
creations_before_seed: a.creations_before_seed.load(Relaxed),
|
||||
cache_writes_dropped: a.cache_writes_dropped.load(Relaxed),
|
||||
cache_bytes_written: a.cache_bytes_written.load(Relaxed),
|
||||
ring_writes: a.ring_writes.load(Relaxed),
|
||||
upload_waits: a.upload_waits.load(Relaxed),
|
||||
@@ -546,6 +551,10 @@ pub struct Metrics {
|
||||
///
|
||||
/// [`DeviceOptions::pipeline_cache_dir`]: crate::DeviceOptions::pipeline_cache_dir
|
||||
pub creations_before_seed: u64,
|
||||
/// Lowerings and refusals not kept in the cache directory: each was handed to the reaper,
|
||||
/// which writes them off every guest thread, while the ones waiting for it held 8 MiB, and was
|
||||
/// dropped rather than waited for. A later device lowers it again.
|
||||
pub cache_writes_dropped: 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
|
||||
|
||||
@@ -542,7 +542,7 @@ impl Compiled {
|
||||
Err(TranslationError::Unsupported(refused))
|
||||
if refused.feature == Feature::GpuEncodedIndirectCommands =>
|
||||
{
|
||||
core.caches.keep_refusal(&variant_key, &core.counters);
|
||||
cache::keep_refusal(&core, &variant_key);
|
||||
None
|
||||
}
|
||||
Err(error) => return Err(Error::Translation(error)),
|
||||
@@ -705,8 +705,7 @@ pub(crate) fn lower(
|
||||
let lowered = translator.compile_function_from_entries(function, inputs, budget, entries);
|
||||
core.note_entries();
|
||||
let lowered = lowered?;
|
||||
core.caches
|
||||
.keep_translation(key.digest(), &lowered.to_bytes(), &core.counters);
|
||||
cache::keep_translation(core, key.digest(), lowered.to_bytes());
|
||||
Ok(lowered)
|
||||
}
|
||||
|
||||
@@ -1158,7 +1157,7 @@ impl Emulated {
|
||||
let compiled = match lower(core, &self.function, &self.inputs, &budget, &core.entries) {
|
||||
Ok(compiled) => compiled,
|
||||
Err(TranslationError::Unsupported(_)) => {
|
||||
core.caches.keep_refusal(&key, &core.counters);
|
||||
cache::keep_refusal(core, &key);
|
||||
return Lowered::Refused;
|
||||
}
|
||||
Err(_) => return Lowered::Refused,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//! The reaper thread: it makes the device's `VkPipelineCache` from its blob first, then frees
|
||||
//! what the runtime's other threads give up, one object at a time, runs a teardown that starts on
|
||||
//! the completion thread, lowers the pipeline states' emulated-SIMD-group variants after their
|
||||
//! creation returned, and looks at the pipeline cache once creation is quiet, writing its blob or
|
||||
//! replacing it past its bound (`crate::cache`). No driver free runs on the completion thread, so
|
||||
//! no completion waits behind one, and a submission on another thread waits behind at most one
|
||||
//! free.
|
||||
//! the completion thread, writes the lowerings the pipeline states hand it to the store, lowers
|
||||
//! the states' emulated-SIMD-group variants after their creation returned, and looks at the
|
||||
//! pipeline cache once creation is quiet, writing its blob or replacing it past its bound
|
||||
//! (`crate::cache`). No driver free runs on the completion thread, so no completion waits behind
|
||||
//! one, and a submission on another thread waits behind at most one free.
|
||||
|
||||
use crate::counters::Gauge;
|
||||
use crate::device::{lock, Core};
|
||||
@@ -121,8 +121,8 @@ impl Reaper {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wakes the reaper to see when to look at the pipeline cache, after the first creation since
|
||||
/// its last look.
|
||||
/// Wakes the reaper: to see when to look at the pipeline cache, after the first creation since
|
||||
/// its last look, or to write a lowering handed to it (`cache::keep_translation`).
|
||||
pub(crate) fn poke(&self) {
|
||||
let _state = lock(&self.state);
|
||||
self.changed.notify_one();
|
||||
@@ -242,6 +242,8 @@ enum Next {
|
||||
Lower(Weak<Compiled>),
|
||||
/// Look at the pipeline cache, creation being quiet.
|
||||
Look,
|
||||
/// Write a lowering or refusal to the store.
|
||||
Write(String, Vec<u8>),
|
||||
/// End, after telling the states whose lowering is left that it will not run.
|
||||
End(VecDeque<Weak<Compiled>>),
|
||||
}
|
||||
@@ -258,6 +260,10 @@ pub(crate) fn run(core: Arc<Core>) {
|
||||
if let Some(job) = state.jobs.pop_front() {
|
||||
break Next::Job(job);
|
||||
}
|
||||
// Before the end, so a teardown writes every lowering handed over.
|
||||
if let Some((file, bytes)) = core.caches.next_write() {
|
||||
break Next::Write(file, bytes);
|
||||
}
|
||||
if state.stop {
|
||||
break Next::End(std::mem::take(&mut state.lowerings));
|
||||
}
|
||||
@@ -281,6 +287,7 @@ pub(crate) fn run(core: Arc<Core>) {
|
||||
Next::Job(Job::Teardown(teardown)) => teardown(&core),
|
||||
// SAFETY: the caches are the core's device's.
|
||||
Next::Look => unsafe { core.caches.look(&core.device, &core.counters) },
|
||||
Next::Write(file, bytes) => core.caches.write_kept(&file, &bytes, &core.counters),
|
||||
Next::Lower(lowering) => {
|
||||
if let Some(state) = lowering.upgrade() {
|
||||
state.lower_emulated();
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
//! blobs kept, and stores in threads and processes sharing one directory without losing a count
|
||||
//! or reading a file another was writing.
|
||||
|
||||
use crate::cache::{blob_name, checksum, frame, prune_blobs, unframe, State, Store, BLOBS_KEPT};
|
||||
use crate::cache::{
|
||||
blob_name, checksum, frame, prune_blobs, unframe, Pending, State, Store, BLOBS_KEPT,
|
||||
};
|
||||
use std::fs;
|
||||
use std::io::ErrorKind;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -506,6 +508,25 @@ fn a_directory_keeps_at_most_four_blobs_the_least_recently_used_removed() {
|
||||
assert!(scratch.0.join("state").exists(), "the state stays");
|
||||
}
|
||||
|
||||
/// The lowerings waiting for the reaper: a file that would take the queue past its bound is
|
||||
/// refused and nothing is queued; the rest come out in order, and each taken makes room.
|
||||
#[test]
|
||||
fn the_write_queue_refuses_a_file_past_its_bound() {
|
||||
let mut pending = Pending::new(10);
|
||||
assert!(pending.push("a".into(), vec![1; 4]));
|
||||
assert!(pending.push("b".into(), vec![2; 6]));
|
||||
assert!(!pending.push("c".into(), vec![3]), "full: dropped");
|
||||
assert!(
|
||||
!pending.push("d".into(), vec![4; 11]),
|
||||
"larger than the bound"
|
||||
);
|
||||
assert_eq!(pending.pop(), Some(("a".into(), vec![1; 4])));
|
||||
assert!(pending.push("c".into(), vec![3; 4]), "room again");
|
||||
assert_eq!(pending.pop(), Some(("b".into(), vec![2; 6])));
|
||||
assert_eq!(pending.pop(), Some(("c".into(), vec![3; 4])));
|
||||
assert_eq!(pending.pop(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_earlier_versions_pipeline_data_is_removed_at_open() {
|
||||
let scratch = Scratch::new("store-earlier");
|
||||
|
||||
@@ -1347,6 +1347,69 @@ mod on_device {
|
||||
}
|
||||
}
|
||||
|
||||
/// A state's lowerings go to the store on the reaper: with the reaper's writes held, the
|
||||
/// creation returns and nothing is written. Once the queue is full, the next state's lowerings
|
||||
/// are dropped and counted, never waited for. Let go, the reaper writes what was queued: a
|
||||
/// device after it reads the first kernel's lowering and lowers the second again.
|
||||
#[test]
|
||||
fn every_device_writes_its_lowerings_off_the_creating_thread_and_drops_them_past_its_queue() {
|
||||
let (Some(first), Some(second)) = (
|
||||
descriptor("a1_sign_and_division"),
|
||||
descriptor("a1_sign_and_division_precise"),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
let instance = Instance::new(&[]).expect("an instance at the floor");
|
||||
let devices = devices_of_the_cfgs_kind(&instance);
|
||||
assert!(!devices.is_empty(), "no device of this cfg's kind");
|
||||
for (name, physical) in &devices {
|
||||
let dir = std::env::temp_dir().join(format!("m2v-rt-pending-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let device = on_directory(name, physical, &dir);
|
||||
let caches = &device.core().caches;
|
||||
let counters = device.counters();
|
||||
caches.stall_writes(true);
|
||||
let a = state(name, &device, &first);
|
||||
let metrics = counters.metrics();
|
||||
assert!(metrics.translations > 0, "{name}: the first kernel lowered");
|
||||
assert_eq!(
|
||||
metrics.cache_bytes_written, 0,
|
||||
"{name}: the creation returned with nothing written"
|
||||
);
|
||||
// Full: the bound is what waits now.
|
||||
let waiting = caches.set_pending_bound(0);
|
||||
caches.set_pending_bound(waiting);
|
||||
let b = state(name, &device, &second);
|
||||
assert!(
|
||||
counters.metrics().cache_writes_dropped > 0,
|
||||
"{name}: the second kernel's lowering dropped and counted"
|
||||
);
|
||||
caches.set_pending_bound(crate::cache::PENDING_BYTES);
|
||||
caches.stall_writes(false);
|
||||
within("the writes", || counters.metrics().cache_bytes_written > 0);
|
||||
drop((a, b));
|
||||
drop(device);
|
||||
within("the teardown", || counters.gauges() == Gauges::default());
|
||||
let next = on_directory(name, physical, &dir);
|
||||
let counters = next.counters();
|
||||
let a = state(name, &next, &first);
|
||||
assert!(
|
||||
counters.metrics().translations_loaded > 0,
|
||||
"{name}: the first kernel's lowering was written"
|
||||
);
|
||||
let lowered = counters.metrics().translations;
|
||||
let b = state(name, &next, &second);
|
||||
assert!(
|
||||
counters.metrics().translations > lowered,
|
||||
"{name}: the second kernel's, dropped, is lowered again"
|
||||
);
|
||||
drop((a, b));
|
||||
drop(next);
|
||||
within("the teardown", || counters.gauges() == Gauges::default());
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
}
|
||||
|
||||
/// A blob the device cannot take, cut short or of another device's header, is removed when
|
||||
/// the reaper makes the cache, which starts empty: creations go on, and the drop writes the
|
||||
/// blob a next device takes. That device's look finds the cache no larger, so neither it nor
|
||||
|
||||
@@ -2325,6 +2325,7 @@ field metal2vulkan-rt::Metrics.blocks_reused pub blocks_reused: u64
|
||||
field metal2vulkan-rt::Metrics.bytes_copied pub bytes_copied: u64
|
||||
field metal2vulkan-rt::Metrics.bytes_zeroed pub bytes_zeroed: u64
|
||||
field metal2vulkan-rt::Metrics.cache_bytes_written pub cache_bytes_written: u64
|
||||
field metal2vulkan-rt::Metrics.cache_writes_dropped pub cache_writes_dropped: u64
|
||||
field metal2vulkan-rt::Metrics.capture_copy_nanos pub capture_copy_nanos: u64
|
||||
field metal2vulkan-rt::Metrics.capture_overflow_bytes pub capture_overflow_bytes: u64
|
||||
field metal2vulkan-rt::Metrics.capture_overflows pub capture_overflows: u64
|
||||
|
||||
|
Can't render this file because it is too large.
|
Reference in new issue
Block a user