Skip to content

perf(kernel): read the wait clock only when wait tracing is on - #18864

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
atinseau:codex/perf-wait-trace-clock
Nov 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
atinseau:codex/perf-wait-trace-clock

Conversation

@atinseau

Copy link
Copy Markdown
Contributor

What

sceKernelWaitSema read steady_clock before and after every wait and passed the difference to KernelTraceWait_nid_postfix, which returns at once unless APS5_TRACE_WAITS is set. The wait now reads the clock only when the variable is set, through one cached flag shared with the trace function. Result codes, wait conditions and trace output are unchanged.

On a signal-and-wait pair on one kernel semaphore (single thread, alternating runs of the parent and the change) the cost drops from 88 ns to 39 ns and from 1,909 to 1,069 instructions; with a timeout, from 147 ns to 87 ns. The figures are a fixture measurement, not a title trace.

Tested

macOS 27.0.1, Apple M3 Max (36 GB), Release build with -DBUILD_TESTING=ON, x86_64 under Rosetta 2. main does not run its libraries on macOS, so both sides are main 3b7f31fa7 with the macOS port (the squash of #8658, which its author upstreams in parts) and local macOS build fixes for tests of main that Apple clang refuses; the change side adds this PR's commits.

  • Kernel, pthread, semaphore, event flag, timer and job manager tests (244 names: the guest_* tests whose names match semaphore, condition, mutex, event, wait, sync, thread, sleep, timer and the like), same regex on both sides: 242 tests match on both sides; 240 pass and 2 abort on both: guest_kernel_sys_wait_wait4 and guest_kernel_sys_wait_wait4_patched expect ECHILD from wait4(INT_MIN) and macOS answers EINVAL. No test changes status.
  • python3 tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py found no open pull request that changes sceKernelWaitSema or the wait trace flag.

Not tested: Linux and Windows.

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

sceKernelWaitSema read steady_clock before and after every wait and passed the difference to KernelTraceWait_nid_postfix, which returns at once unless APS5_TRACE_WAITS is set. The wait now reads the clock only when the variable is set, through one cached flag shared with the trace function. A signal+wait pair drops from 88 ns to 39 ns and from 1909 to 1069 instructions; with a timeout, from 147 ns to 87 ns. The result codes, the wait conditions and the trace output are unchanged.
@github-actions github-actions Bot added libkernel perf Performance change perf numbers missing perf pull request without a before and after summary line labels Nov 12, 2026
@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@github-actions

github-actions Bot commented Nov 12, 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 10558 core/libs/prx/libkernel/Semaphore/src/Semaphore.cpp
PR 12642 core/libs/prx/libkernel/Time/Time.cpp
PR 14557 core/libs/prx/libkernel/Time/Time.cpp
PR 17551 core/libs/prx/libkernel/Time/Time.cpp
PR 17609 core/libs/prx/libkernel/Time/Time.cpp
core/libs/prx/libkernel/Time/include/Time.hpp
PR 17958 core/libs/prx/libkernel/Time/Time.cpp
PR 18515 core/libs/prx/libkernel/Semaphore/src/Semaphore.cpp
core/libs/prx/libkernel/Time/Time.cpp
core/libs/prx/libkernel/Time/include/Time.hpp

@JJenkx

JJenkx commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 271ae954c6, merged onto main 0ce40b8c69 (merge b293a21dc6). Setup: Windows 11 Enterprise 22621, MinGW-w64 GCC 15.2 UCRT, Release.

253 of the 254 selected libkernel tests pass in 3 of 3 runs. The selection covers the wait-clock call sites this PR touches; 28 of the selected targets are not built on Windows and were dropped.

The one failure, exec_arguments, fails in all 3 runs. It also fails on main on this machine, with a Python FileNotFoundError from the test harness, so it is not caused by this change.

This is a correctness check only; I did not measure the timing change.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit 8eff7f0 into boykopovar:main Nov 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libkernel perf numbers missing perf pull request without a before and after summary line perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants