Skip to content

jitv2: the compile pool takes the host's spare CPUs, not the guest's - #768

Merged
techomancer merged 1 commit into
techomancer:mainfrom
Samueltgg12:jitv2-compile-pool-host-spare
Nov 17, 2026
Merged

techomancer merged 1 commit into
techomancer:mainfrom
Samueltgg12:jitv2-compile-pool-host-spare

Conversation

@Samueltgg12

Copy link
Copy Markdown
Contributor

Follow-up to #763 and #764.

The problem

#764 sized the auto-sized compile pool by the host's spare room:

room    = host_cpus - guest_cpus - AUTO_JITV2_HOST_RESERVE
threads = min(want, max(1, room))

On a four-logical-CPU host that gives a 2-CPU guest one worker and a
4-CPU guest one worker. That rule was derived from the model where
every worker polls: a worker cost a core whether it had work or not.

Since #763 the pool parks instead of polling, so a worker with no work
costs nothing, and the guest's CPUs are not the ones a worker competes
with for progress:

  • A guest CPU that reaches a page with no compiled code does not
    block on the pool. The dispatch gate (src/cpu/mips_exec.rs) pushes
    the request and falls through to step_int(), so the guest keeps
    running — in the interpreter — until the pool publishes the page.
  • The measured boot profile (clanker/jitv2/compile-time-profile.md:
    5,000-odd compiles at 50-55 ms over a 2.5-minute run) left four
    workers roughly half busy each. The host was not saturated; the
    compile latency was the limit.

So the old rule left most of a small host idle through exactly the phase
the pool exists for, and doubled the wall-clock of that phase for no
host-CPU saving.

The change

want    = guest_cpus.clamp(1, AUTO_JITV2_THREADS_MAX)   // 4, measured
usable  = host_cpus - AUTO_JITV2_HOST_RESERVE             // 1 for the device threads
threads = min(want, max(1, usable))

The pool's width follows the guest's demand and is capped by the host's
usable CPUs, one of which stays with the device threads (the graphics
compose, SCSI, ethernet, audio, timer).

On an i3-4130 (2 physical cores, 4 logical CPUs):

guest before after
1 CPU 1 1
2 CPUs 1 2
4 CPUs 1 3

On a 16-CPU host nothing changes.

An explicit [jitv2] threads / --jitv2-threads still wins and says so,
and an explicit 0 still reaches validate() and is refused rather than
being silently clamped.

Notes

  • The pool's idle cost is unchanged: jitv2: the compile pool parks; the producer wakes it #763's parking means an extra worker
    with no work costs a wakeup every 20 ms, not a core.
  • j2 threads prints the size and why, as before.
  • The rule and the measurement behind the revision are in
    clanker/jitv2/compile-pool-size-on-small-hosts.md.

The pool's auto size reserved the guest's own CPU threads as well as the
device threads' one CPU, so on a four-logical-CPU host a two-CPU guest
got one compile worker and a four-CPU guest also got one. That was
derived from the model where every worker polled: a worker cost a core
whether it had work or not.

Since the pool parks instead of polling, a worker with no work costs
nothing, and the guest's CPUs are not the ones a worker competes with
for progress: a guest CPU that reaches a page with no compiled code does
not block, it keeps interpreting until the pool publishes the page. The
measured boot profile left four workers about half busy each, so the
host had room to spare during exactly the phase the pool exists for,
and the old rule left most of a small host idle through it.

Size the pool by the guest's demand (one worker per guest CPU, the
measured want) and cap it by the host's usable CPUs, one of which stays
with the device threads. A two-CPU guest on a four-CPU host gets two
workers again, so pages reach compiled code sooner and the compile-bound
part of a boot is shorter.

An explicit [jitv2] threads still wins, and an explicit 0 still reaches
validate() and is refused.
@techomancer
techomancer merged commit f97cb93 into techomancer:main Nov 17, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants