Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) ===============================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) How to conserve battery power using laptop-mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) ===============================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) Document Author: Bart Samwel (bart@samwel.tk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) Date created: January 2, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) Last modified: December 06, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) Introduction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) Laptop mode is used to minimize the time that the hard disk needs to be spun up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) to conserve battery power on laptops. It has been reported to cause significant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) power savings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) .. Contents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)    * Introduction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)    * Installation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)    * Caveats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)    * The Details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)    * Tips & Tricks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)    * Control script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)    * ACPI integration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)    * Monitoring tool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) Installation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) ------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) To use laptop mode, you don't need to set any kernel configuration options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) or anything. Simply install all the files included in this document, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) laptop mode will automatically be started when you're on battery. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) your convenience, a tarball containing an installer can be downloaded at:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	http://www.samwel.tk/laptop_mode/laptop_mode/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) To configure laptop mode, you need to edit the configuration file, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) located in /etc/default/laptop-mode on Debian-based systems, or in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /etc/sysconfig/laptop-mode on other systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) Unfortunately, automatic enabling of laptop mode does not work for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) laptops that don't have ACPI. On those laptops, you need to start laptop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) mode manually. To start laptop mode, run "laptop_mode start", and to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) stop it, run "laptop_mode stop". (Note: The laptop mode tools package now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) has experimental support for APM, you might want to try that first.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) Caveats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) -------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) * The downside of laptop mode is that you have a chance of losing up to 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)   minutes of work. If you cannot afford this, don't use it! The supplied ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)   scripts automatically turn off laptop mode when the battery almost runs out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)   so that you won't lose any data at the end of your battery life.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) * Most desktop hard drives have a very limited lifetime measured in spindown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)   cycles, typically about 50.000 times (it's usually listed on the spec sheet).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)   Check your drive's rating, and don't wear down your drive's lifetime if you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)   don't need to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) * If you mount some of your ext3/reiserfs filesystems with the -n option, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)   the control script will not be able to remount them correctly. You must set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)   DO_REMOUNTS=0 in the control script, otherwise it will remount them with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)   wrong options -- or it will fail because it cannot write to /etc/mtab.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) * If you have your filesystems listed as type "auto" in fstab, like I did, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)   the control script will not recognize them as filesystems that need remounting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)   You must list the filesystems with their true type instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) * It has been reported that some versions of the mutt mail client use file access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)   times to determine whether a folder contains new mail. If you use mutt and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)   experience this, you must disable the noatime remounting by setting the option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)   DO_REMOUNT_NOATIME to 0 in the configuration file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) The Details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) -----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) Laptop mode is controlled by the knob /proc/sys/vm/laptop_mode. This knob is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) present for all kernels that have the laptop mode patch, regardless of any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) configuration options. When the knob is set, any physical disk I/O (that might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) have caused the hard disk to spin up) causes Linux to flush all dirty blocks. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) result of this is that after a disk has spun down, it will not be spun up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) anymore to write dirty blocks, because those blocks had already been written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) immediately after the most recent read operation. The value of the laptop_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) knob determines the time between the occurrence of disk I/O and when the flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) is triggered. A sensible value for the knob is 5 seconds. Setting the knob to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 0 disables laptop mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) To increase the effectiveness of the laptop_mode strategy, the laptop_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) control script increases dirty_expire_centisecs and dirty_writeback_centisecs in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) /proc/sys/vm to about 10 minutes (by default), which means that pages that are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) dirtied are not forced to be written to disk as often. The control script also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) changes the dirty background ratio, so that background writeback of dirty pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) is not done anymore. Combined with a higher commit value (also 10 minutes) for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) ext3 or ReiserFS filesystems (also done automatically by the control script),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) this results in concentration of disk activity in a small time interval which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) occurs only once every 10 minutes, or whenever the disk is forced to spin up by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) a cache miss. The disk can then be spun down in the periods of inactivity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) If you want to find out which process caused the disk to spin up, you can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) gather information by setting the flag /proc/sys/vm/block_dump. When this flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) is set, Linux reports all disk read and write operations that take place, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) all block dirtyings done to files. This makes it possible to debug why a disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) needs to spin up, and to increase battery life even more. The output of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) block_dump is written to the kernel output, and it can be retrieved using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) "dmesg". When you use block_dump and your kernel logging level also includes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) kernel debugging messages, you probably want to turn off klogd, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) the output of block_dump will be logged, causing disk activity that is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) normally there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) Configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) -------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) The laptop mode configuration file is located in /etc/default/laptop-mode on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) Debian-based systems, or in /etc/sysconfig/laptop-mode on other systems. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) contains the following options:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) MAX_AGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) Maximum time, in seconds, of hard drive spindown time that you are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) comfortable with. Worst case, it's possible that you could lose this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) amount of work if your battery fails while you're in laptop mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MINIMUM_BATTERY_MINUTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) Automatically disable laptop mode if the remaining number of minutes of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) battery power is less than this value. Default is 10 minutes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) AC_HD/BATT_HD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) The idle timeout that should be set on your hard drive when laptop mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) is active (BATT_HD) and when it is not active (AC_HD). The defaults are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 20 seconds (value 4) for BATT_HD  and 2 hours (value 244) for AC_HD. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) possible values are those listed in the manual page for "hdparm" for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) "-S" option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) HD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) The devices for which the spindown timeout should be adjusted by laptop mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) Default is /dev/hda. If you specify multiple devices, separate them by a space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) READAHEAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) Disk readahead, in 512-byte sectors, while laptop mode is active. A large
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) readahead can prevent disk accesses for things like executable pages (which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) loaded on demand while the application executes) and sequentially accessed data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) (MP3s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) DO_REMOUNTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) The control script automatically remounts any mounted journaled filesystems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) with appropriate commit interval options. When this option is set to 0, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) feature is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) DO_REMOUNT_NOATIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) When remounting, should the filesystems be remounted with the noatime option?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) Normally, this is set to "1" (enabled), but there may be programs that require
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) access time recording.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) DIRTY_RATIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) The percentage of memory that is allowed to contain "dirty" or unsaved data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) before a writeback is forced, while laptop mode is active. Corresponds to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) the /proc/sys/vm/dirty_ratio sysctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) DIRTY_BACKGROUND_RATIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) The percentage of memory that is allowed to contain "dirty" or unsaved data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) after a forced writeback is done due to an exceeding of DIRTY_RATIO. Set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) this nice and low. This corresponds to the /proc/sys/vm/dirty_background_ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) sysctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) Note that the behaviour of dirty_background_ratio is quite different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) when laptop mode is active and when it isn't. When laptop mode is inactive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dirty_background_ratio is the threshold percentage at which background writeouts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) start taking place. When laptop mode is active, however, background writeouts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) are disabled, and the dirty_background_ratio only determines how much writeback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) is done when dirty_ratio is reached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) DO_CPU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) Enable CPU frequency scaling when in laptop mode. (Requires CPUFreq to be setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) See Documentation/admin-guide/pm/cpufreq.rst for more info. Disabled by default.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) CPU_MAXFREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) When on battery, what is the maximum CPU speed that the system should use? Legal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) values are "slowest" for the slowest speed that your CPU is able to operate at,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) or a value listed in /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) Tips & Tricks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) -------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * Bartek Kania reports getting up to 50 minutes of extra battery life (on top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)   of his regular 3 to 3.5 hours) using a spindown time of 5 seconds (BATT_HD=1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * You can spin down the disk while playing MP3, by setting disk readahead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)   to 8MB (READAHEAD=16384). Effectively, the disk will read a complete MP3 at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)   once, and will then spin down while the MP3 is playing. (Thanks to Bartek
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)   Kania.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * Drew Scott Daniels observed: "I don't know why, but when I decrease the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)   of colours that my display uses it consumes less battery power. I've seen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)   this on powerbooks too. I hope that this is a piece of information that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)   might be useful to the Laptop Mode patch or its users."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * In syslog.conf, you can prefix entries with a dash `-` to omit syncing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)   file after every logging. When you're using laptop-mode and your disk doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)   spin down, this is a likely culprit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * Richard Atterer observed that laptop mode does not work well with noflushd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)   (http://noflushd.sourceforge.net/), it seems that noflushd prevents laptop-mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)   from doing its thing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * If you're worried about your data, you might want to consider using a USB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)   memory stick or something like that as a "working area". (Be aware though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)   that flash memory can only handle a limited number of writes, and overuse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)   may wear out your memory stick pretty quickly. Do _not_ use journalling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)   filesystems on flash memory sticks.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) Configuration file for control and ACPI battery scripts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) -------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) This allows the tunables to be changed for the scripts via an external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) configuration file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) It should be installed as /etc/default/laptop-mode on Debian, and as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /etc/sysconfig/laptop-mode on Red Hat, SUSE, Mandrake, and other work-alikes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) Config file::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)   # Maximum time, in seconds, of hard drive spindown time that you are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)   # comfortable with. Worst case, it's possible that you could lose this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)   # amount of work if your battery fails you while in laptop mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)   #MAX_AGE=600
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)   # Automatically disable laptop mode when the number of minutes of battery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)   # that you have left goes below this threshold.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)   MINIMUM_BATTERY_MINUTES=10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)   # Read-ahead, in 512-byte sectors. You can spin down the disk while playing MP3/OGG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)   # by setting the disk readahead to 8MB (READAHEAD=16384). Effectively, the disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)   # will read a complete MP3 at once, and will then spin down while the MP3/OGG is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)   # playing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)   #READAHEAD=4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)   # Shall we remount journaled fs. with appropriate commit interval? (1=yes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)   #DO_REMOUNTS=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)   # And shall we add the "noatime" option to that as well? (1=yes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)   #DO_REMOUNT_NOATIME=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)   # Dirty synchronous ratio.  At this percentage of dirty pages the process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)   # which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)   # calls write() does its own writeback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)   #DIRTY_RATIO=40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)   # Allowed dirty background ratio, in percent.  Once DIRTY_RATIO has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)   # exceeded, the kernel will wake flusher threads which will then reduce the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)   # amount of dirty memory to dirty_background_ratio.  Set this nice and low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)   # so once some writeout has commenced, we do a lot of it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)   #DIRTY_BACKGROUND_RATIO=5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)   # kernel default dirty buffer age
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)   #DEF_AGE=30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)   #DEF_UPDATE=5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)   #DEF_DIRTY_BACKGROUND_RATIO=10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)   #DEF_DIRTY_RATIO=40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)   #DEF_XFS_AGE_BUFFER=15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)   #DEF_XFS_SYNC_INTERVAL=30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)   #DEF_XFS_BUFD_INTERVAL=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)   # This must be adjusted manually to the value of HZ in the running kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)   # on 2.4, until the XFS people change their 2.4 external interfaces to work in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)   # centisecs. This can be automated, but it's a work in progress that still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)   # needs# some fixes. On 2.6 kernels, XFS uses USER_HZ instead of HZ for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)   # external interfaces, and that is currently always set to 100. So you don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)   # need to change this on 2.6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)   #XFS_HZ=100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)   # Should the maximum CPU frequency be adjusted down while on battery?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)   # Requires CPUFreq to be setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)   # See Documentation/admin-guide/pm/cpufreq.rst for more info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)   #DO_CPU=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)   # When on battery what is the maximum CPU speed that the system should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)   # use? Legal values are "slowest" for the slowest speed that your
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)   # CPU is able to operate at, or a value listed in:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)   # /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)   # Only applicable if DO_CPU=1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)   #CPU_MAXFREQ=slowest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)   # Idle timeout for your hard drive (man hdparm for valid values, -S option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)   # Default is 2 hours on AC (AC_HD=244) and 20 seconds for battery (BATT_HD=4).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)   #AC_HD=244
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)   #BATT_HD=4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)   # The drives for which to adjust the idle timeout. Separate them by a space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)   # e.g. HD="/dev/hda /dev/hdb".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)   #HD="/dev/hda"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)   # Set the spindown timeout on a hard drive?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)   #DO_HD=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) Control script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) --------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) Please note that this control script works for the Linux 2.4 and 2.6 series (thanks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) to Kiko Piris).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) Control script::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)   #!/bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)   # start or stop laptop_mode, best run by a power management daemon when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)   # ac gets connected/disconnected from a laptop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)   # install as /sbin/laptop_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)   # Contributors to this script:   Kiko Piris
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)   #				 Bart Samwel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)   #				 Micha Feigin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)   #				 Andrew Morton
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)   #				 Herve Eychenne
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)   #				 Dax Kelson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)   # Original Linux 2.4 version by: Jens Axboe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)   #############################################################################
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)   # Source config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)   if [ -f /etc/default/laptop-mode ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	# Debian
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	. /etc/default/laptop-mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)   elif [ -f /etc/sysconfig/laptop-mode ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	# Others
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)           . /etc/sysconfig/laptop-mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)   fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)   # Don't raise an error if the config file is incomplete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)   # set defaults instead:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)   # Maximum time, in seconds, of hard drive spindown time that you are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)   # comfortable with. Worst case, it's possible that you could lose this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)   # amount of work if your battery fails you while in laptop mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)   MAX_AGE=${MAX_AGE:-'600'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)   # Read-ahead, in kilobytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)   READAHEAD=${READAHEAD:-'4096'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)   # Shall we remount journaled fs. with appropriate commit interval? (1=yes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)   DO_REMOUNTS=${DO_REMOUNTS:-'1'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)   # And shall we add the "noatime" option to that as well? (1=yes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)   DO_REMOUNT_NOATIME=${DO_REMOUNT_NOATIME:-'1'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)   # Shall we adjust the idle timeout on a hard drive?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)   DO_HD=${DO_HD:-'1'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)   # Adjust idle timeout on which hard drive?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)   HD="${HD:-'/dev/hda'}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)   # spindown time for HD (hdparm -S values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)   AC_HD=${AC_HD:-'244'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)   BATT_HD=${BATT_HD:-'4'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)   # Dirty synchronous ratio.  At this percentage of dirty pages the process which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)   # calls write() does its own writeback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)   DIRTY_RATIO=${DIRTY_RATIO:-'40'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)   # cpu frequency scaling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)   # See Documentation/admin-guide/pm/cpufreq.rst for more info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)   DO_CPU=${CPU_MANAGE:-'0'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)   CPU_MAXFREQ=${CPU_MAXFREQ:-'slowest'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)   # Allowed dirty background ratio, in percent.  Once DIRTY_RATIO has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)   # exceeded, the kernel will wake flusher threads which will then reduce the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)   # amount of dirty memory to dirty_background_ratio.  Set this nice and low,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)   # so once some writeout has commenced, we do a lot of it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)   DIRTY_BACKGROUND_RATIO=${DIRTY_BACKGROUND_RATIO:-'5'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)   # kernel default dirty buffer age
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)   DEF_AGE=${DEF_AGE:-'30'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)   DEF_UPDATE=${DEF_UPDATE:-'5'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)   DEF_DIRTY_BACKGROUND_RATIO=${DEF_DIRTY_BACKGROUND_RATIO:-'10'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)   DEF_DIRTY_RATIO=${DEF_DIRTY_RATIO:-'40'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)   DEF_XFS_AGE_BUFFER=${DEF_XFS_AGE_BUFFER:-'15'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)   DEF_XFS_SYNC_INTERVAL=${DEF_XFS_SYNC_INTERVAL:-'30'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)   DEF_XFS_BUFD_INTERVAL=${DEF_XFS_BUFD_INTERVAL:-'1'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)   # This must be adjusted manually to the value of HZ in the running kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)   # on 2.4, until the XFS people change their 2.4 external interfaces to work in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)   # centisecs. This can be automated, but it's a work in progress that still needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)   # some fixes. On 2.6 kernels, XFS uses USER_HZ instead of HZ for external
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)   # interfaces, and that is currently always set to 100. So you don't need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)   # change this on 2.6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)   XFS_HZ=${XFS_HZ:-'100'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)   #############################################################################
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)   KLEVEL="$(uname -r |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)                {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	       IFS='.' read a b c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	       echo $a.$b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)   )"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)   case "$KLEVEL" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	"2.4"|"2.6")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		echo "Unhandled kernel version: $KLEVEL ('uname -r' = '$(uname -r)')" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)   esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)   if [ ! -e /proc/sys/vm/laptop_mode ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	echo "Kernel is not patched with laptop_mode patch." >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)   fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)   if [ ! -w /proc/sys/vm/laptop_mode ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	echo "You do not have enough privileges to enable laptop_mode." >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)   fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)   # Remove an option (the first parameter) of the form option=<number> from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)   # a mount options string (the rest of the parameters).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)   parse_mount_opts () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	OPT="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	echo ",$*," | sed		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	 -e 's/,'"$OPT"'=[0-9]*,/,/g'	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	 -e 's/,,*/,/g'			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	 -e 's/^,//'			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	 -e 's/,$//'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)   # Remove an option (the first parameter) without any arguments from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)   # a mount option string (the rest of the parameters).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)   parse_nonumber_mount_opts () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	OPT="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	echo ",$*," | sed		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	 -e 's/,'"$OPT"',/,/g'		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	 -e 's/,,*/,/g'			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	 -e 's/^,//'			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	 -e 's/,$//'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)   # Find out the state of a yes/no option (e.g. "atime"/"noatime") in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)   # fstab for a given filesystem, and use this state to replace the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)   # value of the option in another mount options string. The device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)   # is the first argument, the option name the second, and the default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)   # value the third. The remainder is the mount options string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)   # Example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)   # parse_yesno_opts_wfstab /dev/hda1 atime atime defaults,noatime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)   # If fstab contains, say, "rw" for this filesystem, then the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)   # will be "defaults,atime".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)   parse_yesno_opts_wfstab () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	L_DEV="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	OPT="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	DEF_OPT="$3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	shift 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	L_OPTS="$*"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	PARSEDOPTS1="$(parse_nonumber_mount_opts $OPT $L_OPTS)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	PARSEDOPTS1="$(parse_nonumber_mount_opts no$OPT $PARSEDOPTS1)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	# Watch for a default atime in fstab
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	FSTAB_OPTS="$(awk '$1 == "'$L_DEV'" { print $4 }' /etc/fstab)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if echo "$FSTAB_OPTS" | grep "$OPT" > /dev/null ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		# option specified in fstab: extract the value and use it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		if echo "$FSTAB_OPTS" | grep "no$OPT" > /dev/null ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			echo "$PARSEDOPTS1,no$OPT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			# no$OPT not found -- so we must have $OPT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 			echo "$PARSEDOPTS1,$OPT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		# option not specified in fstab -- choose the default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		echo "$PARSEDOPTS1,$DEF_OPT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)   # Find out the state of a numbered option (e.g. "commit=NNN") in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)   # fstab for a given filesystem, and use this state to replace the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)   # value of the option in another mount options string. The device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)   # is the first argument, and the option name the second. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)   # remainder is the mount options string in which the replacement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)   # must be done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)   # Example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)   # parse_mount_opts_wfstab /dev/hda1 commit defaults,commit=7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)   #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)   # If fstab contains, say, "commit=3,rw" for this filesystem, then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)   # result will be "rw,commit=3".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)   parse_mount_opts_wfstab () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	L_DEV="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	OPT="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	shift 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	L_OPTS="$*"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	PARSEDOPTS1="$(parse_mount_opts $OPT $L_OPTS)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	# Watch for a default commit in fstab
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	FSTAB_OPTS="$(awk '$1 == "'$L_DEV'" { print $4 }' /etc/fstab)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if echo "$FSTAB_OPTS" | grep "$OPT=" > /dev/null ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		# option specified in fstab: extract the value, and use it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		echo -n "$PARSEDOPTS1,$OPT="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		echo ",$FSTAB_OPTS," | sed \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		 -e 's/.*,'"$OPT"'=//'	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		 -e 's/,.*//'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		# option not specified in fstab: set it to 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		echo "$PARSEDOPTS1,$OPT=0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)   deduce_fstype () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	MP="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	# My root filesystem unfortunately has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	# type "unknown" in /etc/mtab. If we encounter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	# "unknown", we try to get the type from fstab.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	cat /etc/fstab |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	grep -v '^#' |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	while read FSTAB_DEV FSTAB_MP FSTAB_FST FSTAB_OPTS FSTAB_DUMP FSTAB_DUMP ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		if [ "$FSTAB_MP" = "$MP" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 			echo $FSTAB_FST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 			exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)   if [ $DO_REMOUNT_NOATIME -eq 1 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	NOATIME_OPT=",noatime"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)   fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)   case "$1" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		AGE=$((100*$MAX_AGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		XFS_AGE=$(($XFS_HZ*$MAX_AGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		echo -n "Starting laptop_mode"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		if [ -d /proc/sys/vm/pagebuf ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			# (For 2.4 and early 2.6.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			# This only needs to be set, not reset -- it is only used when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 			# laptop mode is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 			echo $XFS_AGE > /proc/sys/vm/pagebuf/lm_flush_age
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 			echo $XFS_AGE > /proc/sys/fs/xfs/lm_sync_interval
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		elif [ -f /proc/sys/fs/xfs/lm_age_buffer ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 			# (A couple of early 2.6 laptop mode patches had these.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			# The same goes for these.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 			echo $XFS_AGE > /proc/sys/fs/xfs/lm_age_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 			echo $XFS_AGE > /proc/sys/fs/xfs/lm_sync_interval
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		elif [ -f /proc/sys/fs/xfs/age_buffer ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 			# (2.6.6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 			# But not for these -- they are also used in normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 			# operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 			echo $XFS_AGE > /proc/sys/fs/xfs/age_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 			echo $XFS_AGE > /proc/sys/fs/xfs/sync_interval
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		elif [ -f /proc/sys/fs/xfs/age_buffer_centisecs ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 			# (2.6.7 upwards)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 			# And not for these either. These are in centisecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 			# not USER_HZ, so we have to use $AGE, not $XFS_AGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 			echo $AGE > /proc/sys/fs/xfs/age_buffer_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 			echo $AGE > /proc/sys/fs/xfs/xfssyncd_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 			echo 3000 > /proc/sys/fs/xfs/xfsbufd_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		case "$KLEVEL" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 			"2.4")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 				echo 1					> /proc/sys/vm/laptop_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 				echo "30 500 0 0 $AGE $AGE 60 20 0"	> /proc/sys/vm/bdflush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 				;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 			"2.6")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 				echo 5					> /proc/sys/vm/laptop_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 				echo "$AGE"				> /proc/sys/vm/dirty_writeback_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 				echo "$AGE"				> /proc/sys/vm/dirty_expire_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 				echo "$DIRTY_RATIO"			> /proc/sys/vm/dirty_ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 				echo "$DIRTY_BACKGROUND_RATIO"		> /proc/sys/vm/dirty_background_ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 				;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		if [ $DO_REMOUNTS -eq 1 ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 			cat /etc/mtab | while read DEV MP FST OPTS DUMP PASS ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 				PARSEDOPTS="$(parse_mount_opts "$OPTS")"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 				if [ "$FST" = 'unknown' ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 					FST=$(deduce_fstype $MP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 				fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 				case "$FST" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 					"ext3"|"reiserfs")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 						PARSEDOPTS="$(parse_mount_opts commit "$OPTS")"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 						mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,commit=$MAX_AGE$NOATIME_OPT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 						;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 					"xfs")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 						mount $DEV -t $FST $MP -o remount,$OPTS$NOATIME_OPT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 						;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 				esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 				if [ -b $DEV ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 					blockdev --setra $(($READAHEAD * 2)) $DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 				fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 			done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		if [ $DO_HD -eq 1 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 			for THISHD in $HD ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 				/sbin/hdparm -S $BATT_HD $THISHD > /dev/null 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 				/sbin/hdparm -B 1 $THISHD > /dev/null 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 			done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		if [ $DO_CPU -eq 1 -a -e /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 			if [ $CPU_MAXFREQ = 'slowest' ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 				CPU_MAXFREQ=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 			fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 			echo $CPU_MAXFREQ > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		echo "."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	stop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		U_AGE=$((100*$DEF_UPDATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		B_AGE=$((100*$DEF_AGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		echo -n "Stopping laptop_mode"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		echo 0 > /proc/sys/vm/laptop_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		if [ -f /proc/sys/fs/xfs/age_buffer -a ! -f /proc/sys/fs/xfs/lm_age_buffer ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 			# These need to be restored, if there are no lm_*.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 			echo $(($XFS_HZ*$DEF_XFS_AGE_BUFFER))	 	> /proc/sys/fs/xfs/age_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 			echo $(($XFS_HZ*$DEF_XFS_SYNC_INTERVAL)) 	> /proc/sys/fs/xfs/sync_interval
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 		elif [ -f /proc/sys/fs/xfs/age_buffer_centisecs ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 			# These need to be restored as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 			echo $((100*$DEF_XFS_AGE_BUFFER))	> /proc/sys/fs/xfs/age_buffer_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 			echo $((100*$DEF_XFS_SYNC_INTERVAL))	> /proc/sys/fs/xfs/xfssyncd_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 			echo $((100*$DEF_XFS_BUFD_INTERVAL))	> /proc/sys/fs/xfs/xfsbufd_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		case "$KLEVEL" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 			"2.4")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 				echo "30 500 0 0 $U_AGE $B_AGE 60 20 0"	> /proc/sys/vm/bdflush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 				;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 			"2.6")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 				echo "$U_AGE"				> /proc/sys/vm/dirty_writeback_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 				echo "$B_AGE"				> /proc/sys/vm/dirty_expire_centisecs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 				echo "$DEF_DIRTY_RATIO"			> /proc/sys/vm/dirty_ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 				echo "$DEF_DIRTY_BACKGROUND_RATIO"	> /proc/sys/vm/dirty_background_ratio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 				;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		if [ $DO_REMOUNTS -eq 1 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 			cat /etc/mtab | while read DEV MP FST OPTS DUMP PASS ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 				# Reset commit and atime options to defaults.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 				if [ "$FST" = 'unknown' ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 					FST=$(deduce_fstype $MP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 				fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 				case "$FST" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 					"ext3"|"reiserfs")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 						PARSEDOPTS="$(parse_mount_opts_wfstab $DEV commit $OPTS)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 						PARSEDOPTS="$(parse_yesno_opts_wfstab $DEV atime atime $PARSEDOPTS)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 						mount $DEV -t $FST $MP -o remount,$PARSEDOPTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 						;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 					"xfs")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 						PARSEDOPTS="$(parse_yesno_opts_wfstab $DEV atime atime $OPTS)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 						mount $DEV -t $FST $MP -o remount,$PARSEDOPTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 						;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 				esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 				if [ -b $DEV ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 					blockdev --setra 256 $DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 				fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 			done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		if [ $DO_HD -eq 1 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 			for THISHD in $HD ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 				/sbin/hdparm -S $AC_HD $THISHD > /dev/null 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 				/sbin/hdparm -B 255 $THISHD > /dev/null 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 			done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		if [ $DO_CPU -eq 1 -a -e /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 			echo `cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq` > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		echo "."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		echo "Usage: $0 {start|stop}" 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)   esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)   exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ACPI integration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) ----------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) Dax Kelson submitted this so that the ACPI acpid daemon will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) kick off the laptop_mode script and run hdparm. The part that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) automatically disables laptop mode when the battery is low was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) written by Jan Topinski.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) /etc/acpi/events/ac_adapter::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	event=ac_adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	action=/etc/acpi/actions/ac.sh %e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) /etc/acpi/events/battery::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	event=battery.*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	action=/etc/acpi/actions/battery.sh %e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) /etc/acpi/actions/ac.sh::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)   #!/bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)   # ac on/offline event handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)   status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/$2/state`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)   case $status in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)           "on-line")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)                   /sbin/laptop_mode stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)                   exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)           ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)           "off-line")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)                   /sbin/laptop_mode start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)                   exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)           ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)   esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /etc/acpi/actions/battery.sh::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)   #! /bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)   # Automatically disable laptop mode when the battery almost runs out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)   BATT_INFO=/proc/acpi/battery/$2/state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)   if [[ -f /proc/sys/vm/laptop_mode ]]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)   then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)      LM=`cat /proc/sys/vm/laptop_mode`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)      if [[ $LM -gt 0 ]]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)      then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)        if [[ -f $BATT_INFO ]]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)        then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)           # Source the config file only now that we know we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)           if [ -f /etc/default/laptop-mode ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)                   # Debian
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)                   . /etc/default/laptop-mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)           elif [ -f /etc/sysconfig/laptop-mode ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)                   # Others
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)                   . /etc/sysconfig/laptop-mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)           fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)           MINIMUM_BATTERY_MINUTES=${MINIMUM_BATTERY_MINUTES:-'10'}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)           ACTION="`cat $BATT_INFO | grep charging | cut -c 26-`"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)           if [[ ACTION -eq "discharging" ]]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)           then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)              PRESENT_RATE=`cat $BATT_INFO | grep "present rate:" | sed  "s/.* \([0-9][0-9]* \).*/\1/" `
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)              REMAINING=`cat $BATT_INFO | grep "remaining capacity:" | sed  "s/.* \([0-9][0-9]* \).*/\1/" `
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)           fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)           if (($REMAINING * 60 / $PRESENT_RATE < $MINIMUM_BATTERY_MINUTES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)           then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)              /sbin/laptop_mode stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)           fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)        else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)          logger -p daemon.warning "You are using laptop mode and your battery interface $BATT_INFO is missing. This may lead to loss of data when the battery runs out. Check kernel ACPI support and /proc/acpi/battery folder, and edit /etc/acpi/battery.sh to set BATT_INFO to the correct path."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)        fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)      fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)   fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) Monitoring tool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) ---------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) Bartek Kania submitted this, it can be used to measure how much time your disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) spends spun up/down.  See tools/laptop/dslm/dslm.c