Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Specify CPU frequency as a kernel CMD_LINE parameter of Linux on boot?

I replaced my i5 CPU of my laptop with a i7 CPU, so that it can run faster. But because that the power of i7 is more, and the temperature is also higher than before, my laptop crashed frequently. So, I used cpupower to specify the MAX frequency of CPU, it works. Now, my question is "Is there a way to specify the CPU frequency as a cmd_line parameter of the linux kernel, at boot time?", so I can ensure that the system has booted stably and correctly.

Btw, if new cpu runs under the freq of 2.5GHz at most, everything is ok, and the performance is twice more than the older. so I think it is worth to change my CPU.

thanks a lot!

like image 484
Leon Avatar asked Mar 06 '23 01:03


1 Answers

UPDATE - 2018-11-25

Also, I want to mention that there are below commands to use CpuFreq subsystem without using any tool (like cpufrequtils as it is used to achieve the same purpose). Sometimes these tools lack features, or they simply don't work as we want. Because CpuFreq core creates a sysfs directory under /sys/devices/system/cpu/, some attributes are available as read-write to be changed at kernel level. These attribute changes are called as policies as CpuFreq has a Policy Interface in sysfs. Below commands should work at boot time and be persistent between boot times.

If scaling governor is selected as intel_pstate; (This part may help to avoid higher frequencies if intel_pstate is decided to be used)

Also turbo can be disabled because of wanting to prevent higher frequencies.

echo "1" | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo

After this, below command can be useful.

echo "70" | sudo tee /sys/devices/system/cpu/intel_pstate/max_perf_pct (70 can be changed by another percentage if clock speed and turbo speed is higher numbers. 70-80 should be enough to not reaching above 2.5 GHz)

This attribute is explained as below in https://www.kernel.org/doc/Documentation/cpu-freq/intel-pstate.txt and may help to decrement higher CPU frequencies.

max_perf_pct: Limits the maximum P-State that will be requested by the driver. It states it as a percentage of the available performance.

Because P-States are operational states and by going Pn to P0, frequencies are increasing. So, limiting maximum P-states by percent of the maximum supported performance level can be useful. Check this link: https://software.intel.com/en-us/blogs/2008/05/29/what-exactly-is-a-p-state-pt-1

Also, in intel_pstate, CPUs share same properties. While using intel_pstate as scaling governor, per-CPU performance limits as cpufreq attributes (e.g. scaling_max_freq) can be used by adding below kernel parameter;


Otherwise, CPUs can be set separately;

echo -n 2457600 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo -n 2457600 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
echo -n 2457600 > /sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq
echo -n 2457600 > /sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq

But, there is an important part which is built-in script in Linux (/etc/init.d/ondemand). If ondemand or powersave is used as used as scaling governor, then configurations we set (like above) can collide with this script. The script should be disabled by below command;

sudo /usr/sbin/update-rc.d ondemand disable

Further info is in here: https://help.ubuntu.com/community/UbuntuStudio/Setting_CPU_Governor

After disabling ondemand, other scaling governors (like userspace, performance) can be set and be used by regarding above configuration.

These are all fundamental commands (both below and above part) and they should help solving CPU frequency scaling problem as I also wanted to give these information for future reference.

First of all, I want to give some information about CPU Frequency Scaling.

Three terms are related to this process (they are layers of a subsystem which is called as "CPU Performance Scaling") and they should be basically reviewed and discussed to ensure that everything is understood correctly.

  • CPUFreq Core

  • Scaling Driver

  • Scaling Governor

CPUFreq core is a basic framework and contains a common code infrastructure for all platforms that support this feature.

CPU frequency driver change CPU P-states that are managed by scaling governors and it communicates with hardware. (P-States mean they are operational, in contrast of C-States, which they are idle states except C0 state. C0 state is also busy and active state.)

Scaling governors implement scaling algorithms.

By the way, CPU Performance Scaling is a deep topic and there are many things that should be considered. Basically, with the information above, below commands should meet your needs.

Firstly, I think intel_pstate is used as a scaling driver for now in your laptop. So, disabling it may provides us more advanced settings and more governors (intel_pstate has two governors that are powersave and performance). I think powersave is default governor for intel_pstate.

sudo vi /etc/default/grub

Add intel_pstate=disable to the GRUB_CMDLINE_LINUX_DEFAULT parameter.


After adding the parameter execute below commands.

modprobe acpi-cpufreq

sudo update-grub

You can check kernel parameters at boot by below command

cat /proc/cmdline

By this way, acpi-cpufreq will be enabled as the scaling driver (because of disabling intel_pstate). So, the next thing can be setting governor as userspace to run the CPU as desired frequencies or letting it be as the default (ondemand should be default setting for acpi-cpufreq).

First Way of Setting Governor and Maximum Frequency Setting

If you want to change scaling governor (e.g. to userspace):

sudo update-rc.d ondemand disable (This command prevents above commands to be reset after reboot)

sudo apt install cpufrequtils (To control the CPU frequency scaling deamon)

echo 'GOVERNOR="userspace"' | sudo tee /etc/default/cpufrequtils

After these steps, we should have acpi-cpufreq as the scaling driver and ondemand (if you didn't change the governor) as the scaling governor. So, the last thing seem to be setting max frequency of the CPU.

Editing /etc/default/cpufrequtils like below should set CPU frequencies. If the file doesn't exist, create it.


Also check below lines in the same file.

GOVERNOR="ondemand" (or userspace)

But, with this way, I think there is no guarentee for setting all CPU cores to the same frequency values. I saw some people say that below way (second way) set all CPU cores as their desired values but not first way.

Second Way of Setting Governor and Maximum Frequency Setting

Install tlp (Linux Power management tool)

sudo apt install tlp

After installing, edit /etc/default/tlp like below:

# Select a CPU frequency scaling governor: # ondemand, powersave, performance, conservative # Intel Core i processor with intel_pstate driver: # powersave, performance # Important: # You must disable your distribution's governor settings or conflicts will #
occur. ondemand is sufficient for almost all workloads, you should know # what you're doing! CPU_SCALING_GOVERNOR_ON_AC=ondemand

# Set the min/max frequency available for the scaling governor. # Possible values strongly depend on your CPU. For available frequencies see # tlp-stat output, Section "+++ Processor". CPU_SCALING_MIN_FREQ_ON_AC=0

Above settings should be kept after restarting or suspending the device.

I have tried to provide and explain ways to set the CPU frequency (also to keep settings persistent) and I may have forgotten something. So, please check the information above and try if these meet your needs. Also, you can use below command to ensure that everything is right.


Note: Please check below pages for more information.

Governors list



like image 145
Erdem Savasci Avatar answered Apr 08 '23 14:04

Erdem Savasci