Custom kernel option gives more accurate CPU temperature reading

Hello,

I noticed that using my custom kernel build following Gentoo’s guide on customizing linux kernel for Ryzen, I was able to get more accurate temperature readings from btop.

I think this might be related to one of the kernel configurations, but I’m unable to pin point which one. I have tried to use the default the default kernel and load k10temp module at boot time, but it doesn’t seem to change the temperature reading.

Would like to have some help on figure this out to be able to eventually upstream this to NixOS or nixos-hardware.

NixOS linux kernel overlay configuration
final: prev: let
  inherit (final) lib;
in {
  linuxPackages = final.linuxPackagesFor (
    prev.linuxPackages.kernel.override {
      # TODO: The error message is quite unintuitive, maybe improve it?
      # https://github.com/NixOS/nixpkgs/issues/82951
      structuredExtraConfig = with lib.kernel; {
        # optimisation for ryzen 7
        # https://wiki.gentoo.org/wiki/Ryzen
        SMP = yes;
        X86_X2APIC = yes;
        X86_AMD_PLATFORM_DEVICE = yes;

        # Cherry pick my CPU support
        PROCESSOR_SELECT = yes;
        CPU_SUP_AMD = yes;
        # Disable intel CPU support
        CPU_SUP_INTEL = no;
        INTEL_HFI_THERMAL = lib.mkForce unset;
        INTEL_IDLE = lib.mkForce unset;
        INTEL_TDX_GUEST = lib.mkForce unset;
        POWER_RESET_GPIO = lib.mkForce unset;
        POWER_RESET_GPIO_RESTART = lib.mkForce unset;
        TDX_GUEST_DRIVER = lib.mkForce unset;
        X86_INTEL_TSX_MODE_AUTO = lib.mkForce unset;
        X86_SGX = lib.mkForce unset;
        X86_SGX_KVM = lib.mkForce unset;

        SCHED_MC = yes;
        X86_MCE = yes;
        X86_MCE_AMD = yes;
        PERF_EVENTS_INTEL_RAPL = yes;
        X86_AMD_PSTATE = yes;
        X86_POWERNOW_K8 = no;

        # With amd_pstate=active ondemand won't be available anyway.
        # Without more testing, we should accept the claim that its more power efficient and stick to it
        CPU_FREQ = yes;
        X86_INTEL_PSTATE = lib.mkForce no;
        CPU_FREQ_DEFAULT_GOV_SCHEDUTIL = lib.mkForce no;
        CPU_FREQ_DEFAULT_GOV_ONDEMAND = yes;
        # ERROR: could not insert 'amd_freq_sensitivity': No such device
        X86_AMD_FREQ_SENSITIVITY = module;

        # skipping firmware loading section since it's handled by other parts of nixos options
        SENSORS_K10TEMP = yes;
        IOMMU_SUPPORT = yes;
        AMD_IOMMU = yes;

        # additional chipset drivers
        I2C_PIIX4 = yes;
        PINCTRL = yes;
        PINCTRL_AMD = yes;
        CRYPTO = yes;
        CRYPTO_HW = yes;
        CRYPTO_DEV_CCP = yes;
        CRYPTO_DEV_SP_CCP = yes;
        CRYPTO_DEV_CCP_CRYPTO = yes;
        CRYPTO_DEV_CCP_DD = yes;
        CRYPTO_DEV_SP_PSP = yes;

        # Power management controller
        X86_PLATFORM_DEVICES = yes;
        AMD_PMC = yes;

        # Below is my config
        DRM_AMDGPU = yes; # Recent AMD GPU

        # Disable hypervisor guest
        HYPERVISOR_GUEST = lib.mkForce no;
        HYPERV = lib.mkForce unset;
        DRM_HYPERV = lib.mkForce unset;
        FB_HYPERV = lib.mkForce unset;
        HVC_XEN = lib.mkForce unset;
        HVC_XEN_FRONTEND = lib.mkForce unset;
        KVM_GUEST = lib.mkForce unset;
        MOUSE_PS2_VMMOUSE = lib.mkForce unset;
        PARAVIRT = lib.mkForce unset;
        PARAVIRT_SPINLOCKS = lib.mkForce unset;
        PARAVIRT_TIME_ACCOUNTING = lib.mkForce unset;
        PCI_XEN = lib.mkForce unset;
        SWIOTLB_XEN = lib.mkForce unset;
        XEN = lib.mkForce unset;
        XEN_BACKEND = lib.mkForce unset;
        XEN_BALLOON = lib.mkForce unset;
        XEN_BALLOON_MEMORY_HOTPLUG = lib.mkForce unset;
        XEN_DOM0 = lib.mkForce unset;
        XEN_EFI = lib.mkForce unset;
        XEN_HAVE_PVMMU = lib.mkForce unset;
        XEN_MCE_LOG = lib.mkForce unset;
        XEN_PVH = lib.mkForce unset;
        XEN_PVHVM = lib.mkForce unset;
        XEN_SAVE_RESTORE = lib.mkForce unset;
        XEN_SYS_HYPERVISOR = lib.mkForce unset;
      };
    }
  );
}

