Default Ubuntu kernel configurations are such that the performance CPU frequency scaling governor will be used during boot. The relevant section of the kernel configuration file ( /boot/config-4.15.0-36-generic
, in this example) is:
#
# CPU Frequency scaling
#
CONFIG_CPU_FREQ=y
CONFIG_CPU_FREQ_GOV_ATTR_SET=y
CONFIG_CPU_FREQ_GOV_COMMON=y
CONFIG_CPU_FREQ_STAT=y
CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL is not set
CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
CONFIG_CPU_FREQ_GOV_POWERSAVE=y
CONFIG_CPU_FREQ_GOV_USERSPACE=y
CONFIG_CPU_FREQ_GOV_ONDEMAND=y
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
CONFIG_CPU_FREQ_GOV_SCHEDUTIL=y
#
# CPU frequency scaling drivers
#
CONFIG_X86_INTEL_PSTATE=y
CONFIG_X86_PCC_CPUFREQ=y
CONFIG_X86_ACPI_CPUFREQ=y
CONFIG_X86_ACPI_CPUFREQ_CPB=y
CONFIG_X86_POWERNOW_K8=y
CONFIG_X86_AMD_FREQ_SENSITIVITY=m
CONFIG_X86_SPEEDSTEP_CENTRINO=y
CONFIG_X86_P4_CLOCKMOD=m
But also by default during boot up the ondemand
service is executed. It sleeps for 1 minutes and then changes the scaling governor to either interactive
, ondemand
or powersave
, depending on availability. In turn availability depends on which CPU frequency scaling driver you are using. The code is (in multiple locations, search for ondemand
):
#! /bin/sh
### BEGIN INIT INFO
# Provides: ondemand
# Required-Start: $remote_fs $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Set the CPU Frequency Scaling governor to "ondemand"
### END INIT INFO
# Don't run if we're going to start an Android LXC container:
[ ! -f /etc/init/lxc-android-config.conf ] || exit 0
PATH=/sbin:/usr/sbin:/bin:/usr/bin
. /lib/init/vars.sh
. /lib/lsb/init-functions
AVAILABLE="/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
DOWN_FACTOR="/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor"
case "$1" in
start)
start-stop-daemon --start --background --exec /etc/init.d/ondemand -- background
;;
background)
sleep 60 # probably enough time for desktop login
[ -f $AVAILABLE ] || exit 0
read governors < $AVAILABLE
case $governors in
*interactive*)
GOVERNOR="interactive"
break
;;
*ondemand*)
GOVERNOR="ondemand"
case $(uname -m) in
ppc64*)
SAMPLING=100
;;
esac
break
;;
*powersave*)
GOVERNOR="powersave"
break
;;
*)
exit 0
;;
esac
for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
do
[ -f $CPUFREQ ] || continue
echo -n $GOVERNOR > $CPUFREQ
done
if [ -n "$SAMPLING" ] && [ -f $DOWN_FACTOR ]; then
echo -n $SAMPLING > $DOWN_FACTOR
fi
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
Why is it called "ondemand", but it sets other governors (for example with the intel_pstate driver it will set the powersave governor)? Because this tool pre-dates the intel_pstate driver, back to a time when, by far, the dominant frequency scaling driver was the acpi-cpufreq driver, and "ondemand" was the preferred Ubuntu default governor.
So, one way to boot and stay using the performance CPU frequency scaling governor is to disable the service that changes away from it (which was also mentioned in another answer):
Before:
~$ systemctl list-units --all --type=service | grep ondemand
ondemand.service loaded inactive dead Set the CPU Frequency Scaling governor
~$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
ondemand
ondemand
Disable the service:
~$ sudo systemctl disable ondemand
Removed /etc/systemd/system/multi-user.target.wants/ondemand.service.
re-boot, then check again (being sure to wait a minute after the re-boot):
doug@s17:~$ systemctl list-units --all --type=service | grep ondemand
doug@s17:~$
doug@s17:~$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
performance
performance
Note: the examples in this answer are from a computer that uses the acpi-cpufreq CPU frequency scaling driver. If you are using the intel_pstate driver, with no ondemand governor, the powersave governor will be used by default.
Anticipated question: Why do my CPU frequencies scale, even when using the performance governor?
Answer: Modern processors scale the CPU frequency, even in performance mode and as a function of the depth of the idle state they go into. If you really want to lock the CPU frequency then disable all idle states deeper than 0. However, note that it will cost a huge huge amount of power.
Personally, and as mentioned in another answer, I use the performance governor or the powersave governor as a function of whatever work I am doing. My scripts are a little different:
$ cat set_cpu_performance
#! /bin/bash
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "performance" > $file; done
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
and:
$ cat set_cpu_powersave
#! /bin/bash
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
for file in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "powersave" > $file; done
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
example usage (on a computer using the intel_pstate driver):
$ sudo ./set_cpu_performance
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
performance
performance
performance
performance
performance
performance
performance
performance
/etc/rc.local
only in this question, or did you make that same typo when creating it? This question may not be specific to 18.04 and probably shouldn't be a bug report rather than a question here. I think the question could be considered for reopening if you edit it to add more detail.--governor powersave
should be--governor performance
...