Sunday, April 21, 2024

Setting CPU min, max and governor

Use the script below to set the min, max and CPU governor in Linux:


#!/usr/bin/env bash

MIN_FREQ=800000
MAX_FREQ=1000000
GOVERNOR=powersave

for i in `seq 0 3`;
do
  echo ${GOVERNOR} > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor
  echo ${MAX_FREQ} > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_max_freq
  echo ${MIN_FREQ} > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_min_freq
done

Set the max number of cores accordingly.

Script requires the following packages to be installed:

  • cpufrequtils
  • cpufreqd

Run the command below to verify that the changes are applied:

$ cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 4294.55 ms.
  hardware limits: 700 MHz - 3.40 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 1000 MHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 754 MHz.
analyzing CPU 1:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 1
  CPUs which need to have their frequency coordinated by software: 1
  maximum transition latency: 4294.55 ms.
  hardware limits: 700 MHz - 3.40 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 1000 MHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 800 MHz.
analyzing CPU 2:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 2
  CPUs which need to have their frequency coordinated by software: 2
  maximum transition latency: 4294.55 ms.
  hardware limits: 700 MHz - 3.40 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 1000 MHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 800 MHz.
analyzing CPU 3:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 3
  CPUs which need to have their frequency coordinated by software: 3
  maximum transition latency: 4294.55 ms.
  hardware limits: 700 MHz - 3.40 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 1000 MHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 795 MHz.

4 comments:

anitha said...

Great script and clear instructions! This will definitely help optimize CPU performance and energy efficiency. Thanks for sharing such a practical and useful solution! It’s a helpful reminder of how simple tweaks can improve efficiency on Linux systems.
data science internship |
python internship |
artificial intelligence internship |
java internship |
cyber security internship

anjani02 said...

This article provides a good overview of the topic. Thanks for sharing these valuable insights.devops azure course

online it guru said...

Nice article with useful information. I especially liked the practical perspective and the way the main points were explained.ibm datastage training

OnlineITGuru said...

workday online integration training provides structured learning about Workday integration concepts, data processing, and system connectivity. Practical exercises help learners understand common integration scenarios and workflows.