@ Normal Linux suspend
- Source code : kernel_src/kernel/main.c
kernel_src/kernel/arch/arm/mach-xxx/pm.c
- userspace interface: /sys/power/state
You can trace kernel_src/kernel/main.c
echo mem > /sys/power/state
echo standby > /sys/power/syste
- Process
1. suspend_prepare()
2. suspend_freeze_processes(): freeze all process.
3. suspend all devices : suppend_device_and_enter() at kernel/power/suspend.c suspend_device_and_enter() {
.......
dpm_suspend_start(PMSG_SUSPEND)
.......
}
dpm_suspend_start(PMSG_SUSPEND)
{
.......
dpm_suspend()
......
}
dpm_suspend()
{
......
;call all device callback function suspend()
get_device(dev);
device_suspend(dev);
......
}
4. Resume:
1. Get wake up event
2. Resume the devices /sys/devices/system
3. call suspend_ops -> finish() and let it start resume
4. call every devices resume in suspend_devices_and_enter()
5. call suspend_ops -> end()
6. call suspend_finish which will thaw the process and enter user mode helper
@ Android suspend : request_suspend_state() in kernel/power/earlysuspend.c
- Early suspend function
- wakelock function
You can study
- kernel_src/kernel/power/main.c
- kernel_src/kernel/power/earlysuspend.c
- kernel-src/kernel/power/wakelock.c
Definition:
http://kzjblog.appspot.com/2010/11/20/suspend-en.html
- Early Suspend
Early suspend is a mechanism that android introduced into linux kernel.
This state is btween really suspend, and trun off screen. After Screen is off,
several device such as LCD backlight, gsensor, touchscreen will stop for battery life and functional requirement.
- Late Resume
Late resume is a mechinism pairs to early suspend, executed after the kernel and system resume finished.
It will resume the devices suspended during early suspend.
- Wake Lock
Wake lock acts as a core member in android power management system.
wake lock is a lock can be hold by kernel space ,system servers and applications with or without timeout.
In an android patched linux kernel (referenced as android kernel below) will timing how many and how long the lock have.
If there isn't any of wake lock prevent suspend(WAKE_LOCK_SUSPEND),
android kernel will call linux suspend (pm_suspend()) to let entire system going to suspend.
Trace code :
Early suspend :
- state_store() /kernel/power/main()
you write "mem > /sys/power/state" and it will call this function
- state_store(){
request_suspend_state(); ---> call early_suspend_work -> early_suspend()
}
- early_suspend()
{
call early_suspend_handler () function in evenry deivces
}
Late Resume:
After all the kernel resume is finished,
the user space process and service is running, the wake up of system for these reasons:
* If In Calling, the modem will send command to rild (RING command),
and rild will send message to WindowManager and Application to deal with in call event,
PowerManagerSerivce also will write "on" to interface to let kernel execute late resume.
* User Key EventWhen system waked by a key event, such as a power key, or menu key,
these key event will send to WindowManager, and it will deal with it, if the key is not the key can wake up system,
such as return key/home key, the WindowManager will drop the wake lock to let system going to suspend again.
if the key is a wake key, the WindowManager will RPC PowerManagerSerivce interface to execute late resume.
* Late Resume will call the resume func in list of early suspend devices.
* Android power management :
reference:http://www.netmite.com/android/mydroid/development/pdk/docs/power_management.html
- Flow:
Application layer : application using wl.newWakeLock(), wl.acquire() and wl.release()
Application framwork: PowerManagement (Android.os.PowerManager)
Power (Android.os.Power)
PowerManagerService (Android.server.PowerManageService)
JNI layer : Power (lib/hardware/power.c)
Linux kernel : Android Power Management (driver/android/power.c)
Linux driver (android_register_early_suspend(), android_register_early_resume())
Linux power Management
- source :
frameworks/base/core/java/android/os/PowerManager.java
frameworks/base/services/java/com/android/server/PowerManagerService.java
frameworks/base/core/java/android/os/Power.java
frameworks/base/core/jni/android_os_power.cpp
hardware/libhardware/power/power.c