#6189 [Engine] cpu tests: guard the quota/affinity core count against PR #14's dangling else (#13)
closed · @FluxNimbusAi · 0 comentários · No GitHub
Setup & installServer & APIAMD / HIPNVIDIA / CUDAWindowsLinux
Descrição
## Problem and result PR #14 fixed a dangling `else` in the Linux affinity mask read: every CPU id outside the mask re-appended all `hardware_concurrency()` ids, so a 16-of-1024 mask returned `16 + 1008·16 − 1 = 16143` CPUs (issue #13, the container report). The fix landed, but nothing guards it — and the related container-quota path (`cgroup_cpu.hpp` → `plan_pool_workers`) likewise had no end-to-end regression coverage. Before this PR: no test fails if either behavior reappears. After: three new test targets assert (a) a k-of-1024 affinity mask reads back exactly its popcount — with the old blow-up number named and refused, (b) the quota-bounded worker count at the plan level across the edge matrix (truncation, the strict `q < n` boundary, sub-core floors, quota-inert affinity, cap precedence), and (c) the full composition — a quota read from a fake cgroup mount fed into the default plan — including an explicit "cgroup values unavailable" failure path that pins the count at its pre-cgroup value (never a silent collapse to 1). ## Related discussion The fix itself: https://github.com/Niko1221/Strata/pull/14 (merged as ca1758d6); originating report: https://github.com/Niko1221/Strata/issues/13. Test-only change, zero production code, so no scope agreement needed per CONTRIBUTING. ## Approach Two of the three seams are path-injectable by design, and the tests use them instead of mocking: - New `src/kernels/cpu/cgroup_quota_plan_test.cpp`: builds temp-dir cgroup v2/v1/hybrid trees, reads them through `cgroup_cpu_quota_at`, and feeds the result into `plan_pool_workers` — the same composition `fill_plan_fields`/`pool_plan_input` performs in production. Runs on every OS, no root, no real cgroups. - Extended `pool_plan_test.cpp`: the quota × affinity × reserve × cap matrix goldens (e.g. 64 cores under a 13.6-CPU quota → 12 workers, never the 32 of the cap or the 64 of the cores; `quota 8.0` on 8 cores → 7 because the comparison is strict; `0.0` quota leaves the count exactly at the pre-cgroup value). - Extended `pool_affinity_linux_test.cpp` (Linux leg only): `dangling_else_guard()` pins the test process itself to the first few allowed CPUs via `sched_setaffinity` and requires `get_thread_affinity` to return exactly that list (`cpus == restricted`, `size == popcount == k`), computes the dangling-else result `k + (1024 − k)·h − 1` for this machine, refuses it by name, and checks that `physical_cores`/`detect_cpu_topology` stay inside the mask. Under the old bug this fails on any runner, not just 16-thread boxes. - `cmake/backends/cpu.cmake`: registers the new target next to `cgroup_cpu_test`. ## Validation **Passed:** - The pinned goldens were first validated by a faithful stdlib-Python port of `cgroup_cpu.hpp` + `pool_plan.hpp` replaying all upstream `pool_plan_test.cpp` goldens (31/31), a 16-row edge matrix and an 8-row composition — all green, deterministic across repeat runs (the port lives in the swarm's fixture work; the C++ pins above mirror it 1:1). - CI on this PR: queued at open — the Linux `cpu CMake preset` leg runs `cgroup_quota_plan_test`, the extended `pool_plan_test` and the affinity file's Linux leg, plus Windows/macOS portable legs. (As an external-contributor run, the workflow may wait on maintainer approval; no local C++ claim is made where CI has not spoken.) **Failed:** - none observed. **Not run:** - Local native build/ctest: this rig is Windows with no installed C++ toolchain (no compiler by design), so the C++ execution is delegated to CI — every assertion above is a CI gate, not a local claim. - CUDA/HIP/SYCL/Metal build legs: irrelevant to test-only CPU changes. ## Limits - The affinity leg exercises `sched_setaffinity` on the test process only (unprivileged); it cannot fabricate >1024-CPU ids on small runners — the guard asserts sizes and identities, so it holds at any k ≥ 2 the runner allows. - Upstream merge of this PR is, as ever, on the maintainer train schedule; the same tests are landing on our fork main for continuous guarding in the meantime.
No site
Links install, modelos, releases.