summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorQue Quotion2019-07-09 03:35:44 +0900
committerQue Quotion2019-07-09 03:35:44 +0900
commit153b9e512cea8c5a58ffadd0661f5fdd9dec5c63 (patch)
treed0b922b4d34edd99acce19611da1826d3de7c540
parentccf5862c0e84f648bee1b6be971d4e50e077baa8 (diff)
downloadaur-153b9e512cea8c5a58ffadd0661f5fdd9dec5c63.tar.gz
Partial rewrite:
Separate configuration into /etc/throttle.d/{performance,powersave} Use functions to reduce redundancy in throttle Expand natural language syntax ({cpu,gov}), and add more options such as "cpu check", etc. Mimic systemd controller syntax {start, stop}: start means "begin to throttle", so "reduce performance" stop means "cease to throttle", so "improve performance"
-rw-r--r--.SRCINFO12
-rw-r--r--PKGBUILD25
-rw-r--r--performance21
-rw-r--r--powersave21
-rwxr-xr-xthrottle345
5 files changed, 237 insertions, 187 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 060737c3b146..84e83115e954 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
pkgbase = indicator-powersave
pkgdesc = User discretion power managment utility forked from CPU frequency indicator (bzr version)
- pkgver = r98.9
- pkgrel = 2
+ pkgver = r98.10
+ pkgrel = 1
url = https://launchpad.net/indicator-cpufreq
arch = i686
arch = x86_64
@@ -24,6 +24,8 @@ pkgbase = indicator-powersave
provides = indicator-cpufreq-bzr
conflicts = indicator-cpufreq
conflicts = indicator-cpufreq-bzr
+ backup = etc/throttle.d/powersave
+ backup = etc/throttle.d/performance
source = bzr+lp:indicator-cpufreq
source = indicator-cpufreq.rules
source = com.ubuntu.indicator.policy.in.patch
@@ -32,14 +34,18 @@ pkgbase = indicator-powersave
source = no-cpufreq.patch
source = throttle
source = throttle-cut.service
+ source = powersave
+ source = performance
sha512sums = SKIP
sha512sums = 5427f1dcd51fe7fb43bbce1bc020a32312e2f82ccf643129b9887262730989197e2ce2cd4494922df058e78bdb8fbe220eccd69588ff917a891d5a56b3366a24
sha512sums = 9b57d18ef9edc6b609b24f6a62c93c472bc2b72dd158728af1a1d0833a308a72457b0ad32c2d51b357650fa69c0f7f595fa55901ea490a7a3fda3c7c998de2bd
sha512sums = 7e30098e35a72d66a885290a2be2aaf86b72f0242fd4d7ed62e81f9f6e7da378d70c7f7ef54701374dd1440f64173330457cdaf58a3a9bca35a59a57b29123a7
sha512sums = 1b8b56a841e736d5531632a1c4c229508e1c8a5c840cd2d172e2d89e7aa3a00d549bcd941b209692f8e09bff3739f28f971a1028d3acd4c37cc9176b9425e2a1
sha512sums = 2b1229ad56651a8d55590256785119da4eba2a2f8d74e57475a8303dc076d5e9067a6481e3245d05557ea0f983d8fa1f1ac02f705fe695f4a4ef79fa86b00b89
- sha512sums = f0e49ab4e4eb4345cdefdf01ae75b9ed753c2d6f2d29d15ffb5b2826cba0e02add27c2d5f41ed45779aeabcf927a104f25b1d5d462574140d24d830ff3a1f5c9
+ sha512sums = 48fac136a0ff11bec6c7c5fc840f81dc2f04dea5fe1132b4af735940e1360cc320f6a59cac573a356bf7ab25166bbc2da6fb9faf981644196d277824a2219337
sha512sums = 0b2de8aa79a837e399684164b29992ae0ab8a2c07412fe837c920e8d3905620ac98d700ee9ee0e8328d398e1d64aea3b01962f0ba573f9a8ff5a41fea5628ace
+ sha512sums = 3d487961bf86254817fd099b888d6245bbf1e57622166dc8df378d639bfb1c0fc105646038be6093183be102294394b88cde382fe961f7606b68619af4a00595
+ sha512sums = d11ed5f4344f07507497e816ccd7612ffc6df70636ca5f4817a9ce6e3b190b3a17fb02c44c4bf648359f640e4c63cc0b0134968ff4d3d989ad05fa4c095b03d3
pkgname = indicator-powersave
diff --git a/PKGBUILD b/PKGBUILD
index 4a97d75b5b6d..9ed0688beef5 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -2,8 +2,8 @@
# Contributor: Xiao-Long Chen <chenxiaolongcxl.epac.to>
pkgname=indicator-powersave
-pkgver=r98.9
-pkgrel=2
+pkgver=r98.10
+pkgrel=1
pkgdesc="User discretion power managment utility forked from CPU frequency indicator (bzr version)"
arch=('i686' 'x86_64')
url="https://launchpad.net/indicator-cpufreq"
@@ -13,6 +13,7 @@ optdepends=('x86_energy_perf_policy' 'hdparm' 'nvidia-utils' 'iw' 'ethtool')
makedepends=('python2-distutils-extra' 'bzr')
provides=('indicator-cpufreq' 'indicator-cpufreq-bzr')
conflicts=('indicator-cpufreq' 'indicator-cpufreq-bzr')
+backup=(etc/throttle.d/{powersave,performance})
source=("bzr+lp:indicator-cpufreq"
'indicator-cpufreq.rules'
'com.ubuntu.indicator.policy.in.patch'
@@ -20,20 +21,24 @@ source=("bzr+lp:indicator-cpufreq"
'indicator.py.patch'
'no-cpufreq.patch'
'throttle'
- 'throttle-cut.service')
+ 'throttle-cut.service'
+ 'powersave'
+ 'performance')
sha512sums=('SKIP'
'5427f1dcd51fe7fb43bbce1bc020a32312e2f82ccf643129b9887262730989197e2ce2cd4494922df058e78bdb8fbe220eccd69588ff917a891d5a56b3366a24'
'9b57d18ef9edc6b609b24f6a62c93c472bc2b72dd158728af1a1d0833a308a72457b0ad32c2d51b357650fa69c0f7f595fa55901ea490a7a3fda3c7c998de2bd'
'7e30098e35a72d66a885290a2be2aaf86b72f0242fd4d7ed62e81f9f6e7da378d70c7f7ef54701374dd1440f64173330457cdaf58a3a9bca35a59a57b29123a7'
'1b8b56a841e736d5531632a1c4c229508e1c8a5c840cd2d172e2d89e7aa3a00d549bcd941b209692f8e09bff3739f28f971a1028d3acd4c37cc9176b9425e2a1'
'2b1229ad56651a8d55590256785119da4eba2a2f8d74e57475a8303dc076d5e9067a6481e3245d05557ea0f983d8fa1f1ac02f705fe695f4a4ef79fa86b00b89'
- 'f0e49ab4e4eb4345cdefdf01ae75b9ed753c2d6f2d29d15ffb5b2826cba0e02add27c2d5f41ed45779aeabcf927a104f25b1d5d462574140d24d830ff3a1f5c9'
- '0b2de8aa79a837e399684164b29992ae0ab8a2c07412fe837c920e8d3905620ac98d700ee9ee0e8328d398e1d64aea3b01962f0ba573f9a8ff5a41fea5628ace')
+ '48fac136a0ff11bec6c7c5fc840f81dc2f04dea5fe1132b4af735940e1360cc320f6a59cac573a356bf7ab25166bbc2da6fb9faf981644196d277824a2219337'
+ '0b2de8aa79a837e399684164b29992ae0ab8a2c07412fe837c920e8d3905620ac98d700ee9ee0e8328d398e1d64aea3b01962f0ba573f9a8ff5a41fea5628ace'
+ '3d487961bf86254817fd099b888d6245bbf1e57622166dc8df378d639bfb1c0fc105646038be6093183be102294394b88cde382fe961f7606b68619af4a00595'
+ 'd11ed5f4344f07507497e816ccd7612ffc6df70636ca5f4817a9ce6e3b190b3a17fb02c44c4bf648359f640e4c63cc0b0134968ff4d3d989ad05fa4c095b03d3')
pkgver() {
cd indicator-cpufreq
- printf "r%s" "$(bzr revno).9"
+ printf "r%s" "$(bzr revno).10"
}
prepare() {
@@ -55,9 +60,9 @@ package() {
install -m644 "${srcdir}/indicator-cpufreq.rules" \
"${pkgdir}/usr/share/polkit-1/rules.d/"
- # Don't install throttle script if user has a personalized copy
- if [ ! -f "/usr/local/sbin/throttle" ]; then
- install -Dm755 "${srcdir}/throttle" "${pkgdir}/usr/bin/throttle"
- fi
+ install -Dm755 "${srcdir}/throttle" "${pkgdir}/usr/bin/throttle"
+ install -Dm755 "${srcdir}/powersave" "${pkgdir}/etc/throttle.d/powersave"
+ install -Dm755 "${srcdir}/performance" "${pkgdir}/etc/throttle.d/performance"
+
install -Dm644 "${srcdir}/throttle-cut.service" "${pkgdir}/etc/systemd/system/throttle-cut.service"
}
diff --git a/performance b/performance
new file mode 100644
index 000000000000..a99aad22f750
--- /dev/null
+++ b/performance
@@ -0,0 +1,21 @@
+HYPERTHREADS="1"
+GOVERNOR="performance"
+XPSTURBO="0"
+ENERGYPERF="0"
+BACKLIGHT="1" # Higher?
+LAPTOP="0"
+DIRTYWBC="500"
+NMIDOG="1"
+POLICY="max_performance"
+APM="255"
+AAM="254"
+CONTROL="on"
+AUTOSUSPEND="-1"
+DISKAUTOSUSPEND="-1"
+POWERSAVE="0"
+CONTROLLER="N"
+WLPOWERSAVE="off"
+WOLA="g"
+WOLB="enabled"
+LEDBRIGHT="255"
+NVPM="1"
diff --git a/powersave b/powersave
new file mode 100644
index 000000000000..10a08db2c7d5
--- /dev/null
+++ b/powersave
@@ -0,0 +1,21 @@
+HYPERTHREADS="0"
+GOVERNOR="powersave"
+XPSTURBO="1"
+ENERGYPERF="15"
+BACKLIGHT="0"
+LAPTOP="5"
+DIRTYWBC="1500"
+NMIDOG="0"
+POLICY="min_power"
+APM="1"
+AAM="128"
+CONTROL="auto"
+AUTOSUSPEND="1"
+DISKAUTOSUSPEND="60000"
+POWERSAVE="1"
+CONTROLLER="Y"
+WLPOWERSAVE="on"
+WOLA="d"
+WOLB="disabled"
+LEDBRIGHT="0"
+NVPM="0"
diff --git a/throttle b/throttle
index 68f18ba51013..9f1656a6b954 100755
--- a/throttle
+++ b/throttle
@@ -1,83 +1,180 @@
#!/bin/bash
# throttle - user discrection power management utility
+throttle_ht() {
+ for i in /sys/devices/system/cpu/cpu*/online; do \
+ [[ "$(printf "${i}" | tr -cd [:digit:])" -ge "${CORES}" ]] && \
+ printf "${HYPERTHREADS}" > "${i}" ; done &
+ [[ "${HYPERTHREADS}" == "1" ]] && wait
+}
+
+check_ht() {
+ printf "\nHyperthreads\n/sys/devices/system/cpu/cpu*/online\n"
+ for i in /sys/devices/system/cpu/cpu*/online; do \
+ [[ $(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|'
+}
+
+throttle_gov() {
+ for i in /sys/bus/cpu/drivers/processor/cpu*/cpufreq/scaling_governor; do \
+ [[ "$(printf ${i} | tr -cd [:digit:])" -ge "${CORES}" && \
+ "$(cat /sys/devices/system/cpu/cpu$(printf ${i} | tr -cd [:digit:])/online)" == 0 ]] && \
+ continue ; printf "${GOVERNOR}" > "${i}" & done &
+}
+
+check_gov() {
+ 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 \
+ printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/bus/cpu/drivers/processor/||g; s|/.*||g; N;s|\n|\t|'
+}
+
+throttle_turbo() {
+ [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]] && \
+ printf "${XPSTURBO}" > /sys/devices/system/cpu/intel_pstate/no_turbo &
+}
+
+check_turbo() {
+ [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]] && \
+ 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)"
+}
+
+throttle_backlight() {
+ [[ -f /sys/class/backlight/acpi_video0 ]] && \
+ for i in /sys/class/backlight/acpi_video*/brightness; do \
+ printf "${BACKLIGHT}" > "${i}" & done &
+}
+
+check_backlight() {
+ [[ -f /sys/class/backlight/acpi_video0 ]] && \
+ printf "\nBacklight\n/sys/class/backlight/\n" && \
+ for i in /sys/class/backlight/acpi_video*/brightness; do \
+ printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/backlight/||g; s|/.*||g; N;s|\n|\t|'
+}
+
+throttle_nvpm() {
+ printf "nvidia-settings not found; only nvidia currently supported" || \
+ DISPLAY=":0.0" nvidia-settings -a [gpu:0]/GPUPowerMizerMode="${NVPM}" > /dev/null &
+}
+
+check_nvpm() {
+ [[ -n "$(command -v nvidia-settings)" ]] && \
+ 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'
+}
+
+throttle_help() {
+ [[ ! "${1}" == "help" ]] && \
+ 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,cpu} {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 (laptops only?)\n" \
+ "${0} gpu {cut,full} - GPU runtime powersaving (only Nvidia ATM)\n"\
+ "\nOptions also take {{powersave,start},{performace,stop},status} and are stackable:\n"\
+ "\n${0} powersave gov full turbo on gpu full ht on check"
+ exit
+}
+
+[[ -z "$@" ]] && throttle_help
+
+#Find the number of physical cores (for hyperthreading control)
+CORES="$(grep "^core id" /proc/cpuinfo | sort -u | wc -l)"
+
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|true|1|cut|powersave|false|0)
+ ht*)
+ case "${1}" in \
+ ht-on) HYPERTHREADS="1" ;; \
+ ht-off) HYPERTHREADS="0" ;; esac
+ [[ -z "${HYPERTHREADS}" ]] && \
+ case "${2}" in \
+ off|powersave|start) HYPERTHREADS="0"; SHIFT="2" ;; \
+ on|performance|stop) HYPERTHREADS="1"; SHIFT="2" ;; \
+ check|status) check_ht; SHIFT="2" ;; esac
+ [[ -n "${HYPERTHREADS}" ]] && throttle_ht
+ [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
+ unset HYPERTHREADS SHIFT
+ ;;
+ gov*|cpu)
+ case "${1}" in \
+ gov-full) GOVERNOR="performance" ;; \
+ gov-cut) GOVERNOR="powersave" ;; esac
+ [[ -z "${GOVERNOR}" ]] && \
+ case "${2}" in \
+ cut|powersave|start) GOVERNOR="powersave"; SHIFT="2" ;; \
+ full|performance|stop) GOVERNOR="performance"; SHIFT="2" ;; \
+ check|status) check_gov; SHIFT="2" ;; esac
+ [[ -n "${GOVERNOR}" ]] && throttle_gov
+ [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
+ unset GOVERNOR SHIFT
+ ;;
+ turbo*)
+ case "${1}" in \
+ turbo-on) XPSTURBO="0" ;; \
+ turbo-off) XPSTURBO="1" ;; esac
+ [[ -z "${XPSTURBO}" ]] && \
+ case "${2}" in \
+ off|powersave|start) XPSTURBO="1"; SHIFT="2" ;; \
+ on|performance|stop) XPSTURBO="0"; SHIFT="2" ;; \
+ check|status) check_turbo; SHIFT="2" ;; esac
+ [[ -n "${XPSTURBO}" ]] && throttle_turbo
+ [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
+ unset XPSTURBO SHIFT
+ ;;
+ backlight)
+ case "${2}" in \
+ off|0|powersave|start) BACKLIGHT="0"; SHIFT="2" ;; \
+ on|1|performance|stop) BACKLIGHT="1"; SHIFT="2" ;; \
+ 2) BACKLIGHT="2"; SHIFT="2" ;; \
+ check|status) check_backlight; SHIFT="2" ;; esac
+ [[ -n "${BACKLIGHT}" ]] && throttle_backlight
+ [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
+ unset BACKLIGHT SHIFT
+ ;;
+ gpu*)
+ case "${1}" in \
+ gpu-full) NVPM="1" ;; \
+ gpu-cut) NVPM="0" ;; esac
+ [[ -z "${NVPM}" ]] && \
+ case "${2}" in \
+ full|performance|stop) NVPM="1"; SHIFT="2" ;; \
+ cut|powersave|start) NVPM="0"; SHIFT="2" ;; \
+ check|status) check_nvpm; SHIFT="2" ;; esac
+ [[ -n "${NVPM}" ]] && [[ -z "$(command -v nvidia-settings)" ]] && \
+ throttle_nvpm
+ [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
+ unset NVPM SHIFT
+ ;;
+ full|performance|true|1|start|cut|powersave|false|0|stop)
case "${1}" in
- full|performance|false|0)
- HYPERTHREADS="1"
- GOVERNOR="performance"
- XPSTURBO="0"
- ENERGYPERF="0"
- BACKLIGHT="2" # Higher?
- LAPTOP="0"
- DIRTYWBC="500"
- NMIDOG="0" # Always off
- POLICY="max_performance"
- APM="255"
- AAM="254"
- CONTROL="on"
- AUTOSUSPEND="-1"
- DISKAUTOSUSPEND="-1"
- POWERSAVE="0"
- CONTROLLER="N"
- WLPOWERSAVE="off"
- WOLA="g"
- WOLB="enabled"
- LEDBRIGHT="255"
- NVPM="1"
+ full|performance|false|0|stop)
+ . /etc/throttle.d/performance
;;
- cut|powersave|true|1)
- HYPERTHREADS="0"
- GOVERNOR="powersave"
- XPSTURBO="1"
- ENERGYPERF="15"
- BACKLIGHT="0"
- LAPTOP="5"
- DIRTYWBC="1500"
- NMIDOG="0"
- POLICY="min_power"
- APM="1"
- AAM="128"
- CONTROL="auto"
- AUTOSUSPEND="1"
- DISKAUTOSUSPEND="60000"
- POWERSAVE="1"
- CONTROLLER="Y"
- WLPOWERSAVE="on"
- WOLA="d"
- WOLB="disabled"
- LEDBRIGHT="0"
- NVPM="0"
+ cut|powersave|true|1|start)
+ . /etc/throttle.d/powersave
;;
esac
# Hyperthreads
- for i in /sys/devices/system/cpu/cpu*/online; do \
- [[ "$(printf "${i}" | tr -cd [:digit:])" -ge "${CORES}" ]] && \
- printf "${HYPERTHREADS}" > "${i}" ; done &
- [[ "${HYPERTHREADS}" == "1" ]] && wait
+ throttle_ht
# CPU Governor
- for i in /sys/bus/cpu/drivers/processor/cpu*/cpufreq/scaling_governor; do \
- [[ "${HYPERTHREADS}" == "0" && "$(printf ${i} | tr -cd [:digit:])" -ge "${CORES}" ]] && \
- continue ; printf "${GOVERNOR}" > "${i}" & done &
+ throttle_gov
# Disable Intel P-State Turbo
- [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]] && \
- printf "${XPSTURBO}" > /sys/devices/system/cpu/intel_pstate/no_turbo &
+ throttle_turbo
# ENERGY_PERF_BIAS
[[ -n "$(command -v x86_energy_perf_policy)" ]] && \
x86_energy_perf_policy "${ENERGYPERF}" &
# Backlight
- [[ -f /sys/class/backlight/acpi_video0 ]] && \
- for i in /sys/class/backlight/acpi_video*/brightness; do \
- printf "${BACKLIGHT}" > "${i}" & done &
+ throttle_backlight
# Virtual Memory (Swap)
[[ "$(sysctl -n vm.laptop_mode)" == "${LAPTOP}" ]] || \
@@ -113,7 +210,7 @@ while (( "$#" )); do
-f "$(printf ${i} | sed 's|/power.*|/idVendor|g')" && \
"$(cat $(printf ${i} | sed 's|/power.*|/idVendor|g'))" == "0424" && \
"$(cat $(printf ${i} | sed 's|/power.*|/idProduct|g'))" == "a700" ]] && \
- continue ; printf "${CONTROL}" > "${i}" & done &
+ continue ; printf "${CONTROL}" > "${i}" & done &
# USB Autosuspend (with exceptions for devices by VID:PID)
for i in /sys/bus/usb/devices/*/power/autosuspend{,_delay_ms}; do \
@@ -123,7 +220,7 @@ while (( "$#" )); do
-f "$(printf ${i} | sed 's|/power.*|/idVendor|g')" && \
"$(cat $(printf ${i} | sed 's|/power.*|/idVendor|g'))" == "0424" && \
"$(cat $(printf ${i} | sed 's|/power.*|/idProduct|g'))" == "a700" ]] && \
- continue ; printf -- "${AUTOSUSPEND}" > "${i}" & done &
+ continue ; printf -- "${AUTOSUSPEND}" > "${i}" & done &
# Powersaving for modules
for i in /sys/module/*/parameters/power_save; do \
@@ -146,112 +243,25 @@ while (( "$#" )); do
printf "${LEDBRIGHT}" > "${i}" & done &
# Nvidia PowerMizer
- [[ -n "$(command -v nvidia-settings)" ]] && \
- DISPLAY=":0.0" nvidia-settings -a [gpu:0]/GPUPowerMizerMode="${NVPM}" > /dev/null &
+ throttle_nvpm
shift
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 [[ "$(printf "${i}" | tr -cd [:digit:])" -ge "${CORES}" ]] && \
- printf "${HYPERTHREADS}" > "${i}" ; done &
- [[ "${HYPERTHREADS}" == "1" ]] && wait
- [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
- unset HYPERTHREADS SHIFT
- ;;
- gov*)
- case "${1}" in \
- gov-full) GOVERNOR="performance" ;; \
- gov-cut) GOVERNOR="powersave" ;; esac
- [[ -z "${GOVERNOR}" ]] && \
- case "${2}" in \
- full|performance) GOVERNOR="performance"; SHIFT="2" ;; \
- cut|powersave) GOVERNOR="powersave"; SHIFT="2" ;; esac
- [[ -z "${GOVERNOR}" ]] && \
- printf "${0} gov {cut,full} - CPU Governor\n" || \
- for i in /sys/bus/cpu/drivers/processor/cpu*/cpufreq/scaling_governor; do \
- [[ "$(printf ${i} | tr -cd [:digit:])" -ge "${CORES}" && \
- "$(cat /sys/devices/system/cpu/cpu$(printf ${i} | tr -cd [:digit:])/online)" == 0 ]] && \
- continue ; printf "${GOVERNOR}" > "${i}" & done &
- [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
- unset GOVERNOR SHIFT
- ;;
- turbo*)
- case "${1}" in \
- turbo-on) XPSTURBO="0" ;; \
- turbo-off) XPSTURBO="1" ;; esac
- [[ -z "${XPSTURBO}" ]] && \
- case "${2}" in \
- on|performance) XPSTURBO="0"; SHIFT="2" ;; \
- 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 &
- [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
- unset XPSTURBO 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 \
- printf "${BACKLIGHT}" > "${i}" & done &
- [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
- unset BACKLIGHT SHIFT
- ;;
- gpu*)
- case "${1}" in \
- gpu-full) NVPM="1" ;; \
- gpu-cut) NVPM="0" ;; esac
- [[ -z "${NVPM}" ]] && \
- case "${2}" in \
- full|performance) NVPM="1"; SHIFT="2" ;; \
- cut|powersave) NVPM="0"; SHIFT="2" ;; esac
- [[ -z "${NVPM}" ]] && \
- printf "${0} gpu {cut,full} - GPU runtime powersaving (only Nvidia ATM)\n" || \
- [[ -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 &
- [[ -n "${SHIFT}" ]] && shift "${SHIFT}" || shift
- unset NVPM SHIFT
- ;;
- check)
- printf "\nHyperthreads\n/sys/devices/system/cpu/cpu*/online\n"
- for i in /sys/devices/system/cpu/cpu*/online; do \
- [[ $(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|'
+ check|status)
+ check_ht
- 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 \
- printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/bus/cpu/drivers/processor/||g; s|/.*||g; N;s|\n|\t|'
+ check_gov
- [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]] && \
- 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)"
+ check_turbo
[[ -n "$(command -v x86_energy_perf_policy)" ]] && \
printf "\nEnergy Perf Bias\n" && \
x86_energy_perf_policy -r #SUID
- [[ -f /sys/class/backlight/acpi_video0 ]] && \
- printf "\nBacklight\n/sys/class/backlight/\n" && \
- for i in /sys/class/backlight/acpi_video*/brightness; do \
- printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/backlight/||g; s|/.*||g; N;s|\n|\t|'
+ check_backlight
echo -e "\nVirtual Memory (Swap)\n/proc/sys/vm/\n"\
"laptop_mode\t\t\t$(cat /proc/sys/vm/laptop_mode)\n"\
@@ -289,10 +299,10 @@ while (( "$#" )); do
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 \
- 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 \
- 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 \
printf " ${i}\n$(cat ${i})\n"; done | sed 's|/sys/class/net/||g; s|/device/power/wakeup||g; s|/.*||g; N;s|\n|\t|'
@@ -300,27 +310,14 @@ while (( "$#" )); do
for i in /sys/class/leds/*/brightness; do \
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 " && \
- DISPLAY=":0.0" nvidia-settings -q [gpu:0]/GPUPowerMizerMode | grep "Attribute" | sed 's|.*\[||g;s|\]):||g;s| |\t|g;s|\.$||g'
+ check_nvpm
shift
;;
- *|help)
- [[ ! "${1}" == "help" ]] && \
- 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
+ help|*)
+ throttle_help
;;
esac
[[ -z "${1}" ]] || wait # Hey, let's stop! :) *stops* ... YAY! =D
done
+
+unset CORES