VICTORY_HEAP_SYNC_AT_SUBMIT=1: the heaps' records asked for at the title's submit
Ported from Belobug/VIctory-Belobug-AMD 673be0e and a609a2f (renderer port 7, its heaps' records part; the journal in 64 parts, which shares the switch VICTORY_PORT_JOURNAL there, is not taken). There the lane waited 4.5-5.2 ms a frame for the heaps' records and port 7 took 2.4 ms off it. Here the submitting thread waited 2.7-5.8 ms a frame for them (release run 233354). A round of the heap-sync thread is asked for when the title submits (Lane::push, round_after), so it runs while the submission waits in the line (12-15 are in it when one is added), and the submitting thread waits for that round (begin_sync_heaps_after), or for a later one if a wait of its queue that was met in memory went since (the queue's floor in the line), or a step of ours wrote, or may have written, a heap's title memory while preparing an earlier submission (heap_marks::prep_wrote: buffer copies into a heap, copies at their place, our own steps). Added here: a submission that waited for flights to land begins a round of its own after the wait, as without the switch. With the switch off nothing is marked, asked or counted. VICTORY_HEAP_SYNC_FIRST applies only to a submission without a mark. Not behaviour-neutral in timing: a record the title writes for a submission after submitting it (or after a wait behind which the submission stands was met) is left to a later round, as the console's card could miss it too. Off by default. The frame line "the heaps' records asked for at the title's submit" gives the wait per frame, the rounds asked at a submit, the preparings that found theirs asked earlier or had to ask, and those that wrote a heap's memory. Tests: the round given begins after the call (heap_marks), and the line's marks with waits and parts taken along (queue::behind). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
96dfd9bb89
commit
d2e24b3bc3
5 files changed
+458
-13
No files matched your search
@@ -84,12 +84,36 @@ pub(super) trait Work: Send {
|
||||
}
|
||||
/// Does it. `forced`: its wait was not met.
|
||||
fn go(self, forced: bool);
|
||||
/// A mark taken when an entry that runs is put in the line (by the thread
|
||||
/// that puts it, before the line's lock): the round of the heaps' records
|
||||
/// begun after that (`crate::heap_marks`). 0: none.
|
||||
fn mark_now() -> u64 {
|
||||
0
|
||||
}
|
||||
/// A mark taken when a wait goes or is taken along (on our thread): a
|
||||
/// round that begins after.
|
||||
fn mark_later() -> u64 {
|
||||
0
|
||||
}
|
||||
/// Whether what its queue has behind this wait may have been written
|
||||
/// only just before the wait was met (by the CPU, which writes, then
|
||||
/// meets the wait): it was met in memory. A wait met by a bottom-of-pipe
|
||||
/// write of a flight or of the submission it is taken along with is the
|
||||
/// card's order, not the CPU's.
|
||||
fn raises(&self) -> bool {
|
||||
true
|
||||
}
|
||||
/// Told just before [`Work::go`] of a submission: the highest mark of
|
||||
/// what it is made of and of the waits its queue went past.
|
||||
fn marked(&mut self, _mark: u64) {}
|
||||
}
|
||||
|
||||
struct Entry<W> {
|
||||
number: u64,
|
||||
queue: usize,
|
||||
what: W,
|
||||
/// [`Work::mark_now`] when it was put in the line.
|
||||
mark: u64,
|
||||
}
|
||||
|
||||
struct State<W> {
|
||||
@@ -107,6 +131,23 @@ struct State<W> {
|
||||
/// Presents and submissions in the line or being done.
|
||||
presents: usize,
|
||||
runs: usize,
|
||||
/// Per queue, the highest [`Work::mark_later`] of the waits it went past:
|
||||
/// what is behind a wait may have been written only before the wait was
|
||||
/// met, not before it was put in the line.
|
||||
floors: Vec<(usize, u64)>,
|
||||
}
|
||||
|
||||
impl<W> State<W> {
|
||||
fn floor(&self, queue: usize) -> u64 {
|
||||
self.floors.iter().find(|f| f.0 == queue).map_or(0, |f| f.1)
|
||||
}
|
||||
|
||||
fn raise(&mut self, queue: usize, mark: u64) {
|
||||
match self.floors.iter_mut().find(|f| f.0 == queue) {
|
||||
Some(f) => f.1 = f.1.max(mark),
|
||||
None => self.floors.push((queue, mark)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See the module's text.
|
||||
@@ -129,6 +170,7 @@ impl<W: Work> Lane<W> {
|
||||
served: 0,
|
||||
presents: 0,
|
||||
runs: 0,
|
||||
floors: Vec::new(),
|
||||
}),
|
||||
work: Condvar::new(),
|
||||
moved: Condvar::new(),
|
||||
@@ -139,19 +181,21 @@ impl<W: Work> Lane<W> {
|
||||
self.state.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
fn put(state: &mut State<W>, queue: usize, what: W) {
|
||||
fn put(state: &mut State<W>, queue: usize, what: W, mark: u64) {
|
||||
state.presents += usize::from(what.shows());
|
||||
state.runs += usize::from(what.runs());
|
||||
let number = state.next;
|
||||
state.next += 1;
|
||||
state.items.push_back(Entry { number, queue, what });
|
||||
state.items.push_back(Entry { number, queue, what, mark });
|
||||
}
|
||||
|
||||
/// Adds to the end of the line, and has it looked at.
|
||||
pub(super) fn push(&self, queue: usize, what: impl IntoIterator<Item = W>) {
|
||||
let what: Vec<W> = what.into_iter().collect();
|
||||
let mark = if what.iter().any(W::runs) { W::mark_now() } else { 0 };
|
||||
let mut state = self.lock();
|
||||
for what in what {
|
||||
Self::put(&mut state, queue, what);
|
||||
Self::put(&mut state, queue, what, mark);
|
||||
}
|
||||
state.asked += 1;
|
||||
drop(state);
|
||||
@@ -164,7 +208,7 @@ impl<W: Work> Lane<W> {
|
||||
pub(super) fn push_behind(&self, queue: usize, always: bool, what: W, now: impl FnOnce()) {
|
||||
let mut state = self.lock();
|
||||
if always || state.running == Some(queue) || state.items.iter().any(|e| e.queue == queue) {
|
||||
Self::put(&mut state, queue, what);
|
||||
Self::put(&mut state, queue, what, 0);
|
||||
} else {
|
||||
now();
|
||||
}
|
||||
@@ -256,13 +300,13 @@ impl<W: Work> Lane<W> {
|
||||
/// The parts of `entry`, which stands for them, in place `at`.
|
||||
fn unfold(state: &mut State<W>, at: usize, entry: Entry<W>) {
|
||||
let began = Instant::now();
|
||||
let (number, queue, runs) = (entry.number, entry.queue, usize::from(entry.what.runs()));
|
||||
let (number, queue, runs, mark) = (entry.number, entry.queue, usize::from(entry.what.runs()), entry.mark);
|
||||
let parts = entry.what.unfold();
|
||||
STATS[UNFOLDING].fetch_add(began.elapsed().as_micros() as u64, Relaxed);
|
||||
state.runs -= runs;
|
||||
state.runs += parts.iter().filter(|p| p.runs()).count();
|
||||
for (i, what) in parts.into_iter().enumerate() {
|
||||
state.items.insert(at + i, Entry { number, queue, what });
|
||||
state.items.insert(at + i, Entry { number, queue, what, mark });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,6 +363,14 @@ impl<W: Work> Lane<W> {
|
||||
entry
|
||||
};
|
||||
let (shows, mut runs) = (entry.what.shows(), usize::from(entry.what.runs()));
|
||||
// The highest mark of what it is made of (`crate::heap_marks`).
|
||||
let mut mark = entry.mark;
|
||||
if entry.what.ask().is_some() && !entry.what.folded() && entry.what.raises() {
|
||||
// A wait that goes: what its queue has behind it was written
|
||||
// before it was met, which is now at the latest.
|
||||
let later = W::mark_later();
|
||||
self.lock().raise(entry.queue, later);
|
||||
}
|
||||
if entry.what.folded() {
|
||||
// Its parts take its place: behind everything before it, before
|
||||
// everything after it (they share its number; the first of them
|
||||
@@ -353,15 +405,27 @@ impl<W: Work> Lane<W> {
|
||||
state.items.insert(at, next);
|
||||
break;
|
||||
}
|
||||
let Entry { number, queue, what } = next;
|
||||
let Entry { number, queue, what, mark: theirs } = next;
|
||||
let waits = what.ask().is_some() && what.raises();
|
||||
match entry.what.take_along(what) {
|
||||
Ok(run) => runs += usize::from(run),
|
||||
Ok(run) => {
|
||||
runs += usize::from(run);
|
||||
mark = mark.max(theirs);
|
||||
if waits {
|
||||
let later = W::mark_later();
|
||||
self.lock().raise(queue, later);
|
||||
}
|
||||
}
|
||||
Err(what) => {
|
||||
self.lock().items.insert(at, Entry { number, queue, what });
|
||||
self.lock().items.insert(at, Entry { number, queue, what, mark: theirs });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if runs > 0 {
|
||||
let floor = self.lock().floor(entry.queue);
|
||||
entry.what.marked(mark.max(floor));
|
||||
}
|
||||
entry.what.go(forced);
|
||||
{
|
||||
let mut state = self.lock();
|
||||
@@ -449,6 +513,31 @@ impl Work for Job {
|
||||
}
|
||||
}
|
||||
|
||||
fn mark_now() -> u64 {
|
||||
if crate::heap_marks::on() { crate::descriptor::round_after_now() } else { 0 }
|
||||
}
|
||||
|
||||
fn mark_later() -> u64 {
|
||||
// (Asked for now: the round runs while the line does what is before
|
||||
// the part behind the wait.)
|
||||
if crate::heap_marks::on() { crate::descriptor::round_after_now() } else { 0 }
|
||||
}
|
||||
|
||||
fn raises(&self) -> bool {
|
||||
// (Without the switch no mark is taken: the memory is not read.)
|
||||
if !crate::heap_marks::on() {
|
||||
return true;
|
||||
}
|
||||
match self {
|
||||
Job::Value(_, wait) => wait.met(),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn marked(&mut self, mark: u64) {
|
||||
crate::heap_marks::set_mark(mark);
|
||||
}
|
||||
|
||||
fn met(ask: &Ask) -> bool {
|
||||
match ask {
|
||||
&Ask::Wait(fence, value) => crate::fence::completed(fence as This) >= value,
|
||||
@@ -599,6 +688,8 @@ impl Work for Job {
|
||||
QUEUED.fetch_sub(1, Relaxed);
|
||||
}
|
||||
}
|
||||
// (The mark was this submission's alone.)
|
||||
crate::heap_marks::set_mark(0);
|
||||
STATS[BUSY].fetch_add(began.elapsed().as_micros() as u64, Relaxed);
|
||||
}
|
||||
}
|
||||
@@ -956,10 +1047,73 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn mark_now() -> u64 {
|
||||
NOW.get()
|
||||
}
|
||||
fn mark_later() -> u64 {
|
||||
LATER.get()
|
||||
}
|
||||
fn marked(&mut self, mark: u64) {
|
||||
let name = match self {
|
||||
T::Run(name, _) | T::Slow(name, ..) => name.to_string(),
|
||||
T::Group(names, ..) => names.join("+"),
|
||||
_ => "?".into(),
|
||||
};
|
||||
MARKS.with(|m| m.borrow_mut().push((name, mark)));
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static FORCED_HERE: std::cell::Cell<u32> = const { std::cell::Cell::new(0) };
|
||||
/// What [`Work::mark_now`] and [`Work::mark_later`] give in a test.
|
||||
static NOW: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
|
||||
static LATER: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
|
||||
/// The marks submissions were done with, by name.
|
||||
static MARKS: std::cell::RefCell<Vec<(String, u64)>> = const { std::cell::RefCell::new(Vec::new()) };
|
||||
}
|
||||
|
||||
/// (Ported from Belobug/VIctory-Belobug-AMD 673be0e.) A submission is
|
||||
/// done with the mark taken when it was put in the line, or, behind a
|
||||
/// wait of its queue, at least the one taken when that wait went (what
|
||||
/// is behind a wait may be written only before it is met); one taken
|
||||
/// along with others, the highest of all.
|
||||
#[test]
|
||||
fn a_submission_needs_what_was_written_before_it_and_its_queues_waits() {
|
||||
let lane = Lane::new();
|
||||
let log: Log = Default::default();
|
||||
let f = fence();
|
||||
let run = |name| T::Run(name, log.clone());
|
||||
NOW.set(5);
|
||||
lane.push(1, [run("a")]);
|
||||
NOW.set(6);
|
||||
lane.push(1, [T::Wait(f, 1), run("b")]);
|
||||
look(&lane);
|
||||
assert_eq!(MARKS.take(), [("a".to_string(), 5)], "b stands at its wait");
|
||||
// The wait is met later; what b reads may have been written just
|
||||
// before that.
|
||||
LATER.set(9);
|
||||
crate::fence::set(f as This, 1);
|
||||
look(&lane);
|
||||
assert_eq!(MARKS.take(), [("b".to_string(), 9)]);
|
||||
// Another queue went past no wait; this one did, for good.
|
||||
NOW.set(7);
|
||||
lane.push(2, [run("c")]);
|
||||
NOW.set(3);
|
||||
lane.push(1, [run("d")]);
|
||||
look(&lane);
|
||||
assert_eq!(MARKS.take(), [("c".to_string(), 7), ("d".to_string(), 9)]);
|
||||
// Taken along: a met wait between two parts raises them both.
|
||||
let part = |name| T::Group(vec![name], log.clone(), Vec::new());
|
||||
NOW.set(10);
|
||||
LATER.set(12);
|
||||
lane.push(3, [part("x"), T::Wait(f, 1), part("y")]);
|
||||
look(&lane);
|
||||
assert_eq!(MARKS.take(), [("x+y".to_string(), 12)]);
|
||||
// A present is no submission: it is told no mark.
|
||||
lane.push(3, [T::Present("present", log.clone())]);
|
||||
look(&lane);
|
||||
assert!(MARKS.take().is_empty());
|
||||
assert_eq!(*log.lock().unwrap(), ["a", "b", "c", "d", "x+y", "present"]);
|
||||
}
|
||||
|
||||
fn fence() -> usize {
|
||||
|
||||
Reference in new issue
Block a user