mathoudebine/turing-smart-screen-python

Use Tccd/Tdie instead of Tctl for AMD CPUs temperature monitoring

Opened this issue · 0 comments

Currently for AMD CPUs, the script checks for the current CPU temperature with k10temp under sensors, and uses the first result available, which is usually Tctl:

@staticmethod
    def temperature() -> float:
        cpu_temp = math.nan
        try:
            sensors_temps = psutil.sensors_temperatures()
            if 'coretemp' in sensors_temps:
                # Intel CPU
                cpu_temp = sensors_temps['coretemp'][0].current
            elif 'k10temp' in sensors_temps:
                # AMD CPU
                cpu_temp = sensors_temps['k10temp'][0].current
            elif 'cpu_thermal' in sensors_temps:
                # ARM CPU
                cpu_temp = sensors_temps['cpu_thermal'][0].current
            elif 'zenpower' in sensors_temps:
                # AMD CPU with zenpower (k10temp is in blacklist)
                cpu_temp = sensors_temps['zenpower'][0].current
        except:
            # psutil.sensors_temperatures not available on Windows / MacOS
            pass
        return cpu_temp

Running sensors on my system I get the following:

k10temp-pci-00c3
Adapter: PCI adapter
Tctl:         +52.1°C  
Tccd1:        +40.5°C  

The issue here is that for AMD CPUs, Tctl is not the true temperature of the CPU. According to AMD,

The primary temperature reporting sensor of the AMD Ryzen™ processor is a sensor called “T Control,” or tCTL for short. The tCTL sensor is derived from the junction (Tj) temperature—the interface point between the die and heatspreader—but it may be offset on certain CPU models so that all models on the AM4 Platform have the same maximum tCTL value. This approach ensures that all AMD Ryzen™ processors have a consistent fan policy.

sources: 1 2

In short, Tctl is the current die/ccd temperature with an added offset to ensure the CPU fan(s) run as desired, with Tdie and TccdX being the true temperature of the cores.

On my system, I can easily change cpu_temp = sensors_temps['k10temp'][0].current to cpu_temp = sensors_temps['k10temp'][1].current, because I have a 7800X3D CPU with only one CCD, however on CPUs with multiple CCDs, or systems where the Tccd is reported before the Tctl this might be an issue, and I'm not well versed in python to provide a clear and effective way to get this temperature.

My suggestion/request is to have the code identify this, default to the TccdX (or whichever is best on a multiple CCD CPU), and maybe have an option on the configurator GUI to chose between these sensors for AMD CPUs.