Difference between revisions of "ACPI action script for battery events"

From ThinkWiki
Jump to: navigation, search
(updated the script)
Line 3: Line 3:
  
 
  #!/bin/sh
 
  #!/bin/sh
# I' using this on FC2 and FC3
+
# Tried on Gentoo
# cpu throttling off as FC does thisout-of-the-box
+
# cpu throttling is in here it is the cpufreq-set lines
# turning swap off is only for those that feel comfortable
+
# turning swap off is only for those that feel comfortable
# doing something this nasty.
+
# doing something this nasty.
#
+
# comment out the laptop_mode line if you don't have it installed
# pcfe, 2004-11-15
+
# pcfe, 2008-10-28
                                                                                                                                     
+
                                                                                                                                   
# cpu throttling
+
# cpu throttling
# cat /proc/acpi/processor/CPU0/throttling for more info
+
# cat /proc/acpi/processor/CPU0/throttling for more info
ACAD_THR=0
+
ACAD_THR=0
BATT_THR=2
+
BATT_THR=2
 +
                                                                                                                                   
 +
# spindown time for HD (man hdparm for valid values)
 +
# I prefer 2 hours for acad and 2 min for batt
 +
ACAD_HD=244
 +
BATT_HD=24
 +
                                                                                                                                   
 +
# Power management level
 +
# 255 (off) on AC
 +
# 128 (medium) on batt
 +
# lowered to 32, pcfe, 2004-06-23
 +
# upped to 64, pcfe, 2004-07-14
 +
# upped to 96, pcfe, 2004-10-20
 +
ACAD_PM=255
 +
BATT_PM=96
 +
                                                                                                                                   
 +
# ac/battery event handler
 +
                                                                                                                                   
 +
status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/AC/state`
 
                                                                                                                                      
 
                                                                                                                                      
# spindown time for HD (man hdparm for valid values)
+
if [ "$status" = "off-line" ]
# I prefer 2 hours for acad and 2 min for batt
+
then
ACAD_HD=244
+
              logger "Running /sbin/laptop_mode stop"
BATT_HD=24
+
              /sbin/laptop_mode stop
                                                                                                                                   
+
              logger "Setting HD spindown for AC mode with hdparm -S $ACAD_HD /dev/hda."
# Power management level
+
              /sbin/hdparm -S $ACAD_HD /dev/hda > /dev/null 2>&1
# 255 (off) on AC
+
              logger "Setting HD powersaving for AC mode with hdparm -B $ACAD_PM /dev/hda."
# 128 (medium) on batt
+
              /sbin/hdparm -B $ACAD_PM /dev/hda > /dev/null 2>&1
# lowered to 32, pcfe, 2004-06-23
+
              logger "Turning on swap."
# upped to 64, pcfe, 2004-07-14
+
              /sbin/swapon -a
# upped to 96, pcfe, 2004-10-20
+
      /usr/bin/cpufreq-set -g conservative          
ACAD_PM=255
+
else 
BATT_PM=96
+
              logger "Turning off swap."
                                                                                                                                   
+
              /sbin/swapoff -a
# ac/battery event handler
+
              logger "Running /sbin/laptop_mode start"
                                                                                                                                   
+
              /sbin/laptop_mode start
status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/AC/state`
+
              logger "Setting HD spindown for battery mode with hdparm -S $BATT_HD /dev/hda."
                                                                                                                                     
+
              /sbin/hdparm -S $BATT_HD /dev/hda > /dev/null 2>&1
case $status in
+
              logger "Setting HD powersaving for battery mode with hdparm -B $BATT_PM /dev/hda."
        "on-line")
+
              /sbin/hdparm -B $BATT_PM /dev/hda > /dev/null 2>&1
                logger "Running /sbin/laptop_mode stop"
+
              /usr/bin/cpufreq-set -g ondemand
                /sbin/laptop_mode stop
