#!/bin/bash

GOV="ondemand"
CPUFREQDIR="/sys/devices/system/cpu/cpu0/cpufreq"
GOVDIR="/sys/devices/system/cpu/cpufreq/${GOV}"


test -n "${OS_VERSION}" || source /etc/init.d/base

configure() {
    echo ${GOV} > ${CPUFREQDIR}/scaling_governor
    if [[ ${GOV} == "ondemand" ]]; then
        echo 50 > ${GOVDIR}/up_threshold
        echo 100000 > ${GOVDIR}/sampling_rate
        echo 50 > ${GOVDIR}/sampling_down_factor
        echo 1 > ${GOVDIR}/io_is_busy
    fi
}

case "$1" in
    start)
        msg_begin "Configuring CPU frequency"
        configure
        test $? == 0 && msg_done || msg_fail
        ;;

    stop)
        true
        ;;

    *)
        echo $"Usage: $0 {start}"
        exit 1
esac

exit $?

