From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 11 22:39:52 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 819031065670 for ; Wed, 11 Jul 2012 22:39:52 +0000 (UTC) (envelope-from davide.italiano@gmail.com) Received: from mail-pb0-f54.google.com (mail-pb0-f54.google.com [209.85.160.54]) by mx1.freebsd.org (Postfix) with ESMTP id 571FF8FC0C for ; Wed, 11 Jul 2012 22:39:52 +0000 (UTC) Received: by pbbro2 with SMTP id ro2so2998446pbb.13 for ; Wed, 11 Jul 2012 15:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=MizMswMzsptw/QOCrXxSXLWh/jK8bCWWsDVJwUPuYMM=; b=F6BS1WxM78ZGDfsEWMM3akTVC+OJ1XrxnHNPfVVmHw/f+ElwfuVHushEHYIt22Og64 G+O9JoWVUZJhc9cvzXtQiD8ugxS8l5dPd/CbyspzGexmik+Gz90CBHnpKu3Rg9XT35rc s5M98VZfyzUZ+xFK8juqqt1gzzLi8aiY/G9hnMwDX8FInlVvM/t8E+xXSJpSIB9kEwUL noanyMl4gBy+HnpRPJjiW247ybpsQRHfrNbaL0lHYDOjqxRA+n5OT3dl4FpJDNEqpdGD Ehbxmd0ToAYcHek7dUyhVMu+ItIFMRn/E4T10ueeHBbAPT1tz3cN/HjPxmM33J3MRaqO G2hA== MIME-Version: 1.0 Received: by 10.66.83.69 with SMTP id o5mr85231460pay.34.1342046391899; Wed, 11 Jul 2012 15:39:51 -0700 (PDT) Received: by 10.66.82.201 with HTTP; Wed, 11 Jul 2012 15:39:51 -0700 (PDT) In-Reply-To: <1342036332.8313.8.camel@albrecht-desktop> References: <1342036332.8313.8.camel@albrecht-desktop> Date: Thu, 12 Jul 2012 00:39:51 +0200 Message-ID: From: Davide Italiano To: Paul Albrecht Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org Subject: Re: kqueue periodic timer confusion X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jul 2012 22:39:52 -0000 On Wed, Jul 11, 2012 at 9:52 PM, Paul Albrecht 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 > #include > #include > #include > #include > #include > #include > #include > > 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