In various situations it may be useful to communicate information on power requirements or state changes from the kernel to a userspace power policy manager. The information may, for example, request a system suspend in response to an interrupt received due to a button press, or may communicate device status changes that could lead the policy manager to change system power state.
DPM provides functions to notify userspace via the hotplug mechanism, which traditionally notifies userspace policy handlers of changes in devices present (and associated chores such as downloading firmware for new devices). Hotplug executes an agent script to perform userspace handling of the power event. The DPM power events are sent to script /etc/hotplug/power.agent, supplying parameters that are described in the subsections for the particular types of power events below.
The hotplug package must be installed as described in the section on Kernel and System Configuration below. You'll need to create the necessary agent scripts and add the commands necessary to communicate with your power policy manager. See the existing scripts for easily-customized examples and suggested code snippets below.
The notification functions return without waiting for the power.agent script to finish execution.
General-purpose power information may be communicated using function power_event():
power_event(char *msg);
- msg
- a free-format string to be sent to your userspace power policy manager.
The msg string is passed to power.agent in variable EVENT. The ACTION variable is "event". A sample script fragment for this is:
case $ACTION in event) DEBUG=yes debug_mesg "Power event: $EVENT" ;;
In some situations it may be useful to communicate device-specific information on power requirements from drivers to a userspace power policy manager. The information may, for example, request a change in system power state in order to accomodate a change in device power state, or may be a "hint" regarding expected future device activity that the policy manager may use to device system or device power levels.
This information may be communicated using function device_power_event():
device_power_event(struct device *dev, char *msg);
- dev
- pointer to the struct device for the device associated with this power notification event.
- msg
- a free-format string to be sent to your userspace power policy manager.
The msg string is passed to power.agent in variable EVENT. The ACTION variable is "device-event" and DEVICE contains the bus ID of the device (as registered in the Linux Driver Model). A sample script fragment for this is:
case $ACTION in device-event) DEBUG=yes debug_mesg "Device $DEVPATH event: $EVENT" ;;
device_power_event() returns without waiting for the power.agent script to finish execution. If synchronization between driver power state and the userspace power manager is needed then the driver may notify the power manager of its needs and the power manager can later set the appropriate device power state at the proper time via sysfs.
The kernel must be built with CONFIG_HOTPLUG=y and the hotplug package must be installed; see . The agent scripts that handle power events are not a part of the standard linux-hotplug distribution.