On Mon, Jul 28, 2008 at 02:26:44AM +0300, Kalev Soikonen wrote: > - Avoid delaying 1.5 seconds when 0.5 will do. > - Guard for forward time resets as well. Nice patch. > time_resync: > gettimeofday(&beginsystime, NULL); > - newhwtime = sethwtime + (int) time_diff(beginsystime, refsystime) + 1; > + tdiff = time_diff(beginsystime, refsystime); > + newhwtime = sethwtime + (int) (tdiff + 0.5); Note that we want to use a --correct=+0.5 option (and /etc/adjtime value) instead the hardcoded half-second correction. See: http://thread.gmane.org/gmane.linux.utilities.util-linux-ng/1453/focus=1508 > if (debug) > printf(_("Time elapsed since reference time has been %.6f seconds.\n" > - "Delaying further to reach the next full second.\n"), > - time_diff(beginsystime, refsystime)); > + "Delaying further to reach the next full second.\n"), tdiff); > > /* > - * Now delay some more until Hardware Clock time newhwtime arrives. The -500 > - * ms is because the Hardware Clock always sets to your set time plus 500 ms > + * Now delay some more until Hardware Clock time newhwtime arrives. The 0.5 s > + * is because the Hardware Clock always sets to your set time plus 500 ms > * (because it is designed to update to the next second precisely 500 ms > * after you finish the setting). > */ > do { > - float tdiff; > gettimeofday(&nowsystime, NULL); > tdiff = time_diff(nowsystime, beginsystime); > if (tdiff < 0) > goto time_resync; /* probably time was reset */ > - } while (time_diff(nowsystime, refsystime) - 0.5 < newhwtime - sethwtime); > +#if 1 ^^^^^^^^ ???? ... To be or not to be? That is the question. It seems you prefer to be and I don't like the extra "#if" ;-) > + if (tdiff > 0.1) > + goto time_resync; > + beginsystime = nowsystime; > +#endif I think it makes sense to check for forward time reset or any unexpected delay (scheduler, swap, ...), but cannot we found anything better than the 0.1 magic constant ? I think acceptable is arbitrary delay or forward-reset that is less than the wanted delay. > + tdiff = time_diff(nowsystime, refsystime); > + } while (newhwtime == sethwtime + (int) (tdiff + 0.5)); > > set_hardware_clock(newhwtime, universal, testing); > } Karel -- Karel Zak <kzak@xxxxxxxxxx> -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html