This page documents the CPU temperature and frequency detection subsystems, which retrieve real-time thermal data and clock speed information across different platforms. These detection mechanisms complement the basic CPU identification covered in 3.4.1
For CPU name and core count detection, see 3.4.1 For microarchitecture detection via CPUID, see 3.4.2
Temperature and frequency detection provides runtime performance metrics for CPUs. The implementation varies significantly by platform due to different kernel interfaces and hardware access methods:
Both detection systems support user-configurable sensor sources via the tempSensor option in FFCPUOptions.
Sources: src/detection/cpu/cpu.h1-38 src/modules/cpu/cpu.c125-157
Temperature detection is optional and controlled by the temp boolean in FFCPUOptions. The value FF_CPU_TEMP_UNSET (-DBL_MAX) indicates no temperature data is available.
Temperature Detection Logic Flow
Sources: src/detection/cpu/cpu_linux.c66-185 src/detection/cpu/cpu_windows.c21-133 src/detection/cpu/cpu_bsd.c11-35 src/detection/cpu/cpu_apple.c6-37
Linux provides three hierarchical sources for CPU temperature data, scanned in priority order until a valid reading is obtained.
| Priority | Sysfs Path | Description | Sensor Names / Types |
|---|---|---|---|
| 1 | /sys/class/hwmon/hwmonN/ | Hardware monitoring devices | coretemp (Intel), k10temp (AMD), fam15h_power (AMD) |
| 2 | /sys/class/thermal/thermal_zoneN/ | ACPI thermal zones | Types: cpu, soc, x86_pkg_temp |
| 3 | /sys/devices/platform/cputemp.N/ | Platform-specific devices | Sensors starting with cputemp. |
Sources: src/detection/cpu/cpu_linux.c29-64 src/detection/cpu/cpu_linux.c161-182
The tempSensor option in FFCPUOptions accepts multiple formats:
hwmonN: Scans /sys/class/hwmon/hwmonN/temp1_input.thermal_zoneN: Scans /sys/class/thermal/thermal_zoneN/temp.cputemp.N: Scans /sys/class/platform/cputemp.N/temp1_input.Sources: src/detection/cpu/cpu_linux.c70-113
The readTempFile() function reads temperature values (typically in millidegrees Celsius) and converts them to standard degrees.
Sources: src/detection/cpu/cpu_linux.c17-27
Windows utilizes the Performance Counter API (PerfLib) to query thermal information.
The detectThermalTemp function queries the Thermal Zone Information counter set (GUID {52bc5412-dac2-449c-8bc2-96443888fe6b}).
\_TZ.CPUZ.PerfEnumerateCounterSetInstances, opens a query handle with PerfOpenQueryHandle, and retrieves data via PerfQueryCounterData.Sources: src/detection/cpu/cpu_windows.c21-133
BSD systems rely on sysctl to fetch thermal data.
dev.cpu.0.temperature.hw.acpi.thermal.tz0.temperature.(value / 10.0) - 273.15.Sources: src/detection/cpu/cpu_bsd.c11-35
macOS temperature detection is handled via the System Management Controller (SMC).
The detectCpuTemp function selects SMC keys based on the CPU model:
FF_TEMP_CPU_M1X, FF_TEMP_CPU_M2X, FF_TEMP_CPU_M3X, or FF_TEMP_CPU_M4X depending on the chip generation (detected via machdep.cpu.brand_string).FF_TEMP_CPU_X64.Sources: src/detection/cpu/cpu_apple.c6-37
CPU frequency detection populates the FFCPUResult structure with base and maximum frequencies.
| Field | Description | Platform Implementation |
|---|---|---|
frequencyBase | Nominal operating frequency | CPUID (x86), hw.cpufrequency (macOS), hw.clockrate (BSD) |
frequencyMax | Maximum boost/turbo frequency | CPUID (x86), IOKit (Apple Silicon), SMBIOS (Windows fallback) |
Sources: src/detection/cpu/cpu.h26-27 src/detection/cpu/cpu.c68-78
Windows primarily relies on the platform implementation but includes a robust SMBIOS fallback for frequencyMax.
The detectMaxSpeedBySmbios function parses the SMBIOS table (Type 4: Processor Information). It iterates through entries until it finds an enabled Central Processor and reads the MaxSpeed field (offset 0x14).
Sources: src/detection/cpu/cpu_windows.c136-200
Detection uses IOKit to query the pmgr service. It reads the voltage-states5-sram property (for P-cores) which contains frequency/voltage pairs.
Sources: src/detection/cpu/cpu_apple.c44-79
Uses sysctl keys hw.cpufrequency and hw.cpufrequency_max.
Sources: src/detection/cpu/cpu_apple.c81-94
On x86_64, ffCPUDetectByCpuid uses leaf 0x16 to retrieve frequencies directly from the processor hardware.
eax: Base frequency.ebx: Maximum frequency.Sources: src/detection/cpu/cpu.c68-78
Modern heterogeneous CPUs (like Apple Silicon or Intel Alder Lake+) report counts for different core types.
macOS detects these via hw.nperflevels and subsequent hw.perflevelN.logicalcpu sysctl calls. These are stored in the coreTypes array and can be displayed using the showPeCoreCount option.
Sources: src/detection/cpu/cpu_apple.c96-113 src/modules/cpu/cpu.c38-49
The CPU module (src/modules/cpu/cpu.c) acts as the consumer for all detected data, formatting it for the final output.
CPU Module Data Flow
Sources: src/modules/cpu/cpu.c14-123 src/detection/cpu/cpu.c5-25
ffTempsAppendNum, which handles conversion between Celsius, Fahrenheit, and Kelvin based on user configuration.ffFreqAppendNum, which appends appropriate units (GHz/MHz).Sources: src/modules/cpu/cpu.c81-88 src/modules/cpu/cpu.c94-100
Refresh this wiki