Which Linux distro are you using?

  • host os: Linux 6.12.54, NixOS, 25.05 (Warbler), 4d9bd66e
  • multi-user?: yes
  • sandbox: yes
  • version: `nix-env (Lix, like Nix) 2.93.3

Which BIOS version are you using?
0.0.3.9

Which Framework Laptop 13 model are you using?
AMD Ryzen™ 7040 Series

Do you know what actually has changed from the normal kernel config or what? Also, how do you know you are getting more accurate temperature readings from btop? Did you check the output of sensors?

Yes because my custom config is merged with default NixOS kernel config afaik, but I can’t pin point which option did that.

When I build GHC my CPU actually goes to 100°C and not hang around 70°C. The GPU used to spike when I did CPU intensive tasks (which is incoherent) but now it doesn’t anymore.

I haven’t! I’ll boot with two different kernels and diff the output of sensors and come back here.

Did just that but I can’t see a difference in the output of sensors of two different kernel builds :thinking:. I can tell that the kernel config difference is the only difference the two configuration have.

Mainline kernel sensor output
spd5118-i2c-20-50
Adapter: SMBus PIIX4 adapter port 0 at 0b00
temp1:        +45.8°C  (low  =  +0.0°C, high = +55.0°C)
                       (crit low =  +0.0°C, crit = +85.0°C)

ucsi_source_psy_USBC000:004-isa-0000
Adapter: ISA adapter
in0:           0.00 V  (min =  +0.00 V, max =  +0.00 V)
curr1:       680.00 mA (max =  +0.00 A)

k10temp-pci-00c3
Adapter: PCI adapter
Tctl:         +43.9°C  

ucsi_source_psy_USBC000:002-isa-0000
Adapter: ISA adapter
in0:           5.00 V  (min =  +5.00 V, max =  +5.00 V)
curr1:         0.00 A  (max =  +1.50 A)

BAT1-acpi-0
Adapter: ACPI interface
in0:          17.55 V  
curr1:       919.00 mA 

amdgpu-pci-c100
Adapter: PCI adapter
vddgfx:        1.27 V  
vddnb:       855.00 mV 
edge:         +42.0°C  
PPT:          21.25 W  (avg =   4.02 W)

ucsi_source_psy_USBC000:001-isa-0000
Adapter: ISA adapter
in0:           5.00 V  (min =  +5.00 V, max =  +5.00 V)
curr1:         0.00 A  (max =  +1.50 A)

mt7921_phy0-pci-0100
Adapter: PCI adapter
temp1:        +40.0°C  

framework_laptop-isa-0000
Adapter: ISA adapter
fan1:        2302 RPM

ucsi_source_psy_USBC000:003-isa-0000
Adapter: ISA adapter
in0:          20.00 V  (min =  +5.00 V, max = +13.20 V)
curr1:         2.25 A  (max =  +2.98 A)

acpitz-acpi-0
Adapter: ACPI interface
temp1:        +41.8°C  
temp2:        +39.8°C  
temp3:        +39.8°C  
temp4:        +43.8°C  

cros_ec-isa-0000
Adapter: ISA adapter
fan1:            2302 RPM
local_f75303@4d:  +41.9°C  
cpu_f75303@4d:    +39.9°C  
ddr_f75303@4d:    +39.9°C  
cpu@4c:           +43.9°C  

nvme-pci-0200
Adapter: PCI adapter
Composite:    +41.9°C  (low  = -40.1°C, high = +83.8°C)
                       (crit = +87.8°C)
Sensor 1:     +50.9°C  (low  = -273.1°C, high = +65261.8°C)
Sensor 2:     +41.9°C  (low  = -273.1°C, high = +65261.8°C)
Custom kernel output
spd5118-i2c-20-50
Adapter: SMBus PIIX4 adapter port 0 at 0b00
temp1:        +47.2°C  (low  =  +0.0°C, high = +55.0°C)
                       (crit low =  +0.0°C, crit = +85.0°C)

ucsi_source_psy_USBC000:004-isa-0000
Adapter: ISA adapter
in0:           0.00 V  (min =  +0.00 V, max =  +0.00 V)
curr1:       680.00 mA (max =  +0.00 A)

ucsi_source_psy_USBC000:002-isa-0000
Adapter: ISA adapter
in0:           5.00 V  (min =  +5.00 V, max =  +5.00 V)
curr1:         0.00 A  (max =  +1.50 A)

cros_ec-isa-0000
Adapter: ISA adapter
fan1:            2800 RPM
local_f75303@4d:  +44.9°C  
cpu_f75303@4d:    +43.9°C  
ddr_f75303@4d:    +39.9°C  
cpu@4c:           +53.9°C  

nvme-pci-0200
Adapter: PCI adapter
Composite:    +43.9°C  (low  = -40.1°C, high = +83.8°C)
                       (crit = +87.8°C)
Sensor 1:     +55.9°C  (low  = -273.1°C, high = +65261.8°C)
Sensor 2:     +43.9°C  (low  = -273.1°C, high = +65261.8°C)

amdgpu-pci-c100
Adapter: PCI adapter
vddgfx:        1.07 V  
vddnb:       854.00 mV 
edge:         +51.0°C  
PPT:          10.12 W  (avg =   7.10 W)

ucsi_source_psy_USBC000:001-isa-0000
Adapter: ISA adapter
in0:           5.00 V  (min =  +5.00 V, max =  +5.00 V)
curr1:         0.00 A  (max =  +1.50 A)

mt7921_phy0-pci-0100
Adapter: PCI adapter
temp1:        +44.0°C  

framework_laptop-isa-0000
Adapter: ISA adapter
fan1:        2800 RPM

ucsi_source_psy_USBC000:003-isa-0000
Adapter: ISA adapter
in0:          20.00 V  (min =  +5.00 V, max = +13.20 V)
curr1:         2.25 A  (max =  +2.98 A)

acpitz-acpi-0
Adapter: ACPI interface
temp1:        +44.8°C  
temp2:        +43.8°C  
temp3:        +39.8°C  
temp4:        +53.8°C  

BAT1-acpi-0
Adapter: ACPI interface
in0:          17.55 V  
curr1:       724.00 mA 

k10temp-pci-00c3
Adapter: PCI adapter
Tctl:         +54.1°C