Score:0

Unable to limit CPU speed on Ubuntu 22.04 with cpufrequtils

cn flag
s.k

Based on this: How can I easily control CPU speed on Ubuntu? I try to manually force some of my CPU cores on Ubuntu 22.04.1 5.15.0-56-generic x86_64 GNU/Linux to be limited to 800 MHz using cpufreq (from: cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009) but it doesn't seem to work:

$ for i in 1 2 3 4 5 6 7; do sudo cpufreq-set -c $i -d 800 MHz; done

$ watch -n2 'cpufreq-info | grep "current CPU freq"'

Every 2.0s: cpufreq-info | grep "current CPU freq"                                                                                                          
  current CPU frequency is 3.45 GHz.
  current CPU frequency is 1.44 GHz.
  current CPU frequency is 1.85 GHz.
  current CPU frequency is 1.61 GHz.
  current CPU frequency is 2.58 GHz.
  current CPU frequency is 1.97 GHz.
  current CPU frequency is 1.26 GHz.
  current CPU frequency is 3.45 GHz.

Why doesn't it work and how to make it work?

Here's the /proc/cpuinfo on one core:

processor   : 7
vendor_id   : GenuineIntel
cpu family  : 6
model       : 140
model name  : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping    : 1
microcode   : 0xa4
cpu MHz     : 2570.099
cache size  : 12288 KB
physical id : 0
siblings    : 8
core id     : 3
cpu cores   : 4
apicid      : 7
initial apicid  : 7
fpu     : yes
fpu_exception   : yes
cpuid level : 27
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l2 invpcid_single cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags   : vnmi preemption_timer posted_intr invvpid ept_x_only ept_ad ept_1gb flexpriority apicv tsc_offset vtpr mtf vapic ept vpid unrestricted_guest vapic_reg vid ple pml ept_mode_based_exec tsc_scaling
bugs        : spectre_v1 spectre_v2 spec_store_bypass swapgs eibrs_pbrsb
bogomips    : 5606.40
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

and:

$ sudo lshw -class cpu
  *-cpu                     
       description: CPU
       product: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
       vendor: Intel Corp.
       physical id: 10
       bus info: cpu@0
       version: 6.140.1
       serial: None
       slot: U3E1
       size: 3542MHz
       capacity: 4700MHz
       width: 64 bits
       clock: 100MHz
       capabilities: lm fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp x86-64 constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l2 invpcid_single cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities cpufreq
       configuration: cores=4 enabledcores=4 microcode=164 threads=8

Computer is a Lenovo Thinkpad P15s.

EDIT

As suggested by Doug Smythies in the comment below, here are some more command outputs:

$ grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_driver
/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpu1/cpufreq/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpu2/cpufreq/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpu3/cpufreq/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpu4/cpufreq/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpu5/cpufreq/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpu6/cpufreq/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpu7/cpufreq/scaling_driver:intel_pstate
$ grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor:powersave
/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor:powersave
/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor:powersave
/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor:powersave
/sys/devices/system/cpu/cpu4/cpufreq/scaling_governor:powersave
/sys/devices/system/cpu/cpu5/cpufreq/scaling_governor:powersave
/sys/devices/system/cpu/cpu6/cpufreq/scaling_governor:powersave
/sys/devices/system/cpu/cpu7/cpufreq/scaling_governor:powersave
$ grep . /sys/devices/system/cpu/cpu6/cpufreq/*
/sys/devices/system/cpu/cpu6/cpufreq/affected_cpus:6
/sys/devices/system/cpu/cpu6/cpufreq/base_frequency:1200000
/sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_max_freq:4700000
/sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_min_freq:400000
/sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_transition_latency:0
/sys/devices/system/cpu/cpu6/cpufreq/energy_performance_available_preferences:default performance balance_performance balance_power power 
/sys/devices/system/cpu/cpu6/cpufreq/energy_performance_preference:balance_performance
/sys/devices/system/cpu/cpu6/cpufreq/related_cpus:6
/sys/devices/system/cpu/cpu6/cpufreq/scaling_available_governors:performance powersave
/sys/devices/system/cpu/cpu6/cpufreq/scaling_cur_freq:1006285
/sys/devices/system/cpu/cpu6/cpufreq/scaling_driver:intel_pstate
/sys/devices/system/cpu/cpu6/cpufreq/scaling_governor:powersave
/sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq:4700000
/sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq:400000
/sys/devices/system/cpu/cpu6/cpufreq/scaling_setspeed:<unsupported>
$ grep . /sys/devices/system/cpu/intel_pstate/*
/sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost:0
/sys/devices/system/cpu/intel_pstate/max_perf_pct:100
/sys/devices/system/cpu/intel_pstate/min_perf_pct:8
/sys/devices/system/cpu/intel_pstate/no_turbo:0
/sys/devices/system/cpu/intel_pstate/num_pstates:44
/sys/devices/system/cpu/intel_pstate/status:active
/sys/devices/system/cpu/intel_pstate/turbo_pct:44
Doug Smythies avatar
gn flag
Please edit your question adding the CPU frequency scaling driver and governor information. `grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_driver` and `grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor`. And all the information for 1 CPU: `grep . /sys/devices/system/cpu/cpu6/cpufreq/*` and, if you are using the intel_pstate CPU frequency scaling driver `grep . /sys/devices/system/cpu/intel_pstate/*`.
Doug Smythies avatar
gn flag
Thanks for the edit. I think my answer, done after my comment, is correct. You can confirm by doing the same as I did in the answer.
Score:1
gn flag

With Intel processors, at least up to 10th Gen, the issue is that there is only one CPU clock frequency PLL (Phase Locked Loop). Inputs (requests for a frequency) to the PLL come from all the CPUs in addition to some internal contributors. In the case where HWP (Hardware Pstate Control) is enabled, the CPU inputs are merely guidelines and the processor decides. A CPUs vote is dis-guarded if it is in a deep enough idle state. The CPU frequency output from the PLL is presented to all the CPUs. Since you have not set all CPU to a maximum frequency of 800 MHz, it appears the remaining one is asking for a higher frequency. There are frequencies other than 3.45 GHz listed for other CPU because they are sometimes idle and sometimes not, resulting in a different number over the same time.

Example using a i5-10600K, 6 cores, 12 CPUs:

First, set all CPUs except 0, to a max frequency of 800 MHz and check it:

doug@s19:~$ for i in `seq 1 11`; do echo 800000 | sudo tee /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; done
800000
800000
800000
800000
800000
800000
800000
800000
800000
800000
800000
doug@s19:~$ grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu10/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu11/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu5/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu8/cpufreq/scaling_max_freq:800000
/sys/devices/system/cpu/cpu9/cpufreq/scaling_max_freq:800000

Now, look at CPU frequencies:

doug@s19:~$ grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq:799994
/sys/devices/system/cpu/cpu10/cpufreq/scaling_cur_freq:800458
/sys/devices/system/cpu/cpu11/cpufreq/scaling_cur_freq:799748
/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq:800173
/sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu5/cpufreq/scaling_cur_freq:800003
/sys/devices/system/cpu/cpu6/cpufreq/scaling_cur_freq:800063
/sys/devices/system/cpu/cpu7/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu8/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu9/cpufreq/scaling_cur_freq:4100000

The system is idle so nothing is driving up the CPU 0 desire for higher frequency, so the clock is low. The 4.1 GHz numbers are misleading, and actually indicate stale data due to the CPU being in deep idle for a long time (this output is a function of kernel version, and other users might get different).

Now load down CPU 0 and check again:

doug@s19:~$ taskset -c 0 yes > /dev/null &
[1] 3911
doug@s19:~$ grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq:4799997
/sys/devices/system/cpu/cpu10/cpufreq/scaling_cur_freq:4800121
/sys/devices/system/cpu/cpu11/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu5/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu6/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu7/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu8/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu9/cpufreq/scaling_cur_freq:4100000
doug@s19:~$ fg
taskset -c 0 yes > /dev/null
^C
doug@s19:~$

Now, if I set all CPUs to have a maximum frequency of 800 MHz, then it will work:

doug@s19:~$ echo 800000 | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
800000
doug@s19:~$ taskset -c 0 yes > /dev/null &
[1] 3920
doug@s19:~$ grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq:799997
/sys/devices/system/cpu/cpu10/cpufreq/scaling_cur_freq:800322
/sys/devices/system/cpu/cpu11/cpufreq/scaling_cur_freq:800101
/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq:800105
/sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu5/cpufreq/scaling_cur_freq:800001
/sys/devices/system/cpu/cpu6/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu7/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu8/cpufreq/scaling_cur_freq:4100000
/sys/devices/system/cpu/cpu9/cpufreq/scaling_cur_freq:4100000
doug@s19:~$ fg
taskset -c 0 yes > /dev/null
^C
doug@s19:~$

Disclaimer: There might be some inaccuracies in this answer. I am not certain that this 11th gen processor only has one PLL (Phase Locked Loop).

EDIT: To revert the changes, just reverse what was done. If the original maximum CPU frequency setting has been forgotten, then inquire first:

doug@s19:~$ grep . /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_max_freq
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu10/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu11/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu5/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu6/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu7/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu8/cpufreq/cpuinfo_max_freq:4800000
/sys/devices/system/cpu/cpu9/cpufreq/cpuinfo_max_freq:4800000

Set it back, and check it:

doug@s19:~$ echo 4800000 | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
4800000
doug@s19:~$ grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu10/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu11/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu2/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu3/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu5/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu6/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu8/cpufreq/scaling_max_freq:4800000
/sys/devices/system/cpu/cpu9/cpufreq/scaling_max_freq:4800000
s.k avatar
cn flag
s.k
Thank you for your answer! Would you be willing to add to your post a way to reset the default values after such modifications?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.