Date: Wed, 21 Jul 2004 18:13:10 +1000 From: John Birrell <jb@cimlogic.com.au> To: current@freebsd.org Subject: nanosleep returning early Message-ID: <20040721081310.GJ22160@freebsd3.cimlogic.com.au>
next in thread | raw e-mail | index | archive | help
Today I increased HZ in a current kernel to 1000 when adding dummynet. Now I find that nanosleep regularly comes back a little early. Can anyone explain why? I would have expected that the *overrun* beyond the required time to vary, but never that it would come back early. ------------------ #include <stdio.h> #include <time.h> #include <sys/time.h> #include <unistd.h> int main(int argc,char *argv[]) { struct timespec rmt; struct timespec rqt; struct timeval abstime; struct timeval curtime; gettimeofday(&curtime,NULL); rqt.tv_sec = 5; rqt.tv_nsec = 50000000; abstime.tv_sec = curtime.tv_sec + rqt.tv_sec; abstime.tv_usec = curtime.tv_usec + rqt.tv_nsec / 1000; if (abstime.tv_usec >= 1000000) { abstime.tv_sec += 1; abstime.tv_usec -= 1000000; } printf("curtime %ld.%06ld\n",curtime.tv_sec,curtime.tv_usec); printf("rqt %ld.%09ld\n",(long) rqt.tv_sec,rqt.tv_nsec); if (nanosleep(&rqt,&rmt) != 0) { } else if (gettimeofday(&curtime,NULL) != 0) { } else if (curtime.tv_sec < abstime.tv_sec || (curtime.tv_sec == abstime.tv_sec && curtime.tv_usec < abstime.tv_usec)) { printf("Early: curtime %ld.%06ld abstime %ld.%06ld\n",curtime.tv_sec,curtime.tv_usec,abstime.tv_sec,abstime.tv_usec); } return(0); } ------------------ -- John Birrell
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040721081310.GJ22160>