UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / examples / onbattery.cpufreq
blob1d0c1a1899338963abe08091923ff039a6f02cb3
1 #!/bin/sh
3 # This shell script if placed in /etc/apcupsd will be
4 # called by /etc/apcupsd/apccontrol when the UPS goes
5 # on batteries.
7 # We scale the CPU clock frequency back to save power
8 # and send an email message to root to notify him.
10 # NOTE: Assumes Linux-2.6.x kernel with CPUFREQ
11 # support for your chipset. Enable appropriate
12 # modprobe line below to match your hardware.
13 SYSADMIN=root
14 APCUPSD_MAIL="/bin/mail"
16 # Load the appropriate cpufreq module. This is best done
17 # in boot scripts, but throw it here to make sure it has
18 # been done.
19 modprobe p4_clockmod
20 #modprobe cpufreq-nforce2
21 #modprobe powernow-k6
22 #modprobe powernow-k8
23 #modprobe speedstep-smi
25 # Give the cpufreq module a chance to initialize
26 sleep 1
28 # Iterate over all CPUs, enabling the userspace governor
29 # and programming the current clock speed to the minimum.
30 # This is redundant on hyperthread siblings, but it
31 # doesn't hurt anything and it keeps the code simple.
32 for CPU in /sys/devices/system/cpu/cpu*/cpufreq ; do
33 echo -n userspace > $CPU/scaling_governor
34 cat $CPU/scaling_min_freq > $CPU/scaling_setspeed
35 done
37 # Send an email to root
38 HOSTNAME=`hostname`
39 MSG="$HOSTNAME Power Failure!"
42 echo "Subject: $MSG"
43 echo " "
44 echo "$MSG"
45 echo " "
46 for CPU in `ls -1 /sys/devices/system/cpu` ; do
47 echo -n "$CPU freq scaled to "
48 cat /sys/devices/system/cpu/$CPU/cpufreq/scaling_setspeed | tr -d '\n'
49 echo " MHz"
50 done
51 echo " "
52 /sbin/apcaccess status
53 ) | $APCUPSD_MAIL -s "$MSG" $SYSADMIN
54 exit 0