Linux.com

Home Linux Community Forums Programming and Development Kernel Development How to convert TSC cpu cycles into seconds ?

How to convert TSC cpu cycles into seconds ?

Link to this post 20 Sep 10

main()
{
unsigned long long tsc_start, tsc_end;
tsc_start = get_tsc();
// execute some code

tsc_end = get_tsc();
printf("Total time for execution %llu cpu cycles", tsc_end - tsc_start);
printf("Total time in seconds ") ; // How to compute this ?
}

static unsigned long long get_tsc()
{
unsigned long long tsc;
asm volatile ("rdtsc" : "=A" (tsc));
return tsc;
}

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board