set-processor-speed.sh 746 Bytes
Newer Older
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
#!/bin/sh

# Script to "fix" the cpu performance to a given frequency

self="$0"

## sudo cpupower -c 0-3 frequency-set -d 1000000 -u 1000000 && sudo cpupower -c 0-3 frequency-info -f

die() {
	echo >&2 "$@"
	exit 1
}

need() {
	which "$1" >/dev/null 2>/dev/null || die "need executable: $1"
}

need cpupower
need nproc
need sleep
need cat
need id

uid=$(id -u)

numproc=$(nproc)
maxproc=$(($numproc - 1))


if [ "$uid" -ne 0 ]; then
	die "not root"
fi

if [ -z "$1" ]; then
	min=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq)
	max=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)
else
	min="$1"
	max="$1"
fi

cpupower -c "0-$maxproc" frequency-set -d "$min" -u "$max"
sleep 1
cpupower -c "0-$maxproc" frequency-info -f