The CPU idle loop is the piece of code executed by logical CPUs if they have no tasks to run. If the CPU supports idle states allowing it to draw less power while not executing any instructions, the idle loop invokes a CPU idle governor to select the most suitable idle state for the CPU and it puts the CPU into the selected idle state with the help of a CPU idle driver. Generally speaking, the idle state selection carried out by the CPU idle governor is based on predicting the duration of the idle time for the CPU, so it is not deterministic.
That turned out to be problematic due to a design issue in the CPU idle loop which tended to stop the scheduler tick prematurely and it often was stopped when there was no need to stop it. That led either to excessive overhead related to the unnecessary stopping and re-starting of the scheduler tick, or to situations in which the CPU might be put into an idle state that was to shallow and, in consequence, it might draw too much power for a relatively long time. That issue was addressed during the 4.17 kernel development cycle by redesigning the idle loop so that the scheduler tick is only stopped, if necessary, after the idle state for the CPU has been selected which involved resolving a Catch-22 dependency between the idle duration prediction by the governor and the next timer event related to the scheduler tick.
I will explain the design of the CPU idle loop in Linux and how the problem with it was fixed. I also will show some test results demonstrating the achieved improvements and I will discuss some possible future improvements in the area in question.
Rafael J. Wysocki, Intel