Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

OSX: catch power management, screen, screensaver notifications #944

Open
jcoffland opened this issue Oct 28, 2012 · 6 comments · May be fixed by FoldingAtHome/fah-client-bastet#163
Open
Assignees
Labels
1.Type - Enhancement Reported issue is an enhamcement. 3.Component - FAHClient Reported issue relates to FAHClient. 4.OS - macOS Reported issue occurs on macOS (Catalina, Mojave, High Sierra, Sierra, El Capitan, Yosemite, Maveri)

Comments

@jcoffland
Copy link
Member

Trac Data
Ticket 944
Reported by @kbernhagen
Status accepted
Component FAHClient
Priority 5
Milestone Upcoming OSX Release

Create a screensaver proxy LaunchDaemon or LaunchAgent, which would connect to local client and claim to be a screensaver whenever any screensaver is running, screen is locked, or display output is off.

Would register for distributed notifications for sceensaver and screen lock, and power manager notifications for display on/dim/off.

This would have the advantage of letting the user fold with any screensaver, or none at all when the screen is locked or off.

This agent and it's launchd plist would best be part of the fahclient package, not any screensaver package. It should maybe not be loaded by default, unless the client would completely ignore it by default.

@jcoffland
Copy link
Member Author

Comment by @jcoffland
This would not be necessary if FAHClient just tied into the OS's API for detecting when the machine is idle.

Perhaps this ticket should be converted to: Add OS idle folding mode It would also be necessary to disable sleep modes.

@jcoffland
Copy link
Member Author

Comment by @kbernhagen
I think that could be good, but should be a separate ticket.
There is already a ticket for disabling system sleep.
General idle computer, low load detection would be quite different and probably require polling. Detecting user idle states can only be done from that user's security context, so the client could not do that.

The proposed functionality for this agent could be added to the client. This would require some help from you integrating it, rather than taking zero time from you as an external agent. But if you're game so am I. Especially since it would mean less work for me and overall.

The distributed notifications can be flexibly received via the darwin notifications api. Something as simple as a blocking select() on a file descriptor would do.

The power manager notifications seem to require a CFRunLoop. This is something I thought you might object to. I don't know if the CFRunLoop would by happy in any thread, or would need to be on the main thread. Probably any dedicated thread is ok. Need a thread safe way to note state changes in rest of client.

If there is a CFRunLoop, then it would be easiest to also use that for the darwin notifications, rather than a separate select() thread.

@jcoffland
Copy link
Member Author

Comment by @kbernhagen
Created ticket #945 Add OS idle folding mode.

@jcoffland
Copy link
Member Author

Comment by @kbernhagen
This should not be component FAHScreensaver.

The proposed functionality would not work from a screensaver.

This must either be a separate always-running daemon, or integrated into FAHClient.

@jcoffland
Copy link
Member Author

Comment by @kbernhagen
Add CFRunLoop polling to main thread on OSX.

To keep main thread loop responsive, it will need to have its own special loop which will never do anything time-consuming, like upload results.

This will also mean creating one extra worker thread on OSX, to replace the re-purposed main thread loop.

Only the main thread can easily receive darwin notifications, so it is best if all notifications get serviced by the main thread run loop. It would also be impractical and inefficient to have all worker threads poll their own CFRunLoop, and have all notification run loop sources added to all threads' CFRunLoop.

Catch power manager notifications for system sleep, system wake, display on/dim/off.

System sleep/wake notifications may be useful in future to stop GPU slots. It would be better if the GPU cores caught these notifications themselves, or if they could get GPU will power off notifications.

Catch relayed darwin notifications for screensaver start/stop, screen lock/unlock.

Catch console user name changed notifications, to know when login window is showing.

Have a few seconds delay, maybe idle-delay=5, before claiming idle for appropriate notifications. It is common for screensaver to start, and user jiggles mouse a couple seconds later. System sleep must be acted on immediately to delay sleep before "allowing" the power change. Other notifications can set flags to be acted on later by worker threads.

Create trivial LaunchAgent to relay screensaver and screen lock notifications from console context to global darwin notifications. (Already done. Just needs to be added to build system and installer package.)

Ignore idle-seconds on OSX. Or maybe only use it when login window is showing. Since there will be a CFRunLoop, a CFRunLoopTimer can be used instead of polling for idle seconds.

It might be good to have options for what states constitute idleness. E.g., idle-on-loginwindow=true.

Possibly replace battery polling with battery change notifications.

Plan for possible low average system load detection in future as another idle condition.

Although the preceeding may seem like too much for one ticket, it's all mostly related and best to do in one go IMO. The new thread for main loop is a small design change, but is forced by how threads, notifications, and CFRunLoop work on OSX.

Since the PowerManagement class is already handling some of this, it's probably the best place to implement notification handling. It might need a reference to ClientApp in the future to have it handle the system sleep/wake notifications, probably just forwarded to slot manager. Since there are currently no GPU cores for OSX, these can just be stub methods in PowerManagement.

@jcoffland
Copy link
Member Author

Comment by @kbernhagen
Idle on loginwindow or display sleep implemented for 7.3.13.

@jcoffland jcoffland added the 1.Type - Enhancement Reported issue is an enhamcement. label Apr 3, 2015
@jcoffland jcoffland self-assigned this Apr 3, 2015
@jcoffland jcoffland added 4.OS - macOS Reported issue occurs on macOS (Catalina, Mojave, High Sierra, Sierra, El Capitan, Yosemite, Maveri) 3.Component - FAHClient Reported issue relates to FAHClient. labels Aug 19, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.Type - Enhancement Reported issue is an enhamcement. 3.Component - FAHClient Reported issue relates to FAHClient. 4.OS - macOS Reported issue occurs on macOS (Catalina, Mojave, High Sierra, Sierra, El Capitan, Yosemite, Maveri)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant