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.