For my application running under MV Linux I have a thread that has to be active every 10 ms. When I use ulseep/nanosleep/select the thread comes back every 20 ms. Which kernel parameters I have to play with in order to change this behavior? Thanks, Rafi
Asked
Active
Viewed 1,200 times
1 Answers
0
Linux is not a real-time operating system. There is no guarantee about the precision of the sleep. When you call sleep
, the thread is suspended and is not runnable until the requested duration elapses. When it's runnable again, it's up to the scheduler to run the thread again when some execution time is available.
The interval between scheduling events is determined by the kernel compilation parameter CONFIG_HZ
. For exemple when CONFIG_HZ=250
(the default), the scheduling events are triggered every 1s/250Hz = 4ms. So when your thread is runnable again, up to 4 ms can elapse before it's actually resumed, and 4 more ms if your thread didn't have the highest priority at the time, etc.

Grapsus
- 2,714
- 15
- 14
-
there are rt versions of the linux kernel, it's just that non-rt versions are way more popular than that, for example Ubuntu Studio used to provide an rt kernel, it's the only popular GNU/linux desktop distribution that I know of that does this. But the thing is, the linux kernel can be rt. – user2485710 May 13 '14 at 17:28
-
@user2485710 Linux with RT enabled won't make the sleep system call more precise. If you know what you are talking about, please post an answer with code. – Grapsus May 13 '14 at 17:31
-
your first statement is "Linux is not a real-time operating system" which is not true. – user2485710 May 13 '14 at 17:32
-
@user2485710 If OP asks this kind of questions, it means he doesn't know of RT Linux and that he's running a regular kernel. RT patchs enable Linux to do some kinds of real time tasks, but they don't make it a proper real-time OS. And even with RT patchs enabled the `sleep` system call isn't more precise. The only way to get precise delays is to monopolize a CPU and do busy-waiting. See here: http://stackoverflow.com/questions/4986818/how-to-sleep-for-a-few-microseconds So please bring your explanations instead of picking at other's people responses without fully understanding the subject. – Grapsus May 13 '14 at 21:10