2 This directory contains a prototype proof-of-concept system
3 for managing suspend in Linux.
4 Thus the Linux SUSpend Daemon.
9 The main daemon. It is written to run a tight loop and blocks as
10 required. It obeys the wakeup_count protocol to get race-free
11 suspend and allows clients to register to find out about
12 suspend and to block it either briefly or longer term.
13 It uses files in /var/run/suspend for all communication.
17 disabled: This file always exists. If any process holds a
18 shared flock(), suspend will not happen.
19 immediate: If this file exists, lsusd will try to suspend whenever
21 request: If this is created, then lsusd will try to suspend
22 once, and will remove the file when suspend completes or aborts.
23 watching: This is normally empty. Any process wanting to know
24 about suspend should take a shared flock and check the file is
25 still empty, and should watch for modification.
26 When suspend is imminent, lsusd creates 'watching-next', writes
27 a byte to 'watching' and waits for an exclusive lock on 'watching'.
28 Clients should move their lock to 'watching-next' when ready for
30 When suspend completes, another byte (or 2) is written to
31 'watching', and 'watching-next' is renamed over it. Clients can
32 use either of these to know that resume has happened.
34 watching-next: The file that will be 'watching' in the next awake cycle.
36 lsusd does not try to be event-loop based because:
37 - /sys/power/wakeup_count is not pollable. This could probably be
38 'fixed' but I want code to work with today's kernel. It will probably
39 only block 100msec at most, but that might be too long???
40 - I cannot get an event notification when a lock is removed from a
41 file. :-( And I think locks are an excellent light-weight
42 mechanism for blocking suspend.
45 This is an event-loop based daemon that can therefore easily handle
46 socket connections and client protocols which need prompt
47 response. It communicates with lsusd and provides extra
50 lsused (which needs a better name) listens on the socket
51 /var/run/suspend/registration
52 A client may connect and send a list of file descriptors.
53 When a suspend is immanent, if any file descriptor is readable,
54 lsused will send a 'S' message to the client and await an 'R' reply
55 (S == suspend, R == ready). When all replies are in, lsused will
56 allow the suspend to complete. When it does (or aborts), it will send
57 'A' (awake) to those clients to which it sent 'S'.
59 This allows a client to get a chance to handle any wakeup events,
60 but not to be woken unnecessarily on every suspend.
63 This allows clients to register on the socket.
64 /var/run/suspend/wakealarm
65 They write a timestamp in seconds since epoch, and will receive
66 a 'Now' message when that time arrives.
67 Between the time the connection is made and the time a "seconds"
68 number is written, suspend will be blocked.
69 Also between the time that "Now" is sent and when the socket is
70 closed, suspend is also blocked.
73 A simple tool to create the 'request' file and then wait for it
76 libsus.a: A library of client-side interfaces.
77 suspend_open, suspend_block, suspend_allow, suspend_close:
78 easy interface to blocking suspend
79 suspend_watch, suspend_unwatch:
80 For use in libevent program to get notifications of
81 suspend and resume via the 'watching' file.
82 wake_set, wake_destory:
83 create a libevent event for an fd which is protected from
84 suspend. Whenever it is readable, suspend will not be entered.
85 wakealarm_set, wakealarm_destroy:
86 create a libevent event for a particular time which will
87 trigger even if system is suspend, and will protect against
88 suspend while event is happening.
91 block_test watch_test event_test alarm_test
92 simple test programs for the above interfaces.
95 suspend.py dnotify.py:
96 Sample code for detecting suspend/resume from python
97 block.sh test_block.sh:
98 Sample code for disabling suspend from shell.
100 All code is available under GPLv2+. However if you ask for a different
101 license I am unlikely to refuse (at least with the early prototype).
103 Patches and comment are welcome, but please also feel free to include
104 any of this in some more complete framework.