Refine the User Guide CPU Frequency Scaling section (#1331)

* Revert "Refine docs on changing cpufreq governor (#1325)"

This reverts commit 9e859f5bf5.

* Refine the User Guide CPU Frequency Scaling section

The text now describes the cpupower command, so users in a hurry
have something to copy/paste that will likely work.  It then
suggests that there are probably more convenient optons available
that people can look into.

This reverts the prior commit, which introduced a shell script
that doesn't work.  It also retains the spirit of the original
fix: no longer recommend setting the frequency governor to
"powersave", which might not be appropriate or available.

Note: I did attempt to write a bash script that set the govenor
to "powersave" for the duration of a single command, but I gave
up for many reasons:

 1) it got complex, in part because the cpupower command does not
 seem to be designed for scripts (e.g. it prints out complex
 English phrases).

 2) munging /proc/sys files directly feels unstable and less than
 universal.  The libcpupower and cpupower are designed to abstract
 those away, because the details can vary.

 3) there are better options.  E.g. various GUI programs, and
 even Gnome's core Settings UI, let you adjust the system's
 performance mode without root access.

Fixes #1325, #1327
This commit is contained in:
Matt Armstrong 2022-01-21 08:24:49 -08:00 committed by GitHub
parent 9e859f5bf5
commit acd7562034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1227,16 +1227,36 @@ If you see this error:
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
```
you might want to disable the CPU frequency scaling while running the benchmark using a script like:
you might want to disable the CPU frequency scaling while running the
benchmark. Exactly how to do this depends on the Linux distribution,
desktop environment, and installed programs. Specific details are a moving
target, so we will not attempt to exhaustively document them here.
One simple option is to use the `cpupower` program to change the
performance governor to "performance". This tool is maintained along with
the Linux kernel and provided by your distribution.
It must be run as root, like this:
```bash
for f in /sys/devices/system/cpu/cpu?/cpufreq/scaling_governor
do
before=`cat $f`
echo "performance" > $f
./mybench # run your benchmark here
echo $before > $f
done
sudo cpupower frequency-set --governor performance
```
note, you will have to run this as root (under sudo).
After this you can verify that all CPUs are using the performance governor
by running this command:
```bash
cpupower frequency-info -o proc
```
The benchmarks you subsequently run will have less variance.
Note that changing the governor in this way will not persist across
reboots. To set the governor back, run the first command again with the
governor your system usually runs with, which varies.
If you find yourself doing this often, there are probably better options
than running the commands above. Some approaches allow you to do this
without root access, or by using a GUI, etc. The Arch Wiki [Cpu frequency
scaling](https://wiki.archlinux.org/title/CPU_frequency_scaling) page is a
good place to start looking for options.