Skip to content

test(libkernel): time blocking waits from before the writer thread starts - #7670

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:test/kqueue-pipe-read-start
Oct 19, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:test/kqueue-pipe-read-start

Conversation

@thuanquang

Copy link
Copy Markdown
Contributor

What

guest_kqueue (PipeRead) starts a writer thread that sleeps 50 ms and then writes one byte to a pipe, and requires the main thread's blocking kevent to have waited at least 40 ms for it. The wait was measured from a start taken after the writer thread was created. When the main thread is preempted between creating the writer and taking start, the writer's 50 ms run partly or wholly before start, so kevent returns sooner after start than 40 ms although it did wait for the write, and the test aborts at GuestKqueue.cpp:246. This is the abort under parallel load that @wachi35676 (kevent returned 13 us to 35 ms into the wait) and @screamm reported on #7492.

start is now taken before the writer thread is created, so the measured wait always includes the writer's sleep. The blocking read in guest_socket_events (GuestSocketEvents.cpp) has the same order, a sender thread that sends after 50 ms and a 40 ms check on a start taken after the thread, and gets the same change. That sleep does not end early on Windows: with WinLibs GCC 15.2.0 r7, 120 calls of sleep_for(50 ms) here took 58.2 to 77.6 ms (winpthreads rounds timed waits to GetTickCount64 steps, #1471). A kevent that returns before the write still fails the test: before 40 ms at the same check, later at the data == 1 check.

Tested

Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON.

  • The race, on main 6685795f7, 8 parallel copies of guest_kqueue plus 12 busy processes: 9 of 120 runs aborted (0xC0000409). With a local probe (not part of this PR) that printed the timings of PipeRead, every abort looked the same (4 of 4): the main thread took start 38.7 to 67.7 ms after creating the writer, the write came 28.5 to 39.6 ms after start, and kevent returned 0.3 to 1.4 ms after the write with data 1. So the pipe was never reported before the write.
  • sleep_for(50 ms): 120 calls took 58.2 to 77.6 ms (median 62.1 ms).
  • With this change on main 48d61f53b: guest_kqueue and guest_socket_events pass 3 of 3 under ctest --repeat until-fail:3. Run 15 times in a row with 24 busy threads, neither main nor this change failed, so this machine needs the parallel load above to show it.
  • guest_socket_events did not fail on main in our load runs; it is changed because its wait is measured the same way.
  • python tools/check_conventions.py --base origin/main with this title and body passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

…arts

PipeRead (guest_kqueue) and the blocking read in guest_socket_events took
their start time after creating the thread that writes after 50 ms, so a
main thread preempted between the two measured less than the writer's
sleep and failed the 40 ms check although the wait did block until the
write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestKqueue.cpp
core/libs/tests/GuestSocketEvents.cpp
PR 7049 core/libs/tests/GuestKqueue.cpp
PR 7075 core/libs/tests/GuestKqueue.cpp
PR 7088 core/libs/tests/GuestKqueue.cpp
PR 7121 core/libs/tests/GuestKqueue.cpp
PR 7129 core/libs/tests/GuestKqueue.cpp

@karimibrahim07 karimibrahim07 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows check of head e0da1fb1c, merged onto main ccbd40240 together with #7669, #7709, #7717 and #7680 (each merge clean, built once). Windows 11 Pro (26300), Ryzen 5 3600 (6 cores, 12 threads), WinLibs GCC 15.2.0 r7, Ninja Release, BUILD_TESTING=ON.

  • guest_kqueue and guest_socket_events pass, --repeat until-fail:3.

  • Under load, with main's and this PR's test binaries built from the same tree, started directly:

    Load Test main this PR
    8 copies at once + 12 busy processes guest_kqueue 80 of 80 pass 80 of 80 pass
    16 copies at once + 24 busy processes guest_kqueue 159 of 160 pass, 1 abort 160 of 160 pass
    16 copies at once + 24 busy processes guest_socket_events 160 of 160 pass (2 runs) 160 of 160 pass (run first)

    In an earlier run that accidentally overlapped two of these batches, main's guest_kqueue aborted in 4 of 8 copies in one round. Require there calls abort() without a line, so I can't confirm these aborts are the GuestKqueue.cpp:246 check. They do only show up on main's binary.

  • A note so nobody chases it: in two batches where this PR's guest_socket_events ran right after main's, 2 of 160 copies hung past my 60 s limit. With the order swapped, this PR's binary passed 160 of 160 first. So that depends on what ran before (16 copies at once leave many sockets behind), not on this change. It was a hang, not the 40 ms check, and this PR only moves start.

Code: taking start before the thread is created makes the measured wait include the writer's whole 50 ms sleep, so the >= 40 ms bound can't fail because of a slow main thread. A kevent or sceKernelWaitEqueue that returns without the event still fails at the == 1 / data checks after it. The same order in GuestSocketEvents.cpp is right for the same reason. I have no requests.

AI-assisted: yes. I ran the build and the runs above.

@oneandonlydean oneandonlydean self-assigned this Oct 19, 2026
@oneandonlydean
oneandonlydean merged commit 1c2824c into boykopovar:main Oct 19, 2026
10 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.

3 participants