Skip to content

Instantly share code, notes, and snippets.

@thetrung
Last active February 15, 2025 14:53
Show Gist options
  • Save thetrung/6564bd65ba544fdc169202280588ec47 to your computer and use it in GitHub Desktop.
Save thetrung/6564bd65ba544fdc169202280588ec47 to your computer and use it in GitHub Desktop.
Set all CPUs to a certain frequency range [ min, max] with cpufrequtils package.
#!/bin/bash
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check availability :
if [ cpufreq-set ]
then
echo ""
else
echo -e "${RED} [ERROR] cpufreq-set not found. Try installing... ${NC} \n"
echo "`sudo apt install cpufrequtils`"
fi
# Count CPUs :
MAX_CPU=$((`nproc --all` - 1))
CPU_FOUND=$((MAX_CPU + 1))
echo -e "${YELLOW} [INFO] Found ${CPU_FOUND} CPUs.\n"
MIN="400Mhz"
MAX="550Mhz"
# Check params :
if [ $# -eq 2 ]
then
MIN="$1Mhz"
MAX="$2Mhz"
for i in $(seq 0 $MAX_CPU); do
echo -e "${GREEN} [cpufreq-set]: CPU #" $i " >> [" $MIN "~" $MAX "]${NC}";
sudo cpufreq-set -c $i --min $MIN --max $MAX;
done
# Show new CPU frequencies :
# cpufreq-info
else
echo ""
echo -e "${RED}[NOTE]: It require min & max frequencies (in Mhz):"
echo ""
echo -e " ${GREEN} cpufreq-set-range 400 800 ${NC}"
echo ""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment