#include
static inline unsigned long long tick()
{
unsigned long long d;
__asm__ __volatile__ (\"rdtsc\" : \"=A\" (d) );
ret
Instruction cache miss? (this is my guess)
Also, possibly,
Switch to hypervisor in a virtualized system? Remnants of program bootstrap (including network activity on same CPU)?
To Thanatos: On systems more recent than 2008, rdtsc() is a wall clock and does not vary with frequency steps.
Can you try this little code?
int main()
{
long long res;
fflush(stdout); // chnage the exact timing of stdout, in case there is something to write in a ssh connection, together with its interrupts
for (int pass = 0; pass < 2; pass++)
{
res=tick();
res=tick()-res;
}
printf("%d",res); // ignore result on first pass, display the result on second pass.
return 0;
}