Skip to content

feat(libc): implement C11 timespec_get for PPSA34015 - #9388

Closed
xXPBSXx wants to merge 2 commits into
boykopovar:mainfrom
xXPBSXx:carry/6084-timespec-get
Closed

xXPBSXx wants to merge 2 commits into
boykopovar:mainfrom
xXPBSXx:carry/6084-timespec-get

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Carries #6084 (@notaxeltv) onto current main, as @oneandonlydean announced there on 20.10. (24 h without a reply from the author, keeping both commits and crediting both). #6084's commit implements C11 timespec_get for TIME_UTC (import yrx+40YKqiI of PPSA34015, listed by tools/import_audit.py) with the realtime source of _Xtime_get_ticks, returning 0 for a null pointer or an unsupported base. The second commit resolves the review point on #6084: it writes the guest's 16-byte timespec (two 64-bit fields, KernelTimespec), not the host timespec, whose tv_nsec is 32 bits on MinGW, and the test pre-fills a guest struct with a non-zero pattern so a 32-bit write fails. Based on the heads of #6084 and xXPBSXx:fix/timespec-get-guest-layout.

Tested

Windows 10 19045, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on main ea241c0 with both commits merged (the rebased head only differs by its newer base):

  • ctest -R '^guest_timespec_get$' passes 3 of 3; guest_time_conversion and guest_mktime pass (3 of 3 together).
  • With libc/src/Time.cpp restored to main the test does not link (undefined reference to timespec_get_nid_postfix). On feat(libc): implement C11 timespec_get (PPSA34015) #6084's head alone the layout case fails 3 of 3 (0xc0000409), as @xXPBSXx posted there on 20.10.
  • python tools/check_conventions.py --base upstream/main passes; git merge-tree against main is clean.
  • Title run (reported by @klosixgaming-arch on this PR, not run by me): EA SPORTS FC 27 (PPSA34015, 01.000.004), Windows 11 (build 26200), RTX 5090, APS5_PLAYGO_UNLISTED_CHUNKS=absent, main 1a745ae38e plus feat(libc): write the called imports to APS5_TRACE_CALLS_FILE every 10 seconds #9439 (to record calls) plus this PR's head d9d01fa01, merged. The title reaches timespec_get and keeps running: libc.prx yrx+40YKqiI is called 19,588 times in a 2-minute run that ends only because it was stopped (no crash, no NotImplemented). That reporter did not run main without this PR past an unrelated keyboard abort, so what the missing import does there is not shown; and the run needed a local-only revert of sceConvertKeycodeGetImeKeyboardType (not part of this PR), because current main aborts that title 1.8 s in.
  • Not tested: Linux/macOS. Linux: feat(libc): implement C11 timespec_get (PPSA34015) #6084 has an independent Linux run by @isnisk on its own head (not repeated on this head).

