kqueue periodic timer confusion




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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: kqueue periodic timer confusion
    ... So my confusion at this point is whether this is consider to be a bug or ... int i,msec; ... struct kevent outqueue; ... I ran my testcase and these are the results over 100 iterations: ...
    (freebsd-hackers)
  • Re: kqueue periodic timer confusion
    ... So my confusion at this point is whether this is consider to be a bug or ... struct kevent outqueue; ... That routine rounds up by one tick to ... relevant callout routine (so recording the TSC timestamp each time the callout ...
    (freebsd-hackers)
  • Re: Rewriting this magic sword - changes
    ... Confusion in 3.x isn't so good against spellcasters since they all ... this weapon: Contagion (mindfire). ... impacting the victim's INT and ...
    (rec.games.frp.dnd)
  • Re: Rewriting this magic sword - changes
    ... Confusion in 3.x isn't so good against spellcasters since they all have ... this weapon: Contagion (mindfire). ... impacting the victim's INT and ...
    (rec.games.frp.dnd)
  • Re: implicit type template warning
    ... spreading more confusion than knowledge! ... > template parameter and is thus a dependent name. ... i.e. there is no need to wait until instantiation to ... int foo = 0; ...
    (comp.lang.cpp)