Skip to content
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

Merged
merged 1 commit into from
Dec 31, 2021

Conversation

gsnw
Copy link
Contributor

@gsnw gsnw commented Mar 12, 2021

Wrong timestamp on Free- and OpenBSD and macOS fixed by disabling #define CLOCKID CLOCK_MONOTONIC

Issues
#203
#216

@coveralls
Copy link

coveralls commented Mar 12, 2021

Coverage Status

Coverage remained the same at 80.961% when pulling 04af04c on gsnw:bug/203 into 749127f on schweikert:develop.

@tohojo
Copy link
Contributor

tohojo commented Mar 20, 2021

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?

@hmh
Copy link
Contributor

hmh commented Mar 22, 2021

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__)
Copy link
Owner

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?

Copy link
Contributor Author

@gsnw gsnw Aug 7, 2021

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

Copy link
Owner

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)

Copy link
Contributor Author

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants