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

Source: Internet
Author: User

4. Linux Suspend Process

The file path is android4.0/kernel/power/

Next, let's take a detailed look at how Linux sleeps/wakes up:

(1) The user reads/writes/sys/power/state and calls the main. state_store () in c. You can write strings defined in constchar * const pm_state [], such as "mem", "standby", "disk", "on ".

(2) then state_store () will first check whether it is a disk. If it is a disk, hibernate () will be called; otherwise, enter_state () will be called. They will first check some status parameters, then synchronize the file system ..

(3) Prepare and freeze the process

After entering suspend_prepare (), it will allocate a virtual terminal for suspend to output information, broadcast a system to enter suspend's ipvy, and disable the user-mode helper process, then call suspend_freeze_processes () to freeze all processes. The current state of all processes will be saved here. Some processes may refuse to enter the frozen state. When such a process exists, this function will stop freezing processes and restore all the frozen processes.

(4) sleep the peripherals

Now, all processes (including workqueue/kthread) have stopped, and kernel-state characters may hold some semaphores when they are stopped, so if you unlock the semaphores In the peripherals at this time, there may be deadlocks, so you should be very careful when making the lock/unlock lock in the suspend () function of the peripherals, we recommend that you do not wait for the lock in suspend () during design. in addition, some logs cannot be output during suspend, so once a problem occurs, debugging is very difficult.

(5) then the kernel will try to release some memory here.

(6) At last, suspend_devices_and_enter () will be called to sleep all peripherals. In this function, if the platform registers suspend_pos (usually defined and registered in the board-level definition ), here we will call suspend_ops-> begin (), and then driver/base/power/main. in c, device_suspend ()-> dpm_suspend () will be called, and they will call the suspend () callback of the driver in sequence to sleep all devices.

Note: suspend_ops is an on-board power management operation. It is usually registered in the arch/xxx/mach-xxx/pm. c file.

(7) after all devices are sleep, suspend_enter () will call suspend_ops-> prepare (). Executing the device_prepare function usually makes some preparation to sleep the machine. in Linux, the non-startup CPU in the multi-core CPU will be turned off. The comment shows that the other CPUs will not cause racecondion. In the future, only one CPU is running, stop the core device.

(8) Next, suspend_enter () will be called. This function will close archirq and call device_power_down (). It will call the suspend_late () function, this function is the final function called by the system to sleep. It usually performs the final check in this function. if the check is OK, sleep all the system devices and buses and call suspend_pos-> enter () to enable CPU power-saving. At this time, the CPU is sleep, code execution stops here.

5. Linux Resume process

Here we will only introduce the resume of suspend to mem. The suspend of disk is similar to android, And I will plot and explain it. The following is an explanation:

If the system is interrupted or other events are awakened during sleep, the following code starts to run. The wake-up sequence is the opposite to that of sleep, therefore, the system device and bus will first wake up, enable system interruption, enable non-startup CPU to stop during sleep, and call suspend_ops-> finish (), and in suspend_devices_and_enter () the function will also wake up each device, enable the virtual terminal, and finally call suspend_ops-> end (). in the return to the enter_state () function, when suspend_devices_and_enter () returns, the peripherals are awakened, but the processes and tasks are still frozen. suspend_finish () is called here () to unfreeze these processes and tasks, and send a running y to indicate that the system has exited from the suspend status and wakened the terminal. by now, all sleep and wakeup have been completed, and the system continues to run.

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.