That's a good guess (Brian? You know about that?:) ... but a bit doubtful.

When I submitted the first patch using clock_gettime() there was a push back for this, so I moved back to gettimeofday(). I don't remember the argument now, but gettimeofday() is at least better then time() (which was what was there first).

One point, the time value is not being properly stored anyway. Technically it requires a lock around it (volatile is not enough to guarantee synchronous update).

I would argue along with Sean that clock_gettime() would be better, but I can not remember any longer what the objections were.


When in doubt, benchmark (and I'm glad I did). I wasn't present/ involved with the discussion, but I'd guess it had something to do with POSIX being lax in its definition of clockid_t, the meaning of its values and various clockid_t values not being defined universally.

I wrote a small micro-benchmark utility to see what's the fastest time syscall. I cribbed phk@'s recommendation for CLOCK_MONOTONIC/ MONOTONIC_FAST in a post which I blindly repeated earlier in this thread... and that information happened to be either old or incorrect. time(3) is just as expensive as gettimeofday(2) (which surprised the hell out of me - why it's not implemented in terms of CLOCK_SECOND, I'm not sure). clock_gettime(CLOCK_REALTIME_FAST) is the fastest time syscall for non-monotomic time retrieval.

http://sean.chittenden.org/pubfiles/freebsd/bench_time.c

% ./bench_time 9079882 | sort -rnk1
Timing micro-benchmark.  9079882 syscall iterations.
Avg. us/call    Elapsed     Name
9.322484    84.647053       gettimeofday(2)
8.955324    81.313291       time(3)
8.648315    78.525684       clock_gettime(2/CLOCK_REALTIME)
8.598495    78.073325       clock_gettime(2/CLOCK_MONOTONIC)
0.674194    6.121600        clock_gettime(2/CLOCK_PROF)
0.648083    5.884515        clock_gettime(2/CLOCK_VIRTUAL)
0.330556    3.001412        clock_gettime(2/CLOCK_REALTIME_FAST)
0.306514    2.783111        clock_gettime(2/CLOCK_SECOND)
0.262788    2.386085        clock_gettime(2/CLOCK_MONOTONIC_FAST)
Last value from gettimeofday(2): 1212380080.620649
Last value from time(3): 1212380161
Last value from clock_gettime(2/CLOCK_VIRTUAL): 2.296430000
Last value from clock_gettime(2/CLOCK_SECOND): 1212380338.000000000
Last value from clock_gettime(2/CLOCK_REALTIME_FAST): 1212380243.461081040
Last value from clock_gettime(2/CLOCK_REALTIME): 1212380240.459788612
Last value from clock_gettime(2/CLOCK_PROF): 185.560343000
Last value from clock_gettime(2/CLOCK_MONOTONIC_FAST): 5747219.271879584
Last value from clock_gettime(2/CLOCK_MONOTONIC): 5747216.886509281


For the kernel curious:

http://fxr.watson.org/fxr/source/kern/kern_time.c#L200

-sc


--
Sean Chittenden
[EMAIL PROTECTED]
http://sean.chittenden.org/

Reply via email to