0

I've been trying to limit the maximum allowed CPU frequency on a 2nd gen Intel i7 CPU.

To do that, I tried:

  1. sudo cpupower -c all frequency-set --max;
  2. TLP, setting both the percentage and frequency (KHz) based limits;
  3. Changing intel_pstate with echo 50 | sudo tee /sys/devices/system/cpu/intel_pstate/max_perf_pct
  4. each of the above with ondemand.service enabled and disabled

While monitoring the frequencies with conky, the imposed limitations seemed to work as they should.

However, when running more demanding applications (specifically, games on Steam), the limitations would be ignored, and the frequencies would raise as if no restrictions existed.

The command grep . /sys/devices/system/cpu/intel_pstate/*, suggested in another post, seems to indicate that the intel_pstate driver is being used, as it should be.

I haven't been able find an answer nor solve the issue myself.

Cordially, I thank you for your attention.

  • are you saying that grep . /sys/devices/system/cpu/intel_pstate/* still showed max_perf_pct at 50% and that the actuals were higher? Or, that something overwrote that value back to 100%? – Doug Smythies Dec 16 '20 at 00:35
  • First alternative: the amount I set (e.g. 50%) was still there, but some programs simply ignored it. So, nothing overwrote the value itself – Frozenpick Dec 16 '20 at 13:45
  • What you describe should not be possible, and would be well worth investigation. What kernel version? – Doug Smythies Dec 16 '20 at 15:06
  • By the way, I would suggest the thermald service for automated, and persistent through re-boots, processor package temperature limiting via CPU frequency throttling. There are several methods available, but I have only ever used the p-state control method, via max_perf_pct. I haven't tried for quiet awhile, but see here. – Doug Smythies Dec 16 '20 at 15:55
  • The kernel version is 5.4.0-58-generic. Thermald is enabled, AFAIK. And yes, I find the problem rather intriguing myself. Not sure if it could be related to the fact that the game was running under a compatibility tool (Steam's Proton). However, IIRC, it happened with native applications, too. – Frozenpick Dec 17 '20 at 00:24
  • The issue with thermald is that it requires tweeking, as it is impossible to have a default configuration that knows the servo loop gain values for every possible cooling scenario. I toss out most thermald crap, and run only the one servo type (when I use it, which is rarely). And it's default temperatures are too high. I do have 5.4.0-58-generic installed, and will try it, but perhaps you could also try the mainline PPA kernel 5.10.1. – Doug Smythies Dec 17 '20 at 15:37
  • I could not recreate your troubles with kernel 5.4.0-58-generic. – Doug Smythies Dec 17 '20 at 21:17
  • Maybe I could test it with thermald disabled. It is weird, however, that cpufreq-set was the only tool that accomplished what I wanted, even though all of them would have the same purpose (in this case): limiting max. allowed CPU usage (be it % or Hz based). But, unless this can actually be helpful to someone else, I could just stick to the solution provided below – Frozenpick Dec 18 '20 at 00:25
  • for thermald, sure, do what you want. for the other issue that should not be possible, if it can be isolated, I'll take it upstream. the try 5.10.1 suggestion was a test for the not supposed to be possible situation, not anything to do with thermald. I do recall seeing some patch on the linux-pm (power management) e-mail list about a sync issue between max_perf_pct and /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq, but I haven't been able to find it again. Oh, are you using the performance governor? there was a problem with it not updating max (I think). – Doug Smythies Dec 18 '20 at 01:04
  • Nope. While using cpupower, I set the governor to powersave, and the perfbias to 15. On cpufreq-set (which is the one that worked for me), I also set the governor as powersave. Not sure if I did so while using TLP. By the way, I have seen the "ondemand" service popping up in multiple discussions, including ways to disable it (e.g. systemctl disable ondemand). However, I admit I am having problems understanding why some things work and what exactly they do, since it seems that lots of tools deals with similar operations (cpupower, cpufreq-set, cpufrequtils, TLP, intel_pstate...) – Frozenpick Dec 19 '20 at 12:20
  • Only intel_pstate is the actual built into the kernel primitive. All those other things are merely front ends that end up communicating with the kernel via the same primitive commands. I never use any of those front ends, ever. The ondemand service is simply to set the governor to ondemand, if available (i.e. for the acpi-cpufreq CPU scaling driver) or powersave if intel_pstste, or... after boot, because the Ubuntu kernel configuration specifies "perfromance" mode. What I want is to isolate your not supposed to be possible situation, so that I can either fix it myself or get help to. – Doug Smythies Dec 19 '20 at 14:23
  • Hey there. Sorry for taking so long to come back. So, if you are interested into going deep into that issue, I can provide more information. Just tell me what you want me to do/send. cpufreq-set was the only solution that actually worked for me, so far, and I haven't tested others since then. The only "issue" is that, AFAIK, I can't set parameters for all cores at once, so I need to run the command once for each core (using && and etc). – Frozenpick Jan 04 '21 at 21:31
  • If there is a problem, I am still interested to isolate and either create a fix for it, or get help to fix it. I change, for example, the min_scaling_freq with one command like so: echo 1000000 | sudo tee /sys/devices/system/cpu/cpufreq/policy*/scaling_min_freq – Doug Smythies Jan 06 '21 at 06:41
  • Ok, I will test that other option (not sure if I tried it before) and post the results. Also, cpufreq-set (which works for me) DID change the values in the path you mentioned (scaling_max_freq, in my case). If the other tools/options were supposed to do the same, I am confused, since they should have worked – Frozenpick Jan 19 '21 at 17:44

1 Answers1

1

If the goal is to limit the maximum frequency of your CPU, then cpufreq is what you’re looking for. This SuperUser post has a pretty good overview of how it works, but the gist is to:

  1. Install cpufreq from Ubuntu’s repository
  2. Run cpufreq-info to see what governors and limits are in place already
  3. Call cpufreq-set --cpu 0 --max 1.5GHz for each CPU core on your machine, setting the GHz value to your desired limit

Hope this gives you what you’re looking for.

  • Thank you so much! It actually worked. I can't believe I wasted so many hours. Would you know why all the other options I tried didn't work under the described circumstances? Like TLP, cpupower, etc – Frozenpick Dec 15 '20 at 23:40
  • The other tools that you used generally solve different problems. TLP is generally for battery life, cpupower generally focuses on the amount of energy a CPU can use, max_perf_pct is generally reset every time you reboot. cpufreq is the one tool I've seen that consistently works to govern a CPU, which can be important to prevent systems from overheating. I live in a very hot country and every summer my work machines need to be governed to about 70% of their rated maximum to stay under 80°C. –  Dec 16 '20 at 00:28
  • I live under high temperatures, too. Limiting the frequencies is a must, since I can't stand watching temperatures above 90ºC (T. Junction is 105, IIRC). About the tools I used before: it is weird that all of them provided means of limiting the CPU usage, and they actually worked most of the time. For some reason, games were ignoring it, though. But well, at least cpufreq did the job. It still reverts back to the default frequency after rebooting, though. So I will have to write a script to run it at startup – Frozenpick Dec 16 '20 at 13:50