#include <timers.h>void init_timers(int maxtimers);void stamp_timers(int slot);long long diff_timers(int slot1, int slot2);
Timers use a low level assembly routine to directly accces the TSC (Time Stamp Counter), and have the usual flaws on multi proccesing cores and multi-tasking operating systems how to translate this to a CPU usage. For long term stability routines such as cputime(3NEMO) should be used,for short fine grained understanding, these routines could be useful.
init_timers(n+1);
for (i=0; i<n; i++)
stamp_timers(i);
stamp_timers(n);
for (i=0; i<n; i++)
printf("Method-1: %Ld0,diff_timers(i,i+1));
stamp_timers(0);
for (i=0; i<n; i++) {
stamp_timers(i+1);
printf("Method-2: %Ld0,diff_timers(i,i+1));
}
long long is assumed to hold 64 bits, where unsigned is assumed 32 bit.
~/src/kernel/misc timers.c
23-apr-04 created PJT