Bug 259642 - CLOCK_* seems to default to CLOCK_*_PRECISE instead of CLOCK_*_FAST
Summary: CLOCK_* seems to default to CLOCK_*_PRECISE instead of CLOCK_*_FAST
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Mateusz Piotrowski
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-04 09:54 UTC by Mateusz Piotrowski
Modified: 2024-05-13 14:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mateusz Piotrowski freebsd_committer freebsd_triage 2021-11-04 09:54:56 UTC
The clock_gettime(2) manual page [1] documents that:

>    The clock IDs CLOCK_REALTIME_FAST,	CLOCK_MONOTONIC_FAST,
>    CLOCK_UPTIME_FAST are analogs of corresponding IDs	without	_FAST suffix
>    but do not	perform	a full time counter query, so their accuracy is	one
>    timer tick.

However, in the source code of kern_clock_gettime() in sys/kern/kern_time.c [2], the clock IDs without a suffix default to PRECISE instead of FAST.

Is it the manual page or the source code that needs fixing?

[1]: https://www.freebsd.org/cgi/man.cgi?query=clock_gettime&manpath=FreeBSD+13.0-RELEASE+and+Ports
[2]: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c?h=releng%2F13.0#n323
Comment 1 Yuri 2021-11-04 10:19:27 UTC
I am not sure what you are really asking, the excerpt you quoted does not say anything about _FAST versions being default, and rather just describes the difference between the _FAST and non-_FAST IDs.
Comment 2 Mateusz Piotrowski freebsd_committer freebsd_triage 2021-11-04 10:28:22 UTC
(In reply to Yuri from comment #1)

Hmm, the way I read the manual page is that, e.g., CLOCK_REALTIME is just CLOCK_REALTIME_FAST. However, the source code suggests that CLOCK_REALTIME is not CLOCK_REALTIME_FAST but CLOCK_REALTIME_PRECISE instead.
Comment 3 Yuri 2021-11-04 10:53:26 UTC
(In reply to Mateusz Piotrowski from comment #2)
It says that e.g. CLOCK_REALTIME_FAST is the *analog* of CLOCK_REALTIME, i.e. both return wall clock, but CLOCK_REALTIME_FAST does it in less precise way.
Comment 4 Mateusz Piotrowski freebsd_committer freebsd_triage 2021-11-04 11:55:59 UTC
(In reply to Yuri from comment #3)
I see, I misunderstood that part.

So before I close this ticket, do you think we should mention that CLOCK_REALTIME is currently CLOCK_REALTIME_PRECISE implemented as?
Comment 5 Ed Maste freebsd_committer freebsd_triage 2021-11-05 15:20:24 UTC
(In reply to Mateusz Piotrowski from comment #4)

Clearly there is room for improvement in the man page because someone (i.e., you) found it unclear. Perhaps "analogs" is not the best word to use.

That said, I do not think we should document that CLOCK_REALTIME is CLOCK_REALTIME_PRECISE. We should perhaps state something about CLOCK_REALTIME having unspecified fast / precise behaviour. Presumably we chould change the un-suffixed version to a third case that is not exactly _FAST or _PRECISE.
Comment 6 commit-hook freebsd_committer freebsd_triage 2022-07-08 19:58:35 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=16e4487e5f82e1ff501fe5af6afbfbd0435a1cbf

commit 16e4487e5f82e1ff501fe5af6afbfbd0435a1cbf
Author:     Mateusz Piotrowski <0mp@FreeBSD.org>
AuthorDate: 2022-07-08 19:54:10 +0000
Commit:     Mateusz Piotrowski <0mp@FreeBSD.org>
CommitDate: 2022-07-08 19:57:24 +0000

    clock_gettime.2: Clarify CLOCK_*

    Clarify that CLOCK_* (e.g., CLOCK_REALTIME) do not necessarily default
    to CLOCK_*_FAST.

    PR:             259642

 lib/libc/sys/clock_gettime.2 | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
Comment 7 Mateusz Piotrowski freebsd_committer freebsd_triage 2022-07-08 19:59:43 UTC
I simplified the documentation a bit. It is subjectively a bit simpler to understand now.
Comment 8 commit-hook freebsd_committer freebsd_triage 2024-05-13 14:26:59 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c595a834ebbd4b6fa49b40c8f9cb4e3dda082c4b

commit c595a834ebbd4b6fa49b40c8f9cb4e3dda082c4b
Author:     Mateusz Piotrowski <0mp@FreeBSD.org>
AuthorDate: 2022-07-08 19:54:10 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-05-13 14:26:10 +0000

    clock_gettime.2: Clarify CLOCK_*

    Clarify that CLOCK_* (e.g., CLOCK_REALTIME) do not necessarily default
    to CLOCK_*_FAST.

    PR:             259642
    (cherry picked from commit 16e4487e5f82e1ff501fe5af6afbfbd0435a1cbf)

 lib/libc/sys/clock_gettime.2 | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)