[libcxx] std::chrono::steady_clock is not working as expected
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- c
- Domain
- backend, operating-systems
Research direction
Read the referenced implementation in libcxx/src/chrono.cpp around the steady_clock::now() call and the linked Microsoft documentation for QueryPerformanceFrequency behavior. Investigate how the Xbox kernel call can fail and how that affects the clock result; the issue also suggests disabling steady_clock as a temporary option. Done means steady clock behavior on Xbox is reliable, or its use is clearly disabled until that is resolved.
Written by the indexing model from the issue text.
Description
While working on my Kodi port I faced lot of issues with:
- frame time (CTimeUtils::GetFrameTime)
- stopwatch (CStopwatch)
- events (CEvent)
I inspected this and everything leads to use of std::chrono::steady_clock::now(). This is used by std::condition_variable_any::wait_for (used in CEvent), it's used inside CStopwatch to calculate elapsed time and it's used to update frame time inside CTimeUtils. When app is started it behaves normally but after some time it starts behaving unpredictably giving negative and zero values which leads to crashes in case of std::condition_variable_any and brokes complete logic in Kodi because returned value of this functions should be always greater then previous one (somerhing like GetTickCount).
Astarivi helped me to debug this and we came to conslusion that problem is inside kernel functin KeQueryPerformanceFrequency which is invoked when std::chrono::steady_clock::now() is called. This is actually a know problem for Win 2K and older systems. In short, KeQueryPerformanceFrequency on Xbox can fail and LLVM assumes this will always succeed. See here. There are also more details on MS docs
Temporary solution for this is to replace steady_clock with system_clock but this should be fixed anyway. Or at least until this is sorted steady_clock should be disabled so it doesnt lead to confusion.
- Dominant language
- C
- Stars
- 600
- Forks
- 97
- Avg merge
- 11h 48m
- Merged PRs (30d)
- 2
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from XboxDev/nxdk
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Use faster memcpyOpen
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 1/5 Under an hour Newbie friendliness 38/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
libsndfile/libsndfile#1239 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100