Kobo: Set the CPU governor on *every* CPU (if available)

Fix #8578
reviewable/pr8694/r1
NiLuJe 2 years ago committed by poire-z
parent 0216493c43
commit 1084c6e151

@ -17,31 +17,37 @@ if [ "${SCRIPT_DIR}" != "/tmp" ]; then
fi fi
# Attempt to switch to a sensible CPUFreq governor when that's not already the case... # Attempt to switch to a sensible CPUFreq governor when that's not already the case...
IFS= read -r current_cpufreq_gov <"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" # Swap every CPU at once if available
if [ -d "/sys/devices/system/cpu/cpufreq/policy0" ]; then
CPUFREQ_SYSFS_PATH="/sys/devices/system/cpu/cpufreq/policy0"
else
CPUFREQ_SYSFS_PATH="/sys/devices/system/cpu/cpu0/cpufreq"
fi
IFS= read -r current_cpufreq_gov <"${CPUFREQ_SYSFS_PATH}/scaling_governor"
# NOTE: What's available depends on the HW, so, we'll have to take it step by step... # NOTE: What's available depends on the HW, so, we'll have to take it step by step...
# Roughly follow Nickel's behavior (which prefers interactive), and prefer interactive, then ondemand, and finally conservative/dvfs. # Roughly follow Nickel's behavior (which prefers interactive), and prefer interactive, then ondemand, and finally conservative/dvfs.
if [ "${current_cpufreq_gov}" != "interactive" ]; then if [ "${current_cpufreq_gov}" != "interactive" ]; then
if grep -q "interactive" "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"; then if grep -q "interactive" "${CPUFREQ_SYSFS_PATH}/scaling_available_governors"; then
ORIG_CPUFREQ_GOV="${current_cpufreq_gov}" ORIG_CPUFREQ_GOV="${current_cpufreq_gov}"
echo "interactive" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" echo "interactive" >"${CPUFREQ_SYSFS_PATH}/scaling_governor"
elif [ "${current_cpufreq_gov}" != "ondemand" ]; then elif [ "${current_cpufreq_gov}" != "ondemand" ]; then
if grep -q "ondemand" "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"; then if grep -q "ondemand" "${CPUFREQ_SYSFS_PATH}/scaling_available_governors"; then
# NOTE: This should never really happen: every kernel that supports ondemand already supports interactive ;). # NOTE: This should never really happen: every kernel that supports ondemand already supports interactive ;).
# They were both introduced on Mk. 6 # They were both introduced on Mk. 6
ORIG_CPUFREQ_GOV="${current_cpufreq_gov}" ORIG_CPUFREQ_GOV="${current_cpufreq_gov}"
echo "ondemand" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" echo "ondemand" >"${CPUFREQ_SYSFS_PATH}/scaling_governor"
elif [ -e "/sys/devices/platform/mxc_dvfs_core.0/enable" ]; then elif [ -e "/sys/devices/platform/mxc_dvfs_core.0/enable" ]; then
# The rest of this block assumes userspace is available... # The rest of this block assumes userspace is available...
if grep -q "userspace" "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"; then if grep -q "userspace" "${CPUFREQ_SYSFS_PATH}/scaling_available_governors"; then
ORIG_CPUFREQ_GOV="${current_cpufreq_gov}" ORIG_CPUFREQ_GOV="${current_cpufreq_gov}"
export CPUFREQ_DVFS="true" export CPUFREQ_DVFS="true"
# If we can use conservative, do so, but we'll tweak it a bit to make it somewhat useful given our load patterns... # If we can use conservative, do so, but we'll tweak it a bit to make it somewhat useful given our load patterns...
# We unfortunately don't have any better choices on those kernels, # We unfortunately don't have any better choices on those kernels,
# the only other governors available are powersave & performance (c.f., #4114)... # the only other governors available are powersave & performance (c.f., #4114)...
if grep -q "conservative" "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"; then if grep -q "conservative" "${CPUFREQ_SYSFS_PATH}/scaling_available_governors"; then
export CPUFREQ_CONSERVATIVE="true" export CPUFREQ_CONSERVATIVE="true"
echo "conservative" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" echo "conservative" >"${CPUFREQ_SYSFS_PATH}/scaling_governor"
# NOTE: The knobs survive a governor switch, which is why we do this now ;). # NOTE: The knobs survive a governor switch, which is why we do this now ;).
echo "2" >"/sys/devices/system/cpu/cpufreq/conservative/sampling_down_factor" echo "2" >"/sys/devices/system/cpu/cpufreq/conservative/sampling_down_factor"
echo "50" >"/sys/devices/system/cpu/cpufreq/conservative/freq_step" echo "50" >"/sys/devices/system/cpu/cpufreq/conservative/freq_step"
@ -60,7 +66,7 @@ if [ "${current_cpufreq_gov}" != "interactive" ]; then
# (There's also a bug(?) where that behavior is inverted for the *first* Wi-Fi session after a cold boot...) # (There's also a bug(?) where that behavior is inverted for the *first* Wi-Fi session after a cold boot...)
if grep -q "^sdio_wifi_pwr" "/proc/modules"; then if grep -q "^sdio_wifi_pwr" "/proc/modules"; then
# Wi-Fi is enabled, make sure DVFS is on # Wi-Fi is enabled, make sure DVFS is on
echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" echo "userspace" >"${CPUFREQ_SYSFS_PATH}/scaling_governor"
echo "1" >"/sys/devices/platform/mxc_dvfs_core.0/enable" echo "1" >"/sys/devices/platform/mxc_dvfs_core.0/enable"
else else
# Wi-Fi is disabled, make sure DVFS is off # Wi-Fi is disabled, make sure DVFS is off
@ -68,12 +74,12 @@ if [ "${current_cpufreq_gov}" != "interactive" ]; then
# Switch to conservative to avoid being stuck at max clock if we can... # Switch to conservative to avoid being stuck at max clock if we can...
if [ -n "${CPUFREQ_CONSERVATIVE}" ]; then if [ -n "${CPUFREQ_CONSERVATIVE}" ]; then
echo "conservative" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" echo "conservative" >"${CPUFREQ_SYSFS_PATH}/scaling_governor"
else else
# Otherwise, we'll be pegged at max clock... # Otherwise, we'll be pegged at max clock...
echo "userspace" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" echo "userspace" >"${CPUFREQ_SYSFS_PATH}/scaling_governor"
# The kernel should already be taking care of that... # The kernel should already be taking care of that...
cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" cat "${CPUFREQ_SYSFS_PATH}/scaling_max_freq" >"${CPUFREQ_SYSFS_PATH}/scaling_setspeed"
fi fi
fi fi
fi fi
@ -558,7 +564,7 @@ fi
# Restore original CPUFreq governor if need be... # Restore original CPUFreq governor if need be...
if [ -n "${ORIG_CPUFREQ_GOV}" ]; then if [ -n "${ORIG_CPUFREQ_GOV}" ]; then
echo "${ORIG_CPUFREQ_GOV}" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" echo "${ORIG_CPUFREQ_GOV}" >"${CPUFREQ_SYSFS_PATH}/scaling_governor"
# NOTE: Leave DVFS alone, it'll be handled by Nickel if necessary. # NOTE: Leave DVFS alone, it'll be handled by Nickel if necessary.
fi fi

Loading…
Cancel
Save