Power Management-Implementation of suspend to disk in android system (III)

Source: Internet
Author: User

II. Introduction to Android sleep (suspend)

1. Introduction to sleep in android

The android system uses the Linux kernel, but it is also different. Due to its particularity, the code is modified based on the Linux kernel sleep.

The following describes the suspend implemented by the android kernel. suspend to disk will be involved in the debugging file.

In a kernel that has been installed with the android patch, the state_store () function will go to another path and enter request_suspend_state (). The file is located in earlysuspend. c. these functions are added to the android system. earlysuspend and lateresume will be introduced later.

Involved files:

Android4.1/kernel/power/main. c

Android4.1/kernel/power/earlysuspend. c

Android4.1/kernel/power/wakelock. c

2. Features of android sleep

The following describes some unique features of the android system.

1) EarlySuspend

Early suspend is a mechanism introduced by android to disable display-related devices, such as LCD backlights, gravity sensors, and touch screens, however, the system may still be running (at this time there is wakelock) for task processing, such as scanning files on the SD card. in embedded devices, backlight is a huge power consumption, so android will add such a mechanism.

2) LateResume

Late Resume is a mechanism supporting suspend. It is executed after kernel wake-up is completed. It is mainly used to wake up the device that is sleeping during EarlySuspend. after all the wake-up operations are completed, user processes have started to run. Wake-up is usually due to the following reasons:

Incoming call

For incoming calls, the Modem sends a command to rild to notify WindowManager of incoming call response, in this way, the device that remotely calls PowerManagerService to write "on" to/sys/power/state to execute lateresume, such as lighting the screen.

The user presses the user key event and sends it to WindowManager. WindowManager processes these key events. The buttons are divided into several situations. If the case is not a wake-up key, the system can be awakened) windowManager will take the initiative to discard wakeLock to enable the system to sleep again. If the key is the wake-up key, WindowManger will call the interface in PowerManagerService to execute Late Resume.

Late Resume will wake up the device that previously called EarlySuspend.

3) WakeLock

Wake Lock plays a core role in the Android power management system. wakeLock is a lock mechanism. As long as someone holds this lock, the system will not be able to sleep and can be obtained by user State programs and kernels. The lock can be time-out or not time-out. The lock will be automatically unlocked after the time expires. If no lock or timeout occurs, the kernel starts the sleep mechanism to sleep.

4) AndroidSuspend

When the user writes mem or standby to/sys/power/state, state_store () will be called, and Android will call request_suspend_state () here () standard Linux will enter the enter_state () function here. if the request is sleep, the workqueue early_suspend will be called and enters the early_suspend state. Call request_suspend_state () and register an early_suspend_work worker on the suspend_work_queue worker thread,

Then, register a work task early_suspend through staticDECLARE_WORK (early_suspend_work, early_suspend. Therefore, the system will eventually call the early_suspend function.

5) register the suspend and resume Processes

Platform_device_register () --> platform_device_add () --> device_add () --> device_pm_add () --> is added to the dpm_list linked list, in the dpm_suspend and dpm_suspend, traverse the linked list to check which device contains the suspend and resume items.

My opinion. If you have any questions, please correct them !!

Reprinted please indicate the source: http://blog.csdn.net/wang_zheng_kai


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.