linux调度程序线程实际的睡眠时间

时间:2021-11-09 02:13:08

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

对于在MV Linux下运行的应用程序,我有一个必须每10毫秒激活一次的线程。当我使用ulseep / nanosleep / select时,线程每20 ms返回一次。我必须使用哪些内核参数才能改变这种行为?谢谢,拉菲

1 个解决方案

#1


-1  

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.

Linux不是一个实时操作系统。无法保证睡眠的精确度。当您调用sleep时,线程将被挂起,并且在请求的持续时间过去之前无法运行。当它再次可运行时,由调度程序在某些执行时间可用时再次运行该线程。

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.

调度事件之间的间隔由内核编译参数CONFIG_HZ确定。例如,当CONFIG_HZ = 250(默认值)时,每1s / 250Hz = 4ms触发调度事件。因此,当您的线程再次可运行时,在实际恢复之前可以经过最多4毫秒,如果您的线程当时没有最高优先级,则等待4毫秒,等等。

#1


-1  

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.

Linux不是一个实时操作系统。无法保证睡眠的精确度。当您调用sleep时,线程将被挂起,并且在请求的持续时间过去之前无法运行。当它再次可运行时,由调度程序在某些执行时间可用时再次运行该线程。

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.

调度事件之间的间隔由内核编译参数CONFIG_HZ确定。例如,当CONFIG_HZ = 250(默认值)时,每1s / 250Hz = 4ms触发调度事件。因此,当您的线程再次可运行时,在实际恢复之前可以经过最多4毫秒,如果您的线程当时没有最高优先级,则等待4毫秒,等等。