[Ilugc] Scrpit for automatic CPU frequency scaling

  • From: bhargavprasanna@xxxxxxxxx (Bhargav Prasanna)
  • Date: Sun Apr 11 14:27:05 2010

Hi,

I was lazing around this morning when I thought I could do something fun.
The result is the bash script below. I'm a beginner to bash scripting. The
script uses temperature and AC adapter information from /proc/acpi to scale
frequency using cpufrequtils. This is, assuming that cpufrequtils has
already been configured with three governors - performance, ondemand and
powersave.
I did a chown root <script-name>.sh to give it root permissions.

Please let me know if I can do more with this. I want to try and improve it
(just for fun though).

---------

#! /bin/bash

ACPI=/proc/acpi
interval=5
ond='sudo cpufreq-set -r -g ondemand'
psv='sudo cpufreq-set -r -g powersave'
per='sudo cpufreq-set -r -g performance'

        thermometer()
        { # output list of temperatures
        read X Y < $ACPI/thermal_zone/TZ01/temperature
        echo ${Y:0:2};
        }

        acad() { # output the AC Adapter state
        read X Y < $ACPI/ac_adapter/ACAD/state
        echo $Y;
        }

        while true; do
        temp=`thermometer`
        adapter=`acad`
        if [[ $adapter = 'on-line' ]]; then
               if [[ $temp -ge 60 ]]; then
               $ond &
               else
               $per &
               fi
        fi
        if [[ $adapter = 'off-line' ]]; then
        $psv &
        fi
        sleep $interval
        done

---------

Thanks.

-- 
Bhargav Prasanna
"Linux - Because x64 is a terrible thing to waste"

Other related posts:

  • » [Ilugc] Scrpit for automatic CPU frequency scaling - Bhargav Prasanna