-
Notifications
You must be signed in to change notification settings - Fork 251
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
Fixed wrong timestamp under Free- and OpenBSD and macOS #217
Conversation
Using CLOCK_MONOTONIC breaks the timestamp output just as much under Linux as under BSD (but this is hidden by HAVE_SO_TIMESTAMPNS being set so the clock is always CLOCK_REALTIME). So why is CLOCK_MONOTONIC there at all? |
Hmm, you really ought to use CLOCK_MONOTONIC for every time-delta calculation (unless you're using packet timestamps from either kernel or hardware, which is highly OS-specific). Severe weirdness happens when CLOCK_REALTIME steps around due to system administrator action (or even non-slew-mode large ntp corrections, etc). If you need human-readable timing, you timestamp CLOCK_REALTIME and CLOCK_MONOTONIC at program start (or at measurement session start, if there's such a notion in your application -- for fping they're the same), and use the CLOCK_MONOTONIC delta + CLOCK_REALTIME timestamp to calculate a more sane real time that doesn't jump around. This adds a minor, constant, and irrelevant phase error to the real time output, which is already quite uncertain anyway. |
@@ -123,7 +123,7 @@ extern int h_errno; | |||
#endif | |||
|
|||
#if !defined(CLOCKID) | |||
#if defined(CLOCK_MONOTONIC) | |||
#if defined(CLOCK_MONOTONIC) && !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment to explain why we can't use CLOCK_MONOTONIC on these platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On FreeBSD and OpenBSD CLOCK_MONOTONIC begin with 0 after reboot or undefined positive point.
Here is my test result with FreeBSD.
CLOCK_MONOTONIC (sec): 43
CLOCK_REALTIME (sec): 1628355889
CLOCK_UPTIME (sec): 43
OpenBSD Manpage: https://man.openbsd.org/clock_gettime.2
macOS unfortunately I can not test only assume
I have another version when you don't like so many not defined in the code gsnw@2d8d292
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I meant also a comment in the code. Maybe referencing just this PR, something like this:
// don't use CLOCK_MONOTONIC on Mac and FreeBSD because gettime returns uptime (see github PR #217)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups, sorry for misunderstanding. I have add a in code comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Wrong timestamp on Free- and OpenBSD and macOS fixed by disabling #define CLOCKID CLOCK_MONOTONIC
Issues
#203
#216