#!/bin/bash # # Author: Christian Birchinger # # Daemon that monitors the DPMS state of a given display port and adjusts the # CPU scheduling governor. Typically powersave or shedutil during screen # blanking and performance while the display is on. PORT=card0-DVI-D-1 INTERVAL=60 ON_GOV=performance OFF_GOV=schedutil snore() { local IFS [[ -n "${_snore_fd:-}" ]] || { exec {_snore_fd}<> <(:); } 2>/dev/null read -r ${1:+-t "$1"} -u $_snore_fd || : } dpms_path="/sys/class/drm/${PORT}/dpms" prevstat='' if [[ ! -r "$dpms_path" ]]; then echo "ERROR: Unable to read ${dpms_path}" >&2 exit 1 fi while true; do curstat=$(<"${dpms_path}") if [[ "$prevstat" != "$curstat" ]]; then if [[ "$curstat" == "On" ]]; then cpupower frequency-set -g "${ON_GOV}" &> /dev/null logger -t "dpms_cpufreq[$$]" -p daemon.info "Switching governor to ${ON_GOV}" else cpupower frequency-set -g "${OFF_GOV}" &> /dev/null logger -t "dpms_cpufreq[$$]" -p daemon.info "Switching governor to ${OFF_GOV}" fi fi prevstat=$curstat snore ${INTERVAL} done