nanosleep high cpu usage?

前端 未结 2 780
忘掉有多难
忘掉有多难 2020-12-30 14:51

I noticed that a little test program which calls nanosleep is showing a huge difference in CPU usage when run on Linux machines with a kernel newer than 2.6.22.



        
2条回答
  •  伪装坚强ぢ
    2020-12-30 15:16

    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.

提交回复
热议问题