Checklist

  • Based on current main; no other open PR implements the same functions (feat(libc): implement C11 timespec_get (PPSA34015) #6084 is the one this carries; it can be closed as superseded once this merges)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs are listed in technical debt (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA34015 (absent libc import timespec_get)
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

notaxeltv and others added 2 commits October 21, 2026 21:42
Absent libc import yrx+40YKqiI (timespec_get); fill realtime UTC like _Xtime_get_ticks.

Co-authored-by: Cursor <cursoragent@cursor.com>
The guest timespec has two 64-bit fields, but the host timespec on
Windows has a 32-bit tv_nsec, so only the low half of the nanoseconds
was written. Take a guest struct and write both fields; the test
pre-fills the struct so a 32-bit write fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 21, 2026
@github-actions

Copy link
Copy Markdown

Progress report (0c6a5bd → d9d01fa)

📈 System libraries: 42.11% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc timespec_get_nid_postfix

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6084 core/libs/prx/libc/src/Time.cpp L580
core/libs/tests/GuestTimespecGet.cpp
timespec_get core/libs/tests/GuestTimespecGet.cpp

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 3965 core/libs/prx/libc/CMakeLists.txt
PR 5021 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/Time.cpp
PR 6044 core/libs/prx/libc/CMakeLists.txt
PR 7081 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/Time.cpp
PR 7715 core/libs/prx/libc/CMakeLists.txt
PR 8150 core/libs/prx/libc/CMakeLists.txt
PR 8863 core/libs/prx/libc/CMakeLists.txt
PR 8965 core/libs/prx/libc/CMakeLists.txt
PR 9232 core/libs/prx/libc/CMakeLists.txt
PR 9447 core/libs/prx/libc/src/Time.cpp
PR 9929 core/libs/prx/libc/CMakeLists.txt
PR 10129 core/libs/prx/libc/src/Time.cpp

GuestTimespec later{-1, -1};
Require(timespec_get_nid_postfix(&later, TIME_UTC) == TIME_UTC);
Require(later.tv_nsec >= 0 && later.tv_nsec < 1000000000LL);
Require(later.tv_sec > filled.tv_sec || (later.tv_sec == filled.tv_sec && later.tv_nsec >= filled.tv_nsec));

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.

This second-read ordering check assumes UTC wall-clock time is monotonic. Both clock_gettime(CLOCK_REALTIME) and GetSystemTimePreciseAsFileTime can move backward after an administrator/NTP clock correction, so the test can fail even when timespec_get correctly returns UTC. Please avoid comparing two wall-clock reads, or bound the result against an independently sampled wall clock with an allowance that does not require monotonicity.

@MarcZX10 MarcZX10 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.

Reviewed both retained commits and the guest-layout fix. The KernelTimespec fields are written explicitly, and the test now pre-fills the 16-byte guest layout so the MinGW-width regression is observable. The commits retain their original contributor authorship, and the PR describes the superseding relationship to #6084. Hosted eligibility, intake, conventions, relinker and test-support checks are green. I left a non-blocking inline note about the test comparing two UTC wall-clock reads, which can move backward after clock correction.

@wachi35676

Copy link
Copy Markdown
Contributor

Linux run of the current head (the Linux run on #6084 predates the KernelTimespec commit).

Head d9d01fa018 merged onto main a6dcea927 (clean). WSL2 Ubuntu 24.04, GCC 13.3.0, Release.

  • guest_timespec_get, guest_time_conversion, guest_mktime: 3/3, 3 runs.
  • With libc/src/Time.cpp from main the test does not link (timespec_get_nid_postfix), as on Windows.
  • yrx+40YKqiI is timespec_get by the repo's NID algorithm.

AI-assisted: yes (Claude Code); results above were run on this machine.

@MarcZX10

Copy link
Copy Markdown
Contributor

I rechecked this head against current main (d6732b51a64f4322799af89b876b224d3aed6efc). The focused Linux target built successfully and guest_timespec_get passed 3/3 locally; check_conventions.py --base upstream/main and git diff --check also pass. The independent Windows and WSL2 reports in the PR provide complementary runtime coverage.

One coordination item surfaced since the prior review: open #9447 also changes core/libs/prx/libc/src/Time.cpp, and a merge-tree of the two PR heads reports a content conflict in that file. Please coordinate merge order with its author and make sure both changes are retained (for example, rebase the later PR after the first lands). #6084 remains the intentional superseded source of the first commit and should continue to be credited as already described. The current main merge-tree for this PR alone is clean, but its base is 481 commits behind; please refresh it before merge.

@klosixgaming-arch

klosixgaming-arch commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Title run for the "Not tested: a title run" item, EA SPORTS FC 27 (PPSA34015, 01.000.004).

Setup: Windows 11 (build 26200), RTX 5090, driver 617.42, APS5_PLAYGO_UNLISTED_CHUNKS=absent. Build: main 1a745ae38e plus #9439 (to record calls) plus this PR's head d9d01fa01, merged.

Result: the title reaches timespec_get and keeps running: with APS5_TRACE_CALLS=all and APS5_TRACE_CALLS_FILE, libc.prx yrx+40YKqiI is called 19,588 times in a 2-minute run, and the run ends only because I stopped it (no crash, no NotImplemented, last log line a read of its EA persistence files at 72 s). That is the import tools/import_audit.py lists as absent for this title on main. I did not run main without this PR past the keyboard abort below, so I cannot say what the missing import does there, at load or at the first call.

One thing I had to work around, not caused by this PR: on current main this title aborts 1.8 s in, before it can call timespec_get, with sceConvertKeycodeGetImeKeyboardType: user keyboard language and variant are unavailable. That throw came in with b5dbd377ed (20.10); before it the function returned type 0, and the debt entry in docs/dev/debt/libSceConvertKeycode.md describes the throw as intended. For this run I put the old *type = 0; return 0; back on a local branch only (not part of this PR). Without that, the run above would not have got far enough to exercise your change.

AI-assisted: yes. Written with AI assistance and reviewed by me.

@xXPBSXx

xXPBSXx commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks for rechecking. On the order with #9447 (@AlxcBTW): both PRs change core/libs/prx/libc/src/Time.cpp. A git merge-tree of the two heads (d9d01fa018 and 2dc7b701a4, merge-base 80565c5942) reports one conflicting hunk of about 20 lines including the conflict markers; neither PR is on main yet. Whichever lands second needs a rebase onto the first, keeping both changes.

@AlxcBTW: do you prefer #9447 to go first or second? If it helps, I can prepare a rebased branch of either side in my fork (authorship kept) for you to take over or ignore.

On the base being 1039 commits behind: a rebase gives a new head; I would rebase right before the merge or when you ask, and then ask for a look at the new head.
AI-assisted (Claude Code).

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing this as a duplicate of #6084, which implements the same timespec_get and was opened first. Thanks, and sorry for the overlap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build libc unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants