chore: better knowledge in the quest for power efficiency

This commit is contained in:
Michele Cereda
2024-01-12 20:53:50 +01:00
parent dd5bea1cfc
commit 1ad0a14648
6 changed files with 186 additions and 27 deletions

View File

@@ -41,7 +41,9 @@
"configmap",
"containerd",
"cowsay",
"cpufreq",
"cpulimit",
"cpupower",
"cryptsetup",
"csma",
"datagram",
@@ -109,6 +111,7 @@
"nvme",
"ocsp",
"odhcpd",
"ondemand",
"openpgp",
"opkg",
"pacman",
@@ -122,6 +125,8 @@
"portsnap",
"posix",
"poweroff",
"powersave",
"pstate",
"pulumi",
"pvresize",
"radeon",
@@ -136,6 +141,7 @@
"runtimes",
"sata",
"schedulable",
"schedutil",
"scrollback",
"setfacl",
"setfattr",
@@ -168,7 +174,6 @@
"xkcd",
"zstd"
],
"markdown.extension.toc.levels": "2..6",
"markdown.extension.toc.orderedList": true
}

View File

@@ -0,0 +1,73 @@
# Check or set the CPU frequency or governor
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
```sh
# Check what governors are available.
cat '/sys/devices/system/cpu/cpufreq/'*'/scaling_available_governors'
# Get the current active governor.
cat '/sys/devices/system/cpu/cpufreq/policy0/scaling_governor'
cat '/sys/devices/system/cpu/cpufreq/'*'/scaling_governor'
# List the active CPUs affected by the current governor.
cat '/sys/devices/system/cpu/cpufreq/'*'/affected_cpus'
# Enable new governors.
echo 'schedutil' | sudo tee '/sys/devices/system/cpu/cpufreq/policy0/scaling_governor'
echo 'powersave' | sudo tee '/sys/devices/system/cpu/cpufreq/policy1/scaling_governor'
# Get the current frequency of CPUs.
cat '/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq'
cat '/sys/devices/system/cpu/cpufreq/'*'/scaling_cur_freq'
# Do not boost the CPU frequency for niced loads.
# The governor must support it - check if the file exists.
echo 1 | sudo tee '/sys/devices/system/cpu/cpufreq/ondemand/ignore_nice_load'
# Disable (1) or enable (0) turbo boost for Intel CPUs.
echo 1 | sudo tee '/sys/devices/system/cpu/intel_pstate/no_turbo'
# Check what energy vs performance hint are available for CPUs.
cat '/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences'
# Get the current energy vs performance hint used by CPUs.
cat '/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference'
cat '/sys/devices/system/cpu/cpu'*'/cpufreq/energy_performance_preference'
# Set energy vs performance hints.
echo 'balance_performance' | sudo tee '/sys/devices/system/cpu/cpu0/cpufreq/energy_performance_preference'
echo 'power' | sudo tee '/sys/devices/system/cpu/cpu'*'/cpufreq/energy_performance_preference'
```
## Further readings
- [`cpupower`][cpupower]
- [Set the _ondemand_ CPU governor to not rise the frequencies for niced loads][set the ondemand cpu governor to not rise the frequencies for niced loads]
## Sources
All the references in the [further readings] section, plus the following:
- [CPU performance scaling]
- The [*intel_pstate* CPU performance scaling driver][intel_pstate cpu performance scaling driver]
<!--
References
-->
<!-- In-article sections -->
[further readings]: #further-readings
<!-- Knowledge base -->
[cpupower]: cpupower.md
[set the ondemand cpu governor to not rise the frequencies for niced loads]: set%20the%20ondemand%20cpu%20governor%20to%20not%20rise%20the%20frequencies%20for%20niced%20loads.md
[tlp]: tlp.md
<!-- Upstream -->
[cpu performance scaling]: https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html
[intel_pstate cpu performance scaling driver]: https://www.kernel.org/doc/html/next/admin-guide/pm/intel_pstate.html

View File

@@ -1,17 +0,0 @@
# Check or set the CPU frequency or governor
```sh
cat '/sys/devices/system/cpu/cpufreq/'*'/affected_cpus'
cat '/sys/devices/system/cpu/cpufreq/'*'/scaling_available_governors'
# Get the current active governor.
cat '/sys/devices/system/cpu/cpufreq/policy0/scaling_governor'
cat '/sys/devices/system/cpu/cpufreq/'*'/scaling_governor'
# Enable a new governor.
echo 'schedutil' | sudo tee '/sys/devices/system/cpu/cpufreq/policy0/scaling_governor'
echo 'powersave' | sudo tee '/sys/devices/system/cpu/cpufreq/policy1/scaling_governor'
# Do not boost the CPU frequency for nice loads.
echo 1 | sudo tee '/sys/devices/system/cpu/cpufreq/ondemand/ignore_nice_load'
```

View File

@@ -6,19 +6,29 @@ Default governor is _ondemand_ for older CPUs and kernels and _schedutil_ for ne
```sh
# Install.
sudo apt install 'linux-cpupower'
sudo dnf install 'kernel-tools'
apt install 'linux-cpupower'
dnf install 'kernel-tools'
zypper install 'cpupower'
# List the available governors.
cpupower frequency-info --governors
cpupower -c "3-6" frequency-info --governors
cpupower --cpu "0-$(( $(nproc) - 1 ))" frequency-info --governors
# Get the current active governor.
cpupower frequency-info --policy
cpupower -c '4' frequency-info --policy
cpupower --cpu '4,5' frequency-info --policy
# Set a new governor until reboot.
# Set new governors until reboot.
sudo cpupower frequency-set -g 'performance'
sudo cpupower frequency-set --governor 'powersave'
sudo cpupower frequency-set --governor 'schedutil'
sudo cpupower -c '1' frequency-set --governor 'powersave'
sudo cpupower --cpu '2,4,7' frequency-set --governor 'schedutil'
# Get the current frequency of CPUs.
cpupower frequency-info -f
cpupower -c '4-7' frequency-info -fm
cpupower --cpu '2,5' frequency-info --freq --human
```
## Further readings

View File

@@ -8,16 +8,16 @@
## TL;DR
```sh
sudo cpupower frequency-set --governor ondemand
echo 1 | sudo tee /sys/devices/system/cpu/cpufreq/ondemand/ignore_nice_load
sudo cpupower frequency-set --governor 'ondemand'
echo 1 | sudo tee '/sys/devices/system/cpu/cpufreq/ondemand/ignore_nice_load'
# set this on boot
echo "w /sys/devices/system/cpu/cpufreq/ondemand/ignore_nice_load - - - - 1" | sudo tee /etc/tmpfiles.d/ondemand-ignore-nice.conf
echo "w /sys/devices/system/cpu/cpufreq/ondemand/ignore_nice_load - - - - 1" | sudo tee '/etc/tmpfiles.d/ondemand-ignore-nice.conf'
```
## Further readings
- [Cpufreq]
- [`cpupower`][cpupower]
- [Laptop overheating and battery duration reduction]
<!--

88
knowledge base/tlp.md Normal file
View File

@@ -0,0 +1,88 @@
# tlp
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
Manual mode: changes to the power source will be ignored until the next reboot, or until the `tlp start` command is issued to resume automatic mode.
Changes through commands are valid until next reboot.
```sh
# Install it.
zypper install 'tlp' 'tlp-rdw'
# Start the service.
sudo tlp start
sudo systemctl start 'tlp.service'
# Show information about the system.
sudo tlp-stat
# Show information about the CPU only.
# Includes the active scaling driver and available governors.
sudo tlp-stat -p
sudo tlp-stat --processor -v
# Show information about the battery only.
sudo tlp-stat -b
sudo tlp-stat --battery
# Show the service's status.
tlp-stat -s
tlp-stat --system
# Show the active configuration.
tlp-stat -c
tlp-stat --config
# Show differences between the defaults and the user configuration.
# From version 1.4.
tlp-stat --cdiff
# Apply profiles.
# Doing this enters manual mode.
sudo tlp bat
sudo tlp ac
# Change battery charge thresholds.
sudo tlp setcharge '70' '90' 'BAT0'
# Restore battery charge thresholds.
sudo tlp setcharge
# Check, enable, or disable automatic, event based actions on radio devices.
# Leverages the Radio Device Wizard.
tlp-rdw
tlp-rdw enable
tlp-rdw disable
```
## Further readings
- [Documentation]
- [`cpupower`][cpupower]
## Sources
All the references in the [further readings] section, plus the following:
- [Battery care vendor specifics]
<!--
References
-->
<!-- In-article sections -->
[further readings]: #further-readings
<!-- Knowledge base -->
[cpupower]: cpupower.md
<!-- Upstream -->
[battery care vendor specifics]: https://linrunner.de/tlp/settings/bc-vendors.html
[documentation]: https://linrunner.de/tlp/index.html
<!-- Others -->