From a8429795bf957284a7e55dd520f63654bad2d80e Mon Sep 17 00:00:00 2001 From: Alex Bradbury Date: Tue, 18 Sep 2012 11:57:00 +0100 Subject: [PATCH] add init script when overclocking that allows the user to opt out on boot Current kernel builds default to the powersave cpufreq governor, with the intention that this is changed to 'ondemand' after boot. When the user sets overclock in raspi-config, an init script is installed which does this switch, but only does it if it doesn't detect a shift key is held down. This means the user can still boot the system if they set an overclock setting that is higher than their device can manage. --- raspi-config | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/raspi-config b/raspi-config index 5ebb96e..9e26cc1 100755 --- a/raspi-config +++ b/raspi-config @@ -220,6 +220,43 @@ set_overclock() { set_config_var core_freq $3 /boot/config.txt && set_config_var sdram_freq $4 /boot/config.txt && set_config_var over_voltage $5 /boot/config.txt && + # now set up an init.d script +cat <<\EOF > /etc/init.d/switch_cpu_governor && +#!/bin/sh +### BEGIN INIT INFO +# Provides: switch_cpu_governor +# Required-Start: udev mountkernfs $remote_fs +# Required-Stop: +# Default-Start: S +# Default-Stop: +# Short-Description: Switch to ondemand cpu governor (unless shift key is pressed) +# Description: +### END INIT INFO + +. /lib/lsb/init-functions + +case "$1" in + start) + log_daemon_msg "Checking if shift key is held down" + timeout 1 thd --dump /dev/input/event* | grep -q "LEFTSHIFT\|RIGHTSHIFT" + if [ $? -eq 0 ]; then + printf " Yes. Not switching scaling governor" + log_end_msg 0 + else + SYS_CPUFREQ_GOVERNOR=/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + [ -e $SYS_CPUFREQ_GOVERNOR ] && echo "ondemand" > $SYS_CPUFREQ_GOVERNOR + printf " No. Switching to ondemand scaling governor" + log_end_msg 0 + fi + ;; + *) + echo "Usage: $0 start" >&2 + exit 3 + ;; +esac +EOF + chmod +x /etc/init.d/switch_cpu_governor && + update-rc.d switch_cpu_governor defaults && whiptail --msgbox "Set overclock to preset '$1'" 20 60 2 }