nanosleep high cpu usage?

谁说我不能喝 提交于 2019-11-30 07:34:34

This is due to the introduction of NO_HZ into the mainline scheduler.

Previously, your 1,000 ns sleep was usually sleeping for a whole tick - 1,000,000 ns. Now, when the machine is otherwise idle, it's actually only sleeping for what you asked for. So it's running the while() loop and syscall around 1,000 times more frequently - hence a lot more CPU usage. If you increase tv_nsec you should see a reduction in the CPU usage.

I don't have a definitive answer... but the first thing I would look at is the config options with which the kernel was compiled:

cat /boot/config-`uname -r`

Options that I think might be relevant are CONFIG_HZ, CONFIG_HPET_TIMER and CONFIG_HIGH_RES_TIMERS. Maybe those differ among your kernels... that might help you narrow it down.

It used to be on 2.4 kernels that nanosleep would busy-wait for waits of under 2 ms if running under real-time scheduler policies (SCHED_FIFO or SCHED_RR, see the nanosleep man page), but since all of the kernels are 2.6, that doesn't seem to be a factor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!