Re: Utilizing rdtsc on i586?

Ingo Molnar (mingo@pc5829.hil.siemens.at)
Wed, 30 Apr 1997 14:31:35 +0200 (MET DST)


On Wed, 30 Apr 1997, Harald Koenig wrote:

[...]
> it's not necessary to run this in kernel; using user mode is ok too:
>

plus the following is handy too:

> void main(void)
> {
> unsigned int cnt3, cnt2, cnt1;
> int i;
> printf("cc: started... ");

iopl(3);
__asm__("cli");

> __asm__(".byte 0x0f,0x31" : "=a" (cnt1), "=d" (cnt3));
> /* put code to time here */
> for(i=0;i<10000;i++);
> /* end code to time here */
> __asm__(".byte 0x0f,0x31" : "=a" (cnt2), "=d" (cnt3));

__asm__("sti");

> printf(" operation took %d cycles\n", cnt2-cnt1);
> }

you've got to run it as root, and better make no mistakes between cli and
sti ;)

-- mingo