This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
This version uses an offset field in the task and signal structs to store offsets for the thread and process clock. It also includes the check in timer_create for REALTIME or MONOTONIC. The clocks are now independent and therefore the thread clock is not clearedby clock_settime(CLOCK_PROCESS_CPUTIME_ID) in the testrun: Single Thread Testing CLOCK_THREAD_CPUTIME_ID= 0.374943000 resolution= 0.000999848 CLOCK_PROCESS_CPUTIME_ID= 0.374943000 resolution= 0.000999848 Multi Thread Testing Starting Thread: 0 1 2 3 4 5 6 7 8 9 Joining Thread: 0 1 2 3 4 5 6 7 8 9 0 Cycles= 0 Thread= 0.000000000ns Process= 0.000999848ns 1 Cycles=1000000 Thread= 0.036994376ns Process= 0.315951968ns 2 Cycles=2000000 Thread= 0.073988752ns Process= 0.086986776ns 3 Cycles=3000000 Thread= 0.109983280ns Process= 0.517921264ns 4 Cycles=4000000 Thread= 0.146977656ns Process= 0.563914272ns 5 Cycles=5000000 Thread= 0.180972488ns Process= 1.043841312ns 6 Cycles=6000000 Thread= 0.218966712ns Process= 1.112830824ns 7 Cycles=7000000 Thread= 0.254961240ns Process= 1.620753608ns 8 Cycles=8000000 Thread= 0.290955768ns Process= 1.490773368ns 9 Cycles=9000000 Thread= 0.326950296ns Process= 1.641750416ns Clock status at the end of the timer tests: Gettimeofday() = 1096484938.561351000 CLOCK_REALTIME= 1096484938.561363000 resolution= 0.000999848 CLOCK_MONOTONIC= 157.633669432 resolution= 0.000999848 CLOCK_PROCESS_CPUTIME_ID= 1.641750416 resolution= 0.000999848 CLOCK_THREAD_CPUTIME_ID= 0.375942848 resolution= 0.000999848
Attachment:
thread_process_time_v5
Description: V5 of patch
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <errno.h> #include <asm/unistd.h> #include <pthread.h> #define clock_getres(x,y) syscall(__NR_clock_getres, x,y) #define clock_gettime(x,y) syscall(__NR_clock_gettime, x, y) #define clock_settime(x,y) syscall(__NR_clock_settime, x, y) void pr(int clock,const char *n) { struct timespec tv = {1,2}; struct timespec res = {3,4}; int rc; rc=clock_getres(clock,&res); if (rc) { printf("getres return code on %s=%d errno=%d\n",n,rc,errno); } rc=clock_gettime(clock,&tv); if (rc) { printf("gettime return code on %s=%d errno=%d\n",n,rc, errno); } else printf("%25s=% 11d.%09d resolution=% 2d.%09d\n",n,tv.tv_sec,tv.tv_nsec,res.tv_sec,res.tv_nsec); } int y; void kx(long long x) { y=x; }; struct timespec zero; pthread_t thread[10]; struct tinfo { int i; struct timespec ttime,ptime; } tinf[10]; void *thread_function(void *x) { struct tinfo *t=x; int i; for(i=1;i< t->i;i++) kx(1000000000000LL/i); clock_gettime(CLOCK_THREAD_CPUTIME_ID,&t->ttime); clock_gettime(CLOCK_PROCESS_CPUTIME_ID,&t->ptime); } int main(char argc, char *argv[]) { struct timespec tv; int i; /* Waste some time */ printf("Single Thread Testing\n"); for(i=1;i<10000000;i++) kx(1000000000000LL/i); pr(CLOCK_THREAD_CPUTIME_ID,"CLOCK_THREAD_CPUTIME_ID"); pr(CLOCK_PROCESS_CPUTIME_ID,"CLOCK_PROCESS_CPUTIME_ID"); /* Waste some more time in threads */ printf("Multi Thread Testing\nStarting Thread:"); clock_settime(CLOCK_PROCESS_CPUTIME_ID,&zero); for(i=0;i<10;i++) { tinf[i].i=i*1000000; if (pthread_create(&thread[i], NULL, thread_function, tinf+i)) perror("thread"); else printf(" %d",i); } printf("\n Joining Thread:"); for(i=0;i<10;i++) if (pthread_join( thread[i], NULL)) perror("join"); else printf(" %d",i); printf("\n"); for(i=0;i<10;i++) { printf("%d Cycles=%7d Thread=% 3d.%09dns Process=% 3d.%09dns\n",i,tinf[i].i,tinf[i].ttime.tv_sec,tinf[i].ttime.tv_nsec,tinf[i].ptime.tv_sec,tinf[i].ptime.tv_nsec); } gettimeofday((struct timeval *)&tv); tv.tv_nsec = tv.tv_nsec*1000; printf("\nClock status at the end of the timer tests:\n"); printf(" Gettimeofday() =% 11d.%09d\n",tv.tv_sec,tv.tv_nsec); pr(CLOCK_REALTIME,"CLOCK_REALTIME"); pr(CLOCK_MONOTONIC,"CLOCK_MONOTONIC"); pr(CLOCK_PROCESS_CPUTIME_ID,"CLOCK_PROCESS_CPUTIME_ID"); pr(CLOCK_THREAD_CPUTIME_ID,"CLOCK_THREAD_CPUTIME_ID"); printf("\n"); }
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |