Fan Control GUI unnecessarily raising Windows platform timer resolution
Describe the bug
I noticed that after the GUI is rendered for the first time (when Fan Control was either not running before or has been started minimized), it increases the Windows platform timer resolution to 1ms (from the default 15.625ms), which is not reverted even when the GUI is closed (by minimizing Fan Control back to the systray).
This is bad because it reduces usage of the lowest CPU power states and package C states, increasing idle power consumption (more background information on this issue, which is unfortunately rather common for WPF applications, but can be mitigated: https://randomascii.wordpress.com/2013/07/08/windows-timer-resolution-megawatts-wasted/).
One can directly see the influence by monitoring the C state usage using, e.g., ThrottleStop. With Fan Control started minimized, everything is fine as if it would be not running at all, but when the GUI was at least rendered once in the current session, one has to stop Fan Control and restart it minimized (or reboot the PC) in order to get back to the lowest power states.
It might be related to #2520 as the rendering process seems to stay active even in background after the GUI was closed. However, I fear that this has implications that go beyond some increased memory usage, sacrificing even some battery life in portable devices due to unnecessarily raised timer resolution.
Steps to reproduce
- After Windows has booted with Fan Control being started minimized, run "powercfg /energy /duration 1" from elevated shell
- Open the generated "energy-report.html", look at the "Information" section and confirm that Windows platform timer resolution is at its default value 156250 and that no other process is running that raises timer resolution.
- Open Fan Control GUI and then run "powercfg /energy /duration 1" again and you will see that FanControl.exe now has requested a Platform Timer Resolution of 10000 which causes the energy report to issue a warning
- Close Fan Control GUI by pressing "x", which minimized it back to systray but leaves the process running in the background.
- Check "powercfg /energy /duration 1" and see that Platform Timer Resolution is still forced to 10000 by FanControl.exe, even though the GUI is not rendered anymore.
- Completely exit Fan Control. Now, the Platform Timer Resolution is back to default 156250.
Seems like yet another WPF quirk. Is there any known control over this? Once WPF assemblies gets activated, I don't think those can be flushed out.
The usual way, as far as I understand, for an application to raise the timer resolution would be to call timeBeginPeriod(), followed by timeEndPeriod() to reset it to the default resolution.
https://learn.microsoft.com/en-us/windows/win32/api/timeapi/nf-timeapi-timeendperiod
However, I am not sure if you could just call timeEndPeriod() in your application (e.g., when the window is minimized), as the increase was requested by some other rendering subprocess.
Several years ago, I reported the exact same issue to the AdGuard team, as their GUI is also based on WPF. They managed to fix it, but unfortunately there is no information how they did it. (https://github.com/AdguardTeam/AdguardForWindows/issues/2734)
Any updates on that?
Haven't investigated this yet, have more pressing issues with the new driver. Also since this is a native WPF framework behavior, I fear doing native calls to trick the platform timer resolution as I'm basically fighting the framework.
@Rem0o I just thought that the new background service would make it possible to nicely get around the problem. However, this would require Fan Control to automatically switch back to the Service + Client Mode (without UI, so without increased timer resolution) when it is closed, like what was suggested in #4035
I guess? However I don't really see the point from a user feature POV to restart the service mode once you got the full app opened already. I want to minimize the app -> service or service -> app transitions to a minimum.
In your daily usage once setup you don't need to access the UI at all and you can keep it in service mode all the time. The occasional WPF UI access will still raise the platform timer, but then that's now an acceptable edge case?
V270