Android快速启动方案设计原理(hibernation/HyperBoot)

来源:互联网 发布:海宁皮草淘宝真货 编辑:程序博客网 时间:2024/06/12 20:56

概要原理如下:

1. 在kernel空间使用tuxonice(suspend2的演进版本)进行suspend to disk(hibernation),主要动作是保存当前内存中所有的有效内容到hibernate image预留分区,写入前使用lzo算法进行压缩(启动的时间主要取决于image的大小)

2. Kill掉不重要的service进程(可配置),以减少要已用的内存空间。

3. 在Uboot启动时check hibernate分区是否有可用的hibernate image,如果有读入image,并进行解压,完成后将PC指针设置为了suspend前的值,系统resume完成。


下面首先详细解析hibernation流程

用户空间使用命令“echo disk /sys/power/state”,最终调用到kernel/power/main.c中的hibernate()函数启动hibernation流程,下面是该流程的主要动作:

1)pm_prepare_console();//给suspend分配一个虚拟终端来输出信息
2)pm_notifier_call_chain(PM_HIBERNATION_PREPARE);//通过notification chain广播hibernation prepare消息

3)usermodehelper_disable();//停用usermodehelper,它的功能是kernel用来启动用户空间程序
4)create_basic_memory_bitmaps();//为不需要保存和需要释放的页创建bitmap
5)sys_sync();//同步文件系统
6)prepare_processes();//冻结进程
7)hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);//创建hibernation image
8)swsusp_write(flags);//将hibernation image写入预留分区
swsusp_free();
power_down();


hibernation_snapshot流程:

1) hibernate_preallocate_memory//Preallocate image memory before shutting down devices

2) freeze_kernel_threads

3) dpm_prepare

4) suspend_console

5) dpm_suspend//对于注册了动态电源管理的设备驱动,suspend函数将被调用

6) create_image


主要动作在create_image中完成,流程如下:

1) dpm_suspend_end//调用dpm_suspend_late和dpm_suspend_noirq完成动态电源管理相关的suspend

2) platform_pre_snapshot

3) disable_nonboot_cpus//power off ap(从核)

4) local_irq_disable

5) syscore_suspend//系统core suspend,register_syscore_ops用来注册system core operation到syscore_ops_list

6) save_processor_state//架构相关代码,保存当前处理器的所有状态(ARM:R0~R15 以及协处理器的各寄存器),保存到指定位置,resume的kernel起始PC指针为restore_processor_state,它将恢复suspend时保存的所有状态。

7) swsusp_arch_suspend//架构相关代码

0 0