tests: read a guest thread's host state through Mach on macOS (#2487) #2511
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2511
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2511"
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?
@mitsa-ng on GitHub · 2026-11-22 09:49 UTC · original
mitsa-ng:tests-macos-wait-until-sleeping→main· +49 −9 · 1 files · 1 commits · openFixes #2487.
Problem
Since
db7035c3,kernel_file_systemfails on macOS before reaching the checks covered by #1770:WaitUntilSleeping()decides a thread is blocked by reading/proc/self/task/<tid>/stat, which only exists on Linux, so on macOS the predicate never becomes true and the mutex hand-off section gives up.Change
Implements the fix proposed by @rafalohaki in the issue: on macOS, find the thread through
task_threads()+THREAD_IDENTIFIER_INFOand readTH_STATE_WAITINGfromTHREAD_BASIC_INFO. The Linux path is unchanged.Evidence
On Apple M2 (Rosetta 2, current main at
61331721) the test failed at the mutex hand-off before and now passes it, stopping exactly at thePTHREAD_CANCELEDcheck that #1770 covers, matching the issue's prediction. Green on Windows/Linux/macOS CI on my fork (run 44985636788).Written with AI assistance (ZCode); built and tested by the author.
@coderabbitai[bot] on GitHub · 2026-11-22 09:52 UTC · original
No actionable comments were generated in the recent review.
Walkthrough
On Apple platforms,
WaitUntilSleepingnow polls Mach thread state to detect when a guest thread’s host thread is waiting. The new helper matches the host thread ID to a Mach thread and releases the thread ports and allocated thread array. On other platforms, the existing/procpolling remains in use.Suggested reviewers:
nmzikChange: Other · Severity of issue fixed: Low
Merge Risk:
Minimal · up to
5fa7eThis change only affects how a test detects a blocked guest thread on macOS. Production behavior is untouched and the Linux path is unchanged. No merge-blocking risk was found.
Pre-merge checks:
4
#2487requires that WaitUntilSleeping() detect a blocked guest thread on macOS, so that kernel_file_system passes the mutex hand-off section. At the reviewed head, tests/KernelFi…Full details: Title check
Explanation
The title names the main change: a macOS-specific path in the test that reads a guest thread's host state through Mach APIs instead of /proc. It also references the issue number. It is specific and matches the changeset summary.
Full details: Description check
Explanation
The description states the problem (WaitUntilSleeping reads /proc/self/task/<tid>/stat, which fails on macOS), the proposed change (task_threads, THREAD_IDENTIFIER_INFO, TH_STATE_WAITING on macOS with Linux path unchanged), and testing evidence. It is directly related to the changeset.
Full details: Linked Issues check
Explanation
Directly linked issue
#2487requires that WaitUntilSleeping() detect a blocked guest thread on macOS, so that kernel_file_system passes the mutex hand-off section. At the reviewed head, tests/KernelFileSystemTests.cpp adds an Apple-only IsHostThreadWaiting() helper. It calls task_threads(), matches THREAD_IDENTIFIER_INFO.thread_id against PthreadGetHostThreadId(), and returns true when THREAD_BASIC_INFO.run_state == TH_STATE_WAITING. WaitUntilSleeping() uses this helper under APPLE and keeps the /proc/self/task/<tid>/stat path under#else. This matches the issue's proposed fix. The author reports, on Apple M2 under Rosetta 2, that the test now passes the hand-off and stops at the PTHREAD_CANCELED check. That check belongs to#1770, which is not part of this PR. The issue's five-run all-pass result needs#1770and#2269, which this PR does not include. Those fixes are outside this PR's scope. The macOS run is author-reported. Repository evidence confirms the code only. The whole-PR diff could not be read, so this assessment relies on the head file content and the PR summary.Full details: Out of Scope Changes check
Explanation
The change set, as summarized (+49/-9), touches only tests/KernelFileSystemTests.cpp. Every change is in the macOS host-thread wait path: the conditional <mach/mach.h> include, the IsHostThreadWaiting() helper, and the
#ifbranch in WaitUntilSleeping(). The Linux path is unchanged. No unrelated code or other test is modified in the reviewed summary. The whole-PR diff could not be read, so file-level scope relies on the summary. Minor style note only: the new Apple block uses tabs, while the surrounding file uses two-space indentation. This does not affect scope.Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
d63a2249-7db5-4507-8084-77783604e826Reviewing files that changed from the base of the PR and between
6133172164and5fa7e3e71e.tests/KernelFileSystemTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
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.