test(libSceNKWebKit): wait out the whole nap in the JscTimeLimit waiting test #26052

Merged
danosovsky merged 1 commit from upstream-pr/26052 into main 2026-11-23 07:37:59 +00:00
danosovsky commented 2026-11-23 06:16:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by danosovsky on 2026-11-23T06:16:01Z.


What

nkwebkit_jsctimelimit failed about 1 run in 5 on Windows at the last check of TestTimeSpentWaitingIsNotCounted (#26039). Two things in the test made that check race:

  • nap() slept with std::this_thread::sleep_for(400ms), which on Windows (WinLibs GCC 15.2.0) sometimes returns up to about 0.5 ms before 400 ms have passed on steady_clock. It now sleeps the 400 ms and then sleeps 1 ms at a time until steady_clock reaches the 400 ms deadline. The 1 ms steps replace an earlier version that used sleep_until(deadline) and still failed 15 of 60 runs with the old check.

    Clarification (edited after merge): this text first stated as fact that sleep_until with the sub-millisecond rest becomes a 0 ms sleep on MinGW, spins, and charges CPU time to the limit. A later standalone measurement confirms that it loops (485 passes over 2 early naps), but shows no measurable extra CPU time per nap (at most 0.031 ms, against 0.032 ms with 1 ms steps), so why that version failed is not established. The merged code does not depend on it.

  • The check required nap + 50 ms of wall time, but the 50 ms CPU limit starts at Eval, so the CPU used before and during the nap is also charged to it. The check now requires nap plus the part of the limit left when nap() returns. It still fails by about 50 ms if waiting were counted, because the limit would then fire as soon as nap() returns.

WTF::CPUTime and clock_gettime(CLOCK_THREAD_CPUTIME_ID) are not the cause: over a 500 ms busy loop in the test process the thread CPU clock reads 0.997-0.999 of steady_clock, and QueryThreadCycleTime counts 0.995-0.999 of the TSC ticks in a standalone program.

Timings from instrumented runs on main (third nap() and the timed Eval, both on steady_clock):

nap() Eval thread CPU in Eval
fail 399.619 ms 449.825 ms 50.053 ms
fail 399.779 ms 449.922 ms 50.069 ms
fail 399.635 ms 449.945 ms 50.113 ms
pass 400.089 ms 450.193 ms 50.048 ms

Tested

Windows 11 Pro 10.0.26300, AMD Ryzen 5 7600X, WinLibs GCC 15.2.0 r7 (x86_64-ucrt-posix-seh), Release, main 957c68fb42 with this change (the test file is unchanged on main since):

ctest -R "^nkwebkit_jsctimelimit$" alone all nkwebkit_ tests, -j 12
main failed 6 of 30 (all at line 260) not run
this change 0 of 100 238 of 238 pass in each of 8 rounds

python tools/check_conventions.py --base origin/main passes; python tools/pr_overlap.py --branch reports no overlap.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: Fixes #26039
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5448156910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26052). Originally posted by [danosovsky](https://github.com/danosovsky) on 2026-11-23T06:16:01Z. --- ### What `nkwebkit_jsctimelimit` failed about 1 run in 5 on Windows at the last check of `TestTimeSpentWaitingIsNotCounted` (#26039). Two things in the test made that check race: - `nap()` slept with `std::this_thread::sleep_for(400ms)`, which on Windows (WinLibs GCC 15.2.0) sometimes returns up to about 0.5 ms before 400 ms have passed on `steady_clock`. It now sleeps the 400 ms and then sleeps 1 ms at a time until `steady_clock` reaches the 400 ms deadline. The 1 ms steps replace an earlier version that used `sleep_until(deadline)` and still failed 15 of 60 runs with the old check. **Clarification (edited after merge):** this text first stated as fact that `sleep_until` with the sub-millisecond rest becomes a 0 ms sleep on MinGW, spins, and charges CPU time to the limit. A later standalone measurement confirms that it loops (485 passes over 2 early naps), but shows no measurable extra CPU time per nap (at most 0.031 ms, against 0.032 ms with 1 ms steps), so why that version failed is not established. The merged code does not depend on it. - The check required `nap + 50 ms` of wall time, but the 50 ms CPU limit starts at `Eval`, so the CPU used before and during the nap is also charged to it. The check now requires `nap` plus the part of the limit left when `nap()` returns. It still fails by about 50 ms if waiting were counted, because the limit would then fire as soon as `nap()` returns. `WTF::CPUTime` and `clock_gettime(CLOCK_THREAD_CPUTIME_ID)` are not the cause: over a 500 ms busy loop in the test process the thread CPU clock reads 0.997-0.999 of `steady_clock`, and `QueryThreadCycleTime` counts 0.995-0.999 of the TSC ticks in a standalone program. Timings from instrumented runs on `main` (third `nap()` and the timed `Eval`, both on `steady_clock`): | | `nap()` | `Eval` | thread CPU in `Eval` | |---|---|---|---| | fail | 399.619 ms | 449.825 ms | 50.053 ms | | fail | 399.779 ms | 449.922 ms | 50.069 ms | | fail | 399.635 ms | 449.945 ms | 50.113 ms | | pass | 400.089 ms | 450.193 ms | 50.048 ms | ### Tested Windows 11 Pro 10.0.26300, AMD Ryzen 5 7600X, WinLibs GCC 15.2.0 r7 (`x86_64-ucrt-posix-seh`), Release, `main` `957c68fb42` with this change (the test file is unchanged on `main` since): | | `ctest -R "^nkwebkit_jsctimelimit$"` alone | all `nkwebkit_` tests, `-j 12` | |---|---|---| | `main` | failed 6 of 30 (all at line 260) | not run | | this change | 0 of 100 | 238 of 238 pass in each of 8 rounds | `python tools/check_conventions.py --base origin/main` passes; `python tools/pr_overlap.py --branch` reports no overlap. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: Fixes #26039 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-23 06:20:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T06:20:43Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against a10ee9fe22:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_jsctimelimit_tests built cleanly.
  • CTest (nkwebkit_jsctimelimit):
    1/1 Test #4941: nkwebkit_jsctimelimit ............   Passed    3.71 sec
    100% tests passed, 0 tests failed out of 1
    
  • Code reading:
    • libSceNKWebKit/tests/JscTimeLimit.cpp: Nap() deadline calculation and sub-millisecond sleep loop ensuring Clock::now() reaches 400ms without busy spinning
    • libSceNKWebKit/tests/JscTimeLimit.cpp: TestTimeSpentWaitingIsNotCounted calculation of limitLeftAtWake and assertion comparing elapsed wall time to nap + limitLeftAtWake
    • libSceNKWebKit/tests/JscTimeLimit.cpp: Type correctness and chrono duration arithmetic for std::chrono::duration limitLeftAtWake across Linux LP64 and Windows LLP64
    • AGENTS.md compliance: No added comments, no magic constants, no added untracked files, and passes check_conventions.py

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017326254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26052#pullrequestreview-6017326254). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-23T06:20:43Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `a10ee9fe22`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_jsctimelimit_tests` built cleanly. - **CTest** (`nkwebkit_jsctimelimit`): ``` 1/1 Test #4941: nkwebkit_jsctimelimit ............ Passed 3.71 sec 100% tests passed, 0 tests failed out of 1 ``` - **Code reading**: - libSceNKWebKit/tests/JscTimeLimit.cpp: Nap() deadline calculation and sub-millisecond sleep loop ensuring Clock::now() reaches 400ms without busy spinning - libSceNKWebKit/tests/JscTimeLimit.cpp: TestTimeSpentWaitingIsNotCounted calculation of limitLeftAtWake and assertion comparing elapsed wall time to nap + limitLeftAtWake - libSceNKWebKit/tests/JscTimeLimit.cpp: Type correctness and chrono duration arithmetic for std::chrono::duration<double> limitLeftAtWake across Linux LP64 and Windows LLP64 - AGENTS.md compliance: No added comments, no magic constants, no added untracked files, and passes check_conventions.py Looks Good To Me
MarcZX10 commented 2026-11-23 06:22:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T06:22:38Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the reported Windows runs support the fix, but I could not run checks in this review environment.

What I ran

Reviewed head a10ee9fe22c95da3f31d8c8a968caf020ba6901d. Read description.md, commits.md, manifest.json, diff.patch, and the full changed test file. No checks were run.

Results

Check Result Note
Source review passed Changed file read in full
Automated checks not run No command runner available
Negative control not run No test execution available

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports Windows test runs and convention checks; I did not run or independently verify them. No changed files were excluded; the manifest lists one changed file and it was read in full. files.json was not available in the review folder.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017339743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26052#pullrequestreview-6017339743). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T06:22:38Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the reported Windows runs support the fix, but I could not run checks in this review environment. ## What I ran Reviewed head `a10ee9fe22c95da3f31d8c8a968caf020ba6901d`. Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and the full changed test file. No checks were run. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Changed file read in full | | Automated checks | not run | No command runner available | | Negative control | not run | No test execution available | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports Windows test runs and convention checks; I did not run or independently verify them. No changed files were excluded; the manifest lists one changed file and it was read in full. `files.json` was not available in the review folder. ## To get this to a good state Nothing is required.
mihiii1337 commented 2026-11-23 06:43:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T06:43:14Z.

Review: APPROVED


Reviewed exact head a10ee9fe22c95da3f31d8c8a968caf020ba6901d. The steady-clock deadline handles early or spurious sleep_for returns without charging a busy wait to the JSC CPU limit, and the revised lower bound subtracts the thread CPU time already consumed when the callback wakes.

An independent Windows/WinLibs host probe reproduced the underlying early wake with a scoped 1 ms timer request: the old path returned below 400 ms in 1/30 runs. In the new path, the first sleep returned early in 2/30 runs (minimum 399.766 ms), but the deadline loop reached 400 ms in all 30. Wait-charged negative controls still failed both CPU and wall gates. This probe did not execute JSC itself.

The real nkwebkit_jsctimelimit CTest built from this exact head passed in hosted Windows CI (3.37 s), and an independent Ubuntu run passed as well. All hosted checks are terminal with no failures. No blockers found.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6017490109 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26052#pullrequestreview-6017490109). Originally posted by [mihiii1337](https://github.com/mihiii1337) on 2026-11-23T06:43:14Z. **Review:** APPROVED --- Reviewed exact head `a10ee9fe22c95da3f31d8c8a968caf020ba6901d`. The steady-clock deadline handles early or spurious `sleep_for` returns without charging a busy wait to the JSC CPU limit, and the revised lower bound subtracts the thread CPU time already consumed when the callback wakes. An independent Windows/WinLibs host probe reproduced the underlying early wake with a scoped 1 ms timer request: the old path returned below 400 ms in 1/30 runs. In the new path, the first sleep returned early in 2/30 runs (minimum 399.766 ms), but the deadline loop reached 400 ms in all 30. Wait-charged negative controls still failed both CPU and wall gates. This probe did not execute JSC itself. The real `nkwebkit_jsctimelimit` CTest built from this exact head passed in hosted Windows CI (3.37 s), and an independent Ubuntu run passed as well. All hosted checks are terminal with no failures. No blockers found. AI-assisted: yes.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!26052
No description provided.