Even though I run a Desktop, I do whatever I can to save electricity. Turning off the monitor helps a great deal. Then there's
CPU frequency scaling. But when I set my machine to "ondemand", I noticed a marginal drop in performance, especially when playing a game or something. So I kept my machine on "performance", and set it to "ondemand" only when I had to leave the PC unattended for a while. Needless to say, it was quite a pain in the butt. So I made a shellscript to automate the process. Whenever my screen is locked, the script will turn CPU frequency governor to "ondemand"
#!/bin/bash
#Script to put the cpu in "ondemand" if the screen is locked
check=`pidof kdesktop_lock`
if [[ -n $check ]] ; then
/usr/bin/cpufreq-set -g ondemand
else
/usr/bin/cpufreq-set -g performance
fi
exit 0
Then I added a task to my root crontab:
0,10,20,30,40,50 * * * * root /usr/bin/freqmod.sh
where /usr/bin/freqmod.sh is the path to the script.
This is my first "real" bash script, so suggestions are welcome :)