#!/bin/bash CPUPOWER_CONFIG="/etc/default/cpupower" if [ -f "${CPUPOWER_CONFIG}" ]; then source "${CPUPOWER_CONFIG}" else exit 0 fi print_header() { cat << HEADER ############################################################################### # ${@} ############################################################################### HEADER } # Set the CPU governor if [ ! "${CPU_GOVERNOR}" == "" ]; then print_header "Setting CPU governor to ${CPU_GOVERNOR}" cpupower frequency-set --governor "${CPU_GOVERNOR}" &> /dev/null cpupower frequency-info else echo "CPU governor is not set." fi # Set the Cstate by Max C-State if [ ! "${CPU_CSTATE_MAX}" == "" ]; then print_header "Setting CPU CStates to max \"${CPU_CSTATE_MAX}\"" CPU_POWER_SET_ACTION="-e" CPU_POWER_CSTATE=0 for CPU_CSTATE_NAME in /sys/devices/system/cpu/cpu0/cpuidle/state*/name; do cpupower idle-set "${CPU_POWER_SET_ACTION}" "${CPU_POWER_CSTATE}" &> /dev/null CPU_POWER_CSTATE=$((CPU_POWER_CSTATE+1)) if grep -q "\b${CPU_CSTATE_MAX}\b" "${CPU_CSTATE_NAME}"; then CPU_POWER_SET_ACTION="-d" fi done cpupower idle-info # Set the Cstate by latency elif [ ! "${CPU_CSTATES_DISABLE_BY_LATENCY}" == "" ]; then print_header "Setting CPU CStates by latency to ${CPU_CSTATES_DISABLE_BY_LATENCY}" cpupower idle-set --disable-by-latency "${CPU_CSTATES_DISABLE_BY_LATENCY}" &> /dev/null cpupower idle-info else echo "No CPU Cstates configured." fi