echo disk > /sys/power/state
收到的是kernek/power/main.c :
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
suspend to disk 部份超快,就..
if (len == 4 && !strncmp(buf, "disk", len)) {
error = hibernate();
goto Exit;
}
直接 call kernel/power/hibernate.c 的 hibernate( )snapshot_device_available 被用作 snaphot 的 mutex,初始是 1,使用時 -1。
也就是說: 1 可用,0 不行。
所以 kernel code 要操作 snapshot 時,都要先作:
atomic_add_unless(&snapshot_device_available, -1 ,0)
用來確認 snaphot_device_available 是不是 1 (available),再繼續動作。
實際上依靠 snaphost_device_avaiable 的 function 有:
- hibernate()
- software_resume( )
- snapshot_open( ) -- user interface of device "snapshot'
好像有以下幾個 chain:
- PM_HIBERNATION_PREPARE
- PM_POST_HIBERNATION
- PM_RESTORE_PREPARE
- PM_POST_RESTORE
定義在:notifier.h
/* Hibernation and suspend events */
#define PM_HIBERNATION_PREPARE 0x0001 /* Going to hibernate */
#define PM_POST_HIBERNATION 0x0002 /* Hibernation finished */
#define PM_SUSPEND_PREPARE 0x0003 /* Going to suspend the system */
#define PM_POST_SUSPEND 0x0004 /* Suspend finished */
#define PM_RESTORE_PREPARE 0x0005 /* Going to restore a saved image */
#define PM_POST_RESTORE 0x0006 /* Restore failed */
RCU : Read-Copy-Update
static int orig_fgconsole, orig_kmsg;
int pm_prepare_console(void)
{
orig_fgconsole = vt_move_to_console(SUSPEND_CONSOLE, 1);
if (orig_fgconsole < 0)
return 1;
orig_kmsg = vt_kmsg_redirect(SUSPEND_CONSOLE);
return 0;
}
void pm_restore_console(void)
{
if (orig_fgconsole >= 0) {
vt_move_to_console(orig_fgconsole, 0);
vt_kmsg_redirect(orig_kmsg);
}
}
沒有留言:
張貼留言