[CFR] Kevent timer improvements
Konstantin Belousov
kostikbel at gmail.com
Sun Apr 13 14:20:40 UTC 2014
On Sun, Apr 13, 2014 at 03:15:51PM +0200, Baptiste Daroussin wrote:
> I have splitted my patch in multiple parts, let start with the first one:
> adding NOTE_NSECONDS, NOTE_USECONDS, NOTE_NSECONDS
>
> http://people.freebsd.org/~bapt/kevent_timer.diff
> Index: sys/kern/kern_event.c
> ===================================================================
> --- sys/kern/kern_event.c (revision 264413)
> +++ sys/kern/kern_event.c (working copy)
> @@ -524,14 +524,24 @@
> * interval timer support code.
> */
> static __inline sbintime_t
> -timer2sbintime(intptr_t data)
> +timer2sbintime(intptr_t data, int flags)
> {
> + sbintime_t modifier;
>
> + modifier = SBT_1MS;
> +
> + if (flags & NOTE_SECONDS)
> + modifier = SBT_1S;
> + else if (flags & NOTE_USECONDS)
> + modifier = SBT_1US;
> + else if (flags & NOTE_NSECONDS)
> + modifier = SBT_1NS;
It is better to put the 'modifier = SBT_1MS;' statement as the else part.
That said, IMO it would be sometimes beneficial to have real flag to
specify milliseconds precision, in addition to milliseconds be the
default.
> +
> #ifdef __LP64__
> - if (data > SBT_MAX / SBT_1MS)
> + if (data > SBT_MAX / modifier)
> return (SBT_MAX);
> #endif
> - return (SBT_1MS * data);
> + return (modifier * data);
> }
>
> static void
> @@ -547,7 +557,7 @@
> if ((kn->kn_flags & EV_ONESHOT) != EV_ONESHOT) {
> calloutp = (struct callout *)kn->kn_hook;
> callout_reset_sbt_on(calloutp,
> - timer2sbintime(kn->kn_sdata), 0 /* 1ms? */,
> + timer2sbintime(kn->kn_sdata, kn->kn_sfflags), 0 /* 1ms? */,
There, at least the comment about precision should be updated.
But, it seems that for the seconds precision, it makes sense to
specify e.g. 1/2 sec as precision; or add an API flag to allow imprecise
callout scheduling.
> filt_timerexpire, kn, PCPU_GET(cpuid), 0);
> }
> }
> @@ -566,7 +576,7 @@
> return (EINVAL);
> if ((intptr_t)kn->kn_sdata == 0 && (kn->kn_flags & EV_ONESHOT) == 0)
> kn->kn_sdata = 1;
> - to = timer2sbintime(kn->kn_sdata);
> + to = timer2sbintime(kn->kn_sdata, kn->kn_sfflags);
> if (to < 0)
> return (EINVAL);
>
> Index: sys/sys/event.h
> ===================================================================
> --- sys/sys/event.h (revision 264413)
> +++ sys/sys/event.h (working copy)
> @@ -133,6 +133,11 @@
> #define NOTE_TRACKERR 0x00000002 /* could not track child */
> #define NOTE_CHILD 0x00000004 /* am a child process */
>
> +/* additional flags for EVFILE_TIMER */
> +#define NOTE_SECONDS 0x00000001 /* data is seconds */
> +#define NOTE_USECONDS 0x00000002 /* data is microseconds */
> +#define NOTE_NSECONDS 0x00000004 /* data is nanoseconds */
> +
> struct knote;
> SLIST_HEAD(klist, knote);
> struct kqueue;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20140413/e695804d/attachment.sig>
More information about the freebsd-hackers
mailing list