Re: gettimeofday() a special case : faster than times()?

Dan Kegel (dank@alumni.caltech.edu)
Fri, 17 Dec 1999 07:35:43 -0800


Here's a newbie question about the merits of gettimeofday()
versus times() for implementing one's own little timers.

I'm writing a load generator to simulate thousands of dialup clients;
it throttles each client in userspace (rather than using a shaper device).

I'm currently using now = times(&dummy) to retrieve the current
tick count. I do this very frequently to implement my own little
scheduler to simulate slow connections. If I switch to using
sigtimedwait() and SIGIO to reduce the overhead of calling poll(),
my system call trace will look like this:
for (;;) {
sigtimedwait()
now = times()
if (this fd isn't still sleeping)
read(this fd)
while (after(some fd's wakeuptime, now))
read(just woken up fd)
}

So I'm affected by the overhead of times().
If gettimeofday() is going to be specially optimized, maybe
I should switch.

gettimeofday(&tv, 0) would work, but I'd have to munge the
fields of tv together to get a single integer, e.g.
now = (tv.sec << 10) + (tv.usec >> 10)

Do the recent posts on special entry points mean that this
would be faster than calling times()?
Am I better off using gettimeofday() anyway because of
its higher precision and clearer specification?
- Dan

-- 
(The above is just my personal opinion; I don't speak for my employer,
 except on the occasional talk show.)

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