On Tue, 10 Aug 2010 10:53:23 -0400
James Carlson <[email protected]> wrote:
> Sad Clouds wrote:
> > uint64_t current_time;
> > while(1)
> > {
> > get_network_data();
> > current_time = update_current_time();
> > ...
> > use_current_time();
> > }
> >
> > So in a tight loop, if update_current_time() calls clock_gettime()
> > on every loop iteration, what would kill performance.
>
> How much execution time does update_current_time() take when compared
> to get_network_data()?
>
> You might also want to look into the SO_TIMESTAMP option.
It's just an example. The longest time would be time spent in
clock_gettime() call, but it only calls clock_gettime() at specified
intervals, which could be every second, or every microsecond, it
depends on how accurate the application wants the current time to be.
At all other times, the function calls a few simple arithmetic
instructions to adjust 64-bit counters, so it's negligible.
The general idea is not to call clock_gettime() on every loop
iteration, but instead let CPU adjust 64-bit counters until the
specified time interval is detected. This way the function is "self
clocking" and provides a good estimate of current system time in tight
loops.
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code