1
0
Fork 0

functions: used sysfs for governor switching by default

Patching of cpuspeed kept for backward compatibility.

Related: rhbz#1313489

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2016-11-29 16:51:37 +01:00
parent 8b2249bd13
commit 0ce452fc2e

View file

@ -218,6 +218,8 @@ CPUSPEED_ORIG_GOV="${STORAGE}/cpuspeed-governor-%s${STORAGE_SUFFIX}"
CPUSPEED_STARTED="${STORAGE}/cpuspeed-started"
CPUSPEED_CFG="/etc/sysconfig/cpuspeed"
CPUSPEED_INIT="/etc/init.d/cpuspeed"
# do not use cpuspeed
CPUSPEED_USE="0"
CPUS="$(ls -d1 /sys/devices/system/cpu/cpu* | sed 's;^.*/;;' | grep "cpu[0-9]\+")"
# set CPU governor setting and store the old settings
@ -225,24 +227,32 @@ CPUS="$(ls -d1 /sys/devices/system/cpu/cpu* | sed 's;^.*/;;' | grep "cpu[0-9]\+
set_cpu_governor() {
governor=$1
# prefer governor setting using cpuspeed daemon
# always patch cpuspeed configuration if exists, if it doesn't exist and is enabled,
# explictly disable it with hint
if [ -e $CPUSPEED_INIT ]; then
if [ ! -e $CPUSPEED_SAVE_FILE -a -e $CPUSPEED_CFG ]; then
cp -p $CPUSPEED_CFG $CPUSPEED_SAVE_FILE
sed -e 's/^GOVERNOR=.*/GOVERNOR='$governor'/g' $CPUSPEED_SAVE_FILE > $CPUSPEED_CFG
fi
else
if [ "$CPUSPEED_USE" = "1" ]; then
echo >&2
echo "Suggestion: install 'cpuspeed' package to get best tuning results." >&2
echo "Falling back to sysfs control." >&2
echo >&2
fi
CPUSPEED_USE="0"
fi
if [ "$CPUSPEED_USE" = "1" ]; then
service cpuspeed status &> /dev/null
[ $? -eq 3 ] && touch $CPUSPEED_STARTED || rm -f $CPUSPEED_STARTED
service cpuspeed restart &> /dev/null
# direct change using /sys fs
# direct change using sysfs
elif [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
echo >&2
echo "Suggestion: install 'cpuspeed' package to get best tuning results." >&2
echo "Falling back to '$governor' scaling governor for all CPUs." >&2
echo >&2
for cpu in $CPUS; do
gov_file=/sys/devices/system/cpu/$cpu/cpufreq/scaling_governor
@ -265,13 +275,21 @@ restore_cpu_governor() {
rm -f $CPUSPEED_SAVE_FILE
fi
if [ "$CPUSPEED_USE" = "1" ]; then
if [ -e $CPUSPEED_STARTED ]; then
service cpuspeed stop &> /dev/null
else
service cpuspeed restart &> /dev/null
fi
fi
if [ -e $CPUSPEED_STARTED ]; then
rm -f $CPUSPEED_STARTED
service cpuspeed stop &> /dev/null
else
service cpuspeed restart &> /dev/null
fi
elif [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
else
CPUSPEED_USE="0"
fi
if [ "$CPUSPEED_USE" != "1" -a -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
for cpu in $CPUS; do
cpufreq_dir=/sys/devices/system/cpu/$cpu/cpufreq
save_file=$(printf $CPUSPEED_ORIG_GOV $cpu)