Recording: a lock a descriptor slot, a thread's own answers about buffers, tables left as they are when nothing changed

Timeline waits-1 (dorm, 78 ms): the title's render thread stands 20 to 30 ms
a frame at one recording job and the rest at others; recording is the
critical path, and our list calls are 95 % of it. Profile waits-1, the five
recording threads: 21 % contended locks, 11 % HostHeap::keep, 17 % readable,
7 % the look-up of buffers, 8 % clocks and counters of ours.

VICTORY_QUICK_FIND=0 and VICTORY_READY_ONCE=0 go back; counters of the
diagnostics by thread, a coarse clock for what is noted per texture and slot.
VICTORY_AB=<s>,<switches> turns switches on and off while the title runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 08:14:21 -06:00
1 parent 7c62f5b707
commit 66c935eac2
9 files changed
+405 -61

No files matched your search

+50 -17
View File
@@ -131,10 +131,39 @@ pub(crate) enum C {
IndirectBounded,
}
const COUNTERS: usize = 80;
static COUNT: [AtomicU64; COUNTERS] = [const { AtomicU64::new(0) }; COUNTERS];
/// One of some sets of counters, each in lines of the processor's memory of
/// its own: a set for all threads had them wait for each other's lines at
/// every list call (what counts here is summed up for the log alone).
#[repr(align(64))]
struct Bank<const N: usize>([AtomicU64; N]);
/// The sets.
const BANKS: usize = 32;
static COUNT: [Bank<COUNTERS>; BANKS] = [const { Bank([const { AtomicU64::new(0) }; COUNTERS]) }; BANKS];
/// This thread's set.
#[inline]
fn bank() -> usize {
static NEXT: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
thread_local!(static MINE: std::cell::Cell<usize> = const { std::cell::Cell::new(usize::MAX) });
// (Asked by the allocator too: nothing here allocates.)
MINE.try_with(|mine| {
if mine.get() == usize::MAX {
mine.set(NEXT.fetch_add(1, Relaxed) % BANKS);
}
mine.get()
})
.unwrap_or(0)
}
pub(crate) fn add(c: C, n: u64) {
COUNT[c as usize].fetch_add(n, Relaxed);
COUNT[bank()].0[c as usize].fetch_add(n, Relaxed);
}
/// Counter `i`, all sets together, from now on 0.
fn taken(i: usize) -> u64 {
COUNT.iter().map(|b| b.0[i].swap(0, Relaxed)).sum()
}
/// How copies run: 0 guarded (as always), 1 plain, 2 not at all.
@@ -277,7 +306,13 @@ pub(crate) fn range(src: usize, len: usize, us: u64, kind: u32) {
/// runtime and of the driver alike (3.5 GB in run 60's gameplay, growing by
/// some 2 MB a frame, and nothing said whose): this says which part is
/// ours. Bigger blocks are allocations of their own in the map.
static OWN: [AtomicU64; 8] = [const { AtomicU64::new(0) }; 8];
static OWN: [Bank<8>; BANKS] = [const { Bank([const { AtomicU64::new(0) }; 8]) }; BANKS];
/// Count `i` of [`OWN`], all sets together (a block made by one thread and
/// released by another leaves one set below zero: the sum is right).
fn owned(i: usize) -> u64 {
OWN.iter().fold(0u64, |sum, b| sum.wrapping_add(b.0[i].load(Relaxed)))
}
/// The class of [`OWN`] a block of `size` bytes counts in.
fn block_class(size: usize) -> usize {
@@ -291,12 +326,13 @@ fn block_class(size: usize) -> usize {
fn own(size: usize, made: bool) {
let class = block_class(size);
let own = &OWN[bank()].0;
if made {
OWN[class].fetch_add(size as u64, Relaxed);
OWN[4 + class].fetch_add(1, Relaxed);
own[class].fetch_add(size as u64, Relaxed);
own[4 + class].fetch_add(1, Relaxed);
} else {
OWN[class].fetch_sub(size as u64, Relaxed);
OWN[4 + class].fetch_sub(1, Relaxed);
own[class].fetch_sub(size as u64, Relaxed);
own[4 + class].fetch_sub(1, Relaxed);
}
}
@@ -408,7 +444,7 @@ mod command_tests {
#[cfg(test)]
mod own_tests {
use super::{OWN, block_class};
use super::{block_class, owned};
use std::sync::atomic::Ordering::Relaxed;
#[test]
@@ -446,10 +482,10 @@ mod own_tests {
#[test]
fn a_block_is_counted_while_it_lives() {
let block = vec![1u8; 8 << 20];
assert!(OWN[3].load(Relaxed) >= 8 << 20);
assert!(OWN[7].load(Relaxed) >= 1);
assert!(owned(3) >= 8 << 20);
assert!(owned(7) >= 1);
drop(block);
assert!(OWN[7].load(Relaxed) < u64::MAX / 2, "no count below zero");
assert!(owned(7) < u64::MAX / 2, "no count below zero");
}
}
@@ -815,7 +851,7 @@ fn log_memory() {
let alive: Vec<u64> = crate::host::ALIVE.iter().map(|a| a.load(Relaxed)).collect();
let window = crate::shadow::window_use();
let views = crate::descriptor::views_kept();
let own: Vec<u64> = OWN.iter().map(|o| o.load(Relaxed)).collect();
let own: Vec<u64> = (0..8).map(owned).collect();
tracing::info!(
"memory, what holds it: {} host lists alive; their scratch memory: {} chunks {:.0} MB, of them {} chunks {:.0} MB spare ({} taken from the spare ones so far); their other upload buffers: {} alive {:.0} MB; windows outside buffers (grid {} KiB): {:.0} MB of their pages ever copied, {} shown by descriptor slots {:.0} MB, {} held by lists or the pass over the heap {:.0} MB, {} asked for without a length {:.0} MB; buffer views of the heap whose slot showed another copy than the one brought up to date: {}; distinct views kept: {} ({} free) {:.0} MB; our own allocations: {:.0} MB in {} blocks (under 4 KiB {:.0} MB in {}, to 64 KiB {:.0} MB in {}, to 1 MiB {:.0} MB in {}, larger {:.0} MB in {})",
alive[0],
@@ -1095,15 +1131,12 @@ fn page_faults() -> u64 {
/// second or more: a 4 s frame after an unlogged 4 s frame showed two
/// frames' counts as one's).
pub(crate) fn log(frames: f64) {
let counted = COUNT[C::Frames as usize].swap(0, Relaxed);
let counted = taken(C::Frames as usize);
let frames = if counted > 0 { counted as f64 } else { frames };
static FAULTS: AtomicU64 = AtomicU64::new(0);
let faults = page_faults();
let faults = faults - FAULTS.swap(faults, Relaxed).min(faults);
let c: Vec<f64> = COUNT
.iter()
.map(|a| a.swap(0, Relaxed) as f64 / frames)
.collect();
let c: Vec<f64> = (0..COUNTERS).map(|i| taken(i) as f64 / frames).collect();
let mb = |v: f64| v / 1e6;
let ms = |v: f64| v / 1e3;
tracing::info!(