Android-based Linux kernel power management: overview

Source: Internet
Author: User
1. Power Management Status

The android Linux Kernel provides four power states for the system. the source code of the kernel defines the names and corresponding macros For the three of them. The names are defined in kernel/power/suspend. C:

const 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:

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)

It is strange that there is no specific definition of the fourth State (Disk), but it is hard-coded in the code. I don't understand why it is like this, at least the version I see is as follows (2.6.35). This is the so-called suspend to disk or hibernate. However, this is not the focus. At present, few Android devices support hibernate.

 

As the name implies:

Pm_suspend_on -- the device is in full power, that is, normal operation;

Pm_suspend_standby: the device is in the power-saving status, but it can also receive certain events. The specific behavior depends on the specific device;

Pm_suspend_mem -- suspend to memory: The device goes to sleep state, but all data is stored in the memory. Only some external interruptions can wake up the device;

Currently, most Android devices only support two of them: pm_suspend_on and pm_suspend_mem. Therefore, we will discuss suspend in the following sections, which refer to pm_suspend_mem.

2. Early suspend and late resume

Early suspend and late resume are added to Android based on standard Linux. When the user space requests to the kernel to enter the suspend, this will first enter the early suspend state, the driver can register the early suspend callback function, when entering this state, the kernel calls these callback functions one by one. For example, the driver of the display usually registers early suspend. In its callback function, the driver closes both the screen and backlight. In this status, all the background processes are still in the activity, the playing of the song, the download data is still being downloaded, but the display is poor. Enter early
After the suspend status, once all the power locks are released, the system will immediately enter the real suspend process until the system stops working and waits for external events to wake up.

Figure 2.1 Power status conversion

3. Power lock mechanism of Android: Wake lock

Compared with the standard Linux kernel, Android incorporates the wake lock mechanism in power management. Once a type of lock is applied, the power management module will "Lock" a certain type of power status. Currently, Android provides two types of locks:

Wake_lock_suspend -- stops the system from entering the suspend state;

Wake_lock_idle -- stops the system from entering the idle state;

The wake lock can also be set to time-out. The lock is automatically released once the time is reached.

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

4. Power status migration

After the kernel is started, the power management system will create three files in the sysfs File System:

  • /Sys/power/State
  • /Sys/power/wake_lock
  • /Sys/power/wake_unlock

The power status migration is first initiated by the user space application. When the system application detects no user activity within a certain period of time (such as touch screen and buttons ), you can write the corresponding power status name to the/sys/power/State file (refer to section 1). If you write "mem", the kernel starts the suspend process, the kernel will perform status migration according to Figure 2.1. The application can also apply for a lock of the wake_lock_suspend type through/sys/power/wake_lock. Correspondingly, a lock can be released through/sys/power/wake_unlock. If the kernel detects that a lock has not been released before it enters suspend, it will discard this suspend process until the lock is released.

More detailed analysis will be introduced in the subsequent blog.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.