CPU clock work
Ulrich Drepper
drepper@redhat.com
Mon Apr 23 22:39:00 GMT 2001
>From the ChangeLogs you might have seen that I've been working on the
CPU clocks today. Initially I wanted to add only IA-64 support but
this was just too ugly. Over last last months/years I simply added
x86 asm code wherever needed which led to many repetitions and extra
files.
So I cleaned this up now with the result that all one has to do to add
CPU clock support is to write an appropriate pair of hp-timing.{c,h}
files. The rest should fall in place automatically.
I've tested it now on x86 and IA-64 (both have hp-timing.[ch] files
now). I'll start building on Alpha now as a platform without these
files.
Somebody (Jakub, Dave) might want to test SPARC which now suddenly
should also have the functionality. I append a little test program
which should print something like this:
0: t1 thread = 0.000236432
0: t process = 0.004160493
0: t2 thread = 0.000005296
0: t2process = 0.004218780
1: t1 thread = 0.000004708
1: t process = 0.004530499
1: t2 thread = 0.000001179
1: t2process = 0.004562147
2: t1 thread = 0.000004583
I don't know which other platform will have this support. I can
imagine that some PPC incarnations have such a counter. Alpha will
present a challenge which I gladly leave to somebody else. Any of the
small processors (SH, Arm, Cris?) or S390, MIPS? Anyway, whoever
knows the processor will have to do the job.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <pthread.h>
#include <stdio.h>
#include <time.h>
static void *
f (void *arg)
{
clockid_t id;
struct timespec t;
pthread_getcpuclockid (pthread_self (), &id);
clock_gettime (id, &t);
printf ("%d: t1 thread = %ld.%09ld\n", (int) (long) arg, t.tv_sec, t.tv_nsec);
clock_getcpuclockid (0, &id);
clock_gettime (id, &t);
printf ("%d: t process = %ld.%09ld\n", (int)(long) arg, t.tv_sec, t.tv_nsec);
t.tv_sec = t.tv_nsec = 0;
pthread_getcpuclockid (pthread_self (), &id);
clock_settime (id, &t);
clock_gettime (id, &t);
printf ("%d: t2 thread = %ld.%09ld\n", (int) (long) arg, t.tv_sec, t.tv_nsec);
clock_getcpuclockid (0, &id);
clock_gettime (id, &t);
printf ("%d: t2process = %ld.%09ld\n", (int) (long) arg, t.tv_sec, t.tv_nsec);
return NULL;
}
int
main ()
{
int i;
for (i = 0; i < 20; ++i)
{
pthread_t h;
pthread_create (&h, NULL, f, (void *) (long) i);
pthread_join (h, NULL);
}
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
---------------. ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Red Hat `--' drepper at redhat.com `------------------------
More information about the Libc-hacker
mailing list