Cal Bryant Takes Charge of His PC's Cooling System with a Clever Python Script and Grafana
With a new, more powerful CPU in place, Bryant's fans became a problem — until he took control of the problem himself.
Engineer Cal Bryant took on the task of improving the cooling in a newly-upgraded PC in order to reduce its noise levels — by tackling the problem in software, replacing the motherboard's built-in fan control with a homebrew solution based on Python and Grafana.
"I recently upgraded from a[n AMD] Ryzen 3700X to a 5950X. Double the cores, and nearly double the potential heat output. I didn’t upgrade my cooling solution, a 240mm Kraken X53 AIO [All In One] liquid cooler," Bryant explains.
"Doing any real work with the 5950X made my PC significantly louder, and worse yet the fans were now spinning up and down suddenly and erratically. The reason for this is the radiator fans are controlled based on the CPU temperature, which quickly ramps up and down itself. This is the only option using the motherboard based fan control configurable in the UEFI for me — the X53 cannot control fans by itself."
While rapid temperature fluctuations are common to modern processors, as they quickly adjust their power draw and clock speed to accommodate a given workload, having the fans constantly ramping up and down gets old quick. With a water cooling system, there should be enough thermal mass to avoid the need for these rapid changes in fan speed — but Bryant found that the motherboard's Unified Extensible Firmware Interface (UEFI), the modern equivalent to the Basic Input/Output System (BIOS), lacked anything bar simply link the fan speed to the self-reported CPU core temperature on a instantaneous basis.
"If I could instead control the pump speed based on CPU temperature and the fan speed based on liquid temperature, I could take advantage of the thermal mass of the liquid to avoid ramping up the fans unnecessarily as the liquid takes some time to heat," Bryant explains. "The CPU would also be cooled more effectively, and the rate of heat transfer to the liquid would peak with the CPU demand, instead of being tied to liquid temperature."
Bryant's solution is at once simple and powerful: a Python script, installed as a system service in NixOS, which links with the Liquidctl
liquid-cooling control software and that uses the kernel's sysfs
interface to read temperatures and both measure and set fan speeds. With the system now under programmatic control, Bryant took the concept a step further by adding Grafana into the mix — providing charts that prove the Python script's ability to silence those annoying fan fluctuations.
"With the new control scheme, the fan speed change is much more gradual, and that peak in CPU temperature is gone," Bryant says. "That's because the rate of cooling maximizes immediately as the pump spools up based on CPU temperature instead of liquid temperature. Subjectively, the machine is now silent during idle, and doesn’t get audible unless the system is stressed for several minutes. The fans also don’t reach maximum when running games unlike before."
The full project write-up, with source code, is available on Bryant's blog.
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.