LWN.net Logo

Advertisement

GStreamer, Embedded Linux, Android, VoD, Smooth Streaming, DRM, RTSP, HEVC, PulseAudio, OpenGL. Register now to attend.

Advertise here

Fixing the ondemand governor

By Jonathan Corbet
April 20, 2010
The "cpufreq" subsystem is charged with adjusting the CPU clock frequency for optimal performance. Definitions of "optimal" can vary, so there's more than one governor - and, thus, more than one policy - available. The "performance" governor prioritized throughput above all else, while the "powersave" tries to keep power consumption to a minimum. The most commonly-used governor, though, is "ondemand," which attempts to perform a balancing act between power usage and throughput.

In a simplified form, ondemand works like this: every so often the governor wakes up and looks at how busy the CPU is. If the idle time falls below a threshold, the CPU frequency will be bumped up; if, instead, there is too much idle time, the frequency will be reduced. By default, on a system with high-resolution timers, the minimum idle percentage is 5%; CPU frequency will be reduced if idle time goes above 15%. The minimum percentage can be adjusted in sysfs (under /sys/devices/system/cpu/cpuN/cpufreq/); the maximum is wired at 10% above the minimum.

This governor has been in use for some time, but, as it turns out, it can create performance difficulties in certain situations. Whenever the system workload alternates quickly between CPU-intensive and I/O-intensive phases, things slow down. That's because the governor, on seeing the system go idle, drops the frequency down to the minimum. After the CPU gets busy again, it runs for a while at low speed until the governor figures out that the situation has changed. Then things go idle and the cycle starts over. As it happens, this kind of workload is fairly common; "git grep" and the startup of a large program are a couple of examples.

Arjan van de Ven has come up with a fix for this governor which is quite simple in concept. The accounting of "idle time" is changed so that time spent waiting for disk I/O no longer counts. If a processor is dominated by a program alternating between processing and waiting for disk operations, that processor will appear to be busy all the time. So it will remain at a higher frequency and perform better. That makes the immediate problem go away without, says Arjan, significantly increasing power consumption.

But, Arjan says, "there are many things wrong with ondemand, and I'm writing a new governor to fix the more fundamental issues with it." That code has not yet been posted, so it's not clear what sort of heuristics it will contain. Stay tuned; the demand for ondemand may soon be reduced significantly.


(Log in to post comments)

Fixing the ondemand governor

Posted Apr 22, 2010 5:52 UTC (Thu) by acooks (subscriber, #49539) [Link]

Isn't this kind of load where the 'conservative' governor excels?

Fixing the ondemand governor

Posted Apr 22, 2010 7:09 UTC (Thu) by njs (guest, #40338) [Link]

Maybe (presumably it depends on the time constants), but in general the conservative governor wastes more power, so then we need a third governor to switch between ondemand and conservative depending on workload...

Fixing the ondemand governor

Posted Apr 23, 2010 16:28 UTC (Fri) by ssam (subscriber, #46587) [Link]

:-)

please call the new governors conservative, labour and liberal. then let the processes vote for which one they want, and keep it for 4 years.

Fixing the ondemand governor

Posted Apr 22, 2010 14:56 UTC (Thu) by arjan (subscriber, #36785) [Link]

Unfortunately not.
Conservative is pretty much like ondemand, just with a slower ramp up....
so it's be worse not better at this workload.

Fixing the ondemand governor

Posted Apr 22, 2010 9:10 UTC (Thu) by johnflux (guest, #58833) [Link]

What's the difference between a policy and a governor?

The difference

Posted Apr 22, 2010 12:09 UTC (Thu) by corbet (editor, #1) [Link]

A governor is the implementation of a specific policy.

Fixing the ondemand governor

Posted Apr 23, 2010 22:19 UTC (Fri) by i3839 (guest, #31386) [Link]

Why not return the processor to the speed it was before it started waiting for io? Shouldn't that fix this problem without any downsides? Basically ignore iowait for idle calculation, instead of counting it at all, that seems the most sensible solution. That solves both the spiky CPU load and low CPU load, but high iowait load.

Fixing the ondemand governor

Posted Apr 29, 2010 11:57 UTC (Thu) by daenzer (✭ supporter ✭, #7050) [Link]

This problem can also affect 3D apps, where the CPU may alternate between heavy calculations and waiting for the GPU. Will these patches help for that case, or are they strictly for disk I/O?

Copyright © 2010, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds