Linux Kernel suspend-resume 过程.doc
《Linux Kernel suspend-resume 过程.doc》由会员分享,可在线阅读,更多相关《Linux Kernel suspend-resume 过程.doc(7页珍藏版)》请在三一文库上搜索。
1、Linux Kernel suspend/resume 过程休眠/唤醒在嵌入式Linux中是非常重要的部分,嵌入式设备尽可能的进入休眠状 态来延长电池的续航时间.这篇文章就详细介绍一下Linux中休眠/唤醒是如何工作 的我的linux内核版本:3.0.31对于休眠(suspend)的简单介绍在Linux中,休眠主要分三个主要的步骤:1、冻结用户态进程和内核态任务2、调用注册的设备的suspend的回调函数3、顺序是按照注册顺序休眠核心设备和使CPU进入休眠态冻结进程是内核把进程列表中所有的进程的状态都设置为停止,并且保存下所有进程的上下文. 当这些进程被解冻的时候,他们是不知道自己被冻结过的,
2、只是简单的继续执行.如何让Linux进入休眠呢?用户可以通过读写sys文件/sys /power/state 是实现控制系统进入休眠. 比如# echo mem /sys/power/state命令系统进入休眠. 也可以使用# cat /sys/power/state来得到内核支持哪几种休眠方式.Linux Suspend 的流程相关的文件:你可以通过访问Linux内核网站来得到源代码,下面是文件的路径:kernel/kernel/power/main.ckernel/kernel/power/suspend.ckernel/driver/base/power/main.c接下来让我们详细的看
3、一下Linux是怎么休眠/唤醒的. Let s going to see how these happens.用户对于/sys/power/state 的读写会调用到 main.c中的state_store(), 用户可以写入 const char * const pm_state 中定义的字符串, 比如”mem”, “standby”.当然一般是由suspend和resume的按键控制的然后state_store()会调用enter_state(), 它首先会检查一些状态参数,然后同步文件系统. 下面是代码:htmlview plaincopy/*enter_state-Docommonwo
4、rkofenteringlow-powerstate.*state:pm_statestructureforstatewereentering.*Makesureweretheonlyonestryingtoenterasleepstate.Fail*ifsomeonehasbeatustoit,sincewedontwantanythingweirdto*happenwhenwewakeup.*Then,dothesetupforsuspend,enterthestate,andcleaup(after*wevewokenup).*/intenter_state(suspend_state_
5、tstate)interror;if(!valid_state(state)return-ENODEV;if(!mutex_trylock(return-EBUSY;printk(KERN_INFOPM:Syncingfilesystems.);sys_sync();printk(done.n);pr_debug(PM:Preparingsystemfor%ssleepn,pm_statesstate);error=suspend_prepare();if(error)gotoUnlock;if(suspend_test(TEST_FREEZER)gotoFinish;pr_debug(PM:
6、Entering%ssleepn,pm_statesstate);pm_restrict_gfp_mask();error=suspend_devices_and_enter(state);pm_restore_gfp_mask();Finish:pr_debug(PM:Finishingwakeup.n);suspend_finish();Unlock:mutex_unlock(returnerror;准备, 冻结进程当进入到suspend_prepare()中以后, 它会给suspend分配一个虚拟终端来输出信 息, 然后广播一个系统要进入suspend的Notify, 关闭掉用户态的he
7、lper进程, 然后依次调用suspend_freeze_processes()冻结所有的进程, 这里会保存所有进程当前的状态, 也许有一些进程会拒绝进入冻结状态, 当有这样的进程存在的时候, 会导致冻结失败,此函数就会放弃冻结进程,并且解冻刚才冻结的所有进程.htmlview plaincopy/*suspend_prepare-Doprepworkbeforeenteringlow-powerstate.*Thisiscommoncodethatiscalledforeachstatethatwereentering.*RunsuspendnoTIfiers,allocateaconsol
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Linux Kernel suspend-resume 过程 suspend resume
链接地址:https://www.31doc.com/p-3255189.html