Date: Sun, 13 Apr 2014 21:19:28 +0200 From: Baptiste Daroussin <bapt@freebsd.org> To: Konstantin Belousov <kostikbel@gmail.com> Cc: desrt@desrt.ca, John-Mark Gurney <jmg@funkthat.com>, "freebsd-hackers@freebsd.org" <hackers@freebsd.org> Subject: Re: [CFR] Kevent timer improvements Message-ID: <20140413191928.GE17898@ivaldir.etoilebsd.net> In-Reply-To: <20140413142028.GD4016@kib.kiev.ua> References: <20140310131632.GI6900@ithaqua.etoilebsd.net> <CAJ-Vmok7ODK7FfJaHiQej8Za4-JH6Aryctk577vM9cYpeUcHew@mail.gmail.com> <20140310180404.GI32089@funkthat.com> <20140413131550.GD17898@ivaldir.etoilebsd.net> <20140413142028.GD4016@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
--tctmm6wHVGT/P6vA Content-Type: multipart/mixed; boundary="CEUtFxTsmBsHRLs3" Content-Disposition: inline --CEUtFxTsmBsHRLs3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Apr 13, 2014 at 05:20:28PM +0300, Konstantin Belousov wrote: > 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 on= e: > > adding NOTE_NSECONDS, NOTE_USECONDS, NOTE_NSECONDS > >=20 > > http://people.freebsd.org/~bapt/kevent_timer.diff >=20 [...] > > + else if (flags & NOTE_NSECONDS) > > + modifier =3D SBT_1NS; > It is better to put the 'modifier =3D SBT_1MS;' statement as the else par= t. >=20 > That said, IMO it would be sometimes beneficial to have real flag to > specify milliseconds precision, in addition to milliseconds be the > default. Done in the new patch > > + > > + 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. >=20 While I do agree this might be useful I do not have time to work on that ri= ght now so I just removed the comment which wasn't really accurate anyway. Is that ok? regards, Bapt --CEUtFxTsmBsHRLs3 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="kevent_timer.diff" Content-Transfer-Encoding: quoted-printable Index: lib/libc/sys/kqueue.2 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- lib/libc/sys/kqueue.2 (revision 264413) +++ lib/libc/sys/kqueue.2 (working copy) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 7, 2014 +.Dd April 13, 2014 .Dt KQUEUE 2 .Os .Sh NAME @@ -465,9 +465,26 @@ which is controlled by the .Va kern.kq_calloutmax sysctl. +.Bl -tag -width XXNOTE_USECONDS +.It Dv NOTE_SECONDS +.Va data +is in seconds. +.It Dv NOTE_MSECONDS +.Va data +is in milliseconds. +.It Dv NOTE_USECONDS +.Va data +is in microseconds. +.It Dv NOTE_NSECONDS +.Va data +is in nanoseconds. +.It +.El .Pp -On return, +If .Va fflags +is not set, the default is milliseconds. On return, +.Va fflags contains the events which triggered the filter. .It Dv EVFILT_USER Establishes a user event identified by Index: sys/kern/kern_event.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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; =20 + if (flags & NOTE_SECONDS) + modifier =3D SBT_1S; + else if (flags & NOTE_USECONDS) + modifier =3D SBT_1US; + else if (flags & NOTE_NSECONDS) + modifier =3D SBT_1NS; + else + modifier =3D SBT_1MS; + #ifdef __LP64__ - if (data > SBT_MAX / SBT_1MS) + if (data > SBT_MAX / modifier) return (SBT_MAX); #endif - return (SBT_1MS * data); + return (modifier * data); } =20 static void @@ -547,13 +557,13 @@ if ((kn->kn_flags & EV_ONESHOT) !=3D EV_ONESHOT) { calloutp =3D (struct callout *)kn->kn_hook; callout_reset_sbt_on(calloutp, - timer2sbintime(kn->kn_sdata), 0 /* 1ms? */, + timer2sbintime(kn->kn_sdata, kn->kn_sfflags), 0 filt_timerexpire, kn, PCPU_GET(cpuid), 0); } } =20 /* - * data contains amount of time to sleep, in milliseconds + * data contains amount of time to sleep */ static int filt_timerattach(struct knote *kn) @@ -566,7 +576,7 @@ return (EINVAL); if ((intptr_t)kn->kn_sdata =3D=3D 0 && (kn->kn_flags & EV_ONESHOT) =3D=3D= 0) kn->kn_sdata =3D 1; - to =3D timer2sbintime(kn->kn_sdata); + to =3D timer2sbintime(kn->kn_sdata, kn->kn_sfflags); if (to < 0) return (EINVAL); =20 @@ -583,7 +593,7 @@ calloutp =3D malloc(sizeof(*calloutp), M_KQUEUE, M_WAITOK); callout_init(calloutp, CALLOUT_MPSAFE); kn->kn_hook =3D calloutp; - callout_reset_sbt_on(calloutp, to, 0 /* 1ms? */, + callout_reset_sbt_on(calloutp, to, 0 filt_timerexpire, kn, PCPU_GET(cpuid), 0); =20 return (0); Index: sys/sys/event.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sys/sys/event.h (revision 264413) +++ sys/sys/event.h (working copy) @@ -133,6 +133,12 @@ #define NOTE_TRACKERR 0x00000002 /* could not track child */ #define NOTE_CHILD 0x00000004 /* am a child process */ =20 +/* additional flags for EVFILE_TIMER */ +#define NOTE_SECONDS 0x00000001 /* data is seconds */ +#define NOTE_MSECONDS 0x00000002 /* data is milliseconds */ +#define NOTE_USECONDS 0x00000004 /* data is microseconds */ +#define NOTE_NSECONDS 0x00000008 /* data is nanoseconds */ + struct knote; SLIST_HEAD(klist, knote); struct kqueue; --CEUtFxTsmBsHRLs3-- --tctmm6wHVGT/P6vA Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlNK40AACgkQ8kTtMUmk6EwE2gCfWtKfsmg3V0GAjZGlAKveJjTd 5eYAnR+NWLhlET/TNYo9guLmoasjqdsi =Anz6 -----END PGP SIGNATURE----- --tctmm6wHVGT/P6vA--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140413191928.GE17898>