-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ST: Use clock_gettime to prevent time jumping backwards. v7.0.17 #3979
Merged
winlinvip
merged 5 commits into
ossrs:develop
from
suzp1984:issue/3978-refactor-st-utime
Oct 15, 2024
Merged
ST: Use clock_gettime to prevent time jumping backwards. v7.0.17 #3979
winlinvip
merged 5 commits into
ossrs:develop
from
suzp1984:issue/3978-refactor-st-utime
Oct 15, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suzp1984
force-pushed
the
issue/3978-refactor-st-utime
branch
from
March 7, 2024 08:38
c3ee990
to
d952b60
Compare
Thank you for your excellent work. Please add new tests to validate your updates in the pull request. The utest is crucial and a necessary condition for merging the pull request. Without it and automated testing, we risk introducing bugs sooner or later due to many changes over time. |
suzp1984
force-pushed
the
issue/3978-refactor-st-utime
branch
2 times, most recently
from
March 9, 2024 09:58
3ce21e5
to
d59a1d1
Compare
Add a UT in srs root project. |
Failed in cygwin? |
suzp1984
force-pushed
the
issue/3978-refactor-st-utime
branch
2 times, most recently
from
March 18, 2024 09:38
22590ef
to
1aae04f
Compare
suzp1984
force-pushed
the
issue/3978-refactor-st-utime
branch
from
March 18, 2024 13:22
1aae04f
to
5c045b4
Compare
winlinvip
force-pushed
the
develop
branch
2 times, most recently
from
August 12, 2024 10:42
0bb9637
to
2e211f6
Compare
winlinvip
changed the title
issue #3978: improve st_utime's default impl.
ST: Use clock_gettime to prevent issues with time jumping backwards.
Oct 15, 2024
winlinvip
changed the title
ST: Use clock_gettime to prevent issues with time jumping backwards.
ST: Use clock_gettime to prevent time jumping backwards.
Oct 15, 2024
winlinvip
changed the title
ST: Use clock_gettime to prevent time jumping backwards.
ST: Use clock_gettime to prevent time jumping backwards. v7.0.17
Oct 15, 2024
winlinvip
approved these changes
Oct 15, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
try to fix #3978
Background
check #3978
Research
I referred the Android platform's solution, because I have android background, and there is a loop to handle message inside android.
https://github.com/aosp-mirror/platform_frameworks_base/blob/ff007a03c01bf936d1e961a13adff9f266d5189c/core/java/android/os/Handler.java#L701-L706C6
https://github.com/aosp-mirror/platform_system_core/blob/59d9dc1f50b1ae8630ec11a431858a3cb66487b7/libutils/SystemClock.cpp#L37-L51
https://github.com/aosp-mirror/platform_system_core/blob/59d9dc1f50b1ae8630ec11a431858a3cb66487b7/libutils/Timers.cpp#L32-L55
For Linux system, we can use
clock_gettime
api, but it's first appeared in Mac OSX 10.12.man clock_gettime
The requirement is to find an alternative way to get the timestamp in microsecond unit, but the
clock_gettime
get nanoseconds, the math formula is the nanoseconds / 1000 = microsecond. Then I check the performance of this api + math division.I used those code to check the
clock_gettime
performance.Here is output:
env: Mac OS M2 chip.
We can see the
clock_gettime
is faster thangettimeofday
, so there are no performance risks.MacOS solution
clock_gettime
api only available until mac os 10.12, for the mac os older than 10.12, just keep thegettimeofday
.check osx version in
auto/options.sh
, then add MACRO inauto/depends.sh
, the MACRO isMD_OSX_HAS_NO_CLOCK_GETTIME
.CYGWIN
According to google search, it seems the
clock_gettime(CLOCK_MONOTONIC)
is not support well at least 10 years ago, but I didn't own an windows machine, so can't verify it. so keep win's solution.