Re: nonexistent clocks

JJ <[email protected]> Fri, 26 Jun 2026 08:16:20 +1000
Newsgroups gmane.os.netbsd.general
Message-ID <TYZPR02MB6044F1628B3F973DB5B38F4BD6EC2@TYZPR02MB6044.apcprd02.prod.outlook.com>
On 25/06/2026 9:17 pm, Jan Stary wrote:
> Hi,
>
>> According to tests/lib/libc/sys/t_clock_gettime.c
>> ""These clocks aren't supported but are documented"
>> 	    " in clock_gettime(2) for some reason"
> thanks for the pointer. I am new to NetBSD
> and am only getting into tests(7) so please bare with me.
>
> According to these test results (random google hit, but a recent run)
>
> https://www.netbsd.org/~martin/landisk-atf/last_atf.html#lib_libc_sys_t_clock_gettime_clock_getres
>
> calling clock_getres() on these two clocks is expected to fail.
> It seems a bit silly to test that NetBSD does _not_ support a clock.
> (Isn't clock_gettime() also expected to fail, if they do not exist? :-)
> Wouldn't it make more sense to just remove these from the documentation?
>
>> There's also a PR in about CLOCK_MONOTONIC & what it actually represents:
>> https://gnats.netbsd.org/60315


My point with raising the PR also is that clock_getres() et al are 
poorly documented (and as you have discovered),

just plain wrong.


> Thank you. I am in fact studying the clock_*() interface on various
> unixes and what clocks they provide - see my naive take below.
>
> I guess my first question (please excuse the naivety) is where is
> NetBSD's clock_get*() implemented? That must be these, right?
>
> /usr/src/sys/kern/kern_time.c:clock_getres1()
> /usr/src/sys/kern/subr_time.c:clock_gettime1()
>
> These only support
>
>    CLOCK_REALTIME
>    CLOCK_MONOTONIC
>    CLOCK_PROCESS_CPUTIME_ID
>    CLOCK_THREAD_CPUTIME_ID
>
> and set EINVAL otherwise.
>
> 	Jan

Yes.

My tested view of all OS you have macros for test as expected and 
documented by their relevant manual pages.

Only NetBSD is wrong and vague. Actually I'm not sure about OpenBSD, I 
am not expected to cater for that toy OS.

Solaris also has some of these timers, but not all. Newer versions of 
OpenVMS support some as well. I think Solaris has had this for a long 
time, but OpenVMS only under its x86 development due to virtualisation 
support.


>
> #include <stdint.h>
> #include <string.h>
> #include <stdio.h>
> #include <time.h>
> #include <err.h>
>
> void
> show(clockid_t id, char* name)
> {
> 	struct timespec ts;
> 	struct timespec cr;
> 	if (clock_gettime(id, &ts) == -1)
> 		err(1, NULL);
> 	if (clock_getres(id, &cr) == -1)
> 		err(1, NULL);
> 	printf("%s %10lld.%09ld s, %8ld ns resolution\n",
> 		name, ts.tv_sec, ts.tv_nsec, cr.tv_nsec);
> }
>
> int
> main(void)
> {
> #ifdef  __APPLE__
> 	show(CLOCK_REALTIME,		"real time");
> 	show(CLOCK_MONOTONIC,		"monotonic");
> 	show(CLOCK_UPTIME_RAW,		"up time  ");
> 	show(CLOCK_PROCESS_CPUTIME_ID,	"proc time");
> #elif __OpenBSD__
> 	show(CLOCK_REALTIME,		"real time");
> 	show(CLOCK_MONOTONIC,		"monotonic");
> 	show(CLOCK_BOOTTIME,		"boot time");
> 	show(CLOCK_UPTIME,		"up time  ");
> 	show(CLOCK_PROCESS_CPUTIME_ID,	"proc time");
> #elif __FreeBSD__
> 	show(CLOCK_REALTIME,		"real time");
> 	show(CLOCK_MONOTONIC,		"monotonic");
> 	show(CLOCK_BOOTTIME,		"boot time");
> 	show(CLOCK_UPTIME,		"up time  ");
> 	show(CLOCK_PROCESS_CPUTIME_ID,  "proc time");
> #elif __NetBSD__
> 	show(CLOCK_REALTIME,		"real time");
> 	show(CLOCK_MONOTONIC,		"monotonic");
> 	show(CLOCK_PROCESS_CPUTIME_ID,  "proc time");
> #else
> 	show(CLOCK_REALTIME,		"real time");
> 	show(CLOCK_MONOTONIC,		"monotonic");
> 	show(CLOCK_BOOTTIME,		"boot time");
> 	show(CLOCK_PROCESS_CPUTIME_ID,	"proc time");
> #endif
> 	return 0;
> }

Maybe test for CLOCK_???? like : if #defined (CLOCK_UPTIME) makes more 
sense?