Short sleep precision

From: Jan Engelhardt
Date: Sun Mar 20 2005 - 07:29:03 EST


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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/