2011/2/18 dexen deVries <dexen.devr...@gmail.com>: > On Friday, February 18, 2011 04:15:10 pm you wrote: >> Benchmark utilities to measure the overhead of syscalls. It's cheating >> to do for getpid, but for other things like gettimeofday, it's >> *extremely* nice. Linux's gettimeofday(2) beats the socks off of the >> rest of the time implementations. About the only faster thing is to >> get CPU speed and use rdtsc. Certainly no other OS allows you to get >> the timestamp faster with a syscall. > > Would you mind explaining what technique is used by Linux to speed up the > gettimeofday()? I'd guess it's not per-process caching... and if it's not, > then it involves two context-switches; not the fastest thing in my books.
The high level overview is that it is stored in a shared page, mapped into each new process's memory space at start-up. The kernel is never entered; there are no context switches. The kernel has a timer that updates this page atomically. --dho