CLOCK_PROCESS_CPUTIME_ID clock doesn't increment seconds
Jean-Rene David
jrdavid at magma.ca
Wed Feb 28 16:29:25 UTC 2007
The following test case works fine on Core3 but
fails on Core6.
$cat /etc/fedora-release
Fedora Core release 3 (Heidelberg)
$ cat test.c
#include <stdio.h>
#include <unistd.h>
#include <time.h>
int main(void) {
int i;
struct timespec start_rt, start_id;
struct timespec now_rt, now_id;
clock_gettime(CLOCK_REALTIME, &start_rt);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_id);
for(i=0; i<5; i++) {
if(clock_gettime(CLOCK_REALTIME, &now_rt)!=0)
{
fprintf(stderr, "Error!\n");
return 1;
}
if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now_id))
{
fprintf(stderr, "Error!\n");
return 1;
}
// First column CLOCK_REALTIME
printf("%d.%d\t", now_rt.tv_sec - start_rt.tv_sec,
now_rt.tv_nsec - start_rt.tv_nsec);
// Second column CLOCK_PROCESS_CPUTIME_ID
printf("%d.%d\t", now_id.tv_sec - start_id.tv_sec,
now_id.tv_nsec - start_id.tv_nsec);
printf("\n");
sleep(1);
}
return 0;
}
$ gcc test.c -lrt
$ ./a.out
0.73000 0.68477
1.1563000 1.1142818
2.3410000 2.2632301
3.5258000 3.4122795
4.7106000 4.5611411
$ /lib/libc.so.6
GNU C Library stable release version 2.3.3, by Roland McGrath et al.
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3).
Compiled on a Linux 2.4.20 system on 2004-10-27.
Available extensions:
GNU libio by Per Bothner
crypt add-on version 2.1 by Michael Glad and others
linuxthreads-0.10 by Xavier Leroy
The C stubs add-on version 2.1.2.
BIND-8.2.3-T5B
NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Glibc-2.0 compatibility add-on by Cristian Gafton
GNU Libidn by Simon Josefsson
libthread_db work sponsored by Alpha Processor Inc
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
$ uname -a
Linux x.x.x 2.6.9-1.667 #1 Tue Nov 2
14:41:25 EST 2004 i686 i686 i386 GNU/Linux
However on Core6:
$cat /etc/fedora-release
Fedora Core release 6 (Zod)
$ gcc test.c -lrt
$ ./a.out
0.5000 0.69347
1.3222000 0.113973
2.3297000 0.147403
3.3354000 0.180369
4.3417000 0.213781
Note the seconds don't increment on the right
column.
$ /lib/libc.so.6
GNU C Library stable release version 2.5, by Roland McGrath et al.
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.1.1 20060928 (Red Hat 4.1.1-28).
Compiled on a Linux 2.6.9 system on 2006-10-08.
Available extensions:
The C stubs add-on version 2.1.2.
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
GNU libio by Per Bothner
NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
RT using linux kernel aio
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.
$ uname -a
Linux x.x.x 2.6.18-1.2798.fc6xen #1
SMP Mon Oct 16 15:11:19 EDT 2006 i686 i686 i386
GNU/Linux
Any clue?
--
JR
More information about the fedora-list
mailing list