mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4624] [Engine] STRATA_POOL_SPIN_US=0 still runs the pause stage: a parked worker sleeps only after 1,024 pauses #2095
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2095
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @GoodSlopBadSlop on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4624
Area
[Engine] (speed, kernels, models, the server and API)
Desktop app, Terminal or source?
Source (START-HERE.bat, setup.sh or a build)
What happened
STRATA_POOL_SPIN_US=0does not mean zero. A parked CPU expert-pool worker still runs a pause stage before itblocks.
spin_before_sleep_is what the knob sets (src/kernels/cpu/pool.cpp:748, documented atinclude/strata/kernels/cpu/pool.hpp:281as "a test knob: a short spin makes the workers sleep constantly"). At0the duration is already expired when the loop first looks, but the loop reads the clock only once every 1,024 pauses,
so the worker runs 1,024
strata_cpu_pause()before it blocks. The comment above the loop says as much: "The clock isread once every 1024 pauses, so the spin itself is unchanged" (
src/kernels/cpu/pool.cpp:991-992). The counter isdeclared before the wait and advanced inside the mask test, so the count is exact, not approximate.
At
0that is 1,024 pauses and one clock read per park. Every park pays that stage, and a worker that is going tosleep was never going to use it.
Why it matters
src/kernels/cpu/pool_tasks_test.cpp:122sets the knob to0to force every worker to sleep between batches, andrelies on it to drive the late-wake path of issue #29. The test wants a park with no hot stage; what it gets is a
1,024-pause hot stage.
0- the natural reading of "turn it off" - leaves the whole stage in place.and until now nothing measured cost. Nothing in the tree asserts that the default 20 ms reaches the pool either -
the default value appears at
include/strata/kernels/cpu/pool.hpp:282and is used at :349 andsrc/kernels/cpu/pool.cpp:748, and no test reads it back.What I expected instead
0skips the pause stage and the worker blocks onsleep_cv_immediately. I filed pull request #4625 with that change:One bool in the same loop, so the branch a reader sees matches the setting; any other value of the knob keeps the loop
exactly as it is. The default is
kSpinBeforeSleep{20}ms (include/strata/kernels/cpu/pool.hpp:282), so the defaultpath takes the same branch, with the same
spins & 1023ucadence, as before this change.#4625 also carries the guard that keeps unmeasured platforms untouched: the define
STRATA_POOL_SPIN_ZEROis set onthe CPU kernel target on Linux, and not in the HIP or
gfx906variants (CMakeLists.txt:2013-2016); where it isabsent the source reads
const bool spin_hot = true;(src/kernels/cpu/pool.cpp:1004, inside the#if defined(STRATA_POOL_SPIN_ZERO)at :1001), which folds the loop back to what it is today. Three files, 180 linesadded, 1 removed: the gate, the bool, and the cost check.
Smallest steps or command that reproduce it
Reproduce the cost check that ships in #4625: configure the CPU engine with
-DSTRATA_BUILD_TESTS=ON -DSTRATA_POOL_SPIN_US_MICROBENCH=ONand run./pool_tasks_test parkcost assert.It parks 8 workers over 1,000 phases with a 200 µs gap, three repetitions, and
prices a park against the cost of 8,192,000 plain pauses; the bound is a ratio of 1.00, so it fails when a parked
worker costs more than pausing by hand (
src/kernels/cpu/pool_tasks_test.cpp:103-105). No extra switch is needed tomake the change live: the Linux CPU configuration defines
STRATA_POOL_SPIN_ZEROitself(
CMakeLists.txt:2013-2016).Two arms, one tree: this branch's
src/kernels/cpu/pool.cpp, and that file replaced bymain's(
git show ffa80d73:src/kernels/cpu/pool.cpp) with nothing else changed.What this does not claim
No Windows run: the check needs
getrusage, and its section is compiled only on Linux and only where the changeitself is compiled (
src/kernels/cpu/pool_tasks_test.cpp:38), so a Windows build carries no measurement to assertrather than a measurement that reports itself skipped. No macOS or Metal build.
The 1,024-pause count is read from the loop above, not measured: nothing in the tree counts pauses, and adding a
counter per pause iteration would cost more than the pause it counts. That part is static reading of the loop; the
cost difference in the logs below is an observed run.
Reproduction status
Reproduced locally
Strata version
Strata 0.2.10 · engine 0.1.56, built from source at
ffa80d73and at the head of #4625 (f8464bb8).mainis nowStrata 0.2.11 · engine 0.1.57, so these numbers are from 0.2.10 / 0.1.56.
Graphics card, memory and system
NVIDIA GeForce RTX 5090 Laptop GPU 24 GiB (driver 615.71.09) · 62.2 GiB RAM · Linux 7.0.0-42-generic (Ubuntu 26.04.1) ·
Intel Core Ultra 9 275HX (24 cores, 24 threads, no AVX-512), gcc 15.2.0
Model, size and settings
No model is needed for the reproduction:
pool_tasks_testbuilds its own Q4_0 expert and its own 8-worker pool, sothe two arms differ only in the
pool.cppthey were built from. The setting under discussion isSTRATA_POOL_SPIN_US=0against the built-in 20 ms default. The runs were made while a model server was serving on thebox (load average 3.0-3.7), which is why the measurement prints and asserts only when asked. Each arm was built one
job at a time so the build itself did not load the machine; that is how the runs were made, not a requirement to
repeat them.
Logs
With
pool.cppfromffa80d73and nothing else changed, all three repetitions fail:With the change in #4625, all three pass:
With the knob left at its default the two builds cost the same, which is the point of the change: 2019 ms = 7.45 and
2008 ms = 7.05 at the head, 2028 ms = 7.52 and 2030 ms = 7.49 with
pool.cppfromffa80d73. Checked mechanically with eachconfiguration's own compile command for that file and the flag removed:
pool.cppfromffa80d73and the one in #4625 give a byte-identical
.textand.rodatain the CPU configuration (74,859 and 121 bytes), inthe HIP configuration (74,132 and 121) and in the SYCL configuration (100,311 and 512); with the flag defined the same
source becomes 75,179 bytes, so the comparison is not comparing two copies of one object. Windows, macOS/Metal, HIP and
SYCL builds therefore compile the same park loop the last release compiles; the Linux CPU and CUDA configurations do
compile the new branch, and the default-cost rows above are the measured cost of that. With the change in the tree the
pool tests pass unchanged: "360 bitwise comparisons passed, 192 of them in NUMA-split mode".
No engine log applies to this finding - it comes from a test binary, not from a served model, so there is no
strata doctoroutput orstrata-<model>.logto attach. The full build and test log for every configuration isattached to pull request #4625.