Measuring context switches :: a small expedition. Part I
First up some assembler code. It just works for i386 currently. The first routine gives me the core number the code is currently executing under (see Intel Application Note 485 for more details)
.text .globl __apicID __apicID: push %ebx movl $0x1,%eax cpuid mov %ebx, %eax shr $24,%eax popl %ebx ret
and the second function returns the number of cycles elapsed since power on
.text .globl __rdtsc __rdtsc: rdtsc ret
I haven't coded i386 assembler much, it probably shows :)