#!/bin/bash ############################################# # CPU speed setting tool # # By Marcelo Goes # # Under GPLv2 # ############################################# # You must have properly configured frequency scaling before using this script # I am not responsible if this script screws up your computer # Please configure the variables below before using # Location of /sys nodes for VCore and CPU speed SYS_VCORE="/sys/bus/i2c/devices/0-004e/cpu0_vid" SYS_CPUSPEED="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" # VCore * 1000 # CPU Speed in MHz * 1000 SLOW_VCORE="1500" SLOW_CPUSPEED="1300000" MEDIUM_VCORE="1600" MEDIUM_CPUSPEED="1800000" FAST_VCORE="1625" FAST_CPUSPEED="2160000" ############################################## # No configuration necessary below this point# ############################################## VERSION="0.2" TARGET="slow" SYS_VCORE_VALUE=$(cat ${SYS_VCORE}) SYS_CPUSPEED_VALUE=$(cat ${SYS_CPUSPEED}) USER=$(/usr/bin/whoami) show_cpu_version () { echo "CPU speed setting tool ${VERSION} by Marcelo Goes " } show_version_usage () { show_cpu_version echo echo "Usage: cpu [slow|medium|fast]" } show_cpu_help () { show_version_usage echo "Options:" echo " --help, -h Display this information" echo " --version, -v Show version" echo " slow Slow cpu settings" echo " medium Medium cpu settings" echo " fast Maximum cpu settings" echo " custom Custom cpu settings" } show_cpu_speed () { SHOW_VCORE=$(echo "scale=3; ${SYS_VCORE_VALUE}/1000" | bc) echo "VCore: ${SHOW_VCORE}" SHOW_CPUSPEED=$(echo "scale=0; ${SYS_CPUSPEED_VALUE}/1000" | bc) echo "MHz: ${SHOW_CPUSPEED}" } show_current() { show_cpu_version echo echo "Current settings" echo show_cpu_speed } set_cpu_speed() { if [ ${USER} != root ] ; then echo "Error: you must be root to do that." exit 1 fi show_current if [ ${TARGET} == slow ] ; then echo "${SLOW_CPUSPEED}" > ${SYS_CPUSPEED} echo "${SLOW_VCORE}" > ${SYS_VCORE} fi if [ ${TARGET} == medium ] ; then echo "${MEDIUM_VCORE}" > ${SYS_VCORE} echo "${MEDIUM_CPUSPEED}" > ${SYS_CPUSPEED} fi if [ ${TARGET} == fast ] ; then echo "${FAST_VCORE}" > ${SYS_VCORE} echo "${FAST_CPUSPEED}" > ${SYS_CPUSPEED} fi if [ ${TARGET} == custom ] ; then echo "${CUSTOM_VCORE}" > ${SYS_VCORE} echo "${CUSTOM_CPUSPEED}" > ${SYS_CPUSPEED} fi SYS_VCORE_VALUE=$(cat ${SYS_VCORE}) SYS_CPUSPEED_VALUE=$(cat ${SYS_CPUSPEED}) echo echo "New settings" echo show_cpu_speed } set_slow() { TARGET="slow" set_cpu_speed } set_medium() { TARGET="medium" set_cpu_speed } set_fast() { TARGET="fast" set_cpu_speed } set_custom() { TARGET="custom" CUSTOM_VCORE="${SLOW_VCORE}" CUSTOM_CPUSPEED="${SLOW_CPUSPEED}" echo "Enter VCore:" read CUSTOM_VCORE echo "Got ${CUSTOM_VCORE}." echo "Enter CPU speed:" read CUSTOM_CPUSPEED echo "Got ${CUSTOM_CPUSPEED}." echo echo "Are you sure you want to continue? [y/n]" echo "Wrong values might damage your computer beyond repair." read TMP_OPT if [ ${TMP_OPT} == "y" ]; then set_cpu_speed else echo "Bailing out..." exit 1 fi } # process arguments for option in "$@" ; do case ${option} in --help|-h) show_cpu_help exit 0;; --version|-v) show_cpu_version exit 0;; show) show_current exit 0;; slow) set_slow exit 0;; medium) set_medium exit 0;; fast) set_fast exit 0;; custom) set_custom exit 0;; *) show_cpu_version exit 0;; esac done show_current exit 0