Xen and Power Saving
by BenV on Sep.01, 2009, under Software
Or more specific: CPU frequency scaling.
On my laptop this is one of the first things I enabled to make my battery last longer.
Now that we’re going to put a server in a rack where they will bill us depending on the amount of power consumed, this sounds like a welcome thing to have enabled.
Our latest Xen install has Xen 3.4, on which they’ve enabled it by default. Isn’t that nice?
So basically, if your processor etc is good enough to support it, you can mess around with it using the xenpm tool.
For instance we can check the parameters for CPU 0 like this:
root@xenbro:~# xenpm get-cpufreq-para 0
cpu id : 0
affected_cpus : *0 1 2 3
cpuinfo frequency : max [2600000] min [800000] cur [800000]
scaling_driver :
scaling_avail_gov : userspace performance powersave ondemand
current_governor : ondemand
ondemand specific :
sampling_rate : max [10000000] min [10000] cur [20000]
up_threshold : 80
scaling_avail_freq : 2600000 1900000 1400000 *800000
scaling frequency : max [2600000] min [800000] cur [800000]
As you can see, it’s very much like the whole cpufreq ordeal. It has an ondemand governor, a powersave one, etc. Right now this CPU is using the ondemand governor, which will ramp up the clock when demand increases.
However, since this is a quad core and not a real quad processor machine we can only change the governor for all 4 cores at the same time, not for individual ones. (would be cool to have 1 core burning away power while the rest idles by….).
Anyway, the xenpm tool allows us to monitor and change various aspects of this.
For instance this will do a little benchmark and show the processor states during the benchmark.
root@xenbro:~# xenpm start 10
Timeout set to 10 seconds
Start sampling, waiting for CTRL-C or SIGINT or SIGALARM signal ...
Elapsed time (ms): 10003
CPU0: Residency(ms) Avg Res(ms)
C0 49 ( 0.50%) 0.04
C1 9953 (99.50%) 7.19
Avg freq 800000 KHz
CPU1: Residency(ms) Avg Res(ms)
C0 13 ( 0.14%) 0.07
C1 9989 (99.86%) 48.49
Avg freq 800000 KHz
CPU2: Residency(ms) Avg Res(ms)
C0 83 ( 0.83%) 0.21
C1 9919 (99.17%) 25.05
Avg freq 800000 KHz
CPU3: Residency(ms) Avg Res(ms)
C0 28 ( 0.28%) 0.10
C1 9973 (99.72%) 33.92
Avg freq 800000 KHz
As you can see my processor is mostly idle.
State C0 is the most active state, C1 is sleeping with use of the HLT instruction.
Your processor can have many more states, like my laptop which has 4.
Anyway, I put the change to ondemand governor in my /etc/rc.d/rc.local, so let’s hope it helps.
To read some more about the details of this stuff you can check out the Xenpm wiki page.
March 4th, 2011 on 11:37
I let the dom0 handle the cpufreq. I’ve just got an error “xen cpufreq is not enabled!” when I issue “xenpm get-cpufreq-para 0”. I use 4.0.0.1 xen kernel and 2.6.34-1 dom0 kernel with opensuse 11.3 distribusion.
could you please explain what the problem stems from?
any help would be appriciated.
March 5th, 2011 on 12:15
@armin00: Try booting xen with cpufreq=xen as boot parameter for xen.
March 15th, 2011 on 05:37
@BenV: Why does the dom0-base cpufreq fail? How can I fix it? I want to control power in userspace.
March 15th, 2011 on 11:16
@armin00: How should I know?
Boot with cpufreq=xen, then “control power in userspace” as you say using the xenpm tool. If you don’t tell me anything I can’t help.