public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Short sleep precision
@ 2005-03-20 12:25 Jan Engelhardt
  2005-03-20 12:44 ` Jesper Juhl
  2005-03-20 13:04 ` Andrew Morton
  0 siblings, 2 replies; 8+ messages in thread
From: Jan Engelhardt @ 2005-03-20 12:25 UTC (permalink / raw)
  To: linux-kernel

Hello,


I have found that FreeBSD has a very good precision of small sleeps --
what's holding Linux back from doing the same? Using the code snippet below, 
FBSD yields between 2 and 80 us on the average while Linux is at 
"constantly" ~100 (with HZ=1000) and ~1000 (HZ=100).


Jan Engelhardt
-- 

#include <sys/time.h>
#include <stdio.h>
#include <time.h>
#define MICROSECOND 1000000
static unsigned long calc_ovcorr(unsigned long ad, int rd) {
    struct timespec s = {.tv_sec = 0, .tv_nsec = ad};
    struct timeval start, stop;
    unsigned long av = 0;
    int count = rd;

    while(count--) {
        gettimeofday(&start, NULL);
        nanosleep(&s, NULL);
        gettimeofday(&stop, NULL);
        av += MICROSECOND * (stop.tv_sec - start.tv_sec) +
         stop.tv_usec - start.tv_usec;
    }

    av /= rd;
    fprintf(stderr, " %lu us\n", av);
    return av;
}

int main(void) {
    calc_ovcorr(0, 100);
    return 0;
}

//eof

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-03-22 15:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-20 12:25 Short sleep precision Jan Engelhardt
2005-03-20 12:44 ` Jesper Juhl
2005-03-20 13:34   ` Jan Engelhardt
2005-03-21 16:35     ` Chris Friesen
2005-03-22  2:46       ` Robert White
2005-03-22  7:46       ` Jan Engelhardt
     [not found]         ` <424036AE.1040404@nortel.com>
2005-03-22 15:19           ` Jan Engelhardt
2005-03-20 13:04 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox