VICTORY_HEAP_SYNC_FIRST=1: a submission's round of the heaps' records begun as it takes the lock

The round that mirrors descriptor records the title copied into its
heaps as bytes runs on a thread of its own, begun after the submission
planned its steps done on the card and looked at flights, and waited for
at the end of the preparing. That wait was 2.7-5.8 ms a frame of the
submitting thread in release run 233354 (heaps' records line, "ms waited
for"), 5% of its samples in profile-y-prof60 (SyncedHeaps' drop), while
the planning ahead of the round's start took 2-4 ms a frame.

With the switch a submission sent ahead begins the round as soon as it
holds the submission lock, so it runs beside that planning too. A
submission that waits for flights to land (settle or relay wait) begins
another round after the wait, as the round began there saw what they
landed; the first is then not waited for.

Not behaviour-neutral in timing: the round reads the heaps' pages earlier
by the planning's time. A record the title writes for a submission after
submitting it is left to the next round (the console's card could miss
it as well). Off by default. The frame line "the heaps' records begun as
a submission took the lock" counts the rounds begun first and those begun
again; the heaps' records line's "ms waited for" shows the gain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-27 01:11:02 +05:30
1 parent 8c1fa5d578
commit 66f7e545e3
1 file changed
+53 -2
+53 -2
View File
@@ -5646,6 +5646,9 @@ impl Host {
}
let was_working = working(true);
submitting(1, runs.len());
// With [`heap_sync_first`]: the heaps' records begun now, beside the
// planning of steps done on the card and the look at flights.
let first_heaps = (late && heap_sync_first()).then(crate::descriptor::begin_sync_heaps);
let ahead = Split::begin();
SPLIT[11].fetch_add(called.elapsed().as_nanos() as u64, Ordering::Relaxed);
stage.next("submit: steps given to the card");
@@ -5656,11 +5659,13 @@ impl Host {
let own = if late { self.card_steps(runs) } else { None };
ahead.part(12);
stage.next("submit: waiting for flights it reads from");
let mut waited_for_flights = false;
if !late {
self.settle(&mut submitted, WHY_SYNC);
} else if own.is_none()
&& let Some(why) = late_blocked(runs)
{
waited_for_flights = true;
if relay_exact() && why == WHY_READ {
// Only until the flights that may write what is read have
// landed: their copy-back's end, not the card's other work.
@@ -5673,8 +5678,22 @@ impl Host {
}
ahead.part(13);
// Descriptors the title copied into placed heaps directly, before
// command lists that index those slots are submitted.
let heaps_synced = crate::descriptor::begin_sync_heaps();
// command lists that index those slots are submitted. (Begun first:
// again after a wait for flights, whose landings wrote title memory,
// as the round began here saw them; the first is not waited for.)
let heaps_synced = match first_heaps {
Some(first) if !waited_for_flights => {
HEAP_SYNC_FIRST[0].fetch_add(1, Ordering::Relaxed);
first
}
first => {
if let Some(first) = first {
HEAP_SYNC_FIRST[1].fetch_add(1, Ordering::Relaxed);
std::mem::forget(first);
}
crate::descriptor::begin_sync_heaps()
}
};
// That list runs first, and is one of the submission's from here on.
let with: Vec<&HostList>;
let runs = match &own {
@@ -7772,6 +7791,31 @@ static FLUSHES: [std::sync::atomic::AtomicU64; 4] = [const { std::sync::atomic::
/// reset and given back.
static AFTER_SEND: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
/// Whether a submission sent ahead begins the round of the heaps' records
/// (`crate::descriptor::begin_sync_heaps`) as soon as it holds the
/// submission lock, before the steps done on the card are planned and
/// flights are looked at (`VICTORY_HEAP_SYNC_FIRST=1`; off by default: after
/// them, as before).
///
/// The submitting thread waited for those rounds at the end of its
/// preparing, 2.7-5.8 ms a frame in the release run 233354 ("ms waited for"
/// on the heaps' records line, 5% of its samples in profile-y-prof60), while
/// the planning ahead of the round's start took 2-4 ms a frame. What
/// changes: the round reads the heaps' pages earlier, by that planning's
/// time. A record the title writes for this submission after submitting it
/// (which the console's card could miss as well) is left to the next round;
/// a submission that waited for flights to land begins another round after
/// the wait, as the round began there saw what they landed.
fn heap_sync_first() -> bool {
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| crate::switch::on("VICTORY_HEAP_SYNC_FIRST"))
}
/// Since the last frame line, with [`heap_sync_first`]: submissions whose
/// round of the heaps' records was begun first, and those that began
/// another after a wait for flights.
static HEAP_SYNC_FIRST: [std::sync::atomic::AtomicU64; 2] = [const { std::sync::atomic::AtomicU64::new(0) }; 2];
/// Counts into [`SPLIT`].
struct Split(std::cell::Cell<std::time::Instant>);
@@ -7835,6 +7879,13 @@ fn submit_split_line(frames: f64) {
ms[14],
ms[15],
);
let [first, again] = [0, 1].map(|i| HEAP_SYNC_FIRST[i].swap(0, Ordering::Relaxed) as f64 / frames);
if first + again > 0.0 {
tracing::info!(
"the heaps' records begun as a submission took the lock, per frame (VICTORY_HEAP_SYNC_FIRST=1): {first:.1}, and \
{again:.1} begun again after a wait for flights"
);
}
}
/// More of the preparing, per frame, for the frame-rate line (diagnostics).