summaryrefslogtreecommitdiff
path: root/pm
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2010-06-03 15:53:24 -0500
committerVictor Lowther <victor.lowther@gmail.com>2010-06-05 13:42:46 -0500
commit43e64366c2c5c9831c041fb571bf7e92ad3598c2 (patch)
tree92747327ac02e9a326239ae4c1f9372045bba74e /pm
parentded3b131f51ba3aa64536019c4bfb0cb7a0df58b (diff)
Add help and configurability to most of the powersave hooks.
Diffstat (limited to 'pm')
-rw-r--r--pm/power.d/harddrive77
-rw-r--r--pm/power.d/intel-audio-powersave14
-rw-r--r--pm/power.d/journal-commit22
-rw-r--r--pm/power.d/laptop-mode65
-rw-r--r--pm/power.d/readahead26
-rw-r--r--pm/power.d/xfs_buffer54
-rw-r--r--pm/sleep.d/00powersave2
7 files changed, 228 insertions, 32 deletions
diff --git a/pm/power.d/harddrive b/pm/power.d/harddrive
index 604f2ca..4bad394 100644
--- a/pm/power.d/harddrive
+++ b/pm/power.d/harddrive
@@ -2,24 +2,93 @@
[ -x /sbin/hdparm ] || exit $NA
+# Default values on AC
+DRIVE_SPINDOWN_VALUE_AC="${DRIVE_SPINDOWN_VALUE_AC:-0}"
+DRIVE_WRITE_CACHE_AC="${DRIVE_WRITE_CACHE_AC:-1}"
+DRIVE_POWER_MGMT_AC="${DRIVE_POWER_MGMT_AC:-254}"
+DRIVE_ACOUSTIC_MGMT_AC="${DRIVE_ACOUSTIC_MGMT_AC:-0}"
+
+# Default values on battery
+DRIVE_SPINDOWN_VALUE_BAT="${DRIVE_SPINDOWN_VALUE_BAT:-6}"
+DRIVE_WRITE_CACHE_BAT="${DRIVE_WRITE_CACHE_BAT:-0}"
+DRIVE_POWER_MGMT_BAT="${DRIVE_POWER_MGMT_BAT:-1}"
+DRIVE_ACOUSTIC_MGMT_BAT="${DRIVE_ACOUSTIC_MGMT_BAT:-254}"
+
+# Default devices to operate on
+DRIVE_LIST="/dev/[hs]d[a-z]"
+
+help() {
+cat <<EOF
+Hard drive Parameters we support tweaking:
+
+Drive spindown:
+DRIVE_SPINDOWN_VALUE_AC = time until a drive will spin down on AC
+Defaults to 0, which disables drive spindown.
+
+DRIVE_SPINDOWN_VALUE_BAT = time until a drive will spin down on battery
+Defaults to 6, which will spin the drive down after 30 seconds of inactivity.
+
+See the -S option on the hdparm manpage.
+
+Drive write caching:
+DRIVE_WRITE_CACHE_AC = 0 disables write cache, 1 enables it.
+Defaults to 1
+
+DRIVE_WRITE_CACHE_BAT = 0 disables write cache, 1 enables it.
+Defaults to 0
+
+See the -W option on the hdparm man page.
+
+Drive power management:
+DRIVE_POWER_MGMT_AC = Drive Advanced Power Management value on AC
+Defaults to 254 for max performance.
+
+DRIVE_POWER_MGMT_BAT = Drive Advanced Power Management value on battery
+Defaults to 1 for max power savings.
+
+See the -B option on the hdparm man page
+
+Drive acoustic management:
+DRIVE_ACOUSTIC_MGMT_AC = Drive Acoustic Management value on AC
+Defaults to 254 for max head speed.
+
+DRIVE_ACOUSTIC_MGMT_BAT = Drive Acoustic Management value on battery
+Defaults to 128 for max quietness.
+
+See the -M option on the hdparm man page.
+
+Drives to manage:
+DRIVE_LIST = the list of hard drives to manage.
+Defaults to "/dev/[hs]d[a-z]", which will manage up to the first 25 drives.
+
+EOF
+}
+
harddrive_ac () {
- for dev in /dev/[hs]d[a-z]; do
+ for dev in $DRIVE_LIST; do
# disable write caching, do not spin down the drive, disable APM
# and acoustic management, and sync everything to drive.
- hdparm -W 0 -S 0 -B 254 -M 254 -f -F $dev
+ hdparm -W $DRIVE_WRITE_CACHE_AC \
+ -S $DRIVE_SPINDOWN_VALUE_AC \
+ -B $DRIVE_POWER_MGMT_AC \
+ -M $DRIVE_ACOUSTIC_MGMT_AC $dev
done
}
harddrive_battery() {
- for dev in /dev/[hs]d[a-z]; do
+ for dev in $DRIVE_LIST; do
# disable write caching, enable acoustic management
- hdparm -W 0 -M 128 $dev
+ hdparm -W $DRIVE_WRITE_CACHE_BAT \
+ -S $DRIVE_SPINDOWN_VALUE_BAT \
+ -B $DRIVE_POWER_MGMT_BAT \
+ -M $DRIVE_ACOUSTIC_MGMT_BAT -F $dev
done
}
case $1 in
true) harddrive_battery ;;
false) harddrive_ac ;;
+ help) help;;
*) exit $NA ;;
esac
diff --git a/pm/power.d/intel-audio-powersave b/pm/power.d/intel-audio-powersave
index 3d42ae3..aa86950 100644
--- a/pm/power.d/intel-audio-powersave
+++ b/pm/power.d/intel-audio-powersave
@@ -4,15 +4,27 @@
# once the driver has been inactive for a second.
# This hook should work with at least the ac97 and hda codecs.
+INTEL_AUDIO_POWERSAVE=${INTEL_AUDIO_POWERSAVE:-true}
+
+help() {
+cat <<EOF
+Intel Audio powersave parameters:
+INTEL_AUDIO_POWERSAVE = controls whether we will try to save power on battery.
+Defaults to true.
+
+EOF
+}
+
audio_powersave() {
for dev in /sys/module/snd_*_codec/parameters/power_save; do
- [ -w $dev ] && echo $1 > $dev
+ [ -w $dev ] && [ "$INTEL_AUDIO_POWERSAVE" = "true" ] && echo $1 > $dev
done
}
case $1 in
true) audio_powersave 1 ;;
false) audio_powersave 0 ;;
+ help) help;;
*) exit $NA
esac
diff --git a/pm/power.d/journal-commit b/pm/power.d/journal-commit
index be68fed..ac43b1b 100644
--- a/pm/power.d/journal-commit
+++ b/pm/power.d/journal-commit
@@ -2,6 +2,23 @@
. ${PM_FUNCTIONS}
+JOURNAL_COMMIT_TIME_AC=${JOURNAL_COMMIT_TIME_AC:-0}
+JOURNAL_COMMIT_TIME_BAT=${JOURNAL_COMMIT_TIME_BAT:-600}
+
+help() {
+ cat <<EOF
+Journal commit time parameters:
+
+JOURNAL_COMMIT_TIME_AC = number of seconds between journal commits on AC.
+Defaults to 0, which sets the filesystem back to its default value.
+
+JOURNAL_COMMIT_TIME_BAT = number of seconds between journal commits on battery.
+Defaults to 600 (10 minutes).
+
+We currently only handle EXT3 filesystems
+EOF
+}
+
# actually remount the file system
remount_fs()
{
@@ -29,8 +46,9 @@ handle_filesystems()
}
case $1 in
- true) handle_filesystems 600 ;;
- false) handle_filesystems 5 ;;
+ true) handle_filesystems $JOURNAL_COMMIT_TIME_BAT ;;
+ false) handle_filesystems $JOURNAL_COMMIT_TIME_AC ;;
+ help) help;;
*) exit $NA ;;
esac
diff --git a/pm/power.d/laptop-mode b/pm/power.d/laptop-mode
index 62a6af4..844ac85 100644
--- a/pm/power.d/laptop-mode
+++ b/pm/power.d/laptop-mode
@@ -1,34 +1,75 @@
#!/bin/sh
+. "${PM_FUNCTIONS}"
+
VM="/proc/sys/vm"
+vmfiles="laptop_mode dirty_ratio dirty_background_ratio
+ dirty_writeback_centisecs"
+
+LAPTOP_MODE=${LAPTOP_MODE:-5}
+LAPTOP_DIRTY_RATIO=${LAPTOP_DIRTY_RATIO:-60}
+LAPTOP_DIRTY_BG_RATIO=${LAPTOP_DIRTY_BG_RATIO:-40}
+LAPTOP_DIRTY_WRITEBACK=${LAPTOP_DIRTY_WRITEBACK:-60000}
+
+help() {
+ cat <<EOF
+Laptop mode VM tuning parameters:
+
+LAPTOP_MODE = value for laptop_mode on battery.
+Defaults to 1, which enables laptop mode.
+
+LAPTOP_DIRTY_RATIO = the ratio of dirty memory to all memory that
+processes start doing their own writeout. Defaults to 60.
+
+LAPTOP_DIRTY_BG_RATIO = The ratio of dirty memory to all memory that
+pdflush will wake up and start writing to disk. Defaults to 40.
+
+LAPTOP_DIRTY_WRITEBACK = The number of centiseconds between periodic
+wakeups of the pdflush daemons. Defaults to 60000 (10 minutes).
+
+These only take place on battery. This hook will revert to the kernel
+default values on AC power.
+
+EOF
+}
[ -w $VM/laptop_mode -a -w $VM/dirty_ratio ] || exit $NA
-# only actually enable on laptops for now.
-[ "$CHASSIS_TYPE" = "Portable" ] || exit $NA
+read_values() {
+ for f in $vmfiles; do
+ [ -r "$VM/$f" ] && cat "$VM/$f" || echo 0
+ done
+}
+
+write_values() {
+ for f in $vmfiles; do
+ [ -w "$VM/$f" ] && echo $1 > "$VM/$f"
+ shift
+ done
+}
laptop_mode_ac() {
# disable laptop mode, set vm parameters back to sane defaults
- echo 0 >$VM/laptop_mode
- echo 5 >$VM/dirty_background_ratio
- echo 2999 >$VM/dirty_expire_centisecs
- echo 10 >$VM/dirty_ratio
- echo 499 >$VM/dirty_writeback_centisecs
+ if state_exists laptop_mode_default; then
+ write_values $(restorestate laptop_mode_default)
+ else
+ write_values 0 10 5 500
+ fi
}
laptop_mode_battery() {
# enable laptop mode, set vm parameters to buffer as many writes as
# possible.
- echo 1 >$VM/laptop_mode
- echo 1 >$VM/dirty_background_ratio
- echo 60000 >$VM/dirty_expire_centisecs
- echo 85 >$VM/dirty_ratio
- echo 60000 >$VM/dirty_writeback_centisecs
+ state_exists laptop_mode_default || \
+ read_values | savestate laptop_mode_default
+ write_values "$LAPTOP_MODE" "$LAPTOP_DIRTY_RATIO" \
+ "$LAPTOP_DIRTY_BG_RATIO" "$LAPTOP_DIRTY_WRITEBACK"
}
case $1 in
true) laptop_mode_battery ;;
false) laptop_mode_ac ;;
+ help) help;;
*) exit $NA ;;
esac
diff --git a/pm/power.d/readahead b/pm/power.d/readahead
index 5cae541..006034b 100644
--- a/pm/power.d/readahead
+++ b/pm/power.d/readahead
@@ -1,11 +1,30 @@
#!/bin/sh
[ -x /sbin/blockdev ] || exit $NA
-[ "$CHASSIS_TYPE" = "Portable" ] || exit $NA
# more readahead = (hopefully) less hard drive activity.
# less readahead = less trashing the page cache.
+DRIVE_READAHEAD_AC=${DRIVE_READAHEAD_AC:-256}
+DRIVE_READAHEAD_BAT=${DRIVE_READAHEAD_BAT:-3072}
+
+help() {
+ cat <<EOF
+Drive readahead parameters:
+
+DRIVE_READAHEAD_AC = Number of KB to speculatively read on AC.
+Defaults to 256 KB.
+
+DRIVE_READAHEAD_BAT = Number of KB to speculatively read on battery.
+Defaults to 3072 KB.
+
+The theory here is that we trade off the number of times we spin up a drive
+to read for potentially wasted cache if we end up not needing all the data we
+read.
+
+EOF
+}
+
readahead() {
# the intent here is to iterate through all filesystems
# mounted on a local block device. It Works For The Maintainer(tm).
@@ -17,8 +36,9 @@ readahead() {
}
case $1 in
- true) readahead 3072 ;;
- false) readahead 256 ;;
+ true) readahead "$DRIVE_READAHEAD_BAT" ;;
+ false) readahead "$DRIVE_READAHEAD_AC" ;;
+ help) help;;
*) exit $NA ;;
esac
diff --git a/pm/power.d/xfs_buffer b/pm/power.d/xfs_buffer
index e3e9ebd..ebf3384 100644
--- a/pm/power.d/xfs_buffer
+++ b/pm/power.d/xfs_buffer
@@ -3,29 +3,65 @@
. "${PM_FUNCTIONS}"
XFS="/proc/sys/fs/xfs"
+xfsfiles="age_buffer_centisecs xfssyncd_centisecs xfsbufd_centisecs"
+XFS_AGE_BUFFER=${XFS_AGE_BUFFER:-60000}
+XFS_BUFD=${XFS_BUFD:-3000}
+XFS_SYNCD=${XFS_SYNCD:-60000}
+
+help() {
+ cat <<EOF
+XFS filesystem powersaving parameters:
+
+XFS_AGE_BUFFER = How old an XFS filesystem buffer can be before it is flushed.
+Battery value defaults to 60000, or 10 minutes (600 seconds)
+
+XFS_BUFD = How often XFS will scan for dirty metadata to flush it.
+Battery value defaults to 3000, or 30 seconds.
+
+XFS_SYNCD = How often an XFS filesystem will perform other filesystem
+maintenance, Battery value defaults to 60000, or 10 minutes.
+
+These values only affect powersave on battery, on AC power the system will use
+its defaults.
+EOF
+}
+
[ -f $XFS/age_buffer_centisecs ] || exit $NA
-[ "$CHASSIS_TYPE" = "Portable" ] || exit $NA
+
+read_values() {
+ for f in $xfsfiles; do
+ [ -r "$XFS/$f" ] && cat "$XFS/$f" || echo 0
+ done
+}
+
+write_values() {
+ for f in $xfsfiles; do
+ [ -w "$XFS/$f" ] && echo $1 > "$XFS/$f"
+ shift
+ done
+}
# Why does XFS have its own parameters instead of just using the
# VM subsystem ones? Only SGI knows...
xfs_ac() {
- # don't buffer so much, flush data out regularly.
- echo 1500 >$XFS/age_buffer_centisecs
- echo 3000 >$XFS/xfssyncd_centisecs
- echo 100 >$XFS/xfsbufd_centisecs
+ if state_exists xfs_buffer_default; then
+ write_values $(restorestate xfs_buffer_default)
+ else
+ write_values 1500 3000 100
+ fi
}
xfs_battery() {
- # buffer lots
- echo 60000 >$XFS/age_buffer_centisecs
- echo 60000 >$XFS/xfssyncd_centisecs
- echo 3000 >$XFS/xfsbufd_centisecs
+ state_exists xfs_buffer_default || \
+ read_values |savestate xfs_buffer_default
+ write_values "$XFS_AGE_BUFFER" "$XFS_BUFD" "$XFS_SYNCD"
}
case $1 in
true) xfs_battery ;;
false) xfs_ac ;;
+ help) help;;
*) exit $NA ;;
esac
diff --git a/pm/sleep.d/00powersave b/pm/sleep.d/00powersave
index bf0f98b..b9b3ccd 100644
--- a/pm/sleep.d/00powersave
+++ b/pm/sleep.d/00powersave
@@ -5,7 +5,7 @@
command_exists pm-powersave || exit $NA
case $1 in
- suspend|hibernate) pm-powersave false ;;
+# suspend|hibernate) pm-powersave false ;;
resume|thaw) pm-powersave ;;
*) exit $NA ;;
esac