From owner-freebsd-hackers@FreeBSD.ORG Sun Apr 13 19:19:35 2014 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 43C6B1AC for ; Sun, 13 Apr 2014 19:19:35 +0000 (UTC) Received: from mail-we0-x232.google.com (mail-we0-x232.google.com [IPv6:2a00:1450:400c:c03::232]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C3AE91BED for ; Sun, 13 Apr 2014 19:19:34 +0000 (UTC) Received: by mail-we0-f178.google.com with SMTP id u56so7243906wes.37 for ; Sun, 13 Apr 2014 12:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=i59CEZTMCCbzix4zbLYgC6UxSB4dfcKjDlkRwFCTvNs=; b=TsyW9tJ8Naia6XrWtb75k46u9WkwfNrdpx3TnbrYTO92eLKKHYOmjXxjR9riOweJLz uZLQjU0uhBWdnTFIPlqElXUypNbms4+opaR7hPHzeEKT0xPshb5HVkbnEiqRMcx3gmfs HjUJPv6OJ143/IgN7LG1caKk/t5W6TMZU8bmFZLmFfk2Efnqid5NW1lx1gsP02rjwarv nuXLuB4y5PLlAomVGqPZkPHY0JxYIoZKpQO29cf2YWNcgoQfHGidAdfjp+bTt6g235T5 gINEduQbGv/QyOexRh0J6MxeqSfumWV2WnAujN340EIVNRh9L2AtZ7PDjiFmLZ41DK1E /t+Q== X-Received: by 10.180.7.227 with SMTP id m3mr6557487wia.59.1397416772255; Sun, 13 Apr 2014 12:19:32 -0700 (PDT) Received: from ivaldir.etoilebsd.net ([2001:41d0:8:db4c::1]) by mx.google.com with ESMTPSA id h19sm18455048wiw.17.2014.04.13.12.19.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Apr 2014 12:19:30 -0700 (PDT) Sender: Baptiste Daroussin Date: Sun, 13 Apr 2014 21:19:28 +0200 From: Baptiste Daroussin To: Konstantin Belousov Subject: Re: [CFR] Kevent timer improvements Message-ID: <20140413191928.GE17898@ivaldir.etoilebsd.net> References: <20140310131632.GI6900@ithaqua.etoilebsd.net> <20140310180404.GI32089@funkthat.com> <20140413131550.GD17898@ivaldir.etoilebsd.net> <20140413142028.GD4016@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="tctmm6wHVGT/P6vA" Content-Disposition: inline In-Reply-To: <20140413142028.GD4016@kib.kiev.ua> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: desrt@desrt.ca, John-Mark Gurney , "freebsd-hackers@freebsd.org" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Apr 2014 19:19:35 -0000 --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--