0. 文章參考
http://www.wowotech.net/linux_kenrel/suspend_and_resume.html
在suspend狀態(sleep mode)下,爲了降低功耗,當系統做完需要做的事情,處於idle狀態時會進入睡眠模式(用戶將手機空置一段時間系統會自動sleep,或者按下power key強制系統進入sleep mode),此時系統時鐘會由26M切換到32K,某些外部device的電源會被關閉,系統所需的相關core電壓會被調到一個相對較低的值,系統在sleep mode下的耗電要關注如下兩個指標:
- 底電流:手機在sleep狀態下消耗的最小電流,與整個系統的漏電相關;
- 平均電流:在一段時間內,對手機取電流的平均值,與手機的wake up行爲相關。
1. 判斷是否進入suspend的關鍵信息
一個完整的suspend/喚醒log,應該包含關鍵字Chip_pm_enter、md_settle = 99, settle = 99和wake up byXXX。md_settle = 99, settle = 99是系統進入suspend前打印的最後一行log,正常的話這一行log的前後行log時間戳是不會變的,因爲suspend之後kernel時間不會計算,只有32k時鐘工作。
<6>[ 922.885697] (0)[1180:system_server]PM: suspend entry 2017-03-09 06:55:59.675845617 UTC
<6>[ 922.885711] (0)[1180:system_server]PM: Syncing filesystems ... done.
<3>[ 922.993726] (0)[1180:system_server][PBM] PM_SUSPEND_PREPARE:start
<3>[ 922.993747] (0)[1180:system_server][PBM] PM_SUSPEND_PREPARE:end
<7>[ 923.097349] -(0)[1180:system_server][name:mt_sleep&][SLP] @@@Chip_pm_enter@@@
<6>[ 923.097349] -(0)[1180:system_server][Power/clkmgr] [slp_check_pm_mtcmos_pll]
<6>[ 923.097349] -(0)[1180:system_server][Power/clkmgr] SYS_MD1: on
<6>[ 923.097349] -(0)[1180:system_server][Power/clkmgr] SYS_CONN: on
<2>[ 923.097349] -(0)[1180:system_server][SPM-PMIC] [dlpt_R] pre_SOC=57 SOC=57 skip
<4>[ 923.097349] -(0)[1180:system_server]Suspend - 6328 - 0x248 - 0x7673 - 0xfeff - 0x7473 - 9
<4>[ 923.097349] -(0)[1180:system_server]Suspend - 6328 - 0x4d6 - 0x3021 - 0x0001 - 0x0020 - 0
<4>[ 923.097349] -(0)[1180:system_server]Suspend - 6328 - 0xa32 - 0xc102 - 0x000e - 0x0100 - 1
<4>[ 923.097349] -(0)[1180:system_server]Suspend - 6328 - 0xa3a - 0xc102 - 0x000e - 0x0000 - 1
<4>[ 923.097349] -(0)[1180:system_server][SPM] md_settle = 99, settle = 99
<4>[ 923.097349] -(0)[1180:system_server][SPM] sec = 900, wakesrc = 0xe04c5e4 (1)(1)
<4>[ 923.097349] -(0)[1180:system_server][SPM] wake up byEINT, timer_out = 7440931, r13 = 0x10001000, debug_flag = 0x9f
<6>[ 923.334796] (1)[1180:system_server]PM: suspend exit 2017-03-09 06:59:47.201326615 UTC
2. 可以通過log確認suspend的時間點以及suspend的時長
2.1 確認 suspend 的時間點
關鍵字:PM: suspend entry
<6>[ 922.885697] (0)[1180:system_server]PM: suspend entry 2017-03-09 06:55:59.675845617 UTC
2.2 通過 suspend entry 和 md_settle 確定suspend時長
後面跟的時間就是當前的UTC time(跟上層的android time換算要加上時區)。
這個時間就是睡眠的粗略時間,精確時間就是再加上兩句log的時間戳相減:
<6>[ 922.885697] (0)[1180:system_server]PM: suspend entry 2017-03-09 06:55:59.675845617 UTC
<4>[ 923.097349] -(0)[1180:system_server][SPM] md_settle = 99, settle = 99
睡眠的準確時間點 = 06:55:59.675845617 + (923.097349 - 922.885697) = 06:55:59.887497617
2.3 PM: suspend exit的時間戳減去PM: suspend entry的時間戳
390: <6>[ 868.695672] PM: suspend entry 2019-03-05 01:48:36.914426509 UTC
394: <4>[ 868.732182] Suspending console(s) (use no_console_suspend to debug)
395: <6>[ 868.740534] PM: Wakeup pending, aborting suspend
397: <3>[ 868.749441] PM: Some devices failed to suspend, or early wake event detected
401: <6>[ 868.797664] PM: suspend exit 2019-03-05 01:48:37.016425103 UTC
睡眠的準確時間點 = 868.797664 - 868.695672 = 0.101992