On Thursday 22 June 2006 14:23, Chuck Ebbert wrote: > In-Reply-To: <200606211914.37137.ak@suse.de> > > On Wed, 21 Jun 2006 19:14:37 +0200, Andi Kleen wrote: > > >> > >> /* test how fast lsl/jnz/and runs. > >> */ > >> #define _GNU_SOURCE > >> #include > >> #include > >> > >> #define rdtscll(t) asm volatile ("rdtsc" : "=A" (t)) > >> > >> #ifndef ITERS > >> #define ITERS 1000000 > >> #endif > >> > >> int main(int argc, char * const argv[]) > >> { > >> unsigned long long tsc1, tsc2; > >> int count, cpu, junk; > >> > >> rdtscll(tsc1); > >> asm ( > >> " pushl %%ds \n" > >> " popl %2 \n" > >> "1: \n" > >> #ifdef DO_TEST > >> " lsl %2,%0 \n" > >> " jnz 2f \n" > >> " and $0xff,%0 \n" > >> #endif > >> " dec %1 \n" > >> " jnz 1b \n" > >> "2: \n" > >> : "=&r" (cpu), "=&r" (count), "=&r" (junk) > >> : "1" (ITERS), "0" (-1) > >> ); > >> rdtscll(tsc2); > > > > Measuring this way is a bad idea because you get far too much > > noise from the RDTSCs. Usually you need to put a a few thousands entry > > loop inside the RDTSCP and devide the result by the loop count > > I got tired of people (namely me) forgetting to compile the C code > with optimization, so I did the loop in assembler. It does 1000000 > iterations by default. Later I added the DO_TEST that lets you test > the empty loop just because I was curious. > > A more realistic test with the two 'mov' instructions inside the loops > still only takes 16 clocks, so I'm wondering why you get 60? Does the > vsyscall add that much overhead? With this I get 29-30 clocks per loop > on Pentium II: This is the x86-64 test code I used. It's basically an emulation of the vsyscall (including indirect call) in user space. rdtscp shows less cycles, so it's not all overhead of the infrastructure. -Andi K8 E stepping: getpid 168 cycles vgetcpu lsl 79 cycles vgetcpu cached 15 cycles K8 F stepping: getpid 162 cycles vgetcpu lsl 77 cycles vgetcpu rdtscp 32 cycles vgetcpu cached 15 cycles Nocona: getpid 1491 cycles vgetcpu lsl 130 cycles vgetcpu cached 26 cycles