Next: , Previous: Security, Up: Top


13 Internals

13.1 The Daemon

The heart of the package is the daemon (/usr/sbin/powersaved). It listens for client requests (normally from non-root users), listens for hardware changes and checks e.g. the CPU load to adjust the CPU frequency dynamically.

There are a fixed amount of events that the daemon my throw. The events could be triggerd by the underlying hardware/kernel and the daemon just forwards them (e.g. ACPI events) or the daemon can generate his own events when it recognises hardware changes (e.g. low/high CPU usage, changed battery levels, ...). See Events for an complete overview of all events and Scripts how you can use them in your own scripts and programs.

13.2 The User Binary

This binary (/usr/bin/powersave) provides general information about your system (APM/ACPI, battery, throttling, CPU frequency, ...).

For some functionalities you may need a running daemon. The binary then connects to the daemon through a socket and sends its requests (e.g. suspend, standby, change CPU freq policy, ...).

The modifications could only be temporarily. They could e.g. be overridden by the policy of the daemon. E.g. if you plug/unplug AC adapter and another power scheme (see Schemes) is activated which then adjusts your power policy as you specified them for this scheme.

The binary should mainly give you some information of your hardware. Please have a look at the manpage for details.

13.3 The C-Libraries

If you intend to write your own power manageing program you can make use of the provided libraries. All libraries are build statically and shared by the build system.

13.3.1 Library that directly accesses the Hardware

The libpowersave.a/libpowersave.so library directly accesses kernel functions (through /proc, /sys or ioctl) and could be very useful to gain hardware information (Have a look into powerlib.h for provided functions).

13.3.2 Library to sends Requests to and retrieves HW Information from the Daemon and

The libpowersave_daemon.a library needs a running powersave daemon. It connects to the daemon through a socket and sends a request. E.g. suspend, get hardware Info (the send_Action_get_States() function), get current power policy scheme, switch current power policy scheme, ..., see powersave_daemonlib.h for details. This is especially useful for programs to trigger power related functions and to gain power related information about the current system without the need of directly accessing the hardware. The daemon knows the current values, accessing the information directly through the library described above will result in performance losses (imaging dozens of programs accessing hardware directly which is read out over some slow bus).

13.3.3 Library to register at the Daemon to retrieve Events asynchronously

Another library (powersave_clientsocket.a) provides an interface for external programs to get notified about Powersave, ACPI and other events. Programs register at the daemon and send which events they want to get notified about. This should be the preferred way for other programs to be up to date about power related hardware info. It avoids polling the hardware and the daemon. CPU usage is at a minimum as the programs are only awakened when there really is a hardware change. If there is a hardware change the event can be evaluated and specific information retrieved through one of the above libraries. Have a look at the testclient in the CVS for an example implementation. This testclient simply registers at the daemon and prints out all events it receives from the daemon.