KernelX: audit thread priority mappings and CPU affinity mask bounds (#106) #1599
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1609"
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?
Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T18:14:10Z.
Summary
Audits thread priority mappings and CPU affinity mask bounds for console 7-core environments in
crates/xcl/src/hle/kernelx.rsandresolver.rs:map_thread_priorityto valid Win32 constants (3..=6->HIGHEST,>=7->TIME_CRITICAL,-14..=-3->LOWEST,<= -15->IDLE), preventing Windows NTERROR_INVALID_PARAMETER(87) failures.SetThreadPriority,GetThreadPriority,SetThreadPriorityBoost, andGetThreadPriorityBoost.ERROR_INVALID_HANDLE(6) and null pointer validation onp_disable_priority_boostreturningERROR_INVALID_PARAMETER(87).fit_affinity_mask: previously, mixed affinity masks (bits partially inside and partially outside process affinity) discarded out-of-process console cores completely. The updated mapping retains in-process bits and maps out-of-process console cores modulo host available processors.CONSOLE_TITLE_CORES(7),CONSOLE_TITLE_AFFINITY_MASK(0x7F),CONSOLE_TITLE_SMT_AFFINITY_MASK(0x3FFF).fit_ideal_processor,SetThreadIdealProcessor, andSetThreadIdealProcessorEx, mapping console core IDs onto available host processors and validating null out-pointers and handles.SetThreadpoolAffinityMask: validates null threadpool pointers and zero affinity masks, returningERROR_INVALID_PARAMETER.SetThreadAffinityMaskandSetThreadGroupAffinity: validates null thread handles (ERROR_INVALID_HANDLE) and zero masks (ERROR_INVALID_PARAMETER).affinity_masks_outside_the_process_are_fittedset_thread_affinity_mask_takes_console_masksthreadpool_affinity_mask_validation_and_boundsideal_processor_bounds_and_fittingthread_priority_mappings_and_error_handlingChanges
crates/xcl/src/hle/kernelx.rs: thread priority tier mappings, affinity bounds fitting, and validation.crates/xcl/src/resolver.rs: exported thread priority and ideal processor APIs.Tested
cargo test -p xcl -- kernelx: 35 passed, 0 failed.upstream/main, GPL-2.0-only compliant, zero retail game data or keys.Not Tested
AI Use
Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:21:15Z.
Review: COMMENTED
AI-assisted review; I checked the sparse-mask case against the added implementation and tests.
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:23:57Z.
Review: COMMENTED
CONTRIBUTING.md also requires the full workspace GPU suite and a real-title regression comparison for runtime changes. This description reports only
cargo test -p xcl -- kernelxand noscripts/smoke.ps1blocks formainand this head. Please add both results before merge, including the skipped GPU test names. AI-assisted review; I checked the Tested and Regression run sections against the guide.Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T18:23:34Z.
Regression run for this PR: head
a7e3240, based onmain9e3831e. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s, back to back with themainrun.main
9e3831e:this PR:
No device removals or crashes; 95 % of main's frames, 98 % of its peak commit.
Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies a lot from run to run, so it says little about this PR.
Not tested: the whole suite; whether the title reaches the changed code in these 60 s.
Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T19:00:57Z.
Full-suite GPU run (NVIDIA and AMD), which the review above asks for. Tested exact head
a7e3240(on its base9e3831e).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 778 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.threadpool_affinity_mask_validation_and_bounds,ideal_processor_bounds_and_fitting,thread_priority_mappings_and_error_handling.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 779 passed, 0 failed, 41 ignored. SKIPPED:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).heap_window_out_of_memory_falls_back_to_the_switch_formwas skipped with--skip. It fails on main9e3831etoo, not because of this PR: underXCL_REQUIRE_GPU=mesh,runner::skip_testturns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWSunset). Reported as #1651.Not tested
AI use
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:21:15Z.
Code review location:
crates/xcl/src/hle/kernelx.rs; line 1478A mixed mask can collapse onto one allowed CPU. For
mask = 0b0111andallowed = 0b1010, CPUs 0 and 2 map topcs[0](CPU 1), while requested CPU 1 is retained, so this returns only0b0010and never uses allowed CPU 3. This leaves a title that requested three processors pinned to one even though two are available. Could the remapping distribute out-of-range bits without duplicating a retained CPU where possible? AI-assisted review; I verified this case againstaffinity_masks_outside_the_process_are_fitted.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T20:30:17Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.Thanks!
mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #172Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T08:00:06Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:15:43Z.
Triage (#1607) – head
a7e3240No open or merged PR makes the same change: main does not hook SetThreadPriority / SetThreadIdealProcessor, and its
fit_affinity_maskstill cuts a partly-overlapping mask to the allowed bits. The other #106 PRs (#196, #240, #291, #1367, #1376, #1431, #1436) touch TLS, the PE loader, reports and RegisterClassExA, not affinity or priority.Notes on the diff (
kernelx.rs):map_thread_prioritymaps every value from 7 to 31 to TIME_CRITICAL with no source for these console tiers.PROCESSOR_NUMBERand raw-dylib externs instead of usingwindows_sys.PR descriptioncheck fails.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.