diff options
author | brian <brian@FreeBSD.org> | 2000-03-14 01:46:34 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2000-03-14 01:46:34 +0000 |
commit | 56e902f033269992e0f25fc6a20411ff64a58a20 (patch) | |
tree | dc655bfb9bf74c1c3a9d3a0d7468d8fc0bb43714 /usr.sbin | |
parent | 1fa2af66ede91c633df6c1a766877b1b0d1e016a (diff) | |
download | FreeBSD-src-56e902f033269992e0f25fc6a20411ff64a58a20.zip FreeBSD-src-56e902f033269992e0f25fc6a20411ff64a58a20.tar.gz |
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...
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/timer.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c index 989303d..9e69aea 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) |