Power management is based on Android Linux kernel: Overview

1. The status of the power management
Android Linux kernel system provides four power states, in which the kernel source code defines three types corresponding to macro definitions and the names, the name defined in the kernel / power / suspend.c of:

const char *const pm_states[PM_SUSPEND_MAX] = {
#ifdef CONFIG_EARLYSUSPEND
    [PM_SUSPEND_ON]        = "on",
#endif
    [PM_SUSPEND_STANDBY]    = "standby",
    [PM_SUSPEND_MEM]    = "mem",
};

 In corresponding macro definitions: include / linux / suspend.h of:

typedef int __bitwise suspend_state_t;
 
#define PM_SUSPEND_ON        ((__force suspend_state_t) 0)
#define PM_SUSPEND_STANDBY    ((__force suspend_state_t) 1)
#define PM_SUSPEND_MEM        ((__force suspend_state_t) 3)
#define PM_SUSPEND_MAX        ((__force suspend_state_t) 4)

Oddly enough, the fourth state (disk) is not specifically defined, but is hard-coded in the code, do not understand why, at least I now look like this version (2.6.35), this is called the suspend to disk or called hibernate. But this is not the point, say, at present there are few Android devices support hibernate.

 

As the name suggests:

PM_SUSPEND_ON - the device is a full power state, i.e. the normal working state;

PM_SUSPEND_STANDBY - the device is in a power saving state, but may also receive some event, the specific behavior depends on the specific device;

PM_SUSPEND_MEM - suspend to memory, the device goes to sleep, but also all of the data stored in memory, only some external interrupt can wake up the device;

Currently, most of the Android device only supports two of them: PM_SUSPEND_ON and PM_SUSPEND_MEM, so place the following discussion, said suspend, and both refer to PM_SUSPEND_MEM.

Early Suspend 2., Late Resume
Early and Late Resume Suspend is a characteristic of the standard Linux Android based on the increase. When a user requests to the kernel space into the suspend, at this time will first enter the early suspend state, drivers can register early suspend callback function when entering the state, the kernel calls the callback functions one by one. For example, display drivers usually register early suspend, in his callback, the driver will screen and backlight are closed. In this state, all the background processes are still active, the playing of the song playing songs, the downloaded data is still in the download, but poor display only. After entering the early suspend state, once all the power lock (wake lock) is released, the system will immediately enter the real suspend the process until the last system to stop working and wait wake external events.

                                     2.1 power state transition diagram

3. Android power lock mechanism: wake lock
compared to standard Android Linux kernel, adding the wake lock mechanism in power management. Once you apply for some type of lock, power management module will "lock" a certain kind of power status, currently, Android offers two types of locks:

WAKE_LOCK_SUSPEND - prevent the system from entering the suspend state;

WAKE_LOCK_IDLE - prevent the system from entering the idle state;

wake lock timeout may be set, a time to automatically release the lock.

About wake lock code: kernel / power / wakelock.c in.

4. Power state transition 
after the kernel starts is completed, the power management system will create three files in the sysfs file system:

/sys/power/state
/sys/power/wake_lock
/sys/power/wake_unlock

Migration power state is first initiated by a user-space application, when no user activity within the system application detects a predetermined time (e.g., a touchscreen, buttons) can be written to the corresponding power state name to the / sys / power / state file ( reference Section 1), if the write "mem", will trigger the kernel boot suspend the process, the kernel will be in accordance with Figure 2.1 migration status. Applications can also / sys / power / wake_lock WAKE_LOCK_SUSPEND apply a type of lock, Accordingly, by / sys / power / wake_unlock a lock can be released. If the kernel detects that a lock is not released before entering suspend, it will give up this time suspend the process until the lock is released.
 

Guess you like

Origin blog.csdn.net/ds1130071727/article/details/94716134