15

I have a server that, as of the upgrade to 10.04, is now running the "ondemand" CPU scaling daemon. Why would it automatically install this? I don't want my server saving power at the expense of performance.

  • 5
    You're mistaking the ondemand governor for the powersave one. – Leon Nardella Sep 9 '10 at 22:42
  • 3
    Agreed with Leon. Ondemand speeds up if there's something to do and slows down if it's idling. It does not restrict the CPU's ability to change speeds, but rather takes advantage of it. – maco Sep 10 '10 at 0:15
  • Possible Duplicate askubuntu.com/questions/285434/… – Qasim Jun 14 '13 at 14:58
  • It increases response times on a mostly idle server. – A Student at a University Jul 3 '14 at 11:50
33

Ubuntu prior to 18.04

Instead of disabling execution of the /etc/init.d/ondemand (as suggested by George) script you should use the this command

sudo update-rc.d ondemand disable

To make the init system not start the script, this is the recognized way of doing it! Disabling the exec permission (sudo chmod -x /etc/init.d/ondemand) might be overwritten if the package is updated.

Ubuntu 18.04+

Ubuntu relocated this script to ondemand.service which execute /lib/systemd/set-cpufreq; use this command to disable the service

~$ sudo systemctl disable ondemand
Removed /etc/systemd/system/multi-user.target.wants/ondemand.service.
| improve this answer | |
  • If I do : sudo update-rc.d other_governor enable , will it set a permanent desired governor ? – userDepth Mar 22 '16 at 17:25
5

Frequency scaling isn't static. As soon as there is work to do, the CPU hops into action, P states boost up, and everything flies.

It's enabled because it's widely seen as a good thing. Saves you energy (good for your wallet and the environment). Keeps heat down (so important in a server room). And it's pretty unnoticeable.

Moreover on modern Intel chips, if you have scaling on you can use "turbo boost" where one core will run at higher-than-stock speeds for a time. This is very useful for spikes of single-threaded work. Without scaling enabled, you don't get this.

| improve this answer | |
  • How long does it take ondemand to scale up on a P4 Xeon? – A Student at a University Sep 27 '11 at 13:45
  • Came across this old answer and while I agree with Oli, there are specific user cases where you would want to disable CPU scaling - Audio recording for example. Unless you have a specific need, leave it at ondemand – Panther Mar 22 '16 at 17:14
  • By chance is there a way to know which process is constantly changing min/max values of frequency scaling? It always changes and I don't know why. see askubuntu.com/questions/800797/how-to-enable-turbo-boost – Sebastien Lorber Jul 20 '16 at 17:29
3

Set all CPUs to performance governor:

for GOVERNOR in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; \
do \
    echo "performance" | sudo tee $GOVERNOR; \
done

All supported governors by Linux kernel:

  • performance Run the CPU at the maximum frequency.
  • powersave Run the CPU at the minimum frequency.
  • userspace Run the CPU at user specified frequencies.
  • ondemand Scales the frequency dynamically according to current load. Jumps to the highest frequency and then possibly back off as the idle time increases.
  • conservative Scales the frequency dynamically according to current load. Scales the frequency more gradually than ondemand.
  • schedutil Scheduler-driven CPU frequency selection

See https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt

| improve this answer | |
2

On some systems, the 'ondemand' governor is unfortunately broken.

This is the case for "Intel(R) Core(TM)2 Quad CPU Q9300 @ 2.50GHz" and kernel 2.6.32-42.

The kernel thinks it can set the frequency individually for each CPU while the hardware actually only allows setting the frequency on groups of several CPUs (e.g. CPU 0 and 1 together, and CPU 2 and 3 together).

You may find out that the kernel isn't aware of this by looking at the /sys/devices/system/cpu/cpu*/cpufreq/affected_cpus files which contain "0", "1", "2", "3" instead of "0 1", "0 1", "2 3", "2 3".

The visible effect of this missmatch is a single-threaded process that starts running full speed on one CPU (the 'ondemand' governor reacts fast), and then, after about 20 seconds (depends on setting details), looses some of its speed.

The reason is the OS, with the 'ondemand' governor, periodically reapplies low freqs on the idle CPUs, not expecting that it will also implicitly change the freq of our busy CPU. It's not even visible when you look at /sys/devices/system/cpu/cpu*/cpufreq/*cur_freq or /proc/cpuinfo, the OS is just not aware of it!

So, on these systems the solution is to switch back to the simple 'performance' governor.

