On Fri, Feb 09, 2018 at 03:43:52PM +1300, Jonathan Matthew wrote:
> kqueue timers are specified in milliseconds, and timeout_add_msec can do the
> conversion to ticks for us, so we can trim a few lines here.  Using
> timeout_add_msec preserves the 'at least one tick' behaviour that was added
> in r1.65.  kqueue regress tests still pass.

This reduces the maximum timeout from 248 days to 24 days.  And
there is no overflow check when converting __int64_t kn_sdata to
int msecs.

Should we convert timeout_add_msec() to accept long long?

bluhm

> Index: kern_event.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/kern_event.c,v
> retrieving revision 1.84
> diff -u -p -u -p -r1.84 kern_event.c
> --- kern_event.c      13 Jan 2018 12:58:40 -0000      1.84
> +++ kern_event.c      9 Feb 2018 02:30:08 -0000
> @@ -321,18 +321,6 @@ filt_proc(struct knote *kn, long hint)
>       return (kn->kn_fflags != 0);
>  }
>  
> -static void
> -filt_timer_timeout_add(struct knote *kn)
> -{
> -     struct timeval tv;
> -     int tticks;
> -
> -     tv.tv_sec = kn->kn_sdata / 1000;
> -     tv.tv_usec = (kn->kn_sdata % 1000) * 1000;
> -     tticks = tvtohz(&tv);
> -     timeout_add(kn->kn_hook, tticks ? tticks : 1);
> -}
> -
>  void
>  filt_timerexpire(void *knx)
>  {
> @@ -342,7 +330,7 @@ filt_timerexpire(void *knx)
>       KNOTE_ACTIVATE(kn);
>  
>       if ((kn->kn_flags & EV_ONESHOT) == 0)
> -             filt_timer_timeout_add(kn);
> +             timeout_add_msec(kn->kn_hook, kn->kn_sdata);
>  }
>  
>  
> @@ -362,7 +350,7 @@ filt_timerattach(struct knote *kn)
>       to = malloc(sizeof(*to), M_KEVENT, M_WAITOK);
>       timeout_set(to, filt_timerexpire, kn);
>       kn->kn_hook = to;
> -     filt_timer_timeout_add(kn);
> +     timeout_add_msec(kn->kn_hook, kn->kn_sdata);
>  
>       return (0);
>  }

Reply via email to