Difference between revisions of "ACPI sleep power drain test script"

From ThinkWiki
Jump to: navigation, search
Line 11: Line 11:
 
{{NOTE|This Script has some limitations:
 
{{NOTE|This Script has some limitations:
 
*It is not totally reliable, e.g. on some (all?) R32 the values ACPI reports for the battery are wrong by factor 10. They are actually reported in cWh instead of mWh. The script assumes they are reported in mWh as on most ThinkPads - hence the power consumption appearce to be only a tenth of its actual value.
 
*It is not totally reliable, e.g. on some (all?) R32 the values ACPI reports for the battery are wrong by factor 10. They are actually reported in cWh instead of mWh. The script assumes they are reported in mWh as on most ThinkPads - hence the power consumption appearce to be only a tenth of its actual value.
*The script assumes you have only one battery. If you have a second battery (for example, an UltraBay Slim battery), take it out for this test or change occurrances of "BAT0" in the script to "BAT1". If you do the latter, you will get bogus results if the second battery is run down while sleeping.
+
*The script assumes you have only one battery. If you have a second battery (for example, an UltraBay Slim battery), take it out for this test or change the BATTERY variable from "BAT0" to "BAT1". If you do the latter, you will get bogus results if the second battery is run down while sleeping.
*The usage threshold of 1000 mWh might be a bit a bit too tolerant. You can try lowering it to 500 (<tt>if [ $USAGE -gt -500 ]</tt>) to be sure.}}
+
*The usage threshold of 1000 mWh might be a bit a bit too tolerant. You can try lowering it to 500 to be sure.}}
  
 
Please save this script to a file, i.e. {{path|sleep.sh}}, make it executable ({{cmdroot|chmod +x sleep.sh}}) and execute it as root while your notebook is on battery. To get representative values you should leave the notebook suspended for at least 20 minutes.
 
Please save this script to a file, i.e. {{path|sleep.sh}}, make it executable ({{cmdroot|chmod +x sleep.sh}}) and execute it as root while your notebook is on battery. To get representative values you should leave the notebook suspended for at least 20 minutes.
Line 18: Line 18:
 
  #!/bin/sh
 
  #!/bin/sh
 
  # sleep.sh test script for measuring power drain during suspend-to-ram with ACPI
 
  # sleep.sh test script for measuring power drain during suspend-to-ram with ACPI
 +
 +
# default settings, change if needed
 +
LOG=/var/log/battery.log
 +
BATTERY=BAT0
 +
THRESHOLD=1000
 
   
 
   
 
  # remove USB for external mouse before sleeping
 
  # remove USB for external mouse before sleeping
Line 30: Line 35:
 
  fi
 
  fi
 
   
 
   
 +
# save system time
 
  hwclock --systohc
 
  hwclock --systohc
 
   
 
   
  LOG=/var/log/battery.log
+
  # get start values
 
  date >> $LOG
 
  date >> $LOG
 
  DATE_BEFORE=`date +%s`
 
  DATE_BEFORE=`date +%s`
  BAT_BEFORE=`grep 'remaining capacity' /proc/acpi/battery/BAT0/state | awk '{print $3}'`
+
  BAT_BEFORE=`grep 'remaining capacity' /proc/acpi/battery/$BATTERY/state | awk '{print $3}'`
echo "before: $BAT_BEFORE mWh" >> $LOG
+
 
   
+
  # go to sleep
 
  echo 3 > /proc/acpi/sleep
 
  echo 3 > /proc/acpi/sleep
 
   
 
   
 +
# get end values
 
  DATE_AFTER=`date +%s`
 
  DATE_AFTER=`date +%s`
  BAT_AFTER=`grep 'remaining capacity' /proc/acpi/battery/BAT0/state | awk '{print $3}'`
+
  BAT_AFTER=`grep 'remaining capacity' /proc/acpi/battery/$BATTERY/state | awk '{print $3}'`
echo "after: $BAT_AFTER mWh" >> $LOG
+
 
   
+
  # do the calculations
 
  DIFF=`echo "$BAT_AFTER - $BAT_BEFORE" | bc`
 
  DIFF=`echo "$BAT_AFTER - $BAT_BEFORE" | bc`
 
  SECONDS=`echo "$DATE_AFTER - $DATE_BEFORE" | bc`
 
  SECONDS=`echo "$DATE_AFTER - $DATE_BEFORE" | bc`
 +
USAGE=`echo "($DIFF * 60 * 60) / ($SECONDS)" | bc`
 +
 +
# output the results
 +
echo "before: $BAT_BEFORE mWh" >> $LOG
 +
echo "after: $BAT_AFTER mWh" >> $LOG
 
  echo "diff: $DIFF mWh" >> $LOG
 
  echo "diff: $DIFF mWh" >> $LOG
 
  echo "seconds: $SECONDS sec" >> $LOG
 
  echo "seconds: $SECONDS sec" >> $LOG
