gettimeofday() - execution time and underlying implementation details

From: Cagri Balkesen
Date: Fri Feb 06 2009 - 09:37:01 EST


Dear all,

I have a question regarding gettimeofday() function on Linux. I wrote a simple benchmark to understand the execution time of gettimeofday() function. I used ACE High Resolution Timer library to measure the timings (which in fact uses rdtsc instruction). My measurements claim that it takes 1.7 usecs as median and 1.8 usecs as mean value. Which is quite big for the scenario that I'm planning to use gettimeofday(). What I want to learn is whether it is doing a system call or reading the value out of a shared mapping in my system? Also I wonder what timer hardware does linux use for gettimeofday. Also I'm getting kernel timestamped datagrams from network layer (using SO_TIMESTAMP option on the socket), so another question is, does it also take around the same time when kernel receives the packets from the network and timestamps them with gettimeofday()?

Here is information about my system: Linux Red Hat 2.6.18-128.el5 #1 SMP x86_64 GNU/Linux

I'd be grateful to anyone who might share knowledge on this issue.

Thanks,

Cagri

p.s. I hope this is an appropriate message for this mailing list.




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/