~ubuntu-branches/ubuntu/trusty/pm-utils/trusty-updates

« back to all changes in this revision

Viewing changes to pm/power.d/laptop-mode

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl, Michael Biebl, Martin Pitt
  • Date: 2010-07-13 16:24:27 UTC
  • mfrom: (40.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20100713162427-vpmf1kkj79e715j0
[ Michael Biebl ]
* New upstream release. (Closes: #588587)
  The main improvement is that this ships some generally useful power
  management hooks by default. Note that this conflicts with similar
  packages such as laptop-mode-tools or pm-utils-powersave-policy, so you
  should not enable them and pm-utils at the same time.
  Current hooks when switching to battery:
  - [disable_wol] Disable Wake-on-LAN on ethernet cards
  - [hal-cd-polling] Disable HAL's polling of CD drives for automounting
    them. Note that this HAL functionality is already obsolete in Debian's
    current GNOME, but still being used in current KDE and XFCE desktops.
  - [harddrive] More aggressive harddrive spindown times
  - [intel-audio-powersave] Put ac97 and hda cards to sleep when inactive.
  - [journal-commit, xfs_buffer] Delay ext[34]/ext journal/metadata
    writeback
  - [laptop-mode] Delay hard disk writeback times of dirty caches, to avoid
    spin ups
  - [pcie_aspm] PCI express cards power saving
  - [readahead] More speculative readahead, at the expense of using more
    memory
  - [sata_alpm] Enable SATA link power management
  - [sched-powersave] Try to use fewer cores on multi-core machines
  - [wireless] Reduce RX/TX power when idle on some known-working drivers
    (various Intel chips for now)
* video-quirks/*
  - Update quirks to latest upstream release pm-quirks-20100619.
* Drop patches applied upstream
  - debian/patches/05-inspiron-8600-ati-quirk.patch
  - debian/patches/08-fix-lock-file-handling.patch
  - debian/patches/12-man-page-fixes.patch
* Refresh and update all patches so they apply cleanly.
* debian/control
  - Demote radeontool to Suggests. The standard Debian/Ubuntu kernels use
    KMS for radeon which makes this tool obsolete. (Closes: #588768)

[ Martin Pitt ]
* debian/control: Add hdparm Recommends and ethtool/wireless-tools Suggests,
  for the newly added power saving hooks.
* debian/control: Conflicts/Replaces: pm-utils-powersave-policy, superseded
  by the now integrated power.d hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
. "${PM_FUNCTIONS}"
 
4
 
 
5
VM="/proc/sys/vm"
 
6
vmfiles="laptop_mode dirty_ratio dirty_background_ratio 
 
7
         dirty_writeback_centisecs"
 
8
 
 
9
LAPTOP_MODE=${LAPTOP_MODE:-5}
 
10
LAPTOP_DIRTY_RATIO=${LAPTOP_DIRTY_RATIO:-60}
 
11
LAPTOP_DIRTY_BG_RATIO=${LAPTOP_DIRTY_BG_RATIO:-40}
 
12
LAPTOP_DIRTY_WRITEBACK=${LAPTOP_DIRTY_WRITEBACK:-60000}
 
13
 
 
14
help() {
 
15
    cat <<EOF
 
16
--------
 
17
$0: Laptop mode tuning parameters.
 
18
This hook controls how agressive the system is at trying to avoid
 
19
writing to disk.  The longer the disk is idle, the more power you can save.
 
20
 
 
21
This hook is only active on battery power, and it restores these values
 
22
to kernel defaults when on AC power.
 
23
 
 
24
It has 4 tuneable parameters: 
 
25
LAPTOP_MODE = value for laptop_mode on battery.
 
26
Defaults to 5, which enables laptop mode and forces the system to wait 
 
27
5 seconds whenever something asks to write to disk to flush out as much
 
28
data as we can.
 
29
 
 
30
LAPTOP_DIRTY_RATIO = the ratio of dirty memory to all memory that 
 
31
processes start doing their own writeout.  
 
32
Defaults to 60, which means that the kernel will not start forcing process
 
33
to write out file information that has been changed but not saved until 60%
 
34
of usable system memory is filled with dirty information.
 
35
 
 
36
LAPTOP_DIRTY_BG_RATIO = The ratio of dirty memory to all memory that 
 
37
pdflush will wake up and start writing to disk.  
 
38
Defaults to 40, which means that the kernel will wake up a helper process
 
39
to try and write out dirty memory once 40% of usable system memory is dirty.
 
40
 
 
41
LAPTOP_DIRTY_WRITEBACK = The number of centiseconds between periodic
 
42
wakeups of the pdflush daemons.  
 
43
Defaults to 60000 (10 minutes), which menas that the kernel will flush dirty
 
44
memory every 10 minutes if dirty memory never hits 40% of system memory.
 
45
 
 
46
EOF
 
47
}
 
48
 
 
49
[ -w $VM/laptop_mode -a -w $VM/dirty_ratio ] || exit $NA
 
50
 
 
51
read_values() {
 
52
    for f in $vmfiles; do
 
53
        [ -r "$VM/$f" ] && cat "$VM/$f" || echo 0
 
54
    done
 
55
}
 
56
 
 
57
write_values() {
 
58
    for f in $vmfiles; do
 
59
        [ -w "$VM/$f" ] && echo $1 > "$VM/$f"
 
60
        shift
 
61
    done
 
62
}
 
63
 
 
64
laptop_mode_ac() {
 
65
    # disable laptop mode, set vm parameters back to sane defaults
 
66
    if state_exists laptop_mode_default; then
 
67
        write_values $(restorestate laptop_mode_default)
 
68
    else
 
69
        write_values 0 10 5 500
 
70
    fi  
 
71
    echo "Laptop mode disabled."
 
72
}
 
73
 
 
74
laptop_mode_battery() {
 
75
    # enable laptop mode, set vm parameters to buffer as many writes as 
 
76
    # possible.
 
77
    state_exists laptop_mode_default || \
 
78
        read_values | savestate laptop_mode_default
 
79
    write_values "$LAPTOP_MODE" "$LAPTOP_DIRTY_RATIO" \
 
80
        "$LAPTOP_DIRTY_BG_RATIO" "$LAPTOP_DIRTY_WRITEBACK"
 
81
    echo "Laptop mode enabled."
 
82
}
 
83
 
 
84
case $1 in
 
85
    true) laptop_mode_battery ;;
 
86
    false) laptop_mode_ac ;;
 
87
    help) help;;
 
88
    *) exit $NA ;;
 
89
esac
 
90
 
 
91
exit 0