android v2.3linuxv2.6.37wakelock 和 early_suspend能夠實現系統的喚醒和休眠功能1.wakelockwakelock是一種鎖機制,只要有人拿著這個鎖,系統就無法進入休眠,wakelock有加鎖解鎖二種狀態逾時鎖:在設定的時間到了後自動解鎖不逾時鎖:需要顯示的解鎖include/linux/wakelock.henum {WAKE_LOCK_SUSPEND, //防止系統進入睡眠WAKE_LOCK_IDLE, WAKE_LOCK_TYPE_COUNT};2.early_suspend 在linux 核心的睡眠過程前被調用,因為背光需要的電能大,可以在核心中先註冊上early_suspend函數當系統進入睡眠之前會首先調用這些註冊的函數android休眠喚醒的的檔案kernel/power/console.cearlysuspend.cfbearlysuspend.cmain.cpoweroff.csuspend.cwakelock.cuserwakelock.carch/arm/mach-omap2/pm34xx.c pm.c3.android 休眠當使用者讀寫/sys/power/state時,/kernel/power/main.c中的state_store()函數會被調用# echo mem > sys/power/state [ 61.009735] ------state_store------ [ 61.013366] ------request_suspend_state------ [ 61.017944] request_suspend_state: sleep (0->3) at 61399169254 (2000-01-01 00:00:56.084929752 UTC) [ 61.027496] ------early_suspend------ state_store會調用request_suspend_state()然後調用early_suspend_work的工作隊列void request_suspend_state(suspend_state_t new_state){---------------------queue_work(suspend_work_queue, &early_suspend_work);---------------------}static DECLARE_WORK(early_suspend_work, early_suspend);early_suspend_work的工作隊列進入early_suspend()函數中static void early_suspend(struct work_struct *work){-------------------//調用已經註冊的early_suspend函數list_for_each_entry(pos, &early_suspend_handlers, link) {if (pos->suspend != NULL)pos->suspend(pos);}------------------sys_sync();//同步檔案系統}4. android 喚醒# echo on > sys/power/state [ 582.205108] ------state_store------ [ 582.208740] ------request_suspend_state------ [ 582.213317] request_suspend_state: wakeup (3->0) at 582594543042 (2000-01-01 00:09:37.501769604 UTC) [ 582.222839] ------late_resume------ 跟睡眠的過程相反