[DragonFlyBSD - Bug #2951] clock_gettime always repots 0 sec, 0 nsec
bugtracker-admin at leaf.dragonflybsd.org
bugtracker-admin at leaf.dragonflybsd.org
Wed Sep 21 13:18:40 PDT 2016
Issue #2951 has been updated by zhtw.
This is interesting. When you asked me to doublecheck if clock_gettime works with CLOCK_THREAD_CPUTIME_ID (because you said it works for you), I actually tested it on real kernel. So it does work on real kernel.
But now I'm proceeding with testing ChezScheme (this is how I originally found the bug) on a vkernel, I found out again that it clock_gettime doesn't really work even with CLOCK_THREAD_CPUTIME_ID. It always returns 0 as I reported.
So this there is definitely a bug.
Also, when I proceeded testing ChezScheme, I found another bug, also in clock_gettime, but this time it's present in the real kernel: turned out clock_gettime can return nsec greater than one million:
a at kl:~/tmp$ cat t.c
#include <sys/time.h>
#include <stdio.h>
void busywait()
{
for (int i = 0; i != 1000000; ++i)
for (int j = 0; j != 10; ++j)
;
}
int main()
{
struct timespec ts;
for (int i = 0; i != 1000; ++i) {
busywait();
int err = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
if (err) {
printf("err: %d\n", err);
return 1;
}
if (ts.tv_nsec > 1000000000) {
printf("fatal! nsec = %ld\n", ts.tv_nsec);
return 1;
}
}
}
a at kl:~/tmp$ cc t.c
a at kl:~/tmp$ ./a.out
fatal! nsec = 1007424000
Should I create a separate ticket for this?
----------------------------------------
Bug #2951: clock_gettime always repots 0 sec, 0 nsec
http://bugs.dragonflybsd.org/issues/2951#change-12990
* Author: zhtw
* Status: New
* Priority: Normal
* Assignee:
* Category:
* Target version:
----------------------------------------
When called with CLOCK_PROF, clock_gettime always returns 0 sec, 0 nsec:
$ uname -a
DragonFly kl.zta.lk 4.6-RELEASE DragonFly v4.6.0.10.g16fba-RELEASE #10: Wed Aug 17 14:26:31 CEST 2016 root at kl.zta.lk:/usr/obj/usr/src/sys/X86_64_GENERIC x86_64
$ cat time.c
#include <sys/time.h>
#include <stdio.h>
int main()
{
struct timespec ts;
struct timespec *tp = &ts;
for (int i = 0; i != 1000000; ++i)
for (int j = 0; j != 1000; ++j)
;
int err = clock_gettime(CLOCK_PROF, tp);
printf("err: %d\n", err);
printf("sec: %ld\n", ts.tv_sec);
printf("nsec: %ld\n", ts.tv_nsec);
}
$ cc -pedantic -Wall time.c
$ ./a.out
err: 0
sec: 0
nsec: 0
The same program on a FreeBSD machine seems to work:
$ uname -a
FreeBSD fbsd 10.1-RELEASE FreeBSD 10.1-RELEASE #0 r274401: Tue Nov 11 21:02:49 UTC 2014 root at releng1.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
$ cc -pedantic -Wall time.c
$ ./a.out
err: 0
sec: 1
nsec: 604478000
--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account
More information about the Bugs
mailing list