<br><br><div class="gmail_quote">On Mon, Oct 3, 2011 at 6:57 AM, Peter Senna Tschudin <span dir="ltr"><<a href="mailto:peter.senna@gmail.com">peter.senna@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Dear list members,<br>
<br>
I'm following:<br>
<br>
<a href="http://people.virginia.edu/%7Echg5w/page3/assets/MeasuringUnix.pdf" target="_blank">http://people.virginia.edu/~chg5w/page3/assets/MeasuringUnix.pdf</a><br>
<br>
And I'm trying to measure executing time of simple operations with RDTSC.<br>
<br>
See the code below:<br>
<br>
#include <stdio.h><br>
#define CPU_THOUSAND_HZ 800000<br>
typedef unsigned long long ticks;<br>
static __inline__ ticks getticks(void) {<br>
unsigned a, d;<br>
asm("cpuid");<br>
asm volatile("rdtsc" : "=a" (a), "=d" (d));<br>
return (((ticks)a) | (((ticks)d) << 32));<br>
}<br>
<br>
void main() {<br>
ticks tickBegin, tickEnd;<br>
tickBegin = getticks();<br>
<br>
// code to time<br>
<br>
tickEnd = getticks();<br>
double time = (tickEnd-tickBegin)/CPU_THOUSAND_HZ;<br>
<br>
printf ("%Le\n", time);<br>
}<br>
<br>
How can the C code detects the correct value for CPU_THOUSAND_HZ? The<br>
problems I see are:<br>
- It is needed to collect the information for the CPU that will run<br>
the process. On Core i7 processors, different cores can run at<br>
different clock speed at same time.<br>
- If the clock changes during the execution of process, what should<br>
it do? When is the best time for collecting the clock speed?<br>
<br>
The authors of the paper are not sure about the effects of<br>
"asm("cpuid");" Does it ensure that the entire process will run on the<br>
same CPU, and will serialize it avoiding out of order execution by the<br>
CPU?<br>
<br>
Thank you very much! :-)<br>
<br>
Peter<br>
<font color="#888888"><br>
<br>
--<br>
Peter Senna Tschudin<br>
<a href="mailto:peter.senna@gmail.com">peter.senna@gmail.com</a><br>
gpg id: 48274C36<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</font></blockquote></div>Hi Peter,<br><br>Excellent reference <a href="http://en.wikipedia.org/wiki/Time_Stamp_Counter">http://en.wikipedia.org/wiki/Time_Stamp_Counter</a><br><br>Also, your interpretation is right. There are lots of things which need to be considered instead of setting CPU_THOUSAND_HZ to any particular value, some of them are whether its multi-core or single core CPU. On multi-core its quite difficult to get the correct answers, The problems are mentioned in the above wiki link.<br>
<br>Regards,<br>Rohan Puri<br>