Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion crates/victory-gpu/src/copystat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,26 @@ pub(crate) enum C {
TwinToDepthBytes,
TwinToTwin,
TwinToTwinBytes,
/// The heap sync (`crate::descriptor::sync_heaps`): pages of title heaps
/// read, and of their slots those skipped as made from the record they
/// hold, those holding no view, those checked under the locks (and of
/// them those in blocks not verified since views were last forgotten),
/// and those made again; the time spent reading pages, waiting for the
/// heaps' lock, checking and making; the title's releases that forgot
/// views (each makes every block check its slots again).
SyncPages,
SyncFast,
SyncNoView,
SyncChecked,
SyncUnverified,
SyncMade,
SyncReadNs,
SyncLockNs,
SyncCheckNs,
SyncMakeNs,
ViewsForgot,
}
const COUNTERS: usize = C::TwinToTwinBytes as usize + 1;
const COUNTERS: usize = C::ViewsForgot as usize + 1;
static COUNT: [AtomicU64; COUNTERS] = [const { AtomicU64::new(0) }; COUNTERS];

pub(crate) fn add(c: C, n: u64) {
Expand Down Expand Up @@ -450,6 +468,23 @@ pub(crate) fn log(frames: f64) {
c[C::TwinToTwin as usize],
mb(c[C::TwinToTwinBytes as usize]),
);
tracing::info!(
" heap sync per frame: {:.0} pages, {:.0} slots: {:.0} made from their record already, {:.0} no view, \
{:.0} checked ({:.0} in blocks not verified) in {:.1} ms, {:.0} made again in {:.1} ms; pages read in \
{:.1} ms, {:.1} ms waiting for the heaps' lock; {:.1} releases forgot views",
c[C::SyncPages as usize],
c[C::SyncSlots as usize],
c[C::SyncFast as usize],
c[C::SyncNoView as usize],
c[C::SyncChecked as usize],
c[C::SyncUnverified as usize],
c[C::SyncCheckNs as usize] / 1e6,
c[C::SyncMade as usize],
c[C::SyncMakeNs as usize] / 1e6,
c[C::SyncReadNs as usize] / 1e6,
c[C::SyncLockNs as usize] / 1e6,
c[C::ViewsForgot as usize],
);
let mut snapshots: Vec<((u64, u64), u64)> =
SNAPSHOTS.lock().unwrap_or_else(|e| e.into_inner()).take().into_iter().flatten().collect();
snapshots.sort_by_key(|&(_, bytes)| std::cmp::Reverse(bytes));
Expand Down
21 changes: 20 additions & 1 deletion crates/victory-gpu/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,14 @@ pub(crate) fn sync_heaps() {
for (start, at, ranges) in work {
for (from, to) in ranges {
for page in (from & !(page_size - 1)..to).step_by(page_size) {
#[cfg(feature = "diagnostics")]
let waited = crate::watch::TimedNs(
std::time::Instant::now(),
crate::copystat::C::SyncLockNs,
);
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
#[cfg(feature = "diagnostics")]
drop(waited);
if !heaps.iter().any(|&(s, _, h)| (s, h) == (start, at)) {
break;
}
Expand All @@ -259,9 +266,19 @@ pub(crate) fn sync_heaps() {
let len = end - page;
// By page: read the whole mapped range once; one with nothing
// mapped (the title unmaps heap pages too) holds no records.
if !crate::host::read_into(page as *const u8, &mut page_buf[..len]) {
#[cfg(feature = "diagnostics")]
let reading = crate::watch::TimedNs(
std::time::Instant::now(),
crate::copystat::C::SyncReadNs,
);
let mapped = crate::host::read_into(page as *const u8, &mut page_buf[..len]);
#[cfg(feature = "diagnostics")]
drop(reading);
if !mapped {
continue;
}
#[cfg(feature = "diagnostics")]
crate::copystat::add(crate::copystat::C::SyncPages, 1);
let (first, last) = (
(page as u64 - start) / step,
(end as u64 - start).div_ceil(step),
Expand Down Expand Up @@ -675,6 +692,8 @@ pub(crate) fn forget(resource: usize) {
}
if removed {
VIEWS_FORGOT.fetch_add(1, std::sync::atomic::Ordering::Release);
#[cfg(all(windows, feature = "diagnostics"))]
crate::copystat::add(crate::copystat::C::ViewsForgot, 1);
}
}

Expand Down
Loading