✨ The window in which the guest picks 60 Hz or 120 Hz and keeps it was over before the first census line

Component: `crates/reims-vgpu` — `runtime::drain::census::VblCensus`. An
instrument only: nothing branches on the new lines and no rail changes.

A macOS 13 guest latches its display link at either ~60 Hz or ~120 Hz within the
first seconds of the display coming up and then holds it for the life of the
boot. Which one it picks varies boot to boot on a byte-identical device, and it
is worth a factor of two in presented frames, in draws and in every per-second
reading taken off them — larger than any rail this device has been tuned on. Six
boots of 1f36dddc's A/B split 2 fast to 1 slow on both arms.

At `VBL_REPORT_EVERY` the first `display_vbl` line of a boot lands after about
1024 deliveries, roughly eleven seconds in. The guest has long since decided, so
the cadence across the deciding window was not observable at all and no later
line could recover it. Two captures of a fast and a slow boot on one binary
differ in nothing this device logs today.

So each arm's first 1024 events now report every 64 — sixteen extra lines, about
half a second of resolution each, covering the first ~9 s. `VBL_EARLY_UNTIL` is
declared as `VBL_REPORT_EVERY` rather than spelled 1024 a second time, so the two
cadences meet exactly at the boundary and no window is measured across a change
of step; a `const` assertion holds the early step a divisor of it.

`hz` is computed from that step rather than from a fixed constant, which is what
keeps a 64-event window and a 1024-event window the same reading.

Tests: `the_vbl_census_reports_window_rate_and_separates_the_silent_arms` updated
rather than worked around — it asserted "exactly one report per 1024 deliveries"
and now asserts sixteen head lines that each read 125.0 Hz, which is the property
that matters (the rate stays comparable across the cadence boundary). Its doc
says why the count changed. The second-window assertion is untouched and still
covers the ordinary cadence.

Verified: 1898 lib tests plus every integration target green serially; clippy
`-D warnings` clean on all three arms.

Not verified: no boot has been taken with this instrument yet — the next step is
to correlate early cadence against the latched rate over enough boots to band it,
and one boot of each will not do that. This commit does not claim a cause for the
latch, only that the evidence for one is now recordable.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Anees IqbalandClaude committed 2026-08-11 20:52:04 +03:00
1 parent 1f36dddce4
commit 982fda6d0c
2 files changed
+57 -11

No files matched your search

+43 -5
View File
@@ -50,6 +50,35 @@ pub(crate) const VBL_NOT_ENABLED: usize = 3;
/// One report per this many deliveries — about 8 s at the grid rate.
const VBL_REPORT_EVERY: u64 = 1024;
/// One report per this many deliveries, for an arm's first
/// [`VBL_EARLY_UNTIL`] — about half a second at the grid rate.
///
/// # The window this exists to make visible
///
/// A macOS 13 guest latches its display link at either ~60 Hz or ~120 Hz within
/// the first seconds of the display coming up, and then holds it for the life of
/// the boot. Which one it picks varies boot to boot on a byte-identical device,
/// and it is worth a **factor of two** in presented frames, draws and every
/// per-second reading taken off them — far more than any rail this device has
/// been tuned on.
///
/// At [`VBL_REPORT_EVERY`] the first line of a boot lands after about eleven
/// seconds, which is long after the guest has decided. So the cadence during the
/// window that decides it was simply not observable, and no amount of reading
/// later lines could recover it. Sixteen finer lines at the head of each arm cost
/// nothing and cover the first ~9 s.
///
/// This is an instrument, not a rail: nothing branches on it.
const VBL_REPORT_EARLY: u64 = 64;
/// How far into an arm's count the finer [`VBL_REPORT_EARLY`] cadence runs.
///
/// Equal to [`VBL_REPORT_EVERY`] so the two cadences meet exactly at the
/// boundary: the last early report and the first ordinary one are the same
/// event, and no window is ever measured across a change of step.
const VBL_EARLY_UNTIL: u64 = VBL_REPORT_EVERY;
const _: () = assert!(VBL_EARLY_UNTIL.is_multiple_of(VBL_REPORT_EARLY));
/// Width of [`VblCensus::arms`], derived from the last arm index so a new arm
/// cannot be added without the array growing with it.
const VBL_ARMS: usize = VBL_NOT_ENABLED + 1;
@@ -104,17 +133,26 @@ impl VblCensus {
use std::sync::atomic::Ordering::Relaxed;
let n = self.arms[arm].fetch_add(1, Relaxed) + 1;
let reports = arm == VBL_DELIVERED || arm == VBL_NOT_ENABLED;
if !reports || !n.is_multiple_of(VBL_REPORT_EVERY) {
// The head of each arm reports finely, because that is the window in
// which the guest picks the display-link rate it then keeps; see
// `VBL_REPORT_EARLY`. The two cadences meet at `VBL_EARLY_UNTIL`, so
// `step` is also exactly how many events this window covers.
let step = if n <= VBL_EARLY_UNTIL {
VBL_REPORT_EARLY
} else {
VBL_REPORT_EVERY
};
if !reports || !n.is_multiple_of(step) {
return None;
}
let since_ms = now_ms.saturating_sub(self.last_report_ms[arm].swap(now_ms, Relaxed));
// Window rate, not a lifetime average: the lifetime figure carries the
// pre-online stretch forever and would read low long after the display
// came up. The count in the window is `VBL_REPORT_EVERY` by construction
// — this line exists because this arm's own count just reached a
// multiple of it — so the only variable is how long that took.
// came up. The count in the window is `step` by construction — this line
// exists because this arm's own count just reached a multiple of it — so
// the only variable is how long that took.
let hz = if since_ms > 0 {
(VBL_REPORT_EVERY * 1000) as f64 / since_ms as f64
(step * 1000) as f64 / since_ms as f64
} else {
0.0
};
+14 -6
View File
@@ -2082,6 +2082,11 @@ fn a_guest_that_never_enables_cannot_reach_the_online_cap() {
/// - `not_online` and `not_claimed` stay separate, because "the display never
/// came up" and "the 8 ms limiter is working correctly at 125 Hz" are opposite
/// conclusions from the same low delivered count.
///
/// The head of each arm reports at the finer `VBL_REPORT_EARLY` cadence, so the
/// first assertion below counts sixteen lines rather than one. Both cadences
/// measure the window they cover, which is what keeps the rate comparable across
/// the boundary between them.
#[test]
fn the_vbl_census_reports_window_rate_and_separates_the_silent_arms() {
use crate::runtime::drain::{VblCensus, VBL_DELIVERED, VBL_NOT_CLAIMED, VBL_NOT_ONLINE};
@@ -2093,20 +2098,23 @@ fn the_vbl_census_reports_window_rate_and_separates_the_silent_arms() {
assert!(c.note(VBL_NOT_CLAIMED, i).is_none());
}
// 1024 deliveries at the 8 ms grid: one report, and the rate is the grid.
// 1024 deliveries at the 8 ms grid. The head of an arm reports every 64 so
// the display-link latch window is visible at all, so that is 16 lines, and
// each covers 64 deliveries over 512 ms — still the grid rate, because the
// window and the step are the same quantity.
let mut lines = Vec::new();
for i in 1..=1024u64 {
if let Some(l) = c.note(VBL_DELIVERED, i * 8) {
lines.push(l);
}
}
assert_eq!(lines.len(), 1, "exactly one report per 1024 deliveries");
let line = &lines[0];
assert!(line.contains("delivered=1024"), "{line}");
assert_eq!(lines.len(), 16, "one report per 64 deliveries over the head");
assert!(
line.contains("window_hz=125.0"),
"1024 deliveries spanning 8192 ms is 125 Hz: {line}"
lines.iter().all(|l| l.contains("window_hz=125.0")),
"every early window is 64 deliveries over 512 ms: {lines:?}"
);
let line = lines.last().expect("the head reports");
assert!(line.contains("delivered=1024"), "{line}");
assert!(
line.contains("not_online=5000") && line.contains("not_claimed=5000"),
"the silent arms must stay separable and counted: {line}"