Skip to content

Support macsmc_hwmon (Linux 7.3+ T2 Macs), external sensors, fan-curve and crash fixes - #20

Open
DrFedarov wants to merge 6 commits into
ablakely:masterfrom
DrFedarov:macsmc-hwmon
Open

DrFedarov wants to merge 6 commits into
ablakely:masterfrom
DrFedarov:macsmc-hwmon

Conversation

@DrFedarov

Copy link
Copy Markdown

Summary

Linux 7.3 drops applesmc on T2 Macs in favour of the new macsmc family (macsmc_acpi + macsmc_hwmon), so macfand currently exits with "Cannot find applesmc device" and the fans are left at SMC defaults. This PR adds macsmc_hwmon support and fixes several control/stability bugs I hit while getting a MacPro7,1 (2019, Radeon Pro Vega II) working on 7.3.3.

applesmc behaviour is unchanged apart from the bug fixes below.

macsmc_hwmon support

  • Find the hwmon named macsmc_hwmon when applesmc is absent.
  • Fans are driven through fanN_target (a value in [fanN_min, fanN_max] switches the fan to manual, 0 hands it back to the SMC); there is no fanN_manual. The driver needs options macsmc_hwmon fan_control=1.
  • Sensor keys are parsed from labels like GPU 0 Die Cooked Temperature (TG0D), so existing profiles/blacklists keep matching.
  • Unreadable sensors and nonsense values (PECI-relative / trend keys reading ≤ 0, e.g. TC1F = -127 °C) are excluded from averages instead of being sign-flipped into them.
  • Speeds are clamped to the hardware min/max (the driver returns EINVAL otherwise).
  • Fans are handed back to the SMC on exit (SIGTERM/SIGINT), for both drivers.

External sensors

On T2 Macs the SMC has no usable CPU die or GPU junction sensor (TCXc is stuck, TC0P is a slow proximity sensor), so averaging SMC sensors can't protect the machine. fan_sensors entries may now name any hwmon sensor as "<hwmon name>:<temp label>", e.g. "coretemp:Package id 0" or "amdgpu:junction". Per-fan control follows the hottest listed sensor rather than the average, and a fan with no readable sensor runs at max (fail hot).

Bug fixes

  • Fan curve (same problem as fix fan speed scaling algorithm #18): speed was |normalized| * (max - min), so below the floor fans sped up as temperature fell and never reached max_speed. Now a linear ramp from min_speed at floor to max_speed at ceiling.
  • fan_sensors in /etc/macfand.conf crashed with SIGSEGV (per-fan sensor arrays were never allocated in read_cfg).
  • use_avg = false in /etc/macfand.conf could not override a profile's use_avg = true.
  • main allocated sizeof(struct applesmc *) (8 bytes) for struct applesmc (heap overflow).
  • SENSKEY_MAXLEN 16 → 48 so external sensor names fit.
  • Makefile targets are .PHONY; previously a re-run makepkg could silently package a stale binary.
  • PKGBUILD: backup=('etc/macfand.conf') so upgrades don't overwrite a customized config.

Smoothing

Speed-ups apply immediately; slow-downs under rampdown_deadband (default 100 RPM) are ignored and larger ones are limited to rampdown_step per poll (default 250). This stops the fans hunting when a jittery sensor like CPU package temperature moves ±1–2 °C each poll. Both are optional config keys, documented in macfand.conf.

Testing

MacPro7,1, Xeon W, Radeon Pro Vega II, CachyOS linux-cachyos 7.3.3, config: all 4 fans fan_sensors = ("coretemp:Package id 0", "amdgpu:junction", "TG0D"), floor 60 / ceiling 88.

Load CPU package max GPU junction max Fans 2–4 (max 2762)
Before (unpatched logic, fans pinned at 500 RPM), all-core CPU 10 s 98–99 °C – 500
GPU (llama.cpp inference) 90 s 73 °C 74 °C 1390–1630
All-core CPU 60 s 79 °C 51 °C 1870–2050
CPU + GPU 75 s 79 °C 71 °C 1870–2050

With smoothing, a 60 s all-core load held fans 2–4 at a constant 1954 RPM for 40+ s; without it the same load moved them ±80 RPM nearly every poll. Speed-ups are unaffected (903 → 1388 RPM in the first poll of GPU load), and after load stops the fans ease down 250 RPM per poll (~30 s from 1954 to 500) instead of dropping instantly.

I don't have a pre-T2 Mac to test the applesmc path; it compiles and the changes there are limited to the bug fixes above.

🤖 Generated with Claude Code

DrFedarov and others added 6 commits November 12, 2026 13:19
Find the hwmon named macsmc_hwmon when applesmc is absent, drive fans
through fanN_target (value in [min,max] = manual, 0 = SMC auto), parse
sensor keys from 'Description (KEY)' labels, exclude unreadable or
out-of-range sensors from averages, clamp to hardware min/max, and hand
fans back to the SMC on exit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- calc_fan: ramp linearly from min_speed at floor to max_speed at
  ceiling. The old |normalized| * window ran fans faster as temps fell
  below the floor and never reached max_speed.
- read_cfg: allocate per-fan fan_sensors lists (were NULL -> segfault)
  and let /etc/macfand.conf use_avg override the machine profile.
- Per-fan control follows the hottest listed sensor, not the average.
- fan_sensors may name any hwmon sensor as "<hwmon name>:<label>",
  e.g. "coretemp:Package id 0" or "amdgpu:junction". T2 SMCs have no
  usable CPU die / GPU junction sensor.
- No readable sensor for a fan -> run it at max (fail hot).
- main: allocate struct applesmc, not a pointer-sized buffer.
- SENSKEY_MAXLEN 16 -> 48; CFG_FILE overridable at build time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Speed-ups still apply immediately. Slow-downs smaller than
rampdown_deadband (default 100 RPM) are ignored, and larger ones are
limited to rampdown_step RPM per poll (default 250). Jittery sensors
such as the CPU package temperature otherwise move fans +-80 RPM every
poll under steady load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ig on upgrade

PKGBUILD: add backup=('etc/macfand.conf') so pacman does not overwrite
a customized config on upgrade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After easing down in rampdown_step increments a fan could stop within
rampdown_deadband of min_speed (e.g. 570 RPM with min 500) and stay
there indefinitely.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant