Android休眠的内核流程

匿名 (未验证) 提交于 2019-12-03 00:18:01

https://blog.csdn.net/mike8825/article/details/80423842

system/core/libsuspend/autosuspend.c

system/core/libsuspend/autosuspend_wakeup_count.c


kernel/kernel/power/main.c

上面的作用是对/sys/power/wakeup_count进行读写(涉及到变量combined_event_count,

可参考https://blog.csdn.net/mike8825/article/details/80422993),如果所有的锁都已解锁,

则写"mem"到/sys/power/state进行休眠


kernel/kernel/power/main.c

dpm(Device power management),有几个dpm开头的函数,其作用是运行设备的电源管理函数

int dpm_suspend_start(pm_message_t state) { 	dpm_prepare(state);	//prepare  dpm_list 	dpm_suspend(state);	//suspend  dpm_prepared_list }  int dpm_suspend_end(pm_message_t state) { 	dpm_suspend_late(state);   //suspend_late      dpm_suspended_list 	dpm_suspend_noirq(state);  //suspend_noirq    dpm_late_early_list }  void dpm_resume_start(pm_message_t state)   { 	dpm_resume_noirq(state);  //resume_noirq 	dpm_resume_early(state);  //resume_early }  void dpm_resume_end(pm_message_t state) { 	dpm_resume(state);  //resume 	dpm_complete(state);//complete }

休眠prepare--->suspend--->suspend_late--->suspend_noirq

唤醒resume_noirq--->resume_early--->resume--->complete

struct dev_pm_ops { 	int (*prepare)(struct device *dev); 	void (*complete)(struct device *dev); 	int (*suspend)(struct device *dev); 	int (*resume)(struct device *dev); 	int (*freeze)(struct device *dev); 	int (*thaw)(struct device *dev); 	int (*poweroff)(struct device *dev); 	int (*restore)(struct device *dev); 	int (*suspend_late)(struct device *dev); 	int (*resume_early)(struct device *dev); 	int (*freeze_late)(struct device *dev); 	int (*thaw_early)(struct device *dev); 	int (*poweroff_late)(struct device *dev); 	int (*restore_early)(struct device *dev); 	int (*suspend_noirq)(struct device *dev); 	int (*resume_noirq)(struct device *dev); 	int (*freeze_noirq)(struct device *dev); 	int (*thaw_noirq)(struct device *dev); 	int (*poweroff_noirq)(struct device *dev); 	int (*restore_noirq)(struct device *dev); 	int (*runtime_suspend)(struct device *dev); 	int (*runtime_resume)(struct device *dev); 	int (*runtime_idle)(struct device *dev); };

static const struct dev_pm_ops goodix_ts_dev_pm_ops = { 	.suspend = goodix_ts_suspend, 	.resume = goodix_ts_resume, };

类dpm函数的作用是按顺序执行相关的电源函数


上面有个suspend_ops的指针(cpu休眠时的动作),其定义在

kernel/drivers/cpuidle/lpm-levels.c

static int lpm_probe(struct platform_device *pdev) { 	suspend_set_ops(&lpm_suspend_ops); }  static const struct platform_suspend_ops lpm_suspend_ops = { 	.enter = lpm_suspend_enter, 	.valid = suspend_valid_only_mem, 	.prepare_late = lpm_suspend_prepare, 	.wake = lpm_suspend_wake, };

kernel/kernel/power/suspend.c

void suspend_set_ops(const struct platform_suspend_ops *ops) { 	suspend_ops = ops;	 }

参考的内核打印如下

    52.402471:   <6> PM: suspend entry 1970-01-01 00:13:08.409503329 UTC     52.402486:   <2> PM: Syncing filesystems ... done.     52.410354:   <6> Error: returning -512 value     52.409207:   <2> Freezing user space processes ... (elapsed 0.005 seconds) done.     52.415161:   <2> Freezing remaining freezable tasks ... (elapsed 0.002 seconds) done.     52.418063:   <2> Suspending console(s) (use no_console_suspend to debug)     52.451064:   <6> PM: suspend of devices complete after 31.502 msecs     52.452177:   <6> PM: late suspend of devices complete after 1.102 msecs     52.456733:   <6> PM: noirq suspend of devices complete after 4.546 msecs     52.456743:   <2> Disabling non-boot CPUs ...     52.458561:   <6> migrate_irqs: 1510 callbacks suppressed     52.458564:   <6> IRQ32 no longer affine to CPU3     52.458572:   <6> IRQ33 no longer affine to CPU3     52.458579:   <6> IRQ34 no longer affine to CPU3     52.458586:   <6> IRQ36 no longer affine to CPU3     52.458593:   <6> IRQ37 no longer affine to CPU3     52.458600:   <6> IRQ38 no longer affine to CPU3     52.458608:   <6> IRQ40 no longer affine to CPU3     52.458615:   <6> IRQ41 no longer affine to CPU3     52.458622:   <6> IRQ42 no longer affine to CPU3     52.458628:   <6> IRQ43 no longer affine to CPU3     52.460298:   <6> CPU3: shutdown     52.464728:   <6> CPU4: shutdown     52.469291:   <6> CPU5: shutdown     52.473567:   <6> CPU6: shutdown     52.477904:   <6> CPU7: shutdown     52.479231:   <6> CPU0:msm_cpu_pm_enter_sleep mode:3 during suspend


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!