Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Apr 2014 17:20:28 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Baptiste Daroussin <bapt@freebsd.org>
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:  <20140413142028.GD4016@kib.kiev.ua>
In-Reply-To: <20140413131550.GD17898@ivaldir.etoilebsd.net>
References:  <20140310131632.GI6900@ithaqua.etoilebsd.net> <CAJ-Vmok7ODK7FfJaHiQej8Za4-JH6Aryctk577vM9cYpeUcHew@mail.gmail.com> <20140310180404.GI32089@funkthat.com> <20140413131550.GD17898@ivaldir.etoilebsd.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--dc+cDN39EJAMEtIO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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
>=20
> http://people.freebsd.org/~bapt/kevent_timer.diff

> 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
> +	modifier =3D SBT_1MS;
> +
> +	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;
It is better to put the 'modifier =3D 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);
>  }
> =20
>  static void
> @@ -547,7 +557,7 @@
>  	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 /* 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 =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
> 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,11 @@
>  #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_USECONDS	0x00000002		/* data is microseconds */
> +#define NOTE_NSECONDS	0x00000004		/* data is nanoseconds */
> +
>  struct knote;
>  SLIST_HEAD(klist, knote);
>  struct kqueue;

--dc+cDN39EJAMEtIO
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (FreeBSD)

iQIcBAEBAgAGBQJTSp0rAAoJEJDCuSvBvK1BjLwP/j8i6SlKTRYAh8s0DivRFCLd
IRNPTxy6s2EHsos5c+DztwfY1LPbEy/XLm97qE90QuL83JF814+Q0pFwwuqySEb6
sLePohvzH51nFHOzqafe2E942BjNGLXC/sNcRDByS3+j/4cMCyUfsaWj4PpQ7QI/
7MUS+SzeR/zF8eVvbYB9K4RB0B7qKBwZaODX4Uw0GH6CaD7dPOu2ekbt2opdXdKf
a57ZhFaxb5NvuMeGoBdrfsdivHPanDI6rpE64/NWOgBmEiFdzuonudkGIfCJWtk2
n6y3q1SKSPSoBYxO9wEalbTce+wEwukwf9oouE+UErZDdUGFmwsqRpyauAVFtYum
56V8oocn+qonaxESMdpqMbBYc/KQWPy+widvYRVgZZgE1Dcl+w8ZILDhx12IOKXu
V2OIXkjefiT243pcEtWx59p3cG5M1/QNid094nbRLPvO3ggesFRqy+As4siLe+OZ
K6ruVfaQhOYeYJoj7djG+KpAGvOOZiyS9XuSr8Me1qirg5eo5uPkw5LwuqF6YcM1
IftVOinVWLMBt009AZO3R2GiSzNiuCPDRTqLZTEA4DTVx+HpgI6oYHEHgcfL+O9G
ME0O1fPirkiTDnezpqiYmaV9kp46bA5RrrrXatnujJr7AvOw4svNOX6PHhJs4jeq
kR9FgkTutAuqH6yjXVF/
=Aa+6
-----END PGP SIGNATURE-----

--dc+cDN39EJAMEtIO--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140413142028.GD4016>