Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
2261a38
File pages under a buffer joining the residency set are wired by mloc…
seedds Nov 9, 2026
bfa1214
Where Metal's working set is under 8 GB, textures in GPU-only memory …
seedds Nov 9, 2026
3db7eb5
The power line names the threads that make clock waits, with their pr…
seedds Nov 9, 2026
aa82d4c
Ocarina of Time's note: the M1 iPad holds 20 fps at the Great Deku Tr…
seedds Nov 9, 2026
e0209b5
The present takes the shape of the game's crop: a crop whose width / …
seedds Nov 9, 2026
cf623ee
screen_aspect any: a profile's stubs follow any window or screen shap…
seedds Nov 9, 2026
021300a
Probe diagnostics for values the game caches: float arguments, a scan…
seedds Nov 9, 2026
d97bed7
Ocarina of Time fills any window or screen shape, live while playing:…
seedds Nov 9, 2026
a8fe89b
Ocarina of Time's HUD takes the output's shape at its own pixel size …
seedds Nov 9, 2026
2f2c543
Docs for any screen shape: Ocarina of Time's Screen shape section, th…
seedds Nov 9, 2026
6f4c427
file_wire keeps its list when growing it fails: the range it cannot r…
seedds Nov 9, 2026
1c92e40
A shader-code pool's own address keeps it out of the raw pool table: …
seedds Nov 9, 2026
66867a7
OoT3 2b: the frame step calls the GPU slowed only against a reference…
seedds Nov 6, 2026
fb9f13b
OoT5 A-4: a movie the player reads one picture per game frame follows…
seedds Nov 7, 2026
c855a8c
The frame step's GPU reference also matches compute dispatches, so Oc…
seedds Nov 9, 2026
d845268
Docs: Ocarina of Time plays on an iPhone 17 (27-30 fps in Kokiri Fore…
seedds Nov 9, 2026
0e303a6
iOS: a Rotation setting (Automatic, Landscape, Portrait) on the setti…
seedds Nov 9, 2026
e5bc342
iOS: upright, a game that renders any shape fills the space above the…
seedds Nov 9, 2026
7bfa426
screen_aspect any: upright, the vertical angle is held to a square pi…
seedds Nov 9, 2026
c4aae7a
iOS: Portrait layout, Full screen by default: upright, a game that re…
seedds Nov 10, 2026
e0f33bd
screen_aspect any: the shape line no longer adds "screen shape 16:9" …
seedds Nov 10, 2026
2e35fa7
Docs: portrait play on the iPhone (Rotation, Portrait layout, the upr…
seedds Nov 10, 2026
adb6431
OoT-iPhone A-2: a submission's end hands its records to the encode th…
seedds Nov 9, 2026
e73aaac
Frame step: late frames with the GPU idle do not step up, and a longe…
uncraftablexd Nov 9, 2026
1a273e8
OoT-iPhone B-2: frames late at a 30 fps cap's hold 2 are shown at the…
seedds Nov 9, 2026
99a52c8
OoT-iPhone B-3: the frame step's log lines name the cap, the longest …
seedds Nov 9, 2026
4850da5
OoT-iPhone B-2: the 60 Hz link that shows a 30 fps cap's late frames …
seedds Nov 9, 2026
3a625e5
OoT-iPhone B-1: why a 30 fps cap's late frames left a 66.7 ms gap abo…
seedds Nov 9, 2026
47412a7
OoT-iPhone B-3: the game-time line counts the switches to the next vs…
seedds Nov 9, 2026
2fa00c2
OoT-iPhone A (merge): the 20 graphics tests that build nvn_mtl.m and …
seedds Nov 10, 2026
1d91b35
OoT-iPhone B-1: the iPhone's numbers with late frames at the next vsy…
seedds Nov 10, 2026
d17df17
OoT-iPhone A-2 docs: the iPhone 17 frame's profile, the fix's A/B, an…
seedds Nov 10, 2026
f0e390e
DM_NVN_GPUPROF_GEOM=1 stamps each render pass where its vertex and me…
seedds Nov 8, 2026
0ca0186
OoT-iPhone A-1: DM_NVN_GPUPROF logs the host's CPU timeline beside a …
seedds Nov 9, 2026
e66db18
OoT-iPhone A-1 docs: the game note's iPhone 17 table names DM_NVN_GPU…
seedds Nov 10, 2026
3a181b6
test_env_switches passes again: DM_NVN_SUB_DRAIN has its row, and thr…
seedds Nov 10, 2026
1eac389
OoT-iPhone: test_oot_aspect's camera and shape helpers take a float c…
seedds Nov 10, 2026
8a8fb0b
OoT-iPhone: the Python lint baseline drops test_gpuprof.py's unused o…
seedds Nov 10, 2026
ed769e9
OoT-iPhone B-4: Ocarina of Time's smoke route, so regress.py check bo…
seedds Nov 10, 2026
4283410
Ocarina of Time's output-size stub keeps the size it hands the setter…
seedds Nov 10, 2026
e26ff09
iPhone memory 1: large sampled textures leave out their largest level…
seedds Nov 10, 2026
d78ddfa
iPhone memory 1b: the image flag no longer keeps a large sampled text…
seedds Nov 10, 2026
f9f1aa9
Docs for smaller textures on small devices: a memory.md entry with th…
seedds Nov 10, 2026
c5a352e
MetalFX draws Ocarina of Time's upscaler: the shader map's agl_ndsr_v…
seedds Nov 10, 2026
9612bc4
Upload staging is released after each batch where Metal's working set…
seedds Nov 10, 2026
42279e5
DM_SCREEN_PIXELS holds a picture in another shape than 16:9 to a shar…
seedds Nov 10, 2026
5af0e6e
Ocarina of Time's note: the iPhone 17 played through the Great Deku T…
seedds Nov 10, 2026
dbe335e
iPhone memory 2a: a probe of what a shader gets through a pointer to …
seedds Nov 10, 2026
845fdb3
iPhone memory 2b: a read through a pointer to a buffer outside the re…
seedds Nov 10, 2026
5e5be14
iPhone memory: the census counts a heap once and says who holds the t…
seedds Nov 11, 2026
098362b
iPhone memory: memory pressure trims what no frame needs, and the mem…
seedds Nov 11, 2026
bbed3b3
iPhone memory: an upload batch's reads over guest memory have a budge…
seedds Nov 11, 2026
d07be66
iPhone memory docs: the system's memory and the pressure trim, the up…
seedds Nov 11, 2026
e3193df
iPhone memory docs: the iPhone 17 run with the trim lived through Hyr…
seedds Nov 11, 2026
23d12a5
iPhone memory docs: back on the field after the castle town the iPhon…
seedds Nov 11, 2026
93ff62f
iPhone memory docs: the iPhone 17 run with the trim ended for proc-th…
seedds Nov 11, 2026
cb57493
iPhone memory 2: the residency set is described at each memory pressu…
seedds Nov 11, 2026
29b351d
iPhone memory 2: the census says who holds every texture in the resid…
seedds Nov 11, 2026
28083ec
iPhone memory 2 docs: what the residency set holds across loads on th…
seedds Nov 11, 2026
0832d01
iPhone memory 2 docs: the iPhone 17 run with the measuring build live…
seedds Nov 11, 2026
1df6607
iPhone memory 3: a packaged texture's spare that no re-upload took wi…
seedds Nov 11, 2026
c680394
iPhone memory 3: no rule says beforehand which pools a raw-memory sha…
seedds Nov 11, 2026
d634521
iPhone memory 3: at memory pressure, the Metal copies of uploaded tex…
seedds Nov 11, 2026
7374881
iPhone memory 3 docs: the re-uploads' spares, the uploaded textures f…
seedds Nov 11, 2026
c7ebf30
iPhone memory 3 docs: the iPhone 17 lived through 120 loads with trim…
seedds Nov 12, 2026
408e1b4
iPhone memory: DM_NVN_MEM_PRESSURE and DM_NVN_UPLOAD_SRC_MB have thei…
seedds Nov 12, 2026
36e013e
Ocarina of Time: pso_mtl4 on, so the iPhone and the iPad take render …
seedds Nov 12, 2026
b8cb0bd
nvn: give the whole-again texture warning its own RED_ONCE key
seedds Nov 12, 2026
4fc17cb
OoT-night N-1: submissions that end while the GPU still runs an earli…
seedds Nov 14, 2026
52d5c6a
OoT-night N-1: held submissions keep their own command buffers, so an…
seedds Nov 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
The power line names the threads that make clock waits, with their pr…
…edicted sleeps, the waits a sleep ended too late for, how late the sleeps woke and the period: Ocarina of Time makes none, so its slow motion on the M1 iPad is GPU time

Before, the power line counted clock waits only for its two top yielders, so a clock wait on any
other thread was invisible. On an M1 iPad, Ocarina of Time ran at game speed 0.62 in one run
and 0.99 in another with DM_YIELD_CLOCK=0, which pointed at 8bdfcb7's predicted sleep.

dm_clock_top (hle_thread.c), printed by the power report every 300 frames (hle_nvn.c) as
"clock waits up to frame <n>": the two threads with most clock-wait yields since the last
report, their predicted sleeps, how many of those waits had already ended by the first poll
after the sleep (slept through), how late the sleeps woke (mean / max) and the learned period.
No clock wait, no line. No behaviour changes: counters only.

On the M1 iPad, 12 minutes from the title through the Deku Tree (upstream main + this
branch, no switches but the device's own): no line at all, so no thread of the game makes a
clock wait and the predicted sleep never runs. Its slow motion there is the GPU: views that
take 54-67 ms of GPU a frame cannot fit the frame step's longest hold, 3 vsyncs (game speed
0.61, then 0.53), where lighter views hold 20 fps at 34-36 ms.

t_clockwait checks the clause (the thread, 40 predicted sleeps, the waits slept through, a
16.68 ms period, and nothing once no clock wait came); t_pollwait, t_preempt, t_condvar,
t_condvar_old, t_sync_wait, t_system_event and t_notify_sched pass. threads.md "Clock waits
sleep to their predicted end".
  • Loading branch information
seedds committed Nov 12, 2026
commit 3db7eb538db078e8eda6213f8468cec4db9ff992
4 changes: 3 additions & 1 deletion dm/gfx/nvn/hle_nvn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,8 @@ static int link_wait(const win_t *o, uint64_t timeout_ns);
__attribute__((weak)) void dm_main_yield_stats(uint64_t *n, uint64_t *ns) { *n = 0; *ns = 0; } // The host's hle_thread.c provides the ground truth; 0 in graphics unit tests
__attribute__((weak)) uint32_t dm_guest_work_qos(unsigned *count) { if (count) *count = 0; return QOS_CLASS_UNSPECIFIED; }
int mtl_probe_ramp_on(void); // nvn_mtl.m: DM_FSTEP_PROBE_RAMP (default on; ab with DM_AB)
__attribute__((weak)) void dm_yield_top(char *out, size_t n) { if (n) snprintf(out, n, "-"); } // hle_thread.c: the threads that yielded most since the last call; none in graphics unit tests
__attribute__((weak)) void dm_yield_top(char *out, size_t n) { if (n) snprintf(out, n, "-"); }
__attribute__((weak)) void dm_clock_top(char *out, size_t n) { if (n) out[0] = 0; } // hle_thread.c: the threads that made most clock waits since the last call // hle_thread.c: the threads that yielded most since the last call; none in graphics unit tests
__attribute__((weak)) void dm_thread_cpu(char *out, size_t n, double secs) { (void)secs; if (n) snprintf(out, n, "-"); } // hle_thread.c: guest-thread CPU by Switch priority band since the last call
void mtl_res_stats(char *out, size_t n);
void mtl_barrier_stats(uint64_t *skip, uint64_t *full);
Expand Down Expand Up @@ -1986,6 +1987,7 @@ static void power_line(uint64_t frame) {
if (dg + dc + du + dn != pdg + pdc + pdu + pdn) LOG("[nvn] compute dispatches up to frame %llu: %llu after a barrier of the game's, %llu after a copy's range, %llu in the full order (a binding with no range), %llu with no barrier (DM_NVN_DISPATCH_BARRIER)", frame,
(unsigned long long)(dg - pdg), (unsigned long long)(dc - pdc), (unsigned long long)(du - pdu), (unsigned long long)(dn - pdn));
pdg = dg; pdc = dc; pdu = du; pdn = dn;
{ char ck[400]; dm_clock_top(ck, sizeof ck); if (ck[0]) LOG("[nvn] clock waits up to frame %llu: %s", frame, ck); }
char rs[400]; mtl_res_stats(rs, sizeof rs); static uint64_t pbs, pbf; uint64_t bs, bf; mtl_barrier_stats(&bs, &bf);
uint64_t mtl_cut_count(void), mtl_copy_cut_count(void), mtl_blit_splits(void); void mtl_ubd_stats(uint64_t *, uint64_t *); static uint64_t pcut, pccut, pbsp, pud, puc; uint64_t cut = mtl_cut_count(), ccut = mtl_copy_cut_count(), bsp = mtl_blit_splits(), ud, uc; mtl_ubd_stats(&ud, &uc);
void mtl_ubp_stats(uint64_t *, uint64_t *, uint64_t *); static uint64_t ppm, ppr, ppf; uint64_t pm, pr, pf_; mtl_ubp_stats(&pm, &pr, &pf_);
Expand Down
23 changes: 21 additions & 2 deletions dm/host/hle_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ typedef struct thr {
int closed, sync_refs; // Reclaim only after handle close, thread exit and the final synchronization wait reference
uint64_t nsvc; // SVC count (for the state dump)
uint64_t nyield, nyield_seen, nbackoff, nbackoff_seen; // Yields (SleepThread 0/-1/-2) and those the back-off turned into short sleeps, with both counts at the last power report (dm_yield_top)
uint64_t nclkyield, nclkyield_seen; // Yields of clock waits (thr_yield), and their count at the last power report
uint64_t nclkyield, nclkyield_seen, nclkyield_rep; // Yields of clock waits (thr_yield), and their count at the last power report
uint64_t nspin, nspin_seen, spin_site; const char *spin_mod; // Spin wait passes (dm_spin_wait; those that yield count in nyield too) and where the last one was
uint64_t srun_svc, srun_t0, spin_ret; // Current spin wait: nsvc at its passes, when it began, when the last pass returned
uint64_t cpu_seen_us; // CPU time (µs) at the last power report (dm_thread_cpu)
uint64_t yrun_svc, yrun_t0, yrun_sig, yrun_sig2, poll_ret; // Current run of yields: nsvc of the last yield, when the run began, and the caller's x19–x28 at the last two yields (a run lasts while no other SVC comes between two yields and those registers match one of the last two, thr_yield); when the last yield or short timed-out wait returned (poll_wait_begin)
uint64_t yrun_clk; // dm_clock_reads at the last yield: a pass that read the clock since makes the yield a clock wait (thr_yield)
uint64_t cw_sig, cw_run, cw_last, cw_end, cw_per, cw_per2, cw_wake, ncwpred, ncwpred_seen; // The clock wait followed (clock_wait): its x19–x28, the run it was last seen in, when its last yield returned,
uint64_t ncwfirst, cw_late_sum, cw_late_max, ncwfirst_seen, ncwpred_rep, cw_late_seen; // predicted sleeps whose wait had ended at the first poll after them, how late those sleeps woke (sum, max), at the last report (dm_clock_top)
int cw_ok, cw_pred, cw_after, cw_trip; // when its last wait ended, the last two periods between ends, when the predicted sleep ended, predicted sleeps (and at the last power report); periods in a row that matched, a predicted sleep in this run, yields after it, waits in a row that ended at the first poll after it
mach_port_t mport; // Host thread port (to get CPU time)
_Atomic int qos_pending; // SetThreadPriority from another thread changed prio: the thread applies the new class at its next SVC (only a thread can set its own QoS)
Expand Down Expand Up @@ -862,6 +863,7 @@ static void clock_wait(thr_t *me, uint64_t sig, uint64_t now, int predict) {
if (me->cw_sig && now - me->cw_last < 1000000000ull) { yield_for(me, now - me->yrun_t0, 1); return; } // another clock wait: the followed loop is still in use
me->cw_sig = sig; me->cw_end = me->cw_per = me->cw_per2 = 0; me->cw_ok = me->cw_pred = me->cw_trip = 0;
} else {
if (me->cw_pred && !me->cw_after) me->ncwfirst++;
if (me->cw_pred && !me->cw_after) { // the last wait ended at the first poll after its predicted sleep: maybe late
// once: the period learned from waits the back-off ended carries their lateness (up to 250 µs, and nanosleep's quarter): predict it shorter;
// twice in a row: the period changed, learn it again
Expand All @@ -880,7 +882,9 @@ static void clock_wait(thr_t *me, uint64_t sig, uint64_t now, int predict) {
uint64_t per = me->cw_per2 && me->cw_per2 < me->cw_per ? me->cw_per2 : me->cw_per, dl = me->cw_end + per; // the shorter of the last two periods
if (dl > now + 2 * CW_MARGIN) {
me->nbackoff++; me->ncwpred++; me->sleeping = 1; sleep_precise(dl - CW_MARGIN); me->sleeping = 0;
me->cw_pred = 1; me->cw_wake = now_ns(); return;
me->cw_pred = 1; me->cw_wake = now_ns();
{ uint64_t late = me->cw_wake > dl - CW_MARGIN ? me->cw_wake - (dl - CW_MARGIN) : 0; me->cw_late_sum += late; if (late > me->cw_late_max) me->cw_late_max = late; }
return;
}
}
} else if (me->cw_pred) { // polling after the predicted sleep
Expand Down Expand Up @@ -974,6 +978,21 @@ void dm_yield_top(char *out, size_t n) {
pthread_mutex_unlock(&G);
if (!o && n) snprintf(out, n, "none");
}
// The threads that made most clock waits since the last call (the power line every 300 frames, hle_nvn.c), at most two: "handle name: N yields, M predicted sleeps (ended at the first
// poll after it K; the sleeps woke late by mean / max µs), period P ms". A wait that had ended by the first poll after its predicted sleep was slept through: it ended before the sleep did
void dm_clock_top(char *out, size_t n) {
thr_t *top[2] = {0}; uint64_t c[2] = {0};
pthread_mutex_lock(&G);
for (thr_t *t = g_all; t; t = t->all) { uint64_t k = t->nclkyield - t->nclkyield_rep; if (k > c[0]) { top[1] = top[0]; c[1] = c[0]; top[0] = t; c[0] = k; } else if (k > c[1]) { top[1] = t; c[1] = k; } }
size_t o = 0; char nb[32]; if (n) out[0] = 0;
for (int i = 0; i < 2 && top[i] && o < n; i++) { thr_t *t = top[i];
uint64_t pr = t->ncwpred - t->ncwpred_rep, fi = t->ncwfirst - t->ncwfirst_seen, ls = t->cw_late_sum - t->cw_late_seen;
o += snprintf(out + o, n - o, "%s%#x '%s' %llu yields, %llu predicted sleeps (wait over at the first poll after it %llu; woke late by %.0f / %.0f us), period %.2f ms", i ? ", " : "", t->handle, thr_name(t, nb, sizeof nb),
(unsigned long long)c[i], (unsigned long long)pr, (unsigned long long)fi, pr ? ls / 1e3 / (double)pr : 0.0, t->cw_late_max / 1e3, t->cw_per / 1e6);
}
for (thr_t *t = g_all; t; t = t->all) { t->nclkyield_rep = t->nclkyield; t->ncwpred_rep = t->ncwpred; t->ncwfirst_seen = t->ncwfirst; t->cw_late_seen = t->cw_late_sum; t->cw_late_max = 0; }
pthread_mutex_unlock(&G);
}
// CPU time of the guest threads since the last call, by Switch priority band (<= 44: the main thread's level and above; 45-59; >= 60) and the three busiest threads with their priority.
// For the power line (hle_nvn.c power_line): it shows which threads a priority-to-QoS mapping would move and how much CPU they use. secs = the window length
void dm_thread_cpu(char *out, size_t n, double secs) {
Expand Down
11 changes: 11 additions & 0 deletions dm/host/tests/t_clockwait.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,16 @@ int main(void) {
assert(late_frames == 2);
assert(late_max < 2000);
puts("PASS: a shorter period costs two late waits, then the waits end on time again");

// The power line's clause (dm_clock_top) names the thread, its predicted sleeps, the waits a sleep ended too late for (the two above) and the period; a second call, with no clock
// wait since, gives nothing: a game with no clock waits prints no clause
char ck[400]; dm_clock_top(ck, sizeof ck); printf(" clause: %s\n", ck);
unsigned long long y = 0, pr = 0, first = 0; double per = 0;
const char *q = strchr(ck, '\''); q = q ? strchr(q + 1, '\'') : NULL;
assert(q && sscanf(q, "' %llu yields, %llu predicted sleeps (wait over at the first poll after it %llu;", &y, &pr, &first) == 3);
assert(strstr(ck, "period ") && sscanf(strstr(ck, "period ") + 7, "%lf", &per) == 1);
assert(y > 0 && pr >= 40 && first >= 2 && first <= 4 && per > 16.0 && per < 17.0);
dm_clock_top(ck, sizeof ck); assert(!ck[0]);
puts("PASS: the power line names the thread that made clock waits, and says nothing once none did");
return 0;
}
2 changes: 1 addition & 1 deletion docs/reference/threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ The yield back-off (`DM_YIELD_BACKOFF`) and the rewriter's spin waits (`patch_ns

- **Symptom:** a game's frame limiter that yields and reads the clock holds 59.4–59.5 fps instead of 60 (frame time p50 about 16.8 ms instead of 16.68; the HUD rounds it to 60), and uses more CPU energy than the same game sleeping: the power line's top yielder is the main thread with thousands of yields a frame.
- **Cause:** the yield back-off ([development.md](../development.md#power), "Yield loops") lets a run of yields spin for its first 2 ms, which protects handoffs between threads, and then sleeps an eighth of the wait so far, up to 250 µs. A limiter waits for a time, not for another thread, so the spin is pure cost (about 9,700 plain yields a frame on a performance core in Three Houses), and since the back-off cannot know the deadline, each wait ends up to 250 µs late, plus a quarter for `nanosleep`'s slack ([Timer slack in guest sleeps](#timer-slack-in-guest-sleeps-sleep_precise)). A shorter cap trades one for the other: 100 µs gave 16.73 ms at 0.6–1.0 W.
- **Fix:** every guest read of the system counter counts on its thread (`dm_clock_reads`, `guest_clock_read_wait` in `hle_os.c`, through the `cntpct` gate and `svc GetSystemTick`). A run of yields whose passes read the clock is a clock wait (`thr_yield`, `clock_wait` in `hle_thread.c`): it backs off from its start, with no 2 ms of plain yields. A clock wait that ends at a steady period also knows its deadline, its last end plus the period: the loop followed (one per thread, by its x19–x28) learns the period from the times its waits end, and after three periods in a row within 250 µs of each other a wait sleeps on time (`sleep_precise`) to 150 µs before the predicted end, then polls with plain yields. A wait that ends at the first poll after such a sleep may have ended late: the first time, the period is taken 300 µs shorter (one learned from waits the back-off ended carries their lateness); the second time in a row, the period changed (a game going from 30 to 60) and is learned again, so such a change costs two late waits. A prediction that comes early (the period got longer) costs only polls and back-off sleeps. `DM_YIELD_CLOCK=1` keeps the back-off from the start without the predicted sleep, `=0` makes clock waits ordinary yields; the power line's top yielders show `clock waits N, M of them slept to a predicted end`.
- **Fix:** every guest read of the system counter counts on its thread (`dm_clock_reads`, `guest_clock_read_wait` in `hle_os.c`, through the `cntpct` gate and `svc GetSystemTick`). A run of yields whose passes read the clock is a clock wait (`thr_yield`, `clock_wait` in `hle_thread.c`): it backs off from its start, with no 2 ms of plain yields. A clock wait that ends at a steady period also knows its deadline, its last end plus the period: the loop followed (one per thread, by its x19–x28) learns the period from the times its waits end, and after three periods in a row within 250 µs of each other a wait sleeps on time (`sleep_precise`) to 150 µs before the predicted end, then polls with plain yields. A wait that ends at the first poll after such a sleep may have ended late: the first time, the period is taken 300 µs shorter (one learned from waits the back-off ended carries their lateness); the second time in a row, the period changed (a game going from 30 to 60) and is learned again, so such a change costs two late waits. A prediction that comes early (the period got longer) costs only polls and back-off sleeps. `DM_YIELD_CLOCK=1` keeps the back-off from the start without the predicted sleep, `=0` makes clock waits ordinary yields; the power line's top yielders show `clock waits N, M of them slept to a predicted end`. A line of its own every 300 frames, `clock waits up to frame <n>`, names the two threads that made most clock waits, with their predicted sleeps, how many waits had already ended by the first poll after the sleep (slept through), how late the sleeps woke (mean / max) and the period learned; no thread making clock waits, no line. Ocarina of Time makes none: on the M1 iPad, 12 minutes from the title through the Deku Tree printed no such line, so its slow motion there is GPU time, not this rule (its note).
- **Found on:** [Fire Emblem: Three Houses](../../dm/games/010055D009F78000/README.md#frame-rate), whose frame limiter (`main+0x5be430`) had a per-build cut that made it sleep; the cut is removed. On the Mac in a window, 100 s from the boot to the title: without the cut, the old back-off 59.4–59.5 fps, frame p50 16.80–16.85 ms, 0.28–0.79 W of CPU; backing off from the start alone 59.4–59.5 fps, 0.19–0.35 W; with the predicted sleep 59.8–60.0 fps, 16.67–16.81 ms in most windows (up to 17.06), 0.09–0.16 W, about 1,330 wakeups a second, 294–300 of every 300 waits slept to their predicted end. With the cut it was 59.9 fps, 16.68 ms, 0.11–0.49 W.
- **Check:** `make -C dm/host/tests GAME=<id> build/t_clockwait && dm/host/tests/build/t_clockwait`, on a test clock that only sleeps and yields advance: a yield loop that reads the clock backs off from its start and one that does not after 2 ms; a limiter at a steady period sleeps to its predicted end and ends within a few yields of its deadline; a longer period never makes a wait later than the back-off's own lateness; a shorter period costs two late waits, then the waits end on time again.

Expand Down