Skip to content

feat: add hwmon fan profiles - #54

Open
sknowledge1 wants to merge 2 commits into
ShadowBlip:mainfrom
sknowledge1:feat/generic-fan-control
Open

sknowledge1 wants to merge 2 commits into
ShadowBlip:mainfrom
sknowledge1:feat/generic-fan-control

Conversation

@sknowledge1

@sknowledge1 sknowledge1 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds fan control for fans with hwmon pwmN and pwmN_enable files.

Problem: PowerStation can't control fans, so each handheld needs its own fan daemon.

Approach: a profile is a short TOML file (or JSON string) that sets each fan to automatic, manual, software_curve or firmware_curve using fan and sensor IDs from hwmon (e.g. ayaneo_ec/fan1, k10temp/Tctl). Userspace opens the file and sends the fd, and saves/reloads the user's profile itself. Installed profiles live in /usr/share/powerstation/platform/fan_curves/ with overrides in /etc/powerstation/platform/fan_curves.d/, matched to a device by DMI or device tree. Fans start in automatic, return to it on stop or after three failed updates in a row, and run at 100% at 95°C. Software curves speed the fan up at once but slow it down by at most 2% per second.

Testing: on an AYANEO 3 (Bazzite 45): manual mode, software curve, the packaged Quiet profile loaded by fd, invalid profiles rejected without changing the fans, firmware taking control back being reverted, the 95°C override (with a test build set to 40°C), stop returning the fan to automatic, and a software curve winding the fan down from 57% to 11% over about 20 s after a CPU load ended. firmware_curve is untested because this device has no pwmN_auto_point files.

See docs/fan.md for the profile format and DBus API.

Assisted-by: LLM

@pastaq

pastaq commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Please rebase on latest main

@pastaq

pastaq commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

This can't be merged or reviewed as is. The history is all messed up.

I'd suggest you delete your local branch, check out an pull main, remake the branch, cherry pick your commits, and then force push

@sknowledge1
sknowledge1 force-pushed the feat/generic-fan-control branch from 58fcde8 to 9b82591 Compare October 12, 2026 09:38
@sknowledge1

sknowledge1 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebuilt from main (f514585) with only the fan feature and initialization fix, then added follow-up 481b3d7. The PR now has three linear commits and no merge commits. The follow-up adds suspend guards, exact hardware-curve checks, API documentation, and a checked-in lifecycle harness. Third-party state import is deferred.

35 locked tests and 26 lifecycle assertions pass, along with formatting, Clippy using the existing upstream allowances, both release builds, and both distribution targets. Historical hardware results remain attributed to their tested build. Ready for another look.

Comment thread .github/workflows/test.yaml Resolved

@pastaq pastaq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got through most of the readme file before I had to stop. I don't think this is the correct direction for the interface.

I think it should be much more simple. For curves, a yaml or toml that identifies the fan and its sensors, and a simple curve matrix of quant temp to %. hwmon internals don't need relaying, it should handle that transition directly. An average user should be able to read, write, and understand the configuration directly. We should have some hardware pre-built curves in /usr/powerstation/platform/fan_curves and allow for distros to ship overrides in /etc/powerstation/platform/fan_curves.d/. userspace should load a profile on boot if a user has customized it.

For the dbus, loading the profile or accepting one over JSON, listing the current profile name/path, listing available fans and sensors, and listing available/current modes (automatic, manual, fw curve, sw curve) should be sufficient.

Critical safety temps (100% fan, hw takeover) should be baked into the algorithm and not left up to the user.

Comment thread docs/fan-device.md Resolved
Comment thread docs/fan-device.md Resolved
Comment thread docs/fan-device.md Resolved
Comment thread docs/fan-device.md Resolved
Comment thread docs/fan-device.md Resolved
@sknowledge1 sknowledge1 changed the title feat: add YAML-configured hwmon fan control feat: add hwmon fan profiles and API v2 Oct 15, 2026
@sknowledge1

sknowledge1 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Implemented the profile design from your overall review in cb75669. YAML/JSON profiles now contain fan/sensor IDs, modes and percentages; packaged Quiet and whole-file distro overrides are separate from trusted driver configuration. API v0.2 adds profile loading, fan/sensor enumeration and current profile/mode reporting, with valid 0–100% values and no public RPM/PWM/ownership/policy properties. The revised proposal and short examples are documented.

