1. Linux kernel wakelock 定义
A wake_lock prevents the system from entering suspend or other low power states when active. If the type is set to WAKE_LOCK_SUSPEND, the wake_lock prevents a full system suspend. If the type is WAKE_LOCK_IDLE, low power
states that cause large interrupt latencies or that disable a set of interrupts will not entered from idle until the wake_locks are released.
当唤醒锁被激活的时候,它能阻止系统进入挂起状态或者其他低功耗模式。
如果锁类型被设置为 WAKE_LOCK_SUSPEND,该锁阻止整个系统进入挂起状态。
如果锁类型被设置为 WAKE_LOCK_IDLE, 除非该锁被释放,产生中断大延迟或者失能中断集的系统低功耗模式将被阻止进入。但是系统可以进入挂起睡眠状态。
2. 编译标志
根据Kconfig 文件, 相关的内核编译标志分别为:
CONFIG_HAS_WAKELOCK 选择是否使能 wakelock模块。
CONFIG_WAKELOCK: 依赖CONFIG_HAS_WAKELOCK。当用户空间请求睡眠状态时,该请求将被延置直到没有唤醒锁为使能状态。
CONFIG_WAKELOCK_STAT: 报告唤醒锁状态并写入到 /proc/wakelocks 文件
CONFIG_USER_WAKELOCK 用户空间唤醒锁。写入"锁名称" 或者“超时锁名称” 到 /sys/power/wake_lock文件来使能唤醒锁 ( 根据需要与否来创建一个唤醒锁)
写入“锁名称”到 /sys/power/wake_unlock 文件来解锁一个用户空间唤醒锁。
CONFIG_EARLYSUSPEND 当用户空间请求睡眠状态改变时, 调用early suspend handlers
该标志依赖于 CONFIG_WAKELOCK编译标志。
3. /proc/wakelocks 格式
示例如下
root@android:/ # cat /proc/wakelocks
cat /proc/wakelocks
name count expire_count wake_count active_since total_time sleep_time max_time last_change
"em" 4899 0 0 0 129695047374 123649908727 2367225591 29445791758668
"alarm_rtc" 2360 474 0 0 1613420206524 1611455462922 1949640000 27899269419825
"bcmpmu_i2c" 244500 0 1876 0 275160569412 268463363255 996054076 29445791728151
"KeyEvents" 1113