#!/bin/bash # A wrapper for cpupower to set the appropriate governor for frequency # scaling. Sets 'ondemand', 'powersave' or 'performance' if available # (checks availablility in this order). # The user can override this behaviour by specifying the governor in # CPUPOWER_GOVERNOR variable. # # CPUPOWER_OTHER_ARGS can be used to provide additional arguments to # cpupower. AVAIL_FILE=/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors USE_GOVERNOR="" if ! test -e "${AVAIL_FILE}"; then printf "CPU frequency scaling is not supported.\n" exit 1 fi if test -n "${CPUPOWER_GOVERNOR}"; then if grep "${CPUPOWER_GOVERNOR}" "${AVAIL_FILE}" >/dev/null 2>&1; then USE_GOVERNOR="${CPUPOWER_GOVERNOR}" else printf "Unknown governor: ${CPUPOWER_GOVERNOR}.\n" printf "Available governors: " cat "${AVAIL_FILE}" printf "\n" exit 1 fi elif grep "ondemand" "${AVAIL_FILE}" >/dev/null 2>&1; then USE_GOVERNOR=ondemand elif grep "powersave" "${AVAIL_FILE}" >/dev/null 2>&1; then USE_GOVERNOR=powersave elif grep "performance" "${AVAIL_FILE}" >/dev/null 2>&1; then USE_GOVERNOR=performance else printf "Failed to select the governor automatically, " printf "please specify it explicitly in CPUPOWER_GOVERNOR variable.\n" printf "Available governors: " cat "${AVAIL_FILE}" printf "\n" exit 1 fi # Set the governor at last. printf "Using \"${USE_GOVERNOR}\" governor.\n" /usr/bin/cpupower frequency-set -g ${USE_GOVERNOR} ${CPUPOWER_OTHER_ARGS}