startup: make the default hook step cheap (no hold for ntdll stubs) #3461

Closed
opened 2026-11-29 14:50:41 +00:00 by Leyukaka · 0 comments
Leyukaka commented 2026-11-29 14:50:41 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T14:50:41Z.


Measurement. Full run of the application under debug_launch.py --trace-files 1, cold shader cache, about 95 live threads: consecutive traced file calls are about 20 ms apart with the default --suspend-others 1. In an earlier run built before #1408, they were about 3 ms apart, at a different point of the run; the probe below is meant to measure the difference properly.
On that run, the startup did not move past publishing about 2.7k compute requests (in the trace: 19 file calls per request, one request after another) until about 650 s; in an earlier run with the requests already cached, the same point came about 5 s after the preceding step.

Why the hold exists. A hook is one INT3 byte that is restored for a single step, and a thread entering the function during that step runs untraced (#1281); #1408 holds every other thread around each step. #3332 (for #3331) added the opt-out -SuspendOthers 0 / --suspend-others 0, which turns the hold off for timing runs; calls can then go untraced again.

Plan (default path only; --suspend-others 0 stays unchanged):

  • Hook entries on ntdll Nt* stubs: when the first instruction is mov r10, rcx (4C 8B D1), emulate it (R10 = RCX, RIP += 3) instead of restoring the byte and stepping. No byte is restored, so no hold is needed. Any other first instruction keeps today's restore, hold and step.
  • Return breakpoints: when no call is waiting on the address and no other hook owns it, write the original byte back and drop the breakpoint instead of stepping over it. The next call re-arms it on its entry event. A return still pending for another thread keeps today's hold.

Each traced file call opens two step windows today (entry and return); both go away on that path.

How it will be measured. A new mode of tests/startup_launch_probe.cpp: about 96 threads blocked on an event, one thread doing N opens, reporting ms/open. Three legs: main default, main --suspend-others 0, branch default. Expected on the branch: close to the --suspend-others 0 time with unprotected=0 on the hook windows: line and every open traced. The existing overlap check with --suspend-others 0 must still lose opens.

I'm working on this.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6680132874 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3461). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T14:50:41Z. --- **Measurement.** Full run of the application under `debug_launch.py --trace-files 1`, cold shader cache, about 95 live threads: consecutive traced file calls are about 20 ms apart with the default `--suspend-others 1`. In an earlier run built before #1408, they were about 3 ms apart, at a different point of the run; the probe below is meant to measure the difference properly. On that run, the startup did not move past publishing about 2.7k compute requests (in the trace: 19 file calls per request, one request after another) until about 650 s; in an earlier run with the requests already cached, the same point came about 5 s after the preceding step. **Why the hold exists.** A hook is one INT3 byte that is restored for a single step, and a thread entering the function during that step runs untraced (#1281); #1408 holds every other thread around each step. #3332 (for #3331) added the opt-out `-SuspendOthers 0` / `--suspend-others 0`, which turns the hold off for timing runs; calls can then go untraced again. **Plan** (default path only; `--suspend-others 0` stays unchanged): - Hook entries on ntdll `Nt*` stubs: when the first instruction is `mov r10, rcx` (`4C 8B D1`), emulate it (R10 = RCX, RIP += 3) instead of restoring the byte and stepping. No byte is restored, so no hold is needed. Any other first instruction keeps today's restore, hold and step. - Return breakpoints: when no call is waiting on the address and no other hook owns it, write the original byte back and drop the breakpoint instead of stepping over it. The next call re-arms it on its entry event. A return still pending for another thread keeps today's hold. Each traced file call opens two step windows today (entry and return); both go away on that path. **How it will be measured.** A new mode of `tests/startup_launch_probe.cpp`: about 96 threads blocked on an event, one thread doing N opens, reporting ms/open. Three legs: main default, main `--suspend-others 0`, branch default. Expected on the branch: close to the `--suspend-others 0` time with `unprotected=0` on the `hook windows:` line and every open traced. The existing overlap check with `--suspend-others 0` must still lose opens. I'm working on this.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#3461
No description provided.