freebsd 10 kqueue timer regression

Adrian Chadd adrian at freebsd.org
Thu Oct 2 19:42:41 UTC 2014


Right, and jhb@ mentioned callout() and related stuff.

Let me take a look. I bet it's not doing things "right".




-a

On 2 October 2014 11:13, Paul Albrecht <palbrecht at glccom.com> wrote:
>
> On Oct 2, 2014, at 12:18 PM, Adrian Chadd <adrian at freebsd.org> wrote:
>
> On 2 October 2014 08:07, Paul Albrecht <palbrecht at glccom.com> wrote:
>
>
> Hi,
>
> What’s up with freebsd 10? I’m testing some code that uses the kqueue timer
> for timing and it doesn’t work because the precision of the timer is off.
>
>
> Can you provide a test case for it?
>
>
> Here’s the code:
>
> #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>
>
> int
> main(void)
> {
>         int i,msec;
>         int kq,nev;
>         struct kevent inqueue;
>         struct kevent outqueue;
>         struct timeval start,end;
>
>         if ((kq = kqueue()) == -1) {
>                 fprintf(stderr, "kqueue error!? errno = %s",
> strerror(errno));
>                 exit(EXIT_FAILURE);
>         }
>         EV_SET(&inqueue, 1, EVFILT_TIMER, EV_ADD | EV_ENABLE, 0, 20, 0);
>
>         gettimeofday(&start, 0);
>         for (i = 0; i < 50; i++) {
>                 if ((nev = kevent(kq, &inqueue, 1, &outqueue, 1, NULL)) ==
> -1) {
>                         fprintf(stderr, "kevent error!? errno = %s",
> strerror(errno));
>                         exit(EXIT_FAILURE);
>                 } else if (outqueue.flags & EV_ERROR) {
>                         fprintf(stderr, "EV_ERROR: %s\n",
> strerror(outqueue.data));
>                         exit(EXIT_FAILURE);
>                 }
>         }
>         gettimeofday(&end, 0);
>
>         msec = ((end.tv_sec - start.tv_sec) * 1000) + (((1000000 +
> end.tv_usec - start.tv_usec) / 1000) - 1000);
>
>         printf("msec = %d\n", msec);
>
>         close(kq);
>         return EXIT_SUCCESS;
> }
>
> When I run it on my system I get these results:
>
> ./a.out
> msec = 1072
> ./a.out
> msec = 1071
> ./a.out
> msec = 1071
>
> Which is over about 3.5 times the wait time per second.
>
>
>
> I just chased down one of those recently; maybe it's the same thing
> (callout() API changes.)
>
>
> -a
>
>


More information about the freebsd-hackers mailing list