Heaps' records copied as bytes: pages read, compared and sorted out on several threads, empty slots that show nothing left alone; pages of places read by steps on the card asked about once
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2547124475
commit
ee481c02fb
4 files changed
+154
-74
No files matched your search
@@ -302,11 +302,9 @@ pub(crate) fn sync_heaps() {
|
|||||||
let started = std::time::Instant::now();
|
let started = std::time::Instant::now();
|
||||||
let (mut pages, mut looked, mut mirrored, mut tabled, mut later) = (0u64, 0u64, 0u64, 0u64, 0u64);
|
let (mut pages, mut looked, mut mirrored, mut tabled, mut later) = (0u64, 0u64, 0u64, 0u64, 0u64);
|
||||||
let (mut views, mut bytes) = (0u64, 0u64);
|
let (mut views, mut bytes) = (0u64, 0u64);
|
||||||
let mut spent = [0u64; 4];
|
let mut spent = [0u64; 3];
|
||||||
let since = |at: std::time::Instant| at.elapsed().as_nanos() as u64;
|
let since = |at: std::time::Instant| at.elapsed().as_nanos() as u64;
|
||||||
let mut kinds = [0u64; 6];
|
let mut kinds = [0u64; 5];
|
||||||
let mut page_bytes: Vec<u8> = Vec::new();
|
|
||||||
let mut changed: Vec<u32> = Vec::new();
|
|
||||||
let mut wait: Vec<u32> = Vec::new();
|
let mut wait: Vec<u32> = Vec::new();
|
||||||
let frame = crate::frame::current();
|
let frame = crate::frame::current();
|
||||||
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
|
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
|
||||||
@@ -344,38 +342,51 @@ pub(crate) fn sync_heaps() {
|
|||||||
let began = std::time::Instant::now();
|
let began = std::time::Instant::now();
|
||||||
let taken = written.take(start as usize, end as usize);
|
let taken = written.take(start as usize, end as usize);
|
||||||
spent[0] += since(began);
|
spent[0] += since(began);
|
||||||
|
let mut parts: Vec<(usize, usize)> = Vec::new();
|
||||||
for (range_from, range_end) in taken {
|
for (range_from, range_end) in taken {
|
||||||
let mut page = range_from & !(crate::watch::PAGE - 1);
|
let mut page = range_from & !(crate::watch::PAGE - 1);
|
||||||
while page < range_end {
|
while page < range_end {
|
||||||
let from = page.max(range_from);
|
parts.push((page.max(range_from), (page + crate::watch::PAGE).min(range_end)));
|
||||||
let to = (page + crate::watch::PAGE).min(range_end);
|
page += crate::watch::PAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A few pages a thread at a time: read, compared with what was last
|
||||||
|
// seen there and sorted out, beside one another (14 ms a frame of one
|
||||||
|
// thread at 160 pages, run faults-6).
|
||||||
|
let began = std::time::Instant::now();
|
||||||
|
let copied = host.copied_begin(step as usize);
|
||||||
|
let samplers = heap.samplers();
|
||||||
|
let found: Vec<std::sync::Mutex<SyncPart>> = parts.chunks(SYNC_PAGES).map(|_| Default::default()).collect();
|
||||||
|
crate::land::each_view(true, found.len(), &|n| {
|
||||||
|
let mut out = SyncPart::default();
|
||||||
|
let mut page_bytes: Vec<u8> = Vec::new();
|
||||||
|
let mut changed: Vec<u32> = Vec::new();
|
||||||
|
for &(from, to) in parts.chunks(SYNC_PAGES).nth(n).unwrap_or_default() {
|
||||||
// The page's records are read through the kernel, into a
|
// The page's records are read through the kernel, into a
|
||||||
// copy: a page the title unmaps meanwhile fails the read
|
// copy: a page the title unmaps meanwhile fails the read
|
||||||
// where 2,048 reads in place would fault.
|
// where 2,048 reads in place would fault.
|
||||||
page_bytes.resize(to - from, 0);
|
page_bytes.resize(to - from, 0);
|
||||||
let began = std::time::Instant::now();
|
if !crate::host::read_into(from as *const u8, &mut page_bytes) {
|
||||||
let there = crate::host::read_into(from as *const u8, &mut page_bytes);
|
continue;
|
||||||
spent[1] += since(began);
|
}
|
||||||
if there {
|
out.pages += 1;
|
||||||
pages += 1;
|
out.views += u64::from(crate::watch::guarded(from, to));
|
||||||
views += u64::from(crate::watch::guarded(from, to));
|
out.bytes += (to - from) as u64;
|
||||||
bytes += (to - from) as u64;
|
|
||||||
let slots = changed_slots(from, to, start as usize, step, mirrored_count);
|
let slots = changed_slots(from, to, start as usize, step, mirrored_count);
|
||||||
// A record that straddles the range's ends is left
|
// A record that straddles the range's ends is left
|
||||||
// to the range that holds its first byte.
|
// to the range that holds its first byte.
|
||||||
let first = ((from - start as usize) as u64).div_ceil(step).max(slots.start);
|
let first = ((from - start as usize) as u64).div_ceil(step).max(slots.start);
|
||||||
let Some(records) = page_bytes.get((start + first * step) as usize - from..) else {
|
let Some(records) = page_bytes.get((start + first * step) as usize - from..) else {
|
||||||
page += crate::watch::PAGE;
|
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let count = (records.len() as u64 / step).min(slots.end.saturating_sub(first));
|
let count = (records.len() as u64 / step).min(slots.end.saturating_sub(first));
|
||||||
looked += count;
|
out.looked += count;
|
||||||
// Only the records that are not the ones last seen
|
// Only the records that are not the ones last seen
|
||||||
// there (`HostHeap::copied_changes`).
|
// there (`host::Copied::changes`).
|
||||||
changed.clear();
|
changed.clear();
|
||||||
let began = std::time::Instant::now();
|
// SAFETY: the parts are ranges of the heap apart from one
|
||||||
host.copied_changes(first as u32, &records[..(count * step) as usize], step as usize, &mut changed);
|
// another, and only records that lie whole in one are its.
|
||||||
spent[2] += since(began);
|
unsafe { copied.changes(first as u32, &records[..(count * step) as usize], &mut changed) };
|
||||||
for &index in &changed {
|
for &index in &changed {
|
||||||
let at = (u64::from(index) - first) as usize * step as usize;
|
let at = (u64::from(index) - first) as usize * step as usize;
|
||||||
let word = |n: usize| {
|
let word = |n: usize| {
|
||||||
@@ -384,11 +395,11 @@ pub(crate) fn sync_heaps() {
|
|||||||
.and_then(|b| b.try_into().ok())
|
.and_then(|b| b.try_into().ok())
|
||||||
.map_or(0, u32::from_le_bytes)
|
.map_or(0, u32::from_le_bytes)
|
||||||
};
|
};
|
||||||
if !heap.samplers() && word(0) == VIEW_TAG {
|
if !samplers && word(0) == VIEW_TAG {
|
||||||
// A draw's own table: the draw makes what it
|
// A draw's own table: the draw makes what it
|
||||||
// reads of it (`draw.rs` `tables`).
|
// reads of it (`draw.rs` `tables`).
|
||||||
if host.copied_tabled(index, frame) {
|
if host.copied_tabled(index, frame) {
|
||||||
tabled += 1;
|
out.tabled += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Buffer views and placed textures get no host
|
// Buffer views and placed textures get no host
|
||||||
@@ -396,14 +407,19 @@ pub(crate) fn sync_heaps() {
|
|||||||
// or a pass: noted some frames on, unless a
|
// or a pass: noted some frames on, unless a
|
||||||
// draw's table turns out to hold them.
|
// draw's table turns out to hold them.
|
||||||
if matches!(word(2) >> KIND_SHIFT, CONSTANT | PLACED) && host.copied_waits() {
|
if matches!(word(2) >> KIND_SHIFT, CONSTANT | PLACED) && host.copied_waits() {
|
||||||
wait.push(index);
|
out.wait.push(index);
|
||||||
later += 1;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
make.push(index);
|
// No view, in a slot that shows none: nothing to make or
|
||||||
mirrored += 1;
|
// unmake (32,000 of 41,000 a frame on the water, run
|
||||||
kinds[if heap.samplers() {
|
// b2-water).
|
||||||
|
if word(0) != VIEW_TAG && host.shows_none(index) {
|
||||||
|
out.nothing += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out.make.push(index);
|
||||||
|
out.kinds[if samplers {
|
||||||
3
|
3
|
||||||
} else if word(0) != VIEW_TAG {
|
} else if word(0) != VIEW_TAG {
|
||||||
0
|
0
|
||||||
@@ -412,19 +428,35 @@ pub(crate) fn sync_heaps() {
|
|||||||
} else {
|
} else {
|
||||||
2
|
2
|
||||||
}] += 1;
|
}] += 1;
|
||||||
kinds[5] += u64::from(!heap.samplers() && host.near_tabled(index, frame));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
page += crate::watch::PAGE;
|
*found[n].lock().unwrap_or_else(|e| e.into_inner()) = out;
|
||||||
|
});
|
||||||
|
drop(copied);
|
||||||
|
for part in found {
|
||||||
|
let mut part = part.into_inner().unwrap_or_else(|e| e.into_inner());
|
||||||
|
pages += part.pages;
|
||||||
|
views += part.views;
|
||||||
|
bytes += part.bytes;
|
||||||
|
looked += part.looked;
|
||||||
|
tabled += part.tabled;
|
||||||
|
kinds[0] += part.nothing;
|
||||||
|
later += part.wait.len() as u64;
|
||||||
|
mirrored += part.make.len() as u64;
|
||||||
|
wait.append(&mut part.wait);
|
||||||
|
make.append(&mut part.make);
|
||||||
|
for (kind, n) in kinds.iter_mut().zip(part.kinds) {
|
||||||
|
*kind += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
spent[1] += since(began);
|
||||||
let began = std::time::Instant::now();
|
let began = std::time::Instant::now();
|
||||||
crate::land::each_view(true, make.len().div_ceil(SYNC_AT_A_TIME), &|n| {
|
crate::land::each_view(true, make.len().div_ceil(SYNC_AT_A_TIME), &|n| {
|
||||||
for &index in make.chunks(SYNC_AT_A_TIME).nth(n).unwrap_or_default() {
|
for &index in make.chunks(SYNC_AT_A_TIME).nth(n).unwrap_or_default() {
|
||||||
host.mirror(index, start + u64::from(index) * step, false);
|
host.mirror(index, start + u64::from(index) * step, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
spent[3] += since(began);
|
spent[2] += since(began);
|
||||||
if !wait.is_empty() {
|
if !wait.is_empty() {
|
||||||
host.copied_wait(frame, std::mem::take(&mut wait));
|
host.copied_wait(frame, std::mem::take(&mut wait));
|
||||||
}
|
}
|
||||||
@@ -434,8 +466,8 @@ pub(crate) fn sync_heaps() {
|
|||||||
for (count, n) in SYNCED.iter().zip([pages, looked, mirrored, micros, tabled, later]) {
|
for (count, n) in SYNCED.iter().zip([pages, looked, mirrored, micros, tabled, later]) {
|
||||||
count.fetch_add(n, Relaxed);
|
count.fetch_add(n, Relaxed);
|
||||||
}
|
}
|
||||||
let [taking, reading, comparing, making] = spent;
|
let [taking, reading, making] = spent;
|
||||||
for (count, n) in SYNC_SPLIT.iter().zip([views, bytes, taking, reading, comparing, making]) {
|
for (count, n) in SYNC_SPLIT.iter().zip([views, bytes, taking, reading, making]) {
|
||||||
count.fetch_add(n, Relaxed);
|
count.fetch_add(n, Relaxed);
|
||||||
}
|
}
|
||||||
for (count, n) in SYNCED_KINDS.iter().zip(kinds) {
|
for (count, n) in SYNCED_KINDS.iter().zip(kinds) {
|
||||||
@@ -444,9 +476,28 @@ pub(crate) fn sync_heaps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Of those mirrored, since the last frame line: no view, a view of an object,
|
/// Of those mirrored, since the last frame line: no view, a view of an object,
|
||||||
/// another, a sampler; waited and no draw came; next to a slot of a table's.
|
/// another, a sampler; waited and no draw came.
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
static SYNCED_KINDS: [std::sync::atomic::AtomicU64; 6] = [const { std::sync::atomic::AtomicU64::new(0) }; 6];
|
static SYNCED_KINDS: [std::sync::atomic::AtomicU64; 5] = [const { std::sync::atomic::AtomicU64::new(0) }; 5];
|
||||||
|
|
||||||
|
/// What a thread found on its pages of a heap, for [`sync_heaps`].
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[derive(Default)]
|
||||||
|
struct SyncPart {
|
||||||
|
pages: u64,
|
||||||
|
views: u64,
|
||||||
|
bytes: u64,
|
||||||
|
looked: u64,
|
||||||
|
tabled: u64,
|
||||||
|
nothing: u64,
|
||||||
|
make: Vec<u32>,
|
||||||
|
wait: Vec<u32>,
|
||||||
|
kinds: [u64; 5],
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pages [`sync_heaps`] gives a thread at a time.
|
||||||
|
#[cfg(windows)]
|
||||||
|
const SYNC_PAGES: usize = 8;
|
||||||
|
|
||||||
/// Records [`sync_heaps`] gives a thread at a time.
|
/// Records [`sync_heaps`] gives a thread at a time.
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@@ -462,10 +513,10 @@ const SYNC_AT_A_TIME: usize = 256;
|
|||||||
pub(crate) static SYNCED: [std::sync::atomic::AtomicU64; 7] = [const { std::sync::atomic::AtomicU64::new(0) }; 7];
|
pub(crate) static SYNCED: [std::sync::atomic::AtomicU64; 7] = [const { std::sync::atomic::AtomicU64::new(0) }; 7];
|
||||||
|
|
||||||
/// The same, of [`SYNCED`]'s pages: those in view memory that was guarded;
|
/// The same, of [`SYNCED`]'s pages: those in view memory that was guarded;
|
||||||
/// bytes read; nanoseconds asking what was written, reading it, comparing it
|
/// bytes read; nanoseconds asking what was written, reading it and comparing
|
||||||
/// with what was last seen, making views.
|
/// it with what was last seen, making views.
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
static SYNC_SPLIT: [std::sync::atomic::AtomicU64; 6] = [const { std::sync::atomic::AtomicU64::new(0) }; 6];
|
static SYNC_SPLIT: [std::sync::atomic::AtomicU64; 5] = [const { std::sync::atomic::AtomicU64::new(0) }; 5];
|
||||||
|
|
||||||
/// With the frame line: what [`sync_heaps`] did per frame over `frames`.
|
/// With the frame line: what [`sync_heaps`] did per frame over `frames`.
|
||||||
/// Nothing while no heap page changed.
|
/// Nothing while no heap page changed.
|
||||||
@@ -481,8 +532,8 @@ pub(crate) fn sync_line(frames: f64) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
let [pages, looked, mirrored, micros, tabled, later, waited] = [0, 1, 2, 3, 4, 5, 6].map(|i| SYNCED[i].swap(0, std::sync::atomic::Ordering::Relaxed));
|
let [pages, looked, mirrored, micros, tabled, later, waited] = [0, 1, 2, 3, 4, 5, 6].map(|i| SYNCED[i].swap(0, std::sync::atomic::Ordering::Relaxed));
|
||||||
let split = [0, 1, 2, 3, 4, 5].map(|i| SYNC_SPLIT[i].swap(0, std::sync::atomic::Ordering::Relaxed) as f64);
|
let split = [0, 1, 2, 3, 4].map(|i| SYNC_SPLIT[i].swap(0, std::sync::atomic::Ordering::Relaxed) as f64);
|
||||||
let kinds = [0, 1, 2, 3, 4, 5].map(|i| SYNCED_KINDS[i].swap(0, std::sync::atomic::Ordering::Relaxed) as f64 / frames);
|
let kinds = [0, 1, 2, 3, 4].map(|i| SYNCED_KINDS[i].swap(0, std::sync::atomic::Ordering::Relaxed) as f64 / frames);
|
||||||
if pages == 0 {
|
if pages == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -490,8 +541,8 @@ pub(crate) fn sync_line(frames: f64) {
|
|||||||
"descriptor records the title copied into its heap as bytes (VICTORY_HEAP_SYNC=0: not looked for): per frame \
|
"descriptor records the title copied into its heap as bytes (VICTORY_HEAP_SYNC=0: not looked for): per frame \
|
||||||
{:.1} changed heap pages, {:.0} slots looked at, {:.1} whose record was new and was mirrored, {:.1} new ones of \
|
{:.1} changed heap pages, {:.0} slots looked at, {:.1} whose record was new and was mirrored, {:.1} new ones of \
|
||||||
draws' tables left to the draws, {:.1} that waited for a draw first, {:.2} ms ({:.2} ms waited for); of the mirrored \
|
draws' tables left to the draws, {:.1} that waited for a draw first, {:.2} ms ({:.2} ms waited for); of the mirrored \
|
||||||
{:.0} no views, {:.0} of objects, {:.0} others, {:.0} samplers, {:.0} that waited and no draw came, {:.0} near a table's slot; \
|
{:.0} no views (with those of slots that show none), {:.0} of objects, {:.0} others, {:.0} samplers, {:.0} that waited and no draw came; \
|
||||||
{:.1} of the pages guarded views, {:.1} MB read; {:.2} ms asking, {:.2} reading, {:.2} comparing, {:.2} making",
|
{:.1} of the pages guarded views, {:.1} MB read; {:.2} ms asking, {:.2} reading and comparing, {:.2} making",
|
||||||
pages as f64 / frames,
|
pages as f64 / frames,
|
||||||
looked as f64 / frames,
|
looked as f64 / frames,
|
||||||
mirrored as f64 / frames,
|
mirrored as f64 / frames,
|
||||||
@@ -504,13 +555,11 @@ pub(crate) fn sync_line(frames: f64) {
|
|||||||
kinds[2],
|
kinds[2],
|
||||||
kinds[3],
|
kinds[3],
|
||||||
kinds[4],
|
kinds[4],
|
||||||
kinds[5],
|
|
||||||
split[0] / frames,
|
split[0] / frames,
|
||||||
split[1] / (1 << 20) as f64 / frames,
|
split[1] / (1 << 20) as f64 / frames,
|
||||||
split[2] / 1e6 / frames,
|
split[2] / 1e6 / frames,
|
||||||
split[3] / 1e6 / frames,
|
split[3] / 1e6 / frames,
|
||||||
split[4] / 1e6 / frames,
|
split[4] / 1e6 / frames
|
||||||
split[5] / 1e6 / frames
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ pub(crate) struct HostHeap {
|
|||||||
/// [`HostHeap::mirror`] asks first, without the lock. Changed under it.
|
/// [`HostHeap::mirror`] asks first, without the lock. Changed under it.
|
||||||
quick: Vec<std::sync::atomic::AtomicU64>,
|
quick: Vec<std::sync::atomic::AtomicU64>,
|
||||||
/// The records of the title's heap as the pass over records copied in
|
/// The records of the title's heap as the pass over records copied in
|
||||||
/// as bytes last saw them ([`HostHeap::copied_changes`]). Made on first
|
/// as bytes last saw them ([`Copied::changes`]). Made on first
|
||||||
/// use.
|
/// use.
|
||||||
copied: Mutex<Vec<u8>>,
|
copied: Mutex<Vec<u8>>,
|
||||||
/// New ones of them that wait for a draw ([`HostHeap::copied_wait`]),
|
/// New ones of them that wait for a draw ([`HostHeap::copied_wait`]),
|
||||||
@@ -2885,10 +2885,10 @@ impl HostHeap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For a run of records of the title's heap from slot `first`, `step`
|
/// The records last seen of the title's heap, `step` bytes each, held for
|
||||||
/// bytes each, on a page that changed with no call
|
/// threads that compare what they read of its changed pages beside one
|
||||||
/// (`super::sync_heaps`: the title copies records into its heap as
|
/// another ([`Copied::changes`]; `super::sync_heaps`: the title copies
|
||||||
/// bytes): the slots whose record is not the one this last saw there.
|
/// records into its heap as bytes).
|
||||||
///
|
///
|
||||||
/// The page says only that something on it was written, and `mirror`
|
/// The page says only that something on it was written, and `mirror`
|
||||||
/// by itself would take every buffer or placed-texture record on it for
|
/// by itself would take every buffer or placed-texture record on it for
|
||||||
@@ -2896,23 +2896,15 @@ impl HostHeap {
|
|||||||
/// or a pass uses it): the texture queue's entry for the slot would
|
/// or a pass uses it): the texture queue's entry for the slot would
|
||||||
/// start again, and the buffer pass would look at 2,048 slots for one
|
/// start again, and the buffer pass would look at 2,048 slots for one
|
||||||
/// that changed.
|
/// that changed.
|
||||||
/// `records`: their bytes as the caller read them (through the
|
pub(crate) fn copied_begin(&self, step: usize) -> Copied<'_> {
|
||||||
/// kernel, which fails on a page the title unmapped meanwhile where a
|
|
||||||
/// read in place would fault: the title unmaps heap pages too).
|
|
||||||
pub(crate) fn copied_changes(&self, first: u32, records: &[u8], step: usize, out: &mut Vec<u32>) {
|
|
||||||
let mut copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
let mut copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
if copied.is_empty() {
|
if copied.is_empty() {
|
||||||
// Nothing there: a slot never looked at that holds nothing is
|
// Nothing there: a slot never looked at that holds nothing is
|
||||||
// as it was.
|
// as it was.
|
||||||
copied.resize(self.count as usize * step, 0);
|
copied.resize(self.count as usize * step, 0);
|
||||||
}
|
}
|
||||||
let at = first as usize * step;
|
let (at, len) = (copied.as_mut_ptr(), copied.len());
|
||||||
let end = (at + records.len()).min(copied.len());
|
Copied { at, len, step, _held: copied }
|
||||||
let Some(last) = copied.get_mut(at..end) else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let records = &records[..last.len()];
|
|
||||||
changed_records(last, records, step, first, out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether new records of draws' tables are left to the draws
|
/// Whether new records of draws' tables are left to the draws
|
||||||
@@ -2941,13 +2933,6 @@ impl HostHeap {
|
|||||||
stamp != 0 && now.wrapping_sub(stamp) & !TABLED_READ <= COPIED_FRAMES
|
stamp != 0 && now.wrapping_sub(stamp) & !TABLED_READ <= COPIED_FRAMES
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether a slot within 64 of `index` is a table's lately (counted for
|
|
||||||
/// the log: such a slot is likely one of a table not read yet).
|
|
||||||
pub(crate) fn near_tabled(&self, index: u32, frame: u64) -> bool {
|
|
||||||
let first = index & !63;
|
|
||||||
(first..first + 64).any(|i| i < self.count && self.copied_tabled(i, frame))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// New records the title copied into slots `slots` in `frame` wait for
|
/// New records the title copied into slots `slots` in `frame` wait for
|
||||||
/// the draw that may read them through a table.
|
/// the draw that may read them through a table.
|
||||||
pub(crate) fn copied_wait(&self, frame: u64, slots: Vec<u32>) {
|
pub(crate) fn copied_wait(&self, frame: u64, slots: Vec<u32>) {
|
||||||
@@ -3091,6 +3076,12 @@ impl HostHeap {
|
|||||||
Some(view)
|
Some(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether slot `index` was made from no record: what [`HostHeap::mirror`]
|
||||||
|
/// would find before it did nothing for one that holds no view.
|
||||||
|
pub(crate) fn shows_none(&self, index: u32) -> bool {
|
||||||
|
self.made.get(index).unwrap_or(0) == 0
|
||||||
|
}
|
||||||
|
|
||||||
/// Slot `index` is made from record `key` and stays so (0: not). Under
|
/// Slot `index` is made from record `key` and stays so (0: not). Under
|
||||||
/// the lock of `made`.
|
/// the lock of `made`.
|
||||||
fn quick_is(&self, index: u32, key: u64) {
|
fn quick_is(&self, index: u32, key: u64) {
|
||||||
@@ -4318,6 +4309,39 @@ fn quick_mirror() -> bool {
|
|||||||
*ON.get_or_init(|| std::env::var_os("VICTORY_QUICK_MIRROR").is_none_or(|v| v != "0"))
|
*ON.get_or_init(|| std::env::var_os("VICTORY_QUICK_MIRROR").is_none_or(|v| v != "0"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The records last seen of a heap, held ([`HostHeap::copied_begin`]).
|
||||||
|
pub(crate) struct Copied<'a> {
|
||||||
|
at: *mut u8,
|
||||||
|
len: usize,
|
||||||
|
step: usize,
|
||||||
|
_held: std::sync::MutexGuard<'a, Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// SAFETY: the bytes are reached through `changes` alone, whose callers take
|
||||||
|
// parts apart from one another; the guard stays with the thread that has it.
|
||||||
|
unsafe impl Sync for Copied<'_> {}
|
||||||
|
|
||||||
|
impl Copied<'_> {
|
||||||
|
/// The slots of `records` (as the title has them now, from slot `first`
|
||||||
|
/// on) that are not the ones last seen, which they are from here on.
|
||||||
|
/// (`records`: as the caller read them, through the kernel, which fails on
|
||||||
|
/// a page the title unmapped meanwhile where a read in place would fault:
|
||||||
|
/// the title unmaps heap pages too.)
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// No other call beside this one has any of these slots.
|
||||||
|
pub(crate) unsafe fn changes(&self, first: u32, records: &[u8], out: &mut Vec<u32>) {
|
||||||
|
let at = first as usize * self.step;
|
||||||
|
let end = (at + records.len()).min(self.len);
|
||||||
|
if at >= end {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// SAFETY: within the records held; the caller's slots alone.
|
||||||
|
let last = unsafe { std::slice::from_raw_parts_mut(self.at.add(at), end - at) };
|
||||||
|
changed_records(last, &records[..end - at], self.step, first, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The records (`step` bytes each, the first is slot `first`) that differ
|
/// The records (`step` bytes each, the first is slot `first`) that differ
|
||||||
/// between `last` and `records` (of one length) go into `out` and `last`.
|
/// between `last` and `records` (of one length) go into `out` and `last`.
|
||||||
/// Most of a changed page is as it was: it is looked at sixteen records at a
|
/// Most of a changed page is as it was: it is looked at sixteen records at a
|
||||||
|
|||||||
@@ -484,12 +484,19 @@ pub(super) fn cut_for(runs: &[&HostList]) -> Option<usize> {
|
|||||||
|
|
||||||
/// Whether every page of `[from, to)` can be read (through the kernel:
|
/// Whether every page of `[from, to)` can be read (through the kernel:
|
||||||
/// asking Windows walks the page tables, milliseconds in the title's heap).
|
/// asking Windows walks the page tables, milliseconds in the title's heap).
|
||||||
/// `room`: for what is read.
|
/// `known`: pages that could be, of the same submission: its fills' places
|
||||||
fn mapped(from: usize, to: usize, room: &mut Vec<u8>) -> bool {
|
/// lie eight to a page, and each was read whole to find out.
|
||||||
if room.len() < to - from {
|
fn mapped(from: usize, to: usize, known: &mut HashMap<usize, ()>) -> bool {
|
||||||
room.resize(to - from, 0);
|
const PAGE: usize = 4096;
|
||||||
|
(from / PAGE..to.div_ceil(PAGE)).all(|page| {
|
||||||
|
known.contains_key(&page) || {
|
||||||
|
let there = read_into((page * PAGE).max(from) as *const u8, &mut [0]);
|
||||||
|
if there {
|
||||||
|
known.insert(page, ());
|
||||||
}
|
}
|
||||||
read_into(from as *const u8, &mut room[..to - from])
|
there
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A table by addresses and numbers of ours.
|
/// A table by addresses and numbers of ours.
|
||||||
@@ -697,7 +704,7 @@ impl Host {
|
|||||||
// Some 2,800 fills a frame, of a few hundred places: what holds each
|
// Some 2,800 fills a frame, of a few hundred places: what holds each
|
||||||
// is looked for once, as long as no copy is added to the writers.
|
// is looked for once, as long as no copy is added to the writers.
|
||||||
let mut held: HashMap<(usize, usize), Arc<Shadow>> = HashMap::default();
|
let mut held: HashMap<(usize, usize), Arc<Shadow>> = HashMap::default();
|
||||||
let mut room = Vec::new();
|
let mut room = HashMap::default();
|
||||||
let mut end = 0u64;
|
let mut end = 0u64;
|
||||||
for &(i, level) in &chosen {
|
for &(i, level) in &chosen {
|
||||||
let Some(((src, _), (dst, _))) = reads_writes(&does[i]) else {
|
let Some(((src, _), (dst, _))) = reads_writes(&does[i]) else {
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ pub(crate) fn each_under(count: usize, f: &(dyn Fn(usize) + Sync)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Calls `f` with every number below `count`, on this thread and on threads
|
/// Calls `f` with every number below `count`, on this thread and on threads
|
||||||
/// kept for making descriptors (`VICTORY_VIEW_THREADS`, 4 with this one; 1:
|
/// kept for making descriptors (`VICTORY_VIEW_THREADS`, 4 with this one, 6 for records; 1:
|
||||||
/// on this one alone). Those for `records`, the heaps' records copied as
|
/// on this one alone). Those for `records`, the heaps' records copied as
|
||||||
/// bytes, are others than those for the views picked by index: submissions
|
/// bytes, are others than those for the views picked by index: submissions
|
||||||
/// wait for the first, lists for the second, and each kept the other waiting.
|
/// wait for the first, lists for the second, and each kept the other waiting.
|
||||||
@@ -348,7 +348,7 @@ pub(crate) fn each_view(records: bool, count: usize, f: &(dyn Fn(usize) + Sync))
|
|||||||
static POOLS: [OnceLock<&'static Pool>; 2] = [const { OnceLock::new() }; 2];
|
static POOLS: [OnceLock<&'static Pool>; 2] = [const { OnceLock::new() }; 2];
|
||||||
POOLS[usize::from(records)]
|
POOLS[usize::from(records)]
|
||||||
.get_or_init(|| {
|
.get_or_init(|| {
|
||||||
let threads = std::env::var("VICTORY_VIEW_THREADS").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(4usize);
|
let threads = std::env::var("VICTORY_VIEW_THREADS").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(if records { 6usize } else { 4 });
|
||||||
Pool::new(if records { "victory-records" } else { "victory-views" }, threads.clamp(1, 16))
|
Pool::new(if records { "victory-records" } else { "victory-views" }, threads.clamp(1, 16))
|
||||||
})
|
})
|
||||||
.each(count, f);
|
.each(count, f);
|
||||||
|
|||||||
Reference in new issue
Block a user