diff --git a/crates/metal2vulkan-runtime/src/host_ram.rs b/crates/metal2vulkan-runtime/src/host_ram.rs index b319b884e..db8cdf716 100644 --- a/crates/metal2vulkan-runtime/src/host_ram.rs +++ b/crates/metal2vulkan-runtime/src/host_ram.rs @@ -2216,9 +2216,14 @@ impl Device { let (first, last) = (runs.first(), runs.last()); let span = first.zip(last).map(|(first, last)| first.start..last.end); let span = span.ok_or_else(|| internal("a copy's list of no runs of host RAM"))?; + let started = Instant::now(); // SAFETY: the caller's. - let (raw, placement) = unsafe { self.ram_runs_as_dma_buf(importer, runs, source) }?; - self.shared().counts.host_ram_run_list_imported(); + let made = unsafe { self.ram_runs_as_dma_buf(importer, runs, source) }; + let took = u64::try_from(started.elapsed().as_nanos()).unwrap_or(u64::MAX); + let counts = &self.shared().counts; + counts.host_ram_run_list_import_took(took); + let (raw, placement) = made?; + counts.host_ram_run_list_imported(); let mut list = self.ram_chunk(ram, span, Imported::Runs, raw, placement); let mut at = 0; list.runs = (runs.iter()) diff --git a/crates/metal2vulkan-runtime/src/host_ram/copy.rs b/crates/metal2vulkan-runtime/src/host_ram/copy.rs index 343f33791..01dd0666e 100644 --- a/crates/metal2vulkan-runtime/src/host_ram/copy.rs +++ b/crates/metal2vulkan-runtime/src/host_ram/copy.rs @@ -144,7 +144,7 @@ use std::collections::BTreeMap; use std::ops::Range; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, OnceLock}; -use std::time::{Duration, Instant}; +use std::time::Instant; /// The unit of a copy's runs: whole 4 KiB pages at 4 KiB-aligned host addresses (a guest's page; /// every host page and every chunk is whole such pages). diff --git a/crates/metal2vulkan-runtime/src/tests/host_ram_dma_buf.rs b/crates/metal2vulkan-runtime/src/tests/host_ram_dma_buf.rs index 8f67f469b..5f83050b5 100644 --- a/crates/metal2vulkan-runtime/src/tests/host_ram_dma_buf.rs +++ b/crates/metal2vulkan-runtime/src/tests/host_ram_dma_buf.rs @@ -1124,7 +1124,7 @@ impl TileRound<'_> { println!( "HOST-RAM-TILE {}: {}, {name}: {copied:?} in {:.2} ms encoding, {:.2} ms in all; \ copies {}, dispatches {}, regions {}, chunks imported {}, dma-buf imports {}, \ - run lists imported {}, pointer imports failed {}, run imports live {}", + run lists imported {} in {:.2} ms, pointer imports failed {}, run imports live {}", self.device.name(), self.what, encoded.as_secs_f64() * 1e3, @@ -1135,6 +1135,7 @@ impl TileRound<'_> { delta(|c| c.host_ram_chunks_imported), delta(|c| c.host_ram_dma_buf_imports), delta(|c| c.host_ram_run_list_imports), + delta(|c| c.host_ram_run_list_import_nanos) as f64 / 1e6, delta(|c| c.host_ram_pointer_imports_failed), after.run_imports_live, ); @@ -1144,6 +1145,11 @@ impl TileRound<'_> { lists: delta(|c| c.host_ram_run_list_imports), }; let what = format!("{}, {name}", self.what); + // Each list's import is timed, as a chunk's is. + let lists = delta(|c| c.host_ram_run_list_imports); + if lists > 0 && delta(|c| c.host_ram_run_list_import_nanos) == 0 { + failures.push(format!("{what}: {lists} lists imported in no time counted")); + } if let Err(error) = &copied { failures.push(format!("{what}: {error:?}")); continue; diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index 86e878634..dc8d89f31 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -361,6 +361,7 @@ pub(crate) struct Counters { host_ram_staged_fill_nanos: AtomicU64, host_ram_dma_buf_imports: AtomicU64, host_ram_run_list_imports: AtomicU64, + host_ram_run_list_import_nanos: AtomicU64, host_ram_pointer_imports_failed: AtomicU64, host_ram_chunks_imported_ahead: AtomicU64, host_ram_chunks_given_back: AtomicU64, @@ -2857,6 +2858,13 @@ impl Counters { (self.host_ram_run_list_imports).fetch_add(1, Ordering::Relaxed); } + /// The import of a list of a copy's runs of a guest RAM took `nanos` nanoseconds on the + /// copy's encoding thread, the source's dma-buf and the device's import together, made or + /// failed (`host_ram.rs`). + pub(crate) fn host_ram_run_list_import_took(&self, nanos: u64) { + (self.host_ram_run_list_import_nanos).fetch_add(nanos, Ordering::Relaxed); + } + /// An import of a chunk of a guest RAM, or of an object's run inside one, by its pointer /// failed (`host_ram.rs`). pub(crate) fn host_ram_pointer_import_failed(&self) { @@ -6142,6 +6150,12 @@ pub struct WorkCounts { /// cost and whose chunks of the RAM are its dma-bufs (RADV's). Each is live in /// `run_imports_live` until the copy's command buffer completed. pub host_ram_run_list_imports: u64, + /// The nanoseconds those imports took on the copies' encoding threads, failed ones included: + /// the source's dma-buf of the list's pages (`UDMABUF_CREATE_LIST`, which pins them) and the + /// device's import of it. Apart from `host_ram_chunk_import_nanos`, whose imports are a + /// chunk's, and from `host_ram_copy_import_wait_nanos`, whose waits are for a chunk's import: + /// a list is the copy's own import of its pages, as a range's alone is, and no wait for one. + pub host_ram_run_list_import_nanos: u64, /// The imports of guest RAM, chunks and objects' runs alike, by their pointer that failed: /// the driver or the runtime refused the pages (RADV refuses any shared mapping's), or memory /// ran out. For a RAM with a source of dma-bufs each was then tried as one dma-buf where the @@ -7618,6 +7632,9 @@ impl Device { host_ram_staged_fill_nanos: counters.host_ram_staged_fill_nanos.load(Ordering::Relaxed), host_ram_dma_buf_imports: counters.host_ram_dma_buf_imports.load(Ordering::Relaxed), host_ram_run_list_imports: counters.host_ram_run_list_imports.load(Ordering::Relaxed), + host_ram_run_list_import_nanos: counters + .host_ram_run_list_import_nanos + .load(Ordering::Relaxed), host_ram_pointer_imports_failed: counters .host_ram_pointer_imports_failed .load(Ordering::Relaxed), diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 7b4dc323c..a604eaee4 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -2804,6 +2804,7 @@ field metal2vulkan-runtime::WorkCounts.host_ram_copy_import_waits pub host_ram_c field metal2vulkan-runtime::WorkCounts.host_ram_copy_regions pub host_ram_copy_regions: u64 field metal2vulkan-runtime::WorkCounts.host_ram_dma_buf_imports pub host_ram_dma_buf_imports: u64 field metal2vulkan-runtime::WorkCounts.host_ram_pointer_imports_failed pub host_ram_pointer_imports_failed: u64 +field metal2vulkan-runtime::WorkCounts.host_ram_run_list_import_nanos pub host_ram_run_list_import_nanos: u64 field metal2vulkan-runtime::WorkCounts.host_ram_run_list_imports pub host_ram_run_list_imports: u64 field metal2vulkan-runtime::WorkCounts.host_ram_staged_fill_nanos pub host_ram_staged_fill_nanos: u64 field metal2vulkan-runtime::WorkCounts.host_ram_staged_fills_gated pub host_ram_staged_fills_gated: u64