In the design of handheld devices, power management has always been one of the important research topics. What we call power saving is part of the source management, which is one of our most concerned. By hanging unnecessary equipment, reducing the frequency of the CPU or other methods, can reduce the energy consumption, achieve the purpose of saving electricity. Power management is actually a system engineering, from the application to the kernel framework, and then to device drivers and hardware equipment, to participate in order to achieve the optimal power management. This article introduces the working principle of acpid.
ACPI is the advanced Configuration and Power interface abbreviation, and D in Acpid represents daemon. Acpid is a user-space service process that acts as an interface between the Linux kernel and the application, and is responsible for forwarding power management events in kernel to the application.
Acpid and the kernel communication mode: Acpid with the poll function hanging on the/proc/acpi/event file. The kernel implements the interface of the file in Drivers/acpi/event.c, and once a power management event occurs on the Bus event list (acpi_bus_event_list), the kernel wakes up acpid on the/proc/acpi/event, Acpid then reads the corresponding event from the/proc/acpi/event.
Acpid and applications are communicated in two ways, one is through the local socket, its file name is/var/run/acpid.socket, the application as long as the connection to this socket, without sending any command can receive ACPID forwarded power management events.
The second is through the configuration file. When Acpid receives a power management event from the kernel, the specified command is executed according to the rules in the configuration file. The configuration file is in the/etc/acpi/events/directory, and the following is an example:
Event=button/power.*
Action=/sbin/shutdown-h now
The format of the event is: Device_class bus_id type data. Device_class and bus_id are strings, type and data are 16 integers. Wildcard characters can be used in a configuration file to match a specified event.