12 ms·
Automatic CPU speed and power optimizer for Linux
- jmngomes 5y agoTLP [1] covers this use case pretty well, although I confess I didn't expect this to still be an issue these days (until I bought my latest laptop and had to run TLP on Kubuntu 20.04 to ensure battery life on par with the factory specs, and TLP almost tripled it) [1] https://wiki.archlinux.org/title/TLP https://wiki.archlinux.org/title/TLP
- CyberShadow 5y agoCPUs already adjust their own frequency based on load and temperature (maybe with some help from kernel drivers). It would be nice if the README explained how this tool is different from that.
- signa11 5y agoits outlined in the readme “ … Using tools like TLP will help in this situation with extending battery life (which is something I did for numerous years now), but it also might come with its own set of problems, like losing turbo boost. With that said, I needed a simple tool which would automatically make "cpufreq" related changes, save battery like TLP, but let Linux kernel do most of the heavy lifting. That's how auto-cpufreq was born. … “
- marcan_42 5y agoAs far as I can tell, this just switches the cpufreq governor based on whether the laptop is on AC or not. Tools to do this have existed for at least a decade, and integrated into various desktop environments too, so this isn't really novel in any way. It also suggests using "powersave" on battery, based on the old idea that lower CPU frequencies save energy. This is not a given; lower frequencies use less power but also take longer to get the same amount of work done. While the CPU is active, it is consuming static power regardless of frequency. This has gotten even more significant with newer CPUs. What the optimal power saving config is varies from system to system. Ultimately, what you need is to actually benchmark the performance and energy consumption of your system. It's complicated and you also have to deal with things like switching latencies so the cpufreq governor and scheduler can make optimized decisions. Most PCs don't really do a good job of this at all, which is one reason why battery life can be all over the place. Sadly, switching to the "powersave" governor may not, in fact, end up saving you power, depending on what you're doing :)
- pverghese 5y agoLower frequencies consume less power than higher frequencies
- saagarjha 5y agoYes, that's mentioned in the parent comment. The problem is that at slower frequencies also keep the core powered up for longer, which is often bad for power consumption. For many mobile devices, it's often much better to ramp up the processor to 100% and get the work done quickly, then rush to idle as quickly as possible.
- FeepingCreature 5y agoHas anyone actually measured this on a laptop? My view is that this works for CPU heavy tasks, but not for low-frequency repeated background tasks like browser window drawing, where if you speed up your CPU you just burn energy to get a higher framerate, something you generally don't care about on powersave. So optimally you'd want to clock up for "burst tasks" and keep freq low for "per-frame tasks". But I don't know of a scheduler that does that, or even how it could do it. But if you assume most of your battery loss will be to frame tasks, powersave makes sense.
- saagarjha 5y agoThese kinds of things do get used in laptops–the keyword you're looking for is "race to idle", as the processor quickly clocks up and then rushes back to a lower-frequency state or even goes back to sleep. On the mobile side, I do know that Apple did work a couple years back to scale up to maximum clock rate very quickly to handle user-interactive tasks: https://www.anandtech.com/show/13392/the-iphone-xs-xs-max-review-unveiling-the-silicon-secrets/6 https://www.anandtech.com/show/13392/the-iphone-xs-xs-max-re.... Then they'd ramp it back down to save on battery life.
- FeepingCreature 5y ago
- riedel 5y agoWould be great to have more real world benchmarks (in a climate chamber). To me any difference should show empirically. Does anyone have a good suggestion to "debug" performance/battery/thermal issue as a matter of trade-offs. I feel that laptop performance is so subjective and very hard to track. Particularly thermal throttling on mobile Ryzen CPU makes my new Lenovo sometimes close to unusable. Particularly trying to do work while pandemic video conferencing seems to be more difficult than necessary...
- marcan_42 5y agoYou don't need a climate chamber; you can just measure energy consumption. Most modern battery management ICs should have a joule counter (or equivalent).
- Tenoke 5y agoFor what is worth, whatever adjustments are made on Linux (or at least Ubuntu) seem terrible compared to on Windows. If nothing else I can usually hear my fans working overtime even under minimal load on Linux compared to on Windows so I can see why people would look for more advanced tools.
- geokon 5y agoWhat's a straightforward way to clock down a CPU to a fixed rate? I sometimes want to run benchmarks and I'd like my laptop to stick to one speed I understand it's a bit problematic with the latest CPUs bc the gap between turbo and non turbo is so huge - and the CPU is in turbo a good chunk of the time (and your cache performance will be very different running at 1Ghz vs 4Ghz) Anyone have a good solution?
- marcan_42 5y agoChange the cpufreq governor to userspace and then you can echo the desired frequency into its control file. It will stick.
- baybal2 5y ago> the gap between turbo and non turbo is so huge > Anyone have a good solution? A good cooler ---- Downvotes, really? There is really no trick around thermals being the main performance limiting factor for the last 10 years, since CPUs started coming with hardware "turbo" You cannot optimise around that.
- geokon 5y agoYeah but that's prolly not really a solution either (sidestepped the issue of modifying the cooler on a laptop). Bc you can't lock yourself to always be in turbo. So you can't get consistent performance while benchmarking
- baybal2 5y agoThe problem is not understood by the prime majority: As said above, the performance, and power consumption of modern CPUs is an "all, or nothing" choice. Modern laptop CPUs are nothing, but well disguised desktop/server cores. Nobody designs designated mobile use cores, unless you are in ARM world. In principle, they are unable to work in the "middle gear." CPU makers tried to make them to, but never managed to get a reasonable trade off. So you cannot run them reasonably at "half-performance"
- 5y ago
- glandium 5y ago> For example, CPU will run using "performance" governor with turbo boost enabled regardless if it's plugged in to power or not. Don't most distros default to ondemand or schedutil governor these days?
- krzyk 5y agoOndemand was used like 10 years ago, later it was proved that with Intel it is better to use performance (race to idle).
- catdog 5y agoIntel has its custom driver for years now anyways https://www.kernel.org/doc/html/v5.14/admin-guide/pm/intel_pstate.html https://www.kernel.org/doc/html/v5.14/admin-guide/pm/intel_p...
- marcan_42 5y agoActually, schedutil (the new ondemand) gets better perf/watt on modern Intel CPUs. Reality is more complex than "always crank up the CPU to the max" or "always turn it down all the way"; schedutil is optimized to do the right thing.
- Too 5y agoI’ve only ever seen powersave and performance being supported, on a wide range of laptops. With powersave being the default. Powersave is noticeably slower on heavy workloads, and performance drains the battery on idle. So you have to keep toggling manually depending on your workload. Gonna try out this tool and hope it works. Sad it can’t be built into the default governor. It’s not exactly easy to find these settings. There must be a lot of people out there with fancy hardware which they are unaware they are not utilizing to their full potential.
- rcarmo 5y agoI’d like something that would actually disable CPU cores temporarily besides fiddling with governors and clock speeds. I currently do that with a cpufreq GUI wrapper, but it isn’t automatic.
- chrismorgan 5y agoI tried taking 7 of my AMD Ryzen 5800HS’s 8 cores offline with `echo 0 | sudo tee /sys/devices/system/cpu/cpu{2..15}/online >/dev/null` and found it made no measurable difference to battery drain (as in, approximately less than 0.01W and certainly well less than 0.1W). I don’t know if I missed a step for actually turning the cores off, or whether you can’t actually turn them off, or whether the CPU is actually using way less power than I thought when idle (seems rather unlikely given my error bars). But if anyone did know a way of actually turning them off, I’d be very interested to see if I could get the whole laptop stably under 5W.
- jack_pp 5y agoan easy way to test if your cores have gone offlane is to compile a big codebase or transcode a video file. ffmpeg -i input.mp4 output.mp4 will use x264 which is well optimized to use your whole CPU (you can check htop).
- chrismorgan 5y agoOh, they go offline alright so that I can’t use them, but since that didn’t reduce power consumption, I’m not sure if the cores are actually switched off. Or if that’s even an option.
- megous 5y agoIf you're comparing idle CPU power consumption, the cores are likely effectively "turned off" while idle anyway. Offlining CPUs manually is still useful to limit what random software on your computer can do. There should still be difference between loading 1 CPU core to 100% and loading all 8 cores. Though savings may be cancelled out a bit by CPU using higher boost frequencies when only one core is loaded. So you may need to disable boost too, if you want to save power by disabling CPUs for non-idle use case. It would be easiest if I could say to the CPU: limit power use to this maximum. It's still doing it anyway to stay within TDP. Maybe there's some manual setting somewhere for that?
- yewenjie 5y agoCan somebody with experience running this tell me if it actually works?
- chronogram 5y agoReading the scripts it doesn't look like more than the standard Linux ricing script, which means that if you're using a well made distribution it will hurt you but if you're using a poorly made distribution it might help you. In the recent years you really shouldn't have to worry about this anymore. You can check in powertop if your laptop CPU package idles for the most part in C8 or higher, and if it does great don't worry about it, and if it doesn't then look for the rogue software (like maybe some random scripts).
- shmerl 5y agoAMD are working on a better CPPC driver for schedutil for that.
- 1kurac 5y agoA similar tool to prolong laptop autonomy is XSuspender <https://kernc.github.io/xsuspender/ https://kernc.github.io/xsuspender/>. It configurably SIGSTOP-s unfocused X11 applications. It is, sadly, XWindows-only.
- dijit 5y agoWayland doesn't constantly redraw the window (this is why pycharm had issues with Xwayland) so you already have this benefit if you're on Wayland.
- 1kurac 5y agoThat's just about redrawing. It does nothing about other, potentially unwanted process background CPU use.
- ComputerGuru 5y agoMany apps (esp electron) use CPU regardless of whether they’re redrawing the actual desktop window or not.
- account42 5y ago> Wayland doesn't constantly redraw the window Neither do X11 programs (well the ones that care about power effienciency anyways, so not games).
- Valodim 5y agoWho the hell puts a swastika on their software website?
- fooctrl 5y agoauto-cpufreq author here, sorry but what are you talking about, what swastika?
- deleted 5y ago[deleted]
- bno1 5y agoI wish the readme would compare it to laptop mode tools [1]. [1] https://wiki.archlinux.org/title/Laptop_Mode_Tools https://wiki.archlinux.org/title/Laptop_Mode_Tools
- tamrix 5y agoIf you're using Intel 8th gen or above. (7th gen supported if you manually set the flag each boot) you've got speedshift which the CPU will automatically auto scale itself. (changing the p-states) The CPU itself can change frequencies much faster on its own instead of the software based speedstep which programs like this controlled. This eliminates the need for an on-battery or plugged-in performance mode because it changes frequencies so fast, you're no longer losing performance by waiting for the software to speed up the cpu. So you can keep it on all the time. For these CPUs, all this is in the kernel and enabled by default.
- nceqs3 5y agoI believe that feature was just litigated in VLSI v Intel. VLSI won 2.1 billion in damages due to their patent.
- wyager 5y agoThe patent system is so useful, charging vendors billions of dollars for implementing an idea like “use the most obvious possible power saving strategies”.
- orangepurple 5y agoThe patent system also helps small companies with little working capital get started on big, obvious, money intensive challenges without being immediately crushed by megacorps. The razor cuts both ways.
- nceqs3 5y agoYes, this is the truth. Look at the recent Cisco patent case. They pulled a Facebook and stole some startups IP while meeting with them. The startup won over 1.5 billion in damages, mostly because they were able to show willful infringement on Cisco's part. https://www.ipwatchdog.com/2020/10/09/centripetal-networks-awarded-1-9-billion-infringement-suit-cisco/id=126094/ https://www.ipwatchdog.com/2020/10/09/centripetal-networks-a...
- christkv 5y agoI’ve found http://tbswitcher.rugarciap.com/ http://tbswitcher.rugarciap.com/ that can turn of turbo boost on intel macs to be useful when on battery and compiling. Since 100% cpu usage will run at a much lower TDP and not kill my laptop battery as fast.
- londons_explore 5y agoWhats the overhead of this daemon running all the time? It uses RAM which effectively increases power consumption because now something else is pushed out of the cache. It polls therefore waking the CPU every few seconds, even if perhaps nothing else is going on on the machine and the CPU would otherwise be idle. I wonder if its benefits outweigh the disadvantages. Would be good to have numbers for a bunch of different hardware configs...
- easytiger 5y agoYou can certainly write something like this such that it will use as near as makes no difference any CPU time.
- londons_explore 5y agoIt's true it doesn't use much CPU in percentage terms... but wakeups are expensive. When I'm reading a web page, ideally my CPU is halted, using barely any power. With the screen dim, I might be hoping for 20 hours battery life in that state. To wake up, just to poll something, and go back to sleep again uses a lot of energy compared to doing nothing. Something polling a few times a second might reduce my 20 hours down to just 10.
- tomxor 5y ago> Using tools like TLP will help [...] but it also might come with its own set of problems I recently figured out TLP was the source of a couple of irritating issues for me on an XPS 9370: - Bluetooth audio continually cutting in and out, only when wireless module on AC "non power saving mode"!?! - DC bias on the audio out jack, on both modes, worse on power saving. (forcing a power amp into self protect mode). Both resolved by disabling TLP entirely. I knew TLP was not a set and forget tool, but it's easy to forget when on some machines it's fine (and necessary, especially older laptops). But then changing to a new machine where it causes lots of issues. It was a good reminder that these tools need to be used with care because they often exploit unusual hardware modes and can have strange side effects.
- fooctrl 5y agoauto-cpufreq author here, I'm here if you have any questions!
- Zenst 5y agoHow do the the latest Intel and AMD CPU's compare in how they handle speed and power usage with regards to the main stand-out differences between the two?
- fooctrl 5y agoSorry, but can't nswer that since all hardware I have is powered by Intel. Maybe it would be a good idea to ask this same question on: https://github.com/AdnanHodzic/auto-cpufreq/discussions https://github.com/AdnanHodzic/auto-cpufreq/discussions
- eloff 5y agoOn my Alienware AMD laptop, lm- sensors detects nothing. Do you think your program would help me on it? It doesn't support Linux but I'm running Ubuntu on it anyway. I have issues with screen brightness, fan speed, and battery life. Otherwise works great.
- fooctrl 5y agoBest way to find out if it'll help you is to try it out! It has 2 modes, "monitor" which help you evaluate what it would do for you without making any actual changes. If you like what it suggest you can run it in "live" mode, which will make the suggested changes. But after you stop "live" mode after reboot all settings will go back to defaults. If you're happy with results then and want to run it in background all the time proceed with "install". Reference: https://github.com/AdnanHodzic/auto-cpufreq/#how-to-run-auto-cpufreq https://github.com/AdnanHodzic/auto-cpufreq/#how-to-run-auto... Also I suggest you watch auto-cpufreq demo Youtube video which explains it all: https://www.youtube.com/watch?v=QkYRpVEEIlg https://www.youtube.com/watch?v=QkYRpVEEIlg
- 5y ago
- wooque 5y agoThe best thing battery wise for me was to actually disable turbo boost and limit max frequency. It can be done in TLP config.
- 29athrowaway 5y agoFor games you can use gamemode. https://github.com/FeralInteractive/gamemode https://github.com/FeralInteractive/gamemode You run the game with gamemoderun and it will do few adjustments for you, including adjusting the CPU governor.
- bravetraveler 5y agoCool and all, but 'tuned' does this and so much more. Custom profiles that can control boot command line options, sysctl parameters, sysfs, and so on.
- aroundthfur 5y agotuned does not automatically change the profile based on load, so it kind of has a different behavior. The point of auto-cpufreq is to give you power when needed and then switch back to powersave otherwise. Or am I wrong?
- bravetraveler 5y agoNope, you're on the mark - that is an interesting approach. Most of my experience has been with desktops, so take this with a pile of salt I've found the effect can be difficult to notice... performance wise especially. Power wise it might be a dozen watts here and there. Even between powersave/performance it's hard to tell - mostly in latency. As a result, I just stay down on powersave. The firmware does a decent job at 'parking' cores and such as needed, and I still get decent boost performance! All that said, in a laptop I could definitely see squeezing out every last bit like this being a big help