Fresh starts, clean/crash/watchdog restarts and reboots enter firmware Automatic; user applications own profile persistence/reloading. Successful suspend/resume keeps only the live selection. Complete validation precedes hardware writes, and application or partial-resume failure rolls every affected fan back to Automatic. The provisional 95°C/98°C policy is internal, with thermal acceptance explicitly pending. The push-only workflow and custom-only generated fan docs address the inline review. I have replied in each original thread and left all threads unresolved.

Actual local validation on cb75669e488784d095229c0681b332809b1698c2 in the freshly built Rust 1.88 environment: formatting, 42 locked tests, Clippy with only the two existing upstream allowances, both locked release builds, 53 lifecycle assertions, live signatures for all three fan interfaces, and both architectures' archive/RPM contents/bytes/modes/ownership checks pass. The PR description records candidate hashes. ARM RPM dependency qualification remains pending; these artifacts have not been published as qualified releases.

For the earlier rebase request and history request, current upstream main remains f5145850eb649707811648b372eaf1f1066b439d. This head has six linear contribution commits and no contribution merge commits, retaining the rebuilt history and adding one revision after 255e680.

The successful uninterrupted five-minute, 9 W, 352-sample, 64°C-peak device result is preserved as evidence for 255e680 only. Revised-code device testing, full thermal acceptance, HX 370/native hardware curves, ARM dependency/install qualification and official packages/images remain release gates. Client changes, including Decky, remain separate.

GitHub CI was inspected on this exact SHA at 2026-10-15 09:04 UTC: no runs, check runs or statuses were present in either repository. All validation claims above are from the completed local software gate.

@sknowledge1
sknowledge1 requested a review from pastaq October 15, 2026 09:12
@sknowledge1

sknowledge1 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

@pastaq, the follow-up is implemented at fffb4b9. Unprivileged clients can read startup identity/eligibility without accessing recorder files; the startup file/JSON load methods recheck it under the complete profile transaction lock, closing the status-to-write race. Existing profile validation, caller policy, partial-write Automatic fallback and 95°C/98°C policy remain service-owned.

Local validation on that commit passes 52 locked tests, 77 real-systemd/private-D-Bus/fake-sysfs assertions, formatting, strict Clippy with the existing allowances, both release architectures and both archive/RPM payload checks. The actual OpenGamepadUI API v0.2 client additionally passes 32 Godot/native integration assertions with fake hardware. New-head GitHub inspection reports no native test check contexts; these are local results.

The base/history requests are also rechecked: current main is f5145850eb649707811648b372eaf1f1066b439d, with nine linear contribution commits and no contribution merges. The six existing inline thread states are preserved. Decky's separate API v0.2 migration is complete, and #550 now contains the native UI migration.

Physical results remain pinned to 255e680 (352 samples / 64°C) and 1b7330e (342 samples / 65.5°C). Revised-code/device acceptance, the provisional high-temperature policy, native-curve hardware coverage and official testing/stable/ARM package qualification remain open release gates. Firmware handoff transfers responsibility; it does not prove stronger cooling. This is ready for another review.

@pastaq

pastaq commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

API v2 adds profile loading, fan/sensor enumeration and current profile/mode reporting, with valid 0–100% values and no public RPM/PWM/ownership/policy properties. The API break and short examples are documented.

This is not necessary. As the API hasn't been accepted there is no v1/v2 yet. We're on v0 which in semantic versioning means there is no stable API.

@sknowledge1

sknowledge1 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

API v2 adds profile loading, fan/sensor enumeration and current profile/mode reporting, with valid 0–100% values and no public RPM/PWM/ownership/policy properties. The API break and short examples are documented.

This is not necessary. As the API hasn't been accepted there is no v1/v2 yet. We're on v0 which in semantic versioning means there is no stable API.

fair - I'll change it to API v0.2

@sknowledge1 sknowledge1 changed the title feat: add hwmon fan profiles and API v2 feat: add hwmon fan profiles and API v0.2 Oct 15, 2026

@pastaq pastaq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stopped my review.

Please read this:
https://www.eff.org/about/opportunities/volunteer/coding-with-eff

This PR is over 6k lines and half of it is slop readme. I should not be the first person to read "your" PR.

