Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 04 Oct 2014 10:02:23 -0600
From:      Ian Lepore <ian@FreeBSD.org>
To:        Paul Albrecht <palbrecht@glccom.com>
Cc:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>, Adrian Chadd <adrian@freebsd.org>
Subject:   Re: freebsd 10 kqueue timer regression
Message-ID:  <1412438543.12052.107.camel@revolution.hippie.lan>
In-Reply-To: <8587D819-AA2F-4387-A4E9-523014384672@glccom.com>
References:  <8ABC0977-FB8F-45E7-ACCC-BFA92EE22E1C@glccom.com> <CAJ-VmonJQKWeW7K6%2BjY6=FpmZrm%2B6HQOuBmhhjJEapyVpwNFdQ@mail.gmail.com> <8587D819-AA2F-4387-A4E9-523014384672@glccom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 2014-10-02 at 13:13 -0500, Paul Albrecht wrote:
> On Oct 2, 2014, at 12:18 PM, Adrian Chadd <adrian@freebsd.org> wrote:
>=20
> > On 2 October 2014 08:07, Paul Albrecht <palbrecht@glccom.com> wrote:
> >>=20
> >> Hi,
> >>=20
> >> What=FFs up with freebsd 10? I=FFm testing some code that uses the k=
queue timer for timing and it doesn=FFt work because the precision of the=
 timer is off.
> >=20
> > Can you provide a test case for it?
>=20
> Here=FFs the code:
>=20
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <unistd.h>
> #include <errno.h>
> #include <sys/types.h>
> #include <sys/event.h>
> #include <sys/time.h>
>=20
> int
> main(void)
> {
>         int i,msec;
>         int kq,nev;
>         struct kevent inqueue;
>         struct kevent outqueue;
>         struct timeval start,end;
>=20
>         if ((kq =3D kqueue()) =3D=3D -1) {
>                 fprintf(stderr, "kqueue error!? errno =3D %s", strerror=
(errno));
>                 exit(EXIT_FAILURE);
>         }
>         EV_SET(&inqueue, 1, EVFILT_TIMER, EV_ADD | EV_ENABLE, 0, 20, 0)=
;
>=20
>         gettimeofday(&start, 0);
>         for (i =3D 0; i < 50; i++) {
>                 if ((nev =3D kevent(kq, &inqueue, 1, &outqueue, 1, NULL=
)) =3D=3D -1) {
>                         fprintf(stderr, "kevent error!? errno =3D %s", =
strerror(errno));
>                         exit(EXIT_FAILURE);
>                 } else if (outqueue.flags & EV_ERROR) {
>                         fprintf(stderr, "EV_ERROR: %s\n", strerror(outq=
ueue.data));
>                         exit(EXIT_FAILURE);
>                 }
>         }
>         gettimeofday(&end, 0);
>=20
>         msec =3D ((end.tv_sec - start.tv_sec) * 1000) + (((1000000 + en=
d.tv_usec - start.tv_usec) / 1000) - 1000);
>=20
>         printf("msec =3D %d\n", msec);
>=20
>         close(kq);
>         return EXIT_SUCCESS;
> }
>=20
> When I run it on my system I get these results:
>=20
> ./a.out
> msec =3D 1072
> ./a.out
> msec =3D 1071
> ./a.out
> msec =3D 1071
>=20
> Which is over about 3.5 times the wait time per second.
>=20
>=20
> >=20
> > I just chased down one of those recently; maybe it's the same thing
> > (callout() API changes.)
> >=20
> >=20

FYI, I just committed the fix to -current as r272528.  I'll MFC it to
10-stable in 3 days, and then we'll see if it can get into the 10.1
release cycle.

-- Ian





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