PS: In my case, running the CPUs constantly at their full freq didn't change anything concerning fan noise. I suppose when a CPU is idling, a lower or higher frequency will not have much impact on its power usage.

| improve this answer | |
2

You could install the rcconf debian tool:

sudo apt-get install rcconf

then disable the "ondemand" service from there.

| improve this answer | |
  • I can't find any deprecation warning about the rcconf tool: you are missing the point and provided a completely wrong URL. I didn't mean Arch's way of configuring rc scripts, but rather the debian tool and that looks alive and well. – Manuel Feb 6 '13 at 16:30
  • Thanks for pointing it out and supplying a helpful link! (I deleted my initial and wrong comment) – nutty about natty Feb 6 '13 at 17:02
  • Also edited the original response! – Manuel Feb 6 '13 at 18:24
1

To make all CPUs run at maximum performance continually on a Ubuntu desktop or server, run:

sudo chmod -x /etc/init.d/ondemand

at the shell prompt and enter your password. This disables the shell script that makes all CPUs run at speed "OnDemand", making them default to full speed (Performance). You will need to reboot for this to take effect.

I have only tested this in Ubuntu Jaunty 9.04, but it should work and not cause any problems on any version of Ubuntu.

I think the Ubuntu defaults are strange for this. A desktop or server should run at full speed, in my opinion.

Regards, George

| improve this answer | |
  • 1
    I don't think it's strange. Whilst certainly mobile is the most critical scenario for power-saving, reducing power usage also means less fan noise in a desktop scenario, and less heat to deal with in a server room. Running constantly at maximum speed is a bit of a waste, only really necessary for rare cases where ondemand gets it wrong. – bobince Sep 9 '10 at 18:33
  • @bobince - You are probably right, but for a desktop I have noticed that OnDemand gives a sluggish response compared to Performance, and I think the computer can still sleep properly with the above change. It should be an option in System/Administration or System/Preferences. – George Gesslein II Sep 9 '10 at 20:36
  • Right, the only place this makes sense is on laptops where charge-time is shortened and battery-time extended by scaling the CPU. – LassePoulsen Sep 9 '10 at 22:02
  • saving the environment, anyone?? – nutty about natty Feb 3 '13 at 8:14
0

I have a new processor AMD Athlon II X4 631 (Fusion processor for socket FM1) and it doesn't save any energy whatsoever (I looked it with energy meter)! I don't have a turbo core, so I don't need ondemand setting. Most new processors save enery by themselves.

When benchmarking, there is a little difference, in the range on 1-2%, when comparing ondemand and performance setting.

| improve this answer | |
  • Welcome to AskUbuntu! You may want to back up your statements with full statistics/research as your answer could be misunderstood as an opinion rather than a researched answer. – Oyibo Nov 9 '12 at 12:32
  • This is also wrong, Apple's getting in trouble this week for slowing down devices to save power – Xen2050 Dec 22 '17 at 22:39
-1

This is old, but since no one mentioned it, and for the sake of completeness, I will add that the argument how CPU which runs on the maximum speed will waste power, produce heat, fan noise etc. is WRONG.

Almost all modern CPUs, especially Desktop / Server CPUs, will enter deep sleep mode when idle (google race to idle.).

Voltage scaling will probably save more power, so on laptops this could increase running time a little, but on desktop and servers running performance governor will be fine for most of 'normal' users (who don't run server farms or similar.).

I use performance gov with my i7-2600k and the CPU temperature is usually around 30 C.

| improve this answer | |
  • This is just wrong too. Monitor cpu temps and change frequencies to see for yourself (unless your system doesn't implement it fully/correctly). See the Apple link too, sounds like regular frequency/speed scaling – Xen2050 Dec 22 '17 at 22:55
  • @Xen2050, to see what for yourself? Do you imply that CPU which runs at 70 degrees Celsius for 2 sec, might consume more power, than one which runs 5-6 sec at 60 Degrees, or something in that direction? It is not that simple as monitoring CPU temp in particular moment. – Denis Jan 24 '18 at 0:21
  • @Xen2050 your link points to iPhone, which is totally different arch or processors. I have indicated that voltage scaling in combo with particular governor could help on laptops for example, and mentioned desktop (Workstation), and server processors explicitly, but as a matter of fact what I was talking about exist even on phones too for years now (The situation is probably more complicated in this case. A proper governor might be required for MPU to utilize particular C/P state. properly). Anyway read one more time what I have typed, and google 'race to idle' and processor deep sleep modes. – Denis Jan 24 '18 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.