Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Jul 2012 00:39:51 +0200
From:      Davide Italiano <davide.italiano@gmail.com>
To:        Paul Albrecht <albrecht@glccom.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: kqueue periodic timer confusion
Message-ID:  <CACYV=-FtatY9%2BN=nO9YDgw-jRs4x5Qr2L1KkGe97O8v3TgaBMA@mail.gmail.com>
In-Reply-To: <1342036332.8313.8.camel@albrecht-desktop>
References:  <1342036332.8313.8.camel@albrecht-desktop>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jul 11, 2012 at 9:52 PM, Paul Albrecht <albrecht@glccom.com> wrote:
>
> Hi,
>
> Sorry about this repost but I'm confused about the responses I received
> in my last post so I'm looking for some clarification.
>
> Specifically, I though I could use the kqueue timer as essentially a
> "drop in" replacement for linuxfd_create/read, but was surprised that
> the accuracy of the kqueue timer is much less than what I need for my
> application.
>
> So my confusion at this point is whether this is consider to be a bug or
> "feature"?
>
> Here's some test code if you want to verify the problem:
>
> #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;
> }
>
>
> --
> Paul Albrecht
>
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"

Hi.
As I told you before I'm currently working on this problem.
I wrote a testcase myself, you can find it here:
http://people.freebsd.org/~davide/kqueue/kevent_test.c
As part of my callout(9) rewriting work I've recently converted
kqueue(9) in order to exploit the precision allowed by the new backend
and exposed to consumers via the new interface
(callout_reset_bt_on()).
I ran my testcase and these are the results over 100 iterations:
http://people.freebsd.org/~davide/kqueue/kqueue_res.png
(red line-> old, green line -> new). It seems there's some
improvement, at least for now.

If you want to give it a try checkout the projects/calloutng branch
and apply the following patch
http://people.freebsd.org/~davide/kqueue/kqueue_calloutng.diff (still
in an early stage, if there are some issues, feel free to report
them).

Davide



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACYV=-FtatY9%2BN=nO9YDgw-jRs4x5Qr2L1KkGe97O8v3TgaBMA>