On Fri, Sep 30, 2005 at 04:24:08PM -0400, Robert Story wrote: > On Fri, 30 Sep 2005 08:55:44 +0200 Magnus wrote: > MF> 2) It handles only one outstanding timeout, if there are two in the queue > MF> that should happen in the next minute and you set back the clock an hour > MF> your patch will run the first one and the second one will be delayed. > MF> > MF> Now, to run every timeout is also wrong, what is needed is a way to > tell > MF> how big the time warp was and then adjust timeouts that should wait for > MF> N time units but leave those that should run at a certain time alone. > > I don't think the code know the difference between a time that wants to run a > 3:37 and one that wants to run in 53 seconds. Without adding a flag, there is > nothing we can do about that.
Yes, this is true and one of the hard parts of the problem. > My suggestion: when the current time is < last run, loop through the alarms > and calculate the diff between last run and next run for each. Then set each > one to run at (now + diff). Effectively, each alarm will be run after the > amount of time it was expecting to wait has passed. Yes, but under that scheme timeouts might run late. Assume that the last call to run_alarms happened at wall clock time Ta. Then assume that at wall clock time Tb the wall clock is changed to TB. Finally at wall clock time TC run_alarms is called again. Under your scheme the adjustment to be applied to each alarm is (TC-Ta) but the adjustment should be (TB-Tb). Trivally Ta < Tb and TB < TC so the following cases exist: Ta < TC => Timewarp not detected Ta >= TC => Timewarp detected Now assume that we allow the use of a monotonic clock with the value TaM, TbM, TBM and TCM at the timepoints Ta, Tb, TB and TC. The monotonic clock have the following properties: TaM < TbM // It is monotonic (well, yes, obviously) TbM == TBM TBM < TCM (Tb-Ta)==(TbM-TaM) // It uses the same time unit as the wall clock (TC-TB)==(TCM-TBM) Then we get that if (TC-Ta) != (TCM-TaM) there have been a timewarp. Furthermore, the size of the timewarp is (TC-Ta)-(TCM-TaM) == (TB-Tb) and this was the value that the timers should be adjusted with. All this said I agree that your proposal is the best that can be done if we lack the monotonic clock. /MF PS: The return value of times(2) is not always a monotonic clock since it fails the two last properties in the presence of variable tick rates. ------------------------------------------------------- This SF.Net email is sponsored by: Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl _______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders