Android5.1 power sleep management based on DTL-RK3288 hardware platform


The Linux power management mechanism provides a method for the realization of low power consumption of the device.
In different kernel versions of Linux and Android, the hibernation mechanism and process are different. Here is the DLT-RK3288 Android 5.1 source code as an example.


Standard Linux power states:
- On (on) S0 - Working  
                                                                      - Normal working state
- Standby (standby) S1 - CPU and RAM are powered but not executed   
                                                                        - Both CPU and DDR are powered but no commands are executed.
- Suspend to RAM (mem) S3 - RAM is powered and the running content is saved to RAM
                                                                        - Suspend to memory, or standby for short. The CPU, EMMC, LCD, etc. are all powered off, and only the DDR is powered to save the working state before hibernation.
- Suspend to Disk, Hibernation (disk) S4 - All content is saved to Disk and power down
                                                                        - Suspend to Disk, hibernation for short. The running state of the machine is saved to the hard disk, and the machine is turned off.


Several commonly used states can be seen in kernel/include/linux/suspend.h of DLT-RK3288
1. #define PM_SUSPEND_ON ((__force suspend_state_t) 0)
2. #define PM_SUSPEND_FREEZE ((__force suspend_state_t) 1)
3. #define PM_SUSPEND_STANDBY ((__force suspend_state_t) 2)
4. #define PM_SUSPEND_MEM ((__force suspend_state_t) 3)


Sleep related kernel source code:
kernel/kernel/power/main.c
kernel/kernel/power/suspend.c
kernel/kernel/power/wakelock .c
kernel/kernel/power/autosleep.c
main.c mainly provides file interface to user space. The file interface has the following:

 


 

suspend.c is the code that is executed before going to sleep. The main function call flow: pm_suspend -- enter_state -- suspend_prepare -- suspend_devices_and_enter .
autosleep.c is mainly responsible for automatically entering the sleep process.
The lower version of the linux kernel also has earlysuspend.c, earlysuspend is a mechanism for false hibernation (only turning off the power of some peripherals), which has been abandoned in linux 3.10.


How to enter hibernation?
1. When autosleep is turned on, when all wakelocks are released, it will automatically go to sleep.
     In autosleep.c, the try_to_suspend function calls pm_get_wakeup_count, and executes:
1.  for (;;) {
2.                prepare_to_wait(&wakeup_count_wait_queue, &wait,
3.               TASK_INTERRUPTIBLE);


    It can be seen that pm_get_wakeup_count does not return until wakelock is released. Enter hibernate by calling pm_suspend or hibernate.
2. echo mem > /sys/power/state to force sleep.
       Execute this command, the system will go to sleep directly, and no longer judge whether there is an unreleased wakelock. (In the lower version of the kernel, executing this command still needs to wait for the wakelock to be released).


wakelock exists for wake-up from sleep. You can inquire about related information for further information.
cat /sys/power/wake_lock can see which Android lock is currently active. (/sys/power/wake_lock does not count kernel locks).


How to disable automatic hibernation?
1. In the driver source code, initialize a wakelock, lock it, and not release it.
1. #include <linux/wakelock.h>
2. struct wake_lock no_suspend_lock;


The lock type in the kernel is very simple, only WAKE_LOCK_SUSPEND. (There is more WAKE_LOCK_IDLE in the lower version kernel).
   Disadvantages: It can only guarantee not to go to sleep, but the screen is extinguished.


2. Locking in
Android Android defines the following WakeLock types:
       * FULL_WAKE_LOCK keeps the screen fully on, the keyboard backlight is on and the CPU is running.
        * SCREEN_BRIGHT_WAKE_LOCK keeps the screen fully lit and CPU running.
        * SCREEN_DIM_WAKE_LOCK keep the screen on (but let it dim) and the CPU running.


        * PARTIAL_WAKE_LOCK keeps the CPU running.

You can apply for different lock types as needed.




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324582821&siteId=291194637