Skip to content

Instantly share code, notes, and snippets.

@misraX
Last active August 11, 2017 12:08
Show Gist options
  • Save misraX/012b77cd9cb70c2206ce6dc6ac579381 to your computer and use it in GitHub Desktop.
Save misraX/012b77cd9cb70c2206ce6dc6ac579381 to your computer and use it in GitHub Desktop.
Kernel cpu frequency control to lower the power consumtion and fans noise without the need to set up the frequency limits using BIOS settings.
#!/bin/bash
# Created By: misraX
# Github: github.com/misrax
# License: MIT
# CopyWrite: 2017
# A very basic shell script.
# Tested in archlinux
# kernel: 4.11.9-1-ARCH, cpupower: 4.12-1, bash: 4.4.12
# To control the frequency of my Lynnfield Core i5 760 CPU. In a very hot weather :D
# Kernel cpu frequency control to lower the power consumtion and
# fans noise without the need to set up the frequency limits using
# BIOS settings.
# getting the frequency info
#cpupower frequency-info | grep -e "available frequency steps"
echo "The availabe frequency steps supported by your CPU are:"
# PIPES PIPES PIPES awk (is fun) :D
cpupower frequency-info | grep -e "available frequency steps" | awk '{
for(i=1; i<=NF; i++)
{
if ($i ~ /[0-9]+\.[0-9]*/)
{
printf("%sGHz \n",$i)
}
}
}'
echo -n "Chose one of the following frequency spacewise and press [ENTER]: "
# Read frequency from user input.
read freq
# check if it's an empty input
if [ "$freq" == "" ];then
echo "Please enter a valid frequency,"
echo "ex: 1.86GHz"
echo "Exiting...."
# exit if empty.
exit 1
else
# seting a frequency in GHz or MHz without any space
cpupower frequency-set -f "$freq"
# watching the cpu power every 2 second.
watch -n2 --exec cpupower monitor
# The end
fi
# A switch case statment to chose the desired state, To know the available states
# You have to call the cpupower frequency-info, this will outpout the available
# frequency steps in GHz (cpupower version 4.12-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment