Linux suspend/resume code flow (on android phone)

user1804788 picture user1804788 · Nov 7, 2012 · Viewed 8.4k times · Source

Does anyone know any good reading on how the whole process and code flow are for android/linux suspend/resume (after pressing the end key on the phone)? I am trying to understand and read the related code and files.

Or, maybe if somebody can point me to the code to look at...

Answer

shingaridavesh picture shingaridavesh · Nov 7, 2012

I hope i help.

Android is based on Linux, so the base is more or less same as that of Linux Suspend Resume. There are few additional functionality, most important being Wakelocks and Early Suspend which are added to make the mobiles, PDA more power efficient as they have limited battery.

Now let us start with what you are asking: As soon as you press the power button then obviously interrupt is triggered which initiates the sequence.

Difference: You should have noted that as soon as power button is pressed then LCD and touch goes to sleep. They are early_suspend. Device might be up, just the most power consuming LCD, touch are gone to sleep. Then in background Wakelocks are checked, whether anyone is acquiring, as if anyone is acquiring then those pending task are performed.

Common: Then File system is synced(RAM--> NAND) and the processes are freezed. Then device are suspended and then CPU state is saved and then it sleeps. Sequence is common in both Linux and Android.

After Android receice event.POWER and affirm no wake_lock exist, Android trigger the suspend flow in kernel by echo mem > /sys/power/state:

state_store >> pm_suspend >> enter_state >> suspend_prepare >> suspend_devices_and_enter >> dpm_suspend_start >> dpm_suspend >> device_suspend >> __device_suspend ---> suspend_enter (called by suspend_device_and_enter after __device_suspend is completed)

The above sequence is present in both Linux and Android.

Files: suspend.c, (kernel/power/) wakelock.c, main.c (drivers/base/power).

Note: All the SoC specific suspend callbacks like enter, valid, begin are present in pm.c present in arch/arm/< folder.