#!/bin/sh

GOVERNORS="ondemand performance conservative powersave userspace"

_verbose=""
_governor=""

if [ $# -gt 0 -a "$1" = "-v" ]; then
	_verbose="v"
	shift
fi

if [ $# -eq 0 ]; then
	_governor="powersave"
else
	for _tg in ${GOVERNORS}; do
		if echo ${_tg} | grep -E ^$1 > /dev/null 2>&1; then
			_governor=${_tg}
			break
		fi
	done
fi

if [ -z "${_governor}" ]; then
	echo "Unknown scaling governor $1"
	exit 1
fi

[ "${_verbose}" = "v" ] && echo "Setting \"${_governor}\" scaling governor..."

for _cpu in `ls -d /sys/devices/system/cpu/cpu[0-9]*`; do
	echo ${_governor} > ${_cpu}/cpufreq/scaling_governor
done
