Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've got a feeling that your test is very hardware dependent. When I ran your sample program on my system, it appeared to hang at 1ms. To make your test at all meaningful on my computer, I had to change from milliseconds to microseconds. (I changed the multiplier from 1_000_000 to 1_000.)</p> <pre> $ grep 1000 test.c timspec.it_interval.tv_nsec = microseconds * 1000; </pre> <pre> $ for i in 1 2 4 5 7 8 9 15 16 17\ 31 32 33 47 48 49 63 64 65 ; do\ echo "intervals of $i microseconds";\ ./test $i;done intervals of 1 microseconds 11 expirations, 0 iterations intervals of 2 microseconds 5 expirations, 0 iterations intervals of 4 microseconds 3 expirations, 0 iterations intervals of 5 microseconds 2 expirations, 0 iterations intervals of 7 microseconds 2 expirations, 0 iterations intervals of 8 microseconds 2 expirations, 0 iterations intervals of 9 microseconds 2 expirations, 0 iterations intervals of 15 microseconds 2 expirations, 7788 iterations intervals of 16 microseconds 4 expirations, 1646767 iterations intervals of 17 microseconds 2 expirations, 597 iterations intervals of 31 microseconds 2 expirations, 370969 iterations intervals of 32 microseconds 2 expirations, 163167 iterations intervals of 33 microseconds 2 expirations, 3267 iterations intervals of 47 microseconds 2 expirations, 1913584 iterations intervals of 48 microseconds 2 expirations, 31 iterations intervals of 49 microseconds 2 expirations, 17852 iterations intervals of 63 microseconds 2 expirations, 24 iterations intervals of 64 microseconds 2 expirations, 2888 iterations intervals of 65 microseconds 2 expirations, 37668 iterations </pre> <p>(Somewhat interesting that I got the longest runs from 16 and 47 microseconds, but 17 and 48 were awful.)</p> <p>time(7) has some suggestions on why our platforms are so different:</p> <pre> High-Resolution Timers Before Linux 2.6.21, the accuracy of timer and sleep system calls (see below) was also limited by the size of the jiffy. Since Linux 2.6.21, Linux supports high-resolution timers (HRTs), optionally configurable via CONFIG_HIGH_RES_TIMERS. On a system that supports HRTs, the accuracy of sleep and timer system calls is no longer constrained by the jiffy, but instead can be as accurate as the hardware allows (microsecond accuracy is typical of modern hardware). You can determine whether high-resolution timers are supported by checking the resolution returned by a call to clock_getres(2) or looking at the "resolution" entries in /proc/timer_list. HRTs are not supported on all hardware architectures. (Support is provided on x86, arm, and powerpc, among others.) </pre> <p>All the 'resolution' lines in my /proc/timer_list are 1ns on my (admittedly ridiculously powerful) x86_64 system.</p> <p>I decided to try to figure out where the 'breaking point' is on my computer, but gave up on the 110 microsecond run:</p> <pre> $ for i in 70 80 90 100 110 120 130\ ; do echo "intervals of $i microseconds";\ ./test $i;done intervals of 70 microseconds 2 expirations, 639236 iterations intervals of 80 microseconds 2 expirations, 150304 iterations intervals of 90 microseconds 4 expirations, 3368248 iterations intervals of 100 microseconds 4 expirations, 1964857 iterations intervals of 110 microseconds ^C </pre> <p>90 microseconds ran for three million iterations before it failed a few times; that's 22 times better resolution than your very first test, so I'd say that given the right hardware, 10ms shouldn't be anywhere near difficult. (90 microseconds is 111 times better resolution than 10 milliseconds.)</p> <p>But if your hardware doesn't provide the timers for high resolution timers, then Linux can't help you without resorting to SCHED_RR or SCHED_FIFO. And even then, perhaps another kernel could better provide you with the software timer support you need.</p> <p>Good luck. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload