of your code
#include <timers.h>void init_timers(int maxtimers);void init_timers2(int maxtimers, int mode);void stamp_timers(int slot);long long diff_timers(int slot1, int slot2);double diff_timers2(int slot1, int slot2);
init_timers2 (mode=1) was introduced to also use cputime(3NEMO) , at the slight cost of more ticks. diff_timers2 will report the difference in CPU seconds (not minutes!).
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.
This timers method approached something called Frame based profiling
stamp_timers(0); for (i=0; i<n; i++) { stamp_timers(i+1);
printf("Method-2: %Ld\n",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 25-feb-2024 added the cputime option PJT