Android kernel wakelock分析

本文详细介绍了Android内核中的wakelock机制,包括wakelock的定义、相关编译标志、/proc/wakelocks文件格式,以及内核锁函数的使用,特别强调了wakelock在系统挂起过程中的作用。
摘要由CSDN通过智能技术生成

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

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值