summaryrefslogtreecommitdiffstats
path: root/core/modules/cpugovernor/data/opt/openslx/scripts/systemd-cpu_governor
blob: cdde82d5f8ad6937a7f0809ca7b5eb25d5a31856 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/ash
# 
# Script to set the CPU governor to ondemand on all cores
#

# source global config
. /opt/openslx/config || \
	{ echo "ERROR: Could not source /opt/openslx/config."; exit 1; }

# if scaling_driver is acpi-cpufreq:
#   cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
#   conservative ondemand userspace powersave performance schedutil
#   -> use ondemand and performance
# if scaling_driver is intel_cpufreq:
#   cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
#   conservative ondemand userspace powersave performance schedutil
#   -> same as acpi
# if scaling_driver is intel_pstate:
#   cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
#   performance powersave
#   -> we only got two choices anyways :)
# if scaling_driver is amd_pstate:
#   haven't seen this yet, relatively new as of 2024, but it should work
#   almost the same as intel_pstate, i.e. only performance and powersave

# set the governor. Prioritize command-line argument, then SLX_GOVERNOR,
# fall back to powersave.
if [ -n "$1" ]; then
	wanted_gov="$1"
elif [ -n "$SLX_GOVERNOR" ]; then
	wanted_gov="$SLX_GOVERNOR"
else
	wanted_gov="powersave"
fi
echo "Trying to set CPU governor to $wanted_gov"

for dir in /sys/devices/system/cpu/cpu*/cpufreq; do
	driver=$( cat "$dir/scaling_driver" )
	newgov="$wanted_gov"
	if [ "$driver" != "intel_pstate" ] && [ "$driver" != "amd_pstate" ]; then
		[ "$newgov" = "powersave" ] && newgov="ondemand"
	fi
	echo "$newgov" > "$dir/scaling_governor"
done
exit 0