diff options
author | Que Quotion | 2015-09-09 02:41:34 +0900 |
---|---|---|
committer | Que Quotion | 2015-09-09 02:41:34 +0900 |
commit | 6ada4a859eeb24fb3fa6cb65ba1eee416f105b2d (patch) | |
tree | 40ae2b6322c0927d8d5125ccb99f8cbe95dc0d63 /throttle | |
parent | e14ec91050dfe038716672f01564ef8de8d9ee32 (diff) | |
download | aur-6ada4a859eeb24fb3fa6cb65ba1eee416f105b2d.tar.gz |
First official AUR4 release.
Diffstat (limited to 'throttle')
-rwxr-xr-x | throttle | 174 |
1 files changed, 100 insertions, 74 deletions
@@ -1,16 +1,18 @@ #!/bin/bash +# throttle - user discrection power management utility while (( "$#" )); do #Find the number of physical cores (for hyperthreading control) CORES="$(grep "^core id" /proc/cpuinfo | sort -u | wc -l)" case "$1" in full|performance|cut|powersave) - case "$1" in + case "${1}" in full|performance) + HYPERTHREADS="1" GOVERNOR="performance" XPSTURBO="0" - HYPERTHREADS="1" ENERGYPERF="0" + BACKLIGHT="2" # Higher? LAPTOP="0" DIRTYWBC="500" NMIDOG="0" # Always off @@ -28,10 +30,11 @@ while (( "$#" )); do NVPM="1" ;; cut|powersave) - GOVERNOR="powersave" - XPSTURBO="1" HYPERTHREADS="0" + GOVERNOR="powersave" + XPSTURBO="1" ENERGYPERF="15" + BACKLIGHT="0" LAPTOP="5" DIRTYWBC="1500" NMIDOG="0" @@ -50,24 +53,29 @@ while (( "$#" )); do ;; esac + # Hyperthreads + for i in /sys/devices/system/cpu/cpu*/online; do [[ -f "${i}" ]] && \ + [[ "$(printf "${i}" | tr -cd [:digit:])" -ge "${CORES}" ]] && \ + printf "${HYPERTHREADS}" > "${i}" & done & + # CPU Governor for i in /sys/bus/cpu/drivers/processor/cpu*/cpufreq/scaling_governor; do [[ -f "${i}" ]] && \ - printf "${GOVERNOR}" > "${i}" & done & + [[ "${HYPERTHREADS}" == "0" && \ + "$(printf "${i}" | tr -cd [:digit:])" -ge "${CORES}" ]] && \ + continue ; printf "${GOVERNOR}" > "${i}" & done & # Disable Intel P-State Turbo [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]] && \ printf "${XPSTURBO}" > /sys/devices/system/cpu/intel_pstate/no_turbo & - # Hyperthreads - for i in /sys/devices/system/cpu/cpu*/online; do [[ -f "${i}" ]] && \ - [[ "$(printf "${i}" | tr -cd [:digit:])" -ge "${CORES}" ]] && \ - printf "${HYPERTHREADS}" > "${i}" & done & - wait # for cpus on/off - # ENERGY_PERF_BIAS [[ -n "$(command -v x86_energy_perf_policy)" ]] && \ x86_energy_perf_policy "${ENERGYPERF}" & + # Backlight + for i in /sys/class/backlight/acpi_video*/brightness; do [[ -f "${i}" ]] && \ + printf $BACKLIGHT > "${i}" & done & + # Virtual Memory (Swap) printf "${LAPTOP}" > /proc/sys/vm/laptop_mode & printf "${DIRTYWBC}" > /proc/sys/vm/dirty_writeback_centisecs & @@ -85,13 +93,13 @@ while (( "$#" )); do [[ -n "$(command -v hdparm)" ]] && \ hdparm -qB "${APM}" -qM "${AAM}" /dev/[hs]d[a-z] 2> /dev/null & - # Runtime power management for devices (by class and bus) - for i in /sys/{class/*,bus/*/devices}/*/power/control; do [[ -f "${i}" ]] && \ - printf "$CONTROL" > "${i}" & done & + # Runtime power management for devices (with exceptions for devices by VID:PID) + for i in /sys/{class/*,bus/*/devices}/*/power/control; do [[ -f "${i}" ]] && \ + printf "${CONTROL}" > "${i}" & done & - # USB Autosuspend (may disable some older devices!) + # USB Autosuspend (with exceptions for devices by VID:PID) for i in /sys/bus/usb/devices/*/power/autosuspend{,_delay_ms}; do [[ -f "${i}" ]] && \ - printf "$AUTOSUSPEND" > "${i}" & done & + printf -- "${AUTOSUSPEND}" > "${i}" & done & # Powersaving for modules for i in /sys/module/*/parameters/power_save; do \ @@ -119,10 +127,27 @@ while (( "$#" )); do wait # Hey, let's stop! :) *stops* ... YAY! =D shift - unset GOVERNOR XPSTURBO HYPERTHREADS ENERGYPERF LAPTOP DIRTYWBC NMIDOG \ + unset GOVERNOR XPSTURBO HYPERTHREADS ENERGYPERF BACKLIGHT LAPTOP DIRTYWBC NMIDOG \ POLICY APM AAM CONTROL AUTOSUSPEND POWERSAVE CONTROLLER \ WLPOWERSAVE WOLA WOLB LEDBRIGHT NVPM ;; + ht*) + case "${1}" in \ + ht-on) HYPERTHREADS="1" ;; \ + ht-off) HYPERTHREADS="0" ;; esac + [[ -z "${HYPERTHREADS}" ]] && \ + case "${2}" in \ + on|performance) HYPERTHREADS="1"; SHIFT="2" ;; \ + off|powersave) HYPERTHREADS="0"; SHIFT="2" ;; esac + [[ -z "${HYPERTHREADS}" ]] && \ + printf "${0} ht {on,off} - Hyperthreads\n" || \ + for i in /sys/devices/system/cpu/cpu*/online; do [[ -f "${i}" ]] && \ + [[ "$(printf "${i}" | tr -cd [:digit:])" -ge "${CORES}" ]] && \ + printf "${HYPERTHREADS}" > "${i}" & done & + [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift + wait + unset HYPERTHREADS SHIFT + ;; gov*) case "${1}" in \ gov-full) GOVERNOR="performance" ;; \ @@ -134,8 +159,8 @@ while (( "$#" )); do [[ -z "${GOVERNOR}" ]] && \ printf "${0} gov {cut,full} - CPU Governor\n" || \ for i in /sys/bus/cpu/drivers/processor/cpu*/cpufreq/scaling_governor; do [[ -f "${i}" ]] && \ - printf "${GOVERNOR}" > ${i} & done & - shift "${SHIFT}" + printf "${GOVERNOR}" > "${i}" & done & + [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift wait unset GOVERNOR SHIFT ;; @@ -149,28 +174,24 @@ while (( "$#" )); do off|powersave) XPSTURBO="1"; SHIFT="2" ;; esac [[ -z "${XPSTURBO}" ]] && \ printf "${0} turbo {on,off} - Intel P-State Turbo\n" || \ - [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]] && \ - printf "${XPSTURBO}" > /sys/devices/system/cpu/intel_pstate/no_turbo & - shift "${SHIFT}" + [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]] && \ + printf "${XPSTURBO}" > /sys/devices/system/cpu/intel_pstate/no_turbo & + [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift wait unset XPSTURBO SHIFT ;; - ht*) - case "${1}" in \ - ht-on) HYPERTHREADS="1" ;; \ - ht-off) HYPERTHREADS="0" ;; esac - [[ -z "${HYPERTHREADS}" ]] && \ - case "${2}" in \ - on|performance) HYPERTHREADS="1"; SHIFT="2" ;; \ - off|powersave) HYPERTHREADS="0"; SHIFT="2" ;; esac - [[ -z "${HYPERTHREADS}" ]] && \ - printf "${0} ht {on,off} - Hyperthreads\n" || \ - for i in /sys/devices/system/cpu/cpu*/online; do [[ -f "${i}" ]] && \ - [[ "$(printf "${i}" | tr -cd [:digit:])" -ge "${CORES}" ]] && \ - printf "${HYPERTHREADS}" > "${i}" & done & - shift "${SHIFT}" + backlight) + case "${2}" in \ + 0|powersave) BACKLIGHT="0"; SHIFT="2" ;; \ + 1) BACKLIGHT="1"; SHIFT="2" ;; \ + 2|performance) BACKLIGHT="2"; SHIFT="2" ;; esac + [[ -z "${BACKLIGHT}" ]] && \ + printf "${0} backlight {0,1,2} - Backlight brightness\n" || \ + for i in /sys/class/backlight/acpi_video*/brightness; do [[ -f "${i}" ]] && \ + printf "${BACKLIGHT}" > "${i}" & done & + [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift wait - unset HYPERTHREADS SHIFT + unset BACKLIGHT SHIFT ;; gpu*) case "${1}" in \ @@ -185,40 +206,44 @@ while (( "$#" )); do [[ -z "$(command -v nvidia-settings)" ]] && \ printf "nvidia-settings not found; only nvidia currently supported" || \ DISPLAY=":0.0" nvidia-settings -a [gpu:0]/GPUPowerMizerMode="${NVPM}" > /dev/null & - shift "${SHIFT}" + [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift wait unset NVPM SHIFT ;; check) + printf "\nHyperthreads\n/sys/devices/system/cpu/cpu*/online\n" + for i in /sys/devices/system/cpu/cpu*/online; do [[ -f "${i}" ]] && \ + [[ $(printf "${i}" | tr -cd [:digit:]) -ge "$CORES" ]] && \ + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/devices/system/cpu/||g; s|/.*||g; N;s|\n|\t|' + printf "\nCPU Governor\n/sys/bus/cpu/drivers/processor/cpu*/cpufreq/scaling_governor\n" for i in /sys/bus/cpu/drivers/processor/cpu*/cpufreq/scaling_governor; do [[ -f "${i}" ]] && \ - printf "${i}\n$(cat ${i})\n"; done | sed 's|/sys/bus/cpu/drivers/processor/||g; s|/.*||g; N;s|\n|\t|' + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/bus/cpu/drivers/processor/||g; s|/.*||g; N;s|\n|\t|' [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]] && \ - printf "\nDisable Intel P-State Turbo\n/sys/devices/system/cpu/intel_pstate/no_turbo\n"; \ - printf "no_turbo\n$(cat /sys/devices/system/cpu/intel_pstate/no_turbo)\n" | sed 'N;s|\n|\t|' + echo -e "\nDisable Intel P-State Turbo\n/sys/devices/system/cpu/intel_pstate/\n"\ + "no_turbo\t$(cat /sys/devices/system/cpu/intel_pstate/no_turbo)" - printf "\nHyperthreads\n/sys/devices/system/cpu/cpu*/online\n" - for i in /sys/devices/system/cpu/cpu*/online; do [[ -f "${i}" ]] && \ - [[ $(printf "${i}" | tr -cd [:digit:]) -ge "$CORES" ]] && \ - printf "${i}\n$(cat ${i})\n"; done | sed 's|/sys/devices/system/cpu/||g; s|/.*||g; N;s|\n|\t|' - - [[ -z "$(command -v x86_energy_perf_policy)" ]] && \ + [[ -n "$(command -v x86_energy_perf_policy)" ]] && \ printf "\nEnergy Perf Bias\n" && \ x86_energy_perf_policy -r #SUID - printf "\nVirtual Memory (Swap)\n/proc/sys/vm/\n" - printf "laptop_mode\t$(cat /proc/sys/vm/laptop_mode)\n" - printf "dirty_writeback_centisecs\t$(cat /proc/sys/vm/dirty_writeback_centisecs)\n" - printf "dirty_expire_centisecs\t$(cat /proc/sys/vm/dirty_expire_centisecs)\n" + printf "\nBacklight\n/sys/class/backlight/\n" + for i in /sys/class/backlight/acpi_video*/brightness; do [[ -f "${i}" ]] && \ + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/backlight/||g; s|/.*||g; N;s|\n|\t|' + + echo -e "\nVirtual Memory (Swap)\n/proc/sys/vm/\n"\ + "laptop_mode\t\t\t$(cat /proc/sys/vm/laptop_mode)\n"\ + "dirty_writeback_centisecs\t$(cat /proc/sys/vm/dirty_writeback_centisecs)\n"\ + "dirty_expire_centisecs\t\t$(cat /proc/sys/vm/dirty_expire_centisecs)" [[ -f /proc/sys/kernel/watchdog ]] && \ - printf "\nNMI watchdog\n" && \ - printf "/proc/sys/kernel/watchdog\t$(cat /proc/sys/kernel/watchdog)\n" + echo -e "\nNMI watchdog\n"\ + "/proc/sys/kernel/watchdog\t$(cat /proc/sys/kernel/watchdog)" printf "\nSATA link power management\n/sys/class/scsi_host/host*/link_power_management_policy\n" for i in /sys/class/scsi_host/host*/link_power_management_policy; do [[ -f "${i}" ]] && \ - printf "${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/scsi_host/||g; s|/.*||g; N;s|\n|\t|' + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/scsi_host/||g; s|/.*||g; N;s|\n|\t|' [[ -n "$(command -v hdparm)" ]] && \ printf "\nHard drives\n/dev/[hs]d[a-z]\n" && \ @@ -226,48 +251,49 @@ while (( "$#" )); do printf "\nRuntime power management\n/sys/{class,bus}/*/{*,devices/*}/power/control\n" for i in /sys/{class,bus}/*/{*,devices/*}/power/control; do [[ -f "${i}" ]] && \ - printf "${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/||g; s|/sys/bus/||g; s|/devices||g; s|/power/control||g; N;s|\n|\t|' + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/||g; s|/sys/bus/||g; s|/devices||g; s|/power/control||g; N;s|\n|\t|' - printf "\nUSB Autosuspend (may disable some older devices!)\n/sys/bus/usb/devices/*/power/autosuspend{,_delay_ms}\n" + printf "\nUSB Autosuspend\n/sys/bus/usb/devices/*/power/autosuspend{,_delay_ms}\n" for i in /sys/bus/usb/devices/*/power/autosuspend{,_delay_ms}; do [[ -f "${i}" ]] && \ - printf "${i}\n$(cat ${i})\n"; done | sed 's|/sys/bus/usb/devices/||g; s|/.*||g; N;s|\n|\t|' + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/bus/usb/devices/||g; s|/.*||g; N;s|\n|\t|' printf "\nPower saving for modules\n/sys/module/*/parameters/power_save{,_controller}\n" for i in /sys/module/*/parameters/power_save{,_controller}; do [[ -f "${i}" ]] && \ - printf "${i}\n$(cat ${i})\n"; done | sed 's|/sys/module/||g; s|/parameters/.*||g; s|/.*||g; N;s|\n|\t|' + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/module/||g; s|/parameters/.*||g; s|/.*||g; N;s|\n|\t|' printf "\nNetwork device powersaving\n/sys/class/net/{wl*,e*,*/device/power/wakeup}\n"; [[ -n "$(command -v iw)" ]] && \ for i in /sys/class/net/wl*; do [[ -d "${i}" ]] && \ - printf "${i}\n$(iw dev $(printf ${i} | sed 's/^.*wl/wl/') get power_save)"; done | sed 's|^\t| |g;s|/sys/class/net/||g; s|/.*||g' + printf " ${i}\n$(iw dev $(printf ${i} | sed 's/^.*wl/wl/') get power_save)"; done | sed 's|^\t| |g;s|/sys/class/net/||g; s|/.*||g' [[ -n "$(command -v ethtool)" ]] && \ for i in /sys/class/net/e*; do [[ -d "${i}" ]] && \ - printf "${i}\n$(ethtool $(printf ${i} | sed 's/^.*e/e/') | grep Wake-on)"; done | sed 's|^\t| |g;s|/sys/class/net/||g; s|/.*||g' + printf " ${i}\n$(ethtool $(printf ${i} | sed 's/^.*e/e/') | grep Wake-on)"; done | sed 's|^\t| |g;s|/sys/class/net/||g; s|/.*||g' for i in /sys/class/net/*/device/power/wakeup; do [[ -f "${i}" ]] && \ - printf "${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/net/||g; s|/device/power/wakeup||g; s|/.*||g; N;s|\n|\t|' + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/net/||g; s|/device/power/wakeup||g; s|/.*||g; N;s|\n|\t|' printf "\nLEDs\n/sys/class/leds/*/brightness\n" for i in /sys/class/leds/*/brightness; do [[ -f "${i}" ]] && \ - printf "${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/leds/||g; s|/brightness||g; s|/.*||g; N;s|\n|\t|' + printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/leds/||g; s|/brightness||g; s|/.*||g; N;s|\n|\t|' [[ -n "$(command -v nvidia-settings)" ]] && \ - printf "\nNvidia PowerMizer\n" && \ + printf "\nNvidia PowerMizer\n " && \ DISPLAY=":0.0" nvidia-settings -q [gpu:0]/GPUPowerMizerMode | grep "Attribute" | sed 's|.*\[||g;s|\]):||g;s| |\t|g;s|\.$||g' shift ;; *|help) [[ ! "${1}" == "help" ]] && \ - printf "Invalid input: $@\n" - printf "\nRuntime power management:\n" - printf "${0} {cut,full} - system-wide runtime powersaving\n" - printf "${0} check - inspect runtime powersaving\n" - printf "\nExtras:\n" - printf "${0} gov {cut,full} - CPU Governor\n" - printf "${0} turbo {on,off} - Intel P-State Turbo\n" - printf "${0} ht {on,off} - Hyperthreads\n" - printf "${0} gpu {cut,full} - GPU runtime powersaving (only Nvidia ATM)\n" - printf "\nOptions can take {performace,powersave} and are stackable:\n" - printf "\n${0} powersave gov full turbo on gpu full ht on check\n" + printf "Invalid input: ${@}\n" + echo -e "\nRuntime power management:\n"\ + "${0} {cut,full} - system-wide runtime powersaving\n"\ + "${0} check - inspect runtime powersaving\n"\ + "\nExtras:\n" \ + "${0} gov {cut,full} - CPU Governor\n"\ + "${0} turbo {on,off} - Intel P-State Turbo\n"\ + "${0} ht {on,off} - Hyperthreads\n"\ + "${0} backlight {0,1,2} -backlight brightness\n" \ + "${0} gpu {cut,full} - GPU runtime powersaving (only Nvidia ATM)\n"\ + "\nOptions can take {performace,powersave} and are stackable:\n"\ + "\n${0} powersave gov full turbo on gpu full ht on check" exit ;; esac |