USAGE=`echo "($DIFF * 60 * 60) / ($SECONDS)" | bc`
 
 
  echo "result: $USAGE mW" >> $LOG
 
  echo "result: $USAGE mW" >> $LOG
  if [ $USAGE -gt -1000 ]
+
  if [ $USAGE -gt -$THRESHOLD ]
 
  then
 
  then
 
     echo "Congratulations, your model seems NOT to be affected." >> $LOG
 
     echo "Congratulations, your model seems NOT to be affected." >> $LOG
Line 63: Line 74:
 
  fi
 
  fi
 
  echo "" >> $LOG
 
  echo "" >> $LOG
   
+
 
 +
  # restore USB support
 
  if !(lsmod | grep '^ehci_hcd') >/dev/null ; then
 
  if !(lsmod | grep '^ehci_hcd') >/dev/null ; then
 
     /sbin/modprobe -s ehci_hcd
 
     /sbin/modprobe -s ehci_hcd
Line 74: Line 86:
 
  fi
 
  fi
 
   
 
   
 +
# restore system time
 
  hwclock --hctosys
 
  hwclock --hctosys
  

Revision as of 00:31, 1 August 2005

The following script will suspend your notebook to ram and output some statistics about the power drain during suspend to /var/log/battery.log. The output will look something like this:

Di Jan 11 14:01:15 CET 2005
before: 41170 mWh
after: 41000 mWh
diff: -170 mWh
seconds: 1671 sec
result: -366 mW
Congratulations, your model seems NOT to be affected.
NOTE!
This Script has some limitations:
  • It is not totally reliable, e.g. on some (all?) R32 the values ACPI reports for the battery are wrong by factor 10. They are actually reported in cWh instead of mWh. The script assumes they are reported in mWh as on most ThinkPads - hence the power consumption appearce to be only a tenth of its actual value.
  • The script assumes you have only one battery. If you have a second battery (for example, an UltraBay Slim battery), take it out for this test or change the BATTERY variable from "BAT0" to "BAT1". If you do the latter, you will get bogus results if the second battery is run down while sleeping.
  • The usage threshold of 1000 mWh might be a bit a bit too tolerant. You can try lowering it to 500 to be sure.

Please save this script to a file, i.e. sleep.sh, make it executable (# chmod +x sleep.sh) and execute it as root while your notebook is on battery. To get representative values you should leave the notebook suspended for at least 20 minutes.

#!/bin/sh
# sleep.sh test script for measuring power drain during suspend-to-ram with ACPI
# default settings, change if needed
LOG=/var/log/battery.log
BATTERY=BAT0
THRESHOLD=1000

# remove USB for external mouse before sleeping
if lsmod | grep '^usbhid' >/dev/null ; then
   /sbin/modprobe -r -s usbhid
fi
if lsmod | grep '^uhci_hcd' >/dev/null ; then
   /sbin/modprobe -r -s uhci_hcd
fi
if lsmod | grep '^ehci_hcd' >/dev/null ; then
   /sbin/modprobe -r -s ehci_hcd
fi

# save system time
hwclock --systohc

# get start values
date >> $LOG
DATE_BEFORE=`date +%s`
BAT_BEFORE=`grep 'remaining capacity' /proc/acpi/battery/$BATTERY/state | awk '{print $3}'`
# go to sleep 
echo 3 > /proc/acpi/sleep

# get end values
DATE_AFTER=`date +%s`
BAT_AFTER=`grep 'remaining capacity' /proc/acpi/battery/$BATTERY/state | awk '{print $3}'`
# do the calculations 
DIFF=`echo "$BAT_AFTER - $BAT_BEFORE" | bc`
SECONDS=`echo "$DATE_AFTER - $DATE_BEFORE" | bc`
USAGE=`echo "($DIFF * 60 * 60) / ($SECONDS)" | bc`
# output the results
echo "before: $BAT_BEFORE mWh" >> $LOG
echo "after: $BAT_AFTER mWh" >> $LOG
echo "diff: $DIFF mWh" >> $LOG
echo "seconds: $SECONDS sec" >> $LOG
echo "result: $USAGE mW" >> $LOG
if [ $USAGE -gt -$THRESHOLD ]
then
    echo "Congratulations, your model seems NOT to be affected." >> $LOG
else
    echo "Your model seems to be affected." >> $LOG
fi
if [ $SECONDS -lt 1200 ]
then
    echo "!!! The notebook was suspended less than 20 minutes." >> $LOG
    echo "!!! To get representative values please let the notebook sleep" >> $LOG
    echo "!!! for at least 20 minutes." >> $LOG
fi
echo "" >> $LOG
# restore USB support 
if !(lsmod | grep '^ehci_hcd') >/dev/null ; then
   /sbin/modprobe -s ehci_hcd
fi
if !(lsmod | grep '^uhci_hcd') >/dev/null ; then
   /sbin/modprobe -s uhci_hcd
fi
if !(lsmod | grep '^usbhid')   >/dev/null ; then
   /sbin/modprobe -s usbhid
fi

# restore system time
hwclock --hctosys

The script was originally written by Jan-Hendrik Benter and was modified a little for this page.