linux_source/driver/base/power/main.c
接下来让我们详细的看一下 Linux 是怎么休眠/唤醒的. Let 's going to see
how these happens.
用户对于/sys/power/state 的读写会调用到 main.c 中的 state_store(), 用
户可以写入 const char * const pm_state[] 中定义的字符串, 比如"mem",
"standby".
然后 state_store()会调用 enter_state(), 它首先会检查一些状态参数,然后同
步文件系统. 下面是代码:
/**
* enter_state - Do common work of entering low-power state.
* @state: pm_state structure for state we're
entering.
*
* Make sure we're the only ones trying to enter a sleep
state. Fail
* if someone has beat us to it, since we don't want
anything weird to
* happen when we wake up.
* Then, do the setup for suspend, enter the state, and
cleaup (after
* we've woken up).
*/
static int enter_state(suspend_state_t state)
{
int error;
if (!valid_state(state))
return -ENODEV;
if (!mutex_trylock(&pm_mutex))
return -EBUSY;
printk(KERN_INFO "PM: Syncing filesystems ... ");
sys_sync();
printk("done.\n");
pr_debug("PM: Preparing system for %s sleep\n",
pm_states[state]);
error = suspend_prepare();