Residency: host_imports_resident counts releasable imports alone; host_imports_held_for_good the rest
What: an import a read other than a blit's keeps for good (Residency::held_for_good) leaves the host_imports_resident gauge and joins a new gauge, host_imports_held_for_good, as it already left the device's count against its most (Shared::resident). Every move of an import's memory (a release, an import again, let_go, the drop) now goes through one place, Residency::holds_memory, which counts it as releasable or as kept for good, by the flag under the state lock, as the most was counted. WorkCounts docs, host_residency.rs's Counted list and HOWTO.md say so; the API table and host_ab's list name the new field. Why: host_imports_resident's doc said 'the imports the device may release', but it went down only at a release, a let_go or a drop, so it also counted every import kept for good. A guest walk on the RX 7900 XTX showed about 1,040 'resident' beside a cap of 64 releasable imports, which read as the cap failing. The two gauges show both numbers without subtracting. Verified: the dma-buf and pointer residency tests now check the exposure step moves the import from one gauge to the other, and that a gone import leaves both (job ids in the report).
This commit is contained in:
1 parent
618b495e39
commit
dc859fee56
7 files changed
+78
-35
No files matched your search
@@ -1863,6 +1863,7 @@ impl Gpu for Runtime {
|
||||
("host_imports_released", c.host_imports_released),
|
||||
("host_imports_reimported", c.host_imports_reimported),
|
||||
("host_imports_resident", c.host_imports_resident),
|
||||
("host_imports_held_for_good", c.host_imports_held_for_good),
|
||||
("host_imports_lost", c.host_imports_lost),
|
||||
("host_import_fds_kept", c.host_import_fds_kept),
|
||||
("host_imports_kept_for_fds", c.host_imports_kept_for_fds),
|
||||
|
||||
@@ -101,10 +101,12 @@
|
||||
//! it may be stale, and lists it again at its exposure). A read that keeps it imported finds it
|
||||
//! released only where its address was never handed out: it imports it again first.
|
||||
//! - **Counted.** `WorkCounts::host_imports_released`, `host_imports_reimported`,
|
||||
//! `host_imports_resident` (releasable imports holding their memory now),
|
||||
//! `host_import_fds_kept`, and `host_imports_kept_for_fds` (imports kept as their descriptors
|
||||
//! did not fit); the device's dma-buf memories (`dma_buf_memories_live`) and its
|
||||
//! imports of host pages by their pointer (`host_imports_live`) fall as imports are released.
|
||||
//! `host_imports_resident` (releasable imports holding their memory now, which the most above
|
||||
//! bounds), `host_imports_held_for_good` (imports a read other than a blit's kept imported for
|
||||
//! good, holding their memory now: never released, whatever the most), `host_import_fds_kept`,
|
||||
//! and `host_imports_kept_for_fds` (imports kept as their descriptors did not fit); the
|
||||
//! device's dma-buf memories (`dma_buf_memories_live`) and its imports of host pages by their
|
||||
//! pointer (`host_imports_live`) fall as imports are released.
|
||||
|
||||
use super::buffer::{FixedPages, HostImport, Imported, Pages, Shape};
|
||||
use super::device::lock;
|
||||
@@ -385,11 +387,28 @@ impl Residency {
|
||||
}
|
||||
|
||||
/// No longer releasable, under `state`'s lock: where it was and holds its memory, one fewer
|
||||
/// releasable import does.
|
||||
/// releasable import does, and one more kept for good.
|
||||
fn held_for_good(&self, state: &State) {
|
||||
let was = self.releasable.swap(false, Ordering::AcqRel);
|
||||
if was && state.held.is_some() {
|
||||
self.device.shared().residency.resident(&self.device, false);
|
||||
let shared = self.device.shared();
|
||||
shared.counts.host_import_resident(false);
|
||||
shared.residency.resident(&self.device, false);
|
||||
shared.counts.host_import_held_for_good(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// It came to hold its memory (`held`) or let go of it, under `state`'s lock: counted as a
|
||||
/// releasable import (`WorkCounts::host_imports_resident`, and against the device's most)
|
||||
/// while it is one, else as one kept for good (`WorkCounts::host_imports_held_for_good`).
|
||||
fn holds_memory(&self, held: bool) {
|
||||
let shared = self.device.shared();
|
||||
match self.releasable.load(Ordering::Acquire) {
|
||||
true => {
|
||||
shared.counts.host_import_resident(held);
|
||||
shared.residency.resident(&self.device, held);
|
||||
}
|
||||
false => shared.counts.host_import_held_for_good(held),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,10 +443,8 @@ impl Residency {
|
||||
return None;
|
||||
}
|
||||
state.released_once = true;
|
||||
let counts = &self.device.shared().counts;
|
||||
counts.host_import_released();
|
||||
counts.host_import_resident(false);
|
||||
self.device.shared().residency.resident(&self.device, false);
|
||||
self.device.shared().counts.host_import_released();
|
||||
self.holds_memory(false);
|
||||
state.held.take()
|
||||
}
|
||||
|
||||
@@ -463,12 +480,8 @@ impl Residency {
|
||||
}
|
||||
state.held = Some(Arc::clone(&held));
|
||||
state.window = (2 * state.window).min(IDLE_MOST.as_millis() as u64);
|
||||
let counts = &self.device.shared().counts;
|
||||
counts.host_import_reimported();
|
||||
counts.host_import_resident(true);
|
||||
if self.releasable.load(Ordering::Acquire) {
|
||||
self.device.shared().residency.resident(&self.device, true);
|
||||
}
|
||||
self.device.shared().counts.host_import_reimported();
|
||||
self.holds_memory(true);
|
||||
Ok(held)
|
||||
}
|
||||
}
|
||||
@@ -482,10 +495,7 @@ impl Residency {
|
||||
pub(super) fn let_go(&self) -> Option<Arc<Imported>> {
|
||||
let mut state = lock(&self.state);
|
||||
let held = state.held.take()?;
|
||||
self.device.shared().counts.host_import_resident(false);
|
||||
if self.releasable.load(Ordering::Acquire) {
|
||||
self.device.shared().residency.resident(&self.device, false);
|
||||
}
|
||||
self.holds_memory(false);
|
||||
drop(state);
|
||||
Some(held)
|
||||
}
|
||||
@@ -494,10 +504,7 @@ impl Residency {
|
||||
impl Drop for Residency {
|
||||
fn drop(&mut self) {
|
||||
if lock(&self.state).held.is_some() {
|
||||
self.device.shared().counts.host_import_resident(false);
|
||||
if self.releasable.load(Ordering::Acquire) {
|
||||
self.device.shared().residency.resident(&self.device, false);
|
||||
}
|
||||
self.holds_memory(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
//! (`Device::release_idle_host_imports`), except one that waits for the device's residency
|
||||
//! thread, and check:
|
||||
//! - the counts that show the release and the import again ran (`WorkCounts::host_imports_released`,
|
||||
//! `host_imports_reimported`, `host_imports_resident`, `host_import_fds_kept`,
|
||||
//! `dma_buf_memories_live`);
|
||||
//! `host_imports_reimported`, `host_imports_resident`, `host_imports_held_for_good`,
|
||||
//! `host_import_fds_kept`, `dma_buf_memories_live`);
|
||||
//! - the bytes a blit reads and writes after a release, the CPU's writes made while released among
|
||||
//! them, and that the source is never called again;
|
||||
//! - the pages a release keeps across a remap of the buffer's addresses;
|
||||
@@ -536,7 +536,9 @@ pub(super) fn residency(counts: &WorkCounts) -> (u64, u64, u64, u64) {
|
||||
/// source;
|
||||
/// - released again, a GPU fill lands in the pages;
|
||||
/// - released again, its Metal address handed out imports it again at once and for good,
|
||||
/// closing the descriptors kept, and the hook releases it no more.
|
||||
/// closing the descriptors kept, counted as kept for good, no longer as releasable
|
||||
/// (`WorkCounts::host_imports_held_for_good`, `host_imports_resident`), and the hook releases
|
||||
/// it no more; gone, it leaves both gauges.
|
||||
///
|
||||
/// Where the device imports the pointer, the hook releases nothing and the counts stay 0 unless a
|
||||
/// held pointer import costs the device's every submission (`tests/pointer_residency.rs`).
|
||||
@@ -610,8 +612,10 @@ fn an_idle_dma_buf_import_is_released_and_imported_again_at_its_next_blit() {
|
||||
release(TEST, device, 1);
|
||||
let address = buffer.gpu_address();
|
||||
assert_ne!(address.0, 0, "{TEST}");
|
||||
// It holds its memory as an import kept for good, no longer a releasable one.
|
||||
let counts = device.work_counts();
|
||||
assert_eq!(residency(&counts), (3, 3, 1, 0), "{TEST}: exposed");
|
||||
assert_eq!(residency(&counts), (3, 3, 0, 0), "{TEST}: exposed");
|
||||
assert_eq!(counts.host_imports_held_for_good, 1, "{TEST}: exposed");
|
||||
assert_eq!(counts.dma_buf_memories_live, live, "{TEST}");
|
||||
assert!(read(&queue, &buffer, len) == filled, "{TEST}");
|
||||
assert_eq!(device.release_idle_host_imports(), 0, "{TEST}: exposed");
|
||||
@@ -622,7 +626,7 @@ fn an_idle_dma_buf_import_is_released_and_imported_again_at_its_next_blit() {
|
||||
);
|
||||
drop(buffer);
|
||||
let gone = counts_once(TEST, device, "the import gone", |counts| {
|
||||
counts.host_imports_resident == 0 && counts.dma_buf_memories_live == live - chunks
|
||||
counts.host_imports_held_for_good == 0 && counts.dma_buf_memories_live == live - chunks
|
||||
});
|
||||
assert_eq!(residency(&gone), (3, 3, 0, 0), "{TEST}: gone");
|
||||
eprintln!(
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
//! The tests release imports at once through the crate's hook (`Device::release_idle_host_imports`)
|
||||
//! and check:
|
||||
//! - the counts that show the release and the import again ran (`WorkCounts::host_imports_released`,
|
||||
//! `host_imports_reimported`, `host_imports_resident`, `host_imports_live`), and none of a
|
||||
//! dma-buf's descriptors kept;
|
||||
//! `host_imports_reimported`, `host_imports_resident`, `host_imports_held_for_good`,
|
||||
//! `host_imports_live`), and none of a dma-buf's descriptors kept;
|
||||
//! - the bytes a blit reads and writes after a release, the CPU's writes made while released among
|
||||
//! them;
|
||||
//! - that a released import, made again at its pointer, reads the pages a remap put there while
|
||||
@@ -286,8 +286,10 @@ fn an_idle_pointer_import_is_released_and_imported_again_at_its_next_blit() {
|
||||
release(TEST, device, 1);
|
||||
let address = buffer.gpu_address();
|
||||
assert_ne!(address.0, 0, "{TEST}");
|
||||
// It holds its memory as an import kept for good, no longer a releasable one.
|
||||
let counts = device.work_counts();
|
||||
assert_eq!(residency(&counts), (3, 3, 1, 0), "{TEST}: exposed");
|
||||
assert_eq!(residency(&counts), (3, 3, 0, 0), "{TEST}: exposed");
|
||||
assert_eq!(counts.host_imports_held_for_good, 1, "{TEST}: exposed");
|
||||
assert_eq!(counts.host_imports_live, live, "{TEST}");
|
||||
assert!(read(&queue, &buffer, len) == filled, "{TEST}");
|
||||
assert_eq!(device.release_idle_host_imports(), 0, "{TEST}: exposed");
|
||||
|
||||
@@ -396,6 +396,7 @@ pub(crate) struct Counters {
|
||||
host_imports_released_over_most: AtomicU64,
|
||||
host_imports_reimported: AtomicU64,
|
||||
host_imports_resident: AtomicU64,
|
||||
host_imports_held_for_good: AtomicU64,
|
||||
host_imports_lost: AtomicU64,
|
||||
host_import_fds_kept: AtomicU64,
|
||||
host_imports_kept_for_fds: AtomicU64,
|
||||
@@ -3564,7 +3565,8 @@ impl Counters {
|
||||
self.host_imports_reimported.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// A releasable import holds its memory from now on (`resident`), or no longer.
|
||||
/// A releasable import holds its memory from now on (`resident`), or no longer (released,
|
||||
/// gone, or kept for good).
|
||||
pub(crate) fn host_import_resident(&self, resident: bool) {
|
||||
match resident {
|
||||
true => self.host_imports_resident.fetch_add(1, Ordering::Relaxed),
|
||||
@@ -3572,6 +3574,19 @@ impl Counters {
|
||||
};
|
||||
}
|
||||
|
||||
/// An import a read other than a blit's kept for good holds its memory from now on
|
||||
/// (`held`), or no longer (gone).
|
||||
pub(crate) fn host_import_held_for_good(&self, held: bool) {
|
||||
match held {
|
||||
true => self
|
||||
.host_imports_held_for_good
|
||||
.fetch_add(1, Ordering::Relaxed),
|
||||
false => self
|
||||
.host_imports_held_for_good
|
||||
.fetch_sub(1, Ordering::Relaxed),
|
||||
};
|
||||
}
|
||||
|
||||
/// A committed command buffer's commands use `count` host imports (`Buffer::distinct_host_imports`).
|
||||
pub(crate) fn commit_used_host_imports(&self, count: u64) {
|
||||
self.host_imports_used.fetch_add(count, Ordering::Relaxed);
|
||||
@@ -7757,8 +7772,17 @@ pub struct WorkCounts {
|
||||
/// Released imports imported again from the dma-bufs kept, each at the first blit that read
|
||||
/// the buffer after its release (on the encoding thread).
|
||||
pub host_imports_reimported: u64,
|
||||
/// The imports the device may release that hold their memory now.
|
||||
/// The releasable imports that hold their memory now: those no read but a blit's took, which
|
||||
/// the device may release while idle, and releases past its most where a held import adds to
|
||||
/// every submission's cost (`host_imports_released_over_most`). An import a read other than a
|
||||
/// blit's took leaves it for `host_imports_held_for_good`.
|
||||
pub host_imports_resident: u64,
|
||||
/// The imports that were releasable until a read other than a blit's took them (a binding, a
|
||||
/// texture over the bytes, the Metal address or `VkBuffer` handed out, a second buffer lying
|
||||
/// in the import: `host_imports_read_apart`), which hold their memory now: kept imported for
|
||||
/// good, whatever the device's most, until their buffer goes. With `host_imports_resident`,
|
||||
/// every import with a residency that holds its memory.
|
||||
pub host_imports_held_for_good: u64,
|
||||
/// Reads other than a blit's that found an import released and the device unable to import
|
||||
/// it again: the device was lost then. None but out of memory.
|
||||
pub host_imports_lost: u64,
|
||||
@@ -10125,6 +10149,8 @@ impl Device {
|
||||
.load(Ordering::Relaxed),
|
||||
host_imports_reimported: counters.host_imports_reimported.load(Ordering::Relaxed),
|
||||
host_imports_resident: counters.host_imports_resident.load(Ordering::Relaxed),
|
||||
host_imports_held_for_good: (counters.host_imports_held_for_good)
|
||||
.load(Ordering::Relaxed),
|
||||
host_imports_used: counters.host_imports_used.load(Ordering::Relaxed),
|
||||
host_imports_read_apart: counters.host_imports_read_apart.load(Ordering::Relaxed),
|
||||
host_imports_read_apart_address: read_apart(ReadApart::Address),
|
||||
|
||||
@@ -2957,6 +2957,7 @@ field metal2vulkan-runtime::WorkCounts.host_holds_looked_up pub host_holds_looke
|
||||
field metal2vulkan-runtime::WorkCounts.host_import_fds_kept pub host_import_fds_kept: u64
|
||||
field metal2vulkan-runtime::WorkCounts.host_import_releases_pending pub host_import_releases_pending: u64
|
||||
field metal2vulkan-runtime::WorkCounts.host_import_releases_posted pub host_import_releases_posted: u64
|
||||
field metal2vulkan-runtime::WorkCounts.host_imports_held_for_good pub host_imports_held_for_good: u64
|
||||
field metal2vulkan-runtime::WorkCounts.host_imports_kept_for_fds pub host_imports_kept_for_fds: u64
|
||||
field metal2vulkan-runtime::WorkCounts.host_imports_kept_no_stand_in pub host_imports_kept_no_stand_in: u64
|
||||
field metal2vulkan-runtime::WorkCounts.host_imports_kept_of_heap pub host_imports_kept_of_heap: u64
|
||||
|
||||
|
Can't render this file because it is too large.
|
+3
-1
@@ -314,7 +314,9 @@ texture in place over a dma-buf import's bytes lies in an import of a dma-buf of
|
||||
asked of the buffer's source, and leaves the buffer's import releasable: on RADV a guest surface (a
|
||||
no-copy buffer and a texture in place over it) lists the texture's import alone in each kernel
|
||||
submission while the buffer is idle. `WorkCounts::host_imports_released`,
|
||||
`host_imports_reimported`, `host_imports_resident` and `host_import_fds_kept` count it. For imports
|
||||
`host_imports_reimported`, `host_imports_resident` (the releasable imports holding their memory)
|
||||
and `host_import_fds_kept` count it, and `host_imports_held_for_good` the imports that were
|
||||
releasable until a read other than a blit's kept them for good. For imports
|
||||
of either kind, `host_imports_read_apart` counts the live ones that a read other than a blit's keeps
|
||||
for good (the
|
||||
`host_imports_read_apart_*` gauges by reason: the Metal address, the `VkBuffer`, a binding, a
|
||||
|
||||
Reference in new issue
Block a user