Re: Reading timestamp counter (IA-32/64)
Greg,
Yes, I think that would work on Titan. CLOCKS_PER_SEC is 1 000 000,
so multiplying that by the cpu MHz should get it right. You can
either hardcode the 800 in or get it from /proc/cpuinfo on either
Titan or Platinum, which is pretty close (there are probably other ways
but I don't know of any offhand).
An aside - gettimeofday() may also be reading the same counter value.
The main difference would be avoiding the function overhead - depends
on the situation/need, I guess...
Rick
> ============ Gregory Bauer's message of Apr 24, 5:35pm ================
> Rick-
>
> What or where is the correct multiplier ? I seem to need to use something
> like val/(double)(800*CLOCKS_PER_SEC) where CLOCKS_PER_SEC is from
> <time.h>.
>
> -Greg
>
>
> #include <stdio.h>
> #include <unistd.h>
> #include <time.h>
> #include <sys/time.h> /* struct timeval */
>
> double When1();
> long long When2();
>
> void main()
> {
> double t1a,t1b;
> long long t2a,t2b;
>
> t1a=When1();
> t2a=When2();
> sleep(1);
> t2b=When2();
> t1b=When1();
> printf("%lf %lf %ld %ld\n",t1b,t1a,t2b,t2b);
> printf("%lf %lf\n",t1b-t1a,(t2b-t2a)/(double)(800*CLOCKS_PER_SEC));
> }
>
> /* Return the current time in seconds, using a double precision number.
> */
> double When1()
> {
> struct timeval tp;
> gettimeofday(&tp, NULL);
> return ((double) tp.tv_sec + (double) tp.tv_usec * 1e-6);
> }
>
> long long When2()
> {
> unsigned long long val;
> __asm__ __volatile__("mov %0=ar.itc" : "=r"(val) :: "memory");
> return(val);
> }
>
>
> ============ End of Gregory Bauer's message of Apr 24, 5:35pm =========