+
fi
                logger "Setting HD spindown for AC mode with hdparm -S $ACAD_HD /dev/hda."
+
 
                /sbin/hdparm -S $ACAD_HD /dev/hda > /dev/null 2>&1
+
                logger "Setting HD powersaving for AC mode with hdparm -B $ACAD_PM /dev/hda."
+
                /sbin/hdparm -B $ACAD_PM /dev/hda > /dev/null 2>&1
+
                #logger "Turning on swap."
+
                #/sbin/swapon -a
+
                #echo -n $ACAD_CPU:$ACAD_THR > /proc/acpi/processor/CPU0/limit
+
                exit 0
+
         ;;
+
        "off-line")
+
                #logger "Turning off swap."
+
                #/sbin/swapoff -a
+
                logger "Running /sbin/laptop_mode start"
+
                /sbin/laptop_mode start
+
                logger "Setting HD spindown for battery mode with hdparm -S $BATT_HD /dev/hda."
+
                /sbin/hdparm -S $BATT_HD /dev/hda > /dev/null 2>&1
+
                logger "Setting HD powersaving for battery mode with hdparm -B $BATT_PM /dev/hda."
+
                /sbin/hdparm -B $BATT_PM /dev/hda > /dev/null 2>&1
+
                #echo -n $BATT_CPU:$BATT_THR > /proc/acpi/processor/CPU0/limit
+
                exit 0
+
        ;;
+
esac
+
  
 
[[Category:Scripts]]
 
[[Category:Scripts]]

Revision as of 20:24, 28 October 2008

This is an example ACPI action script that makes Power Management adjustments according to if you are on battery or on AC. Usually this is saved as /etc/acpid/actions/battery.sh.

#!/bin/sh
  1. Tried on Gentoo
  2. cpu throttling is in here it is the cpufreq-set lines
  3. turning swap off is only for those that feel comfortable
  4. doing something this nasty.
  5. comment out the laptop_mode line if you don't have it installed
  6. pcfe, 2008-10-28
  1. cpu throttling
  2. cat /proc/acpi/processor/CPU0/throttling for more info

ACAD_THR=0 BATT_THR=2

  1. spindown time for HD (man hdparm for valid values)
  2. I prefer 2 hours for acad and 2 min for batt

ACAD_HD=244 BATT_HD=24

  1. Power management level
  2. 255 (off) on AC
  3. 128 (medium) on batt
  4. lowered to 32, pcfe, 2004-06-23
  5. upped to 64, pcfe, 2004-07-14
  6. upped to 96, pcfe, 2004-10-20

ACAD_PM=255 BATT_PM=96

  1. ac/battery event handler

status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/AC/state`

if [ "$status" = "off-line" ] then

              logger "Running /sbin/laptop_mode stop"
              /sbin/laptop_mode stop
              logger "Setting HD spindown for AC mode with hdparm -S $ACAD_HD /dev/hda."
              /sbin/hdparm -S $ACAD_HD /dev/hda > /dev/null 2>&1
              logger "Setting HD powersaving for AC mode with hdparm -B $ACAD_PM /dev/hda."
              /sbin/hdparm -B $ACAD_PM /dev/hda > /dev/null 2>&1
              logger "Turning on swap."
              /sbin/swapon -a

/usr/bin/cpufreq-set -g conservative else

              logger "Turning off swap."
              /sbin/swapoff -a
              logger "Running /sbin/laptop_mode start"
              /sbin/laptop_mode start
              logger "Setting HD spindown for battery mode with hdparm -S $BATT_HD /dev/hda."
              /sbin/hdparm -S $BATT_HD /dev/hda > /dev/null 2>&1
              logger "Setting HD powersaving for battery mode with hdparm -B $BATT_PM /dev/hda."
              /sbin/hdparm -B $BATT_PM /dev/hda > /dev/null 2>&1
              /usr/bin/cpufreq-set -g ondemand

fi