lkml.org 
[lkml]   [2005]   [Mar]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectShort sleep precision
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:11    [W:0.089 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site