VectorLinux
November 23, 2014, 02:50:44 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: How to switch cpu freq depending on battery/ac (w/ vcpufreq)  (Read 2132 times)
wcs
Packager
Vectorian
****
Posts: 1144


« on: March 08, 2009, 12:43:50 pm »

With laptops, I found myself going to vcpufreq often, usually to put it in "ondemand" when on battery, and sometimes "performance" when on AC power. Not that "ondemand" doesn't do the job properly, but you might want it to go at full speed all the time.

A way to automate something like this is to create a script that checks the current state (battery or AC) and asks vcpufreq to go into the desired cpu frequency mode.

I put the following in a file called acpicpu:
Code:
#!/bin/sh                                                                                                                         
status=$(grep -o off-line /proc/acpi/ac_adapter/ACAD/state)
                                                                                                                             
if [ "$status" = "off-line" ]
then
              sed -i 's|\(Setting.ScalingGov=\).*|\1"ondemand"|' /etc/vcpufreq.conf
              /sbin/vcpufreq-loader.gambas
else   
              sed -i 's|\(Setting.ScalingGov=\).*|\1"performance"|' /etc/vcpufreq.conf
              /sbin/vcpufreq-loader.gambas
fi

Line number 2 is checking if the power cable is connected or not. You should change this to the right directory in your system (some have AC, I think, rather than ACAD). Also check if the state file says "off-line" when on battery.

The other lines then replace whatever governor is currently in vcpufreq's configuration file to what you desire when on battery or not: here it changes to "ondemand" when off-line (i.e, battery) and "performance" otherwise (i.e., cable). Then vcpufreq is called to change to the new configuration.

As root, I copied this new file to /usr/local/bin, and changed its permissions so that only root can execute it:
Code:
chmod u+x /usr/local/bin/acpicpu

A way to automate this when plugging or unplugging the power cable is to create another file with the following:
Code:
event=battery.*
action=/usr/local/bin/acpicpu

I copied this file inside /etc/acpi/events/ and called it cpu (though it can have any other name).

Finally, I wanted to have this run on boot, rather than having vcpufreq go with the previous configuration. That is, I wanted the right cpu governor when I boot the laptop with the cable on or off.

So I clicked "load on boot" in vcpufreq, but changed /etc/rc.d/rc.local.
Instead of this line at the end of rc.local:
Code:
/sbin/vcpufreq-loader.gambas

I commented the vcpufreq line and call the new script instead:
Code:
# vcpufreq is called by the acpiscript, according to AC state
#/sbin/vcpufreq-loader.gambas
/usr/local/bin/acpicpu

If you do all 3 steps, you can still use vcpufreq to change the governor manually.
Just remember that the governor will automatically change if the cable is plugged or unplugged, and your next configuration on boot will depend on whether you're running on battery and not on the last configuration you chose in vcpufreq.

Also, for this stuff to work, make sure the acpi daemon is running (VasmCC > Hardware > Hardware Set).

EDIT: To be fair, I don't find much use in running in "perfomance" whenever I'm on AC power. It has the disadvantage of making my fan spin much louder. The governors can be changed, though. Say, "ondemand" when on AC, and "powersave" when on battery. Just adjust the acpicpu script above.
« Last Edit: March 08, 2009, 12:56:15 pm by wcs » Logged
Joe1962
Administrator
Vectorian
*****
Posts: 2499



WWW
« Reply #1 on: March 10, 2009, 07:14:31 am »

This is very cool wcs! I will give some thought, time permitting, to integrating this in vcpufreq.
Logged

O'Neill (RE the Asgard): "Usually they ask nicely before they ignore us and do what they damn well please."
http://joe1962.bigbox.info
Running: VL 7 Std 64 + self-cooked XFCE-4.10
wcs
Packager
Vectorian
****
Posts: 1144


« Reply #2 on: March 10, 2009, 08:58:55 am »

Quote
This is very cool wcs! I will give some thought, time permitting, to integrating this in vcpufreq.

That's great!
Thanks, Joe.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!