#!/bin/sh
# Script to turn on or tune power-effeciency

#
# Copyright (c) 2008-2009 Carsten B. Jensen <carsten@carstenbjensen.com>
# 
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

#
# The commands used in this script is inspired by tips found at
# LessWatts.org
#
# CPU Power Managemnent
# Scale cpu frequency accourding to load (ondemand)
modprobe acpi_cpufreq
modprobe cpufreq_ondemand
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo ondemand > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
#
# Distribute processor load on multiple cores
echo 1 > /sys/devices/system/cpu/sched_mc_power_savings

# Disk power management
# Set hard drive to the most aggressive power savings mode after 60 seconds
# of idle time:
/sbin/hdparm -B 1 -S 12 /dev/sda
#
# Increase the writeback time from 500 (5 sec) to 1500 (15 seconds)
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
#
# Enable laptop-mode (optimizes the IO even more)
echo 5 > /proc/sys/vm/laptop_mode

# Disable wake-on-LAN (to check: ehttool eth0)
/usr/sbin/ethtool -s eth0 wol d

# Disable hal from pulling the cdrom
#hal-disable-pulling --device /dev/hda

# Enable power saving mode for HDA-Intel (sound)
# cat the file to check (greater than 0 = enabled)
echo 10 > /sys/module/snd_hda_intel/parameters/power_save

#------------------
# Monitor power savings (run as user) put section in ~/.xinitrc
# Reduse backlight brightness to 50%
#xbacklight -set 50
#
# Enable DPMS
#xset +dpms
# Turn off screen after 120 seconds of inactivity
#xset dpms 0 0 120
#
# Disable TV, VGA or DVI our (check with xrandr)
#xrandr --output TMDS -off
#------------------

