From 56e902f033269992e0f25fc6a20411ff64a58a20 Mon Sep 17 00:00:00 2001 From: brian Date: Tue, 14 Mar 2000 01:46:34 +0000 Subject: [PATCH] When adjusting timer::rest, round to the closest TICKUNIT usecs value. This has minimal impact here, but if ppp ever needs to frequently remove timers before they've timed out, it can badly skew the next item in the timer list without this change. The correct fix would be to store usecs in `rest' rather than TICKUNITs, but the math is easier if we just round... --- usr.sbin/ppp/timer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c index 989303d056cb..9e69aea6e87b 100644 --- a/usr.sbin/ppp/timer.c +++ b/usr.sbin/ppp/timer.c @@ -35,6 +35,11 @@ #include "descriptor.h" #include "prompt.h" + +#define RESTVAL(t) \ + ((t).it_value.tv_sec * SECTICKS + (t).it_value.tv_usec / TICKUNIT + \ + ((((t).it_value.tv_usec % TICKUNIT) >= (TICKUNIT >> 1)) ? 1 : 0)) + static struct pppTimer *TimerList = NULL, *ExpiredList = NULL; static void StopTimerNoBlock(struct pppTimer *); @@ -80,8 +85,7 @@ timer_Start(struct pppTimer *tp) /* Adjust our first delta so that it reflects what's really happening */ if (TimerList && getitimer(ITIMER_REAL, &itimer) == 0) - TimerList->rest = itimer.it_value.tv_sec * SECTICKS + - itimer.it_value.tv_usec / TICKUNIT; + TimerList->rest = RESTVAL(itimer); pt = NULL; for (t = TimerList; t; t = t->next) { @@ -145,8 +149,7 @@ StopTimerNoBlock(struct pppTimer *tp) struct itimerval itimer; if (getitimer(ITIMER_REAL, &itimer) == 0) - t->rest = itimer.it_value.tv_sec * SECTICKS + - itimer.it_value.tv_usec / TICKUNIT; + t->rest = RESTVAL(itimer); } t->next->rest += t->rest; if (!pt) /* t->next is now the first in the list */ @@ -225,8 +228,7 @@ timer_Show(int LogLevel, struct prompt *prompt) /* Adjust our first delta so that it reflects what's really happening */ if (TimerList && getitimer(ITIMER_REAL, &itimer) == 0) - TimerList->rest = itimer.it_value.tv_sec * SECTICKS + - itimer.it_value.tv_usec / TICKUNIT; + TimerList->rest = RESTVAL(itimer); #define SECS(val) ((val) / SECTICKS) #define HSECS(val) (((val) % SECTICKS) * 100 / SECTICKS)