Power Management for Android-Based Linux Kernels: An Overview

1. Status of power management

The Linux kernel of Android provides four power states for the system. The source code of the kernel defines the name and corresponding macro definition for three of them. The name is defined in kernel/power/suspend.c:

[cpp] view plain copyconst char *const pm_states[PM_SUSPEND_MAX] = {

#ifdef CONFIG_EARLYSUSPEND

[PM_SUSPEND_ON] = "on",

#endif

[PM_SUSPEND_STANDBY] = "standby",

[PM_SUSPEND_MEM] = "mem",

};

The corresponding macro is defined in: include/linux/suspend.h:

[cpp] view plain copytypedef 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)

It is very strange that the fourth state (disk) has no specific definition, but is hard coded in the code. I don't understand why this is done. At least the version I am looking at now is this (2.6.35). This is called Suspend to disk or hibernate. However, this is not the point. Besides, there are currently few Android devices that support hibernate.

As the name suggests:

PM_SUSPEND_ON -- The device is in full power state, which is normal working state;

PM_SUSPEND_STANDBY -- The device is in a power-saving state, but it can also receive certain events, depending on the specific device;

PM_SUSPEND_MEM -- suspend to memory, the device goes to sleep, but all the data is still stored in the memory, only some external interrupts can wake up the device;

Currently, most Android devices only support two of them: PM_SUSPEND_ON and PM_SUSPEND_MEM, so the discussion below says that suspend is PM_SUSPEND_MEM.

2. Early Suspend, Late Resume

Early Suspend and Late Resume are a feature added by Android to standard Linux. When the user space requests the kernel to enter suspend, this time will enter the early suspend state, the driver can register the callback function of the early suspend, when the state is entered, the kernel will call these callback functions one by one. For example, the driver of the display usually registers early suspend. In his callback function, the driver will turn off both the screen and the backlight. In this state, all the background processes are still active, the songs of the playing songs, the downloaded data is still being downloaded, but the display is bad. After entering the early suspend state, once all the power locks are released, the system will immediately enter the real suspend process until the system stops working and waits for an external event to wake up.

Figure 2.1 Conversion of power state

3. Android power lock mechanism: wake lock

Compared to the standard Linux kernel, Android has added the wake lock mechanism to power management. Once a certain type of lock is applied, the power management module will "lock" a certain power state. Currently, Android provides two types of locks:

WAKE_LOCK_SUSPEND -- Prevents the system from entering the suspend state;

WAKE_LOCK_IDLE -- prevents the system from entering the idle state;

The wake lock can also set a timeout, and the lock is automatically released as soon as the time is up.

The code for wake lock is in: kernel/power/wakelock.c.

4. Power state migration

After the kernel boot is complete, the power management system will create 3 files in the sysfs file system:

/sys/power/state

/sys/power/wake_lock

/sys/power/wake_unlock

The migration of the power state is first initiated by the user space application. When the system application detects that there is no user activity for a certain period of time (such as touch screen or button), the corresponding power state name can be written to the /sys/power/state file (please Referring to the first section), if you write "mem", it will trigger the process of starting the suspend by the kernel, and the kernel will migrate the state according to Figure 2.1. Applications can also request a lock of type WAKE_LOCK_SUSPEND via /sys/power/wake_lock, and a lock can be released via /sys/power/wake_unlock accordingly. If the kernel detects that a lock has not been released before entering suspend, it will abandon this suspend process until the lock is released.

Lead Acid Battery For Railway

2V Lead Acid Battery,Rechargeable Lead Acid Battery,12V 60Ah Lead Acid Battery,Lead Acid Battery For Railway

Henan Xintaihang Power Source Co.,Ltd , https://www.taihangbattery.com