Comment thread .github/workflows/test.yaml Resolved
Comment thread docs/fan-platform-yaml.md Resolved
Comment thread docs/fan-startup.md Resolved
Comment thread docs/fan-startup.md Resolved
Comment thread docs/fan-startup.md Resolved
Comment thread docs/fan-validation.md Resolved
@sknowledge1

Copy link
Copy Markdown
Contributor Author

Appreciate the feedback - still new to this, not sure what to add / what to keep when reviewing the code.
Getting there! And thank you again

@sknowledge1 sknowledge1 changed the title feat: add hwmon fan profiles and API v0.2 feat: add hwmon fan profiles Oct 19, 2026
@sknowledge1

Copy link
Copy Markdown
Contributor Author

Following the version discussion, the description and documentation now describe an experimental, unmerged interface. Stable API-break/migration claims are removed. The existing integer revision marker remains provisional and has not been bumped.

@sknowledge1

Copy link
Copy Markdown
Contributor Author

The revision removes startup records and guarded loading in favor of ordinary FD/JSON profile transactions, adds DT/XDG portability and reduces the documentation and repeated implementation. I have reviewed the revised code. These changes are AI-assisted.

The complete PR adds 5,606 lines versus 6,664 previously. The README adds eight lines; the profile guide is 422 words and validation instructions are 187. Shared error, curve and fixture code retains the distinct failure scenarios.

Local validation matches this commit's source: 46 Rust tests, 71 lifecycle assertions, formatting, Clippy with existing allowances, both architecture builds, live XML and archive/RPM inspection. OpenGamepadUI and Decky integration pass 28 and 11 assertions respectively against the real daemon with fake sysfs/private D-Bus. GitHub reports no CI runs or check contexts for this SHA; the validation above is local.

The branch contains base f5145850eb649707811648b372eaf1f1066b439d with 15 linear contribution commits and no merge commits, including six focused follow-ups. This updates the earlier rebase/history confirmation.

Revised-device, thermal/95°C/98°C, native-curve/HX 370, actual NixOS and qualified ARM/package acceptance remain pending. Historical device observations remain attributed to their original builds.

@sknowledge1
sknowledge1 requested a review from pastaq October 19, 2026 11:33
Add fan control for fans with hwmon pwmN and pwmN_enable files.
Profiles are TOML files or JSON strings that set each fan to automatic,
manual, software_curve or firmware_curve mode using the fan and sensor
IDs from hwmon. Userspace opens the profile file and passes the file
descriptor. Installed profiles can be limited to a device with DMI or
device tree matching.

Fans start in automatic mode and return to it when PowerStation stops
or a sensor cannot be read. A fan runs at 100% when one of its sensors
reaches 95°C.

Tested on an AYANEO 3 (Bazzite 45, ayaneo_ec).

Assisted-by: LLM
@sknowledge1
sknowledge1 force-pushed the feat/generic-fan-control branch from 5913268 to 5833241 Compare November 12, 2026 17:00
The AYANEO 3 embedded controller occasionally fails a single pwm1 read
with an I/O error. Return a fan to automatic only after three failed
updates in a row instead of on the first error.

Tctl jumps by several degrees from one second to the next, so a software
curve made the fan follow every spike. Software curves now lower the fan
speed by at most 2% per update; increases and the 95°C override still
apply at once.

Assisted-by: LLM
@sknowledge1

Copy link
Copy Markdown
Contributor Author

down to 1100 lines - simple TOML profiles in /usr/share/.../fan_curves with /etc overrides, device tree matching, and the startup and locking parts removed. I've read it all again, tested on device, ready for your review 👍

sknowledge1 added a commit to sknowledge1/OpenGamepadUI that referenced this pull request Nov 12, 2026
PowerStation can now set fan profiles (ShadowBlip/PowerStation#54), but
OpenGamepadUI has no way to choose one. Add a Fan card to the quick bar.

The card lists Automatic, the profiles PowerStation has installed for this
device, and Manual with a speed slider. The choice is saved in the settings.
PowerStation does not save it, so it is loaded again whenever PowerStation
starts or the choice changes.

The new Fan class only wraps PowerStation's fan D-Bus API, like the existing
Cpu and Gpu classes. Automatic and Manual are sent as small JSON profiles,
and installed profiles are opened and passed as a file. The card is hidden
when PowerStation has no fans to control.

Assisted-by: LLM
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.

2 participants