Two measurements for placing memory: bytes over the bus by host copy, and what the title asks its memory to be
Diagnostics: per copy what goes up and what is fetched (every five seconds, the eight that move most), and the protections title memory is asked for with (write-combined and GPU bits). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
efca06ba45
commit
bc478bb832
3 files changed
+94
No files matched your search
@@ -3564,6 +3564,8 @@ pub(crate) use send::{goes_as_words, words_under};
|
||||
#[cfg(feature = "diagnostics")]
|
||||
pub(crate) mod spans;
|
||||
mod torn;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
mod traffic;
|
||||
pub(crate) mod upcheck;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
mod stamps;
|
||||
@@ -4184,6 +4186,8 @@ impl Host {
|
||||
crate::shadow::CARD_STATS[0].fetch_add((b - a) as u64, Ordering::Relaxed);
|
||||
}
|
||||
crate::shadow::CARD_STATS[1].fetch_add(ranges.len() as u64, Ordering::Relaxed);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
traffic::moved(traffic::UP, shadow.span(), ranges.iter().copied());
|
||||
if own.is_none() && before.is_some() && !ranges.is_empty() {
|
||||
sent.push(transition(
|
||||
&shadow.buffer,
|
||||
@@ -4527,6 +4531,10 @@ impl Host {
|
||||
if let Some(check) = &check {
|
||||
total = check.total;
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
for (shadow, lo, hi, _) in &pieces {
|
||||
traffic::moved(traffic::FETCHED, shadow.span(), std::iter::once((*lo, *hi)));
|
||||
}
|
||||
// The sends these flights ran behind, all a fetch on the copy queue
|
||||
// is known to have run behind.
|
||||
let behind = plans.iter().map(|p| p.0.sent_as).max().unwrap_or(0);
|
||||
@@ -8551,6 +8559,7 @@ impl Meter {
|
||||
put[2] / 1e6,
|
||||
put[3]
|
||||
);
|
||||
traffic::line(self.copy_stats_frames as f64);
|
||||
crate::copystat::log(std::mem::take(&mut self.copy_stats_frames) as f64);
|
||||
for (why, n) in drops.iter().take(40) {
|
||||
tracing::info!(
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//! Diagnostics: which host copies' bytes cross the bus, and which way: per
|
||||
//! copy (title address, bytes) what was sent up and what shaders wrote that
|
||||
//! was fetched, a frame; and how many different 64 KiB pieces of it. Every
|
||||
//! five seconds, the eight that move most. For placing resources: a copy whose
|
||||
//! pieces are fetched every frame and never sent up is written by shaders
|
||||
//! alone, and nobody but shaders may read it.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// Of a copy, each way (up, fetched): bytes, and the pieces (64 KiB).
|
||||
#[derive(Default)]
|
||||
struct Moved {
|
||||
bytes: [u64; 2],
|
||||
pieces: [HashSet<u32>; 2],
|
||||
}
|
||||
|
||||
pub(super) const UP: usize = 0;
|
||||
pub(super) const FETCHED: usize = 1;
|
||||
|
||||
static MOVED: Mutex<Option<HashMap<(u64, u64), Moved>>> = Mutex::new(None);
|
||||
|
||||
/// Offsets `ranges` of the copy of `span` (title address, bytes) went `way`.
|
||||
pub(super) fn moved(way: usize, span: (u64, u64), ranges: impl Iterator<Item = (usize, usize)>) {
|
||||
let mut all = MOVED.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let m = all.get_or_insert_with(Default::default).entry(span).or_default();
|
||||
for (from, to) in ranges.filter(|r| r.0 < r.1) {
|
||||
m.bytes[way] += (to - from) as u64;
|
||||
m.pieces[way].extend((from >> 16) as u32..=((to - 1) >> 16) as u32);
|
||||
}
|
||||
}
|
||||
|
||||
/// For the log, over `frames` frames.
|
||||
pub(super) fn line(frames: f64) {
|
||||
let all = MOVED.lock().unwrap_or_else(|e| e.into_inner()).take().unwrap_or_default();
|
||||
let mut all: Vec<_> = all.into_iter().collect();
|
||||
all.sort_by_key(|(_, m)| std::cmp::Reverse(m.bytes[0] + m.bytes[1]));
|
||||
let mb = |b: u64| b as f64 / 1e6 / frames.max(1.0);
|
||||
let sum = |way: usize| all.iter().map(|(_, m)| m.bytes[way]).sum::<u64>();
|
||||
// Copies that only move one way.
|
||||
let only = |way: usize| all.iter().filter(|(_, m)| m.bytes[1 - way] == 0).map(|(_, m)| m.bytes[way]).sum::<u64>();
|
||||
tracing::info!(
|
||||
"bytes of host copies over the bus per frame: {:.1} MB up ({:.1} of copies nothing was fetched from), {:.1} MB fetched \
|
||||
({:.1} of copies nothing was sent up to), {} copies; the most:",
|
||||
mb(sum(UP)),
|
||||
mb(only(UP)),
|
||||
mb(sum(FETCHED)),
|
||||
mb(only(FETCHED)),
|
||||
all.len()
|
||||
);
|
||||
for ((start, len), m) in all.into_iter().take(8) {
|
||||
let both = m.pieces[0].intersection(&m.pieces[1]).count();
|
||||
tracing::info!(
|
||||
" {start:#x}+{len:#x}: {:.2} MB up in {} different pieces, {:.2} MB fetched in {}, {both} of them both ways",
|
||||
mb(m.bytes[0]),
|
||||
m.pieces[0].len(),
|
||||
mb(m.bytes[1]),
|
||||
m.pieces[1].len()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,7 @@ pub extern "system" fn XMemVirtualAlloc(
|
||||
0
|
||||
},
|
||||
};
|
||||
let asked = protect;
|
||||
let mut protect = match protect & HOST_PROTECTION {
|
||||
0 => PAGE_NOACCESS,
|
||||
p => p,
|
||||
@@ -179,9 +180,32 @@ pub extern "system" fn XMemVirtualAlloc(
|
||||
if !at.is_null() && !placeholder {
|
||||
victory_gpu::title_memory_allocated(at as usize, size);
|
||||
}
|
||||
note_protection(asked, kind, flags, at as usize, size);
|
||||
at
|
||||
}
|
||||
|
||||
/// What the title asks its memory to be (the console's protection, with the
|
||||
/// bits that say how each processor reaches it: 0x200 uncached, 0x400
|
||||
/// write-combined, 0x800 and on the GPU's): said for the 1st, 2nd, 4th.. time of
|
||||
/// each, with how much so far. (For placing it: memory the CPU reaches
|
||||
/// uncached or write-combined is memory it does not read.)
|
||||
fn note_protection(protect: u32, kind: u32, flags: u64, at: usize, size: usize) {
|
||||
type Seen = std::collections::HashMap<(u32, u32, u64), (u64, usize)>;
|
||||
static SEEN: std::sync::Mutex<Option<Seen>> = std::sync::Mutex::new(None);
|
||||
let (n, bytes) = {
|
||||
let mut seen = SEEN.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let e = seen.get_or_insert_with(Default::default).entry((protect, kind, flags)).or_default();
|
||||
*e = (e.0 + 1, e.1 + size);
|
||||
*e
|
||||
};
|
||||
if n.is_power_of_two() {
|
||||
tracing::info!(
|
||||
"title memory asked for as protection {protect:#x}, kind {kind:#x}, flags {flags:#x}: {n} times, {} MB, last {at:#x}+{size:#x}",
|
||||
bytes >> 20
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// `MEMORY_BASIC_INFORMATION` (the console's first 0x30 bytes are the
|
||||
/// same), then the XMem flags and tag.
|
||||
#[repr(C)]
|
||||
|
||||
Reference in new issue
Block a user