uevent拔插事件分析--基于imx8

UEVENTD详解
本文深入解析UEVENTD的工作原理,包括其在内核与应用层间传输状态变化信息的机制,如USB线插拔和电池电量变化。UEVENTD不仅处理设备节点创建、文件权限设置及SELinux标签设定,还负责固件加载和设备符号链接创建。文章详细介绍了UEVENTD的冷启动过程,如何并行处理UEVENT消息以加速启动,以及在冷启动过程中高效处理SELinux restorecon。

 

1.uevent介绍

Uevent是内核通知android有状态变化的一种方法,比如USB线插入、拔出,电池电量变化等等。其本质是内核发送(可以通过socket)一个字符串,应用层(android)接收并解释该字符串,获取相应信息。

 

路径:

system/core/init/ueventd.cpp

 

imx8 uevent说明:

At a high level, ueventd listens for uevent messages generated by the kernel through a netlink
socket.  When ueventd receives such a message it handles it by taking appropriate actions,
which can typically be creating a device node in /dev, setting file permissions, setting selinux
labels, etc.
Ueventd also handles loading of firmware that the kernel requests, and creates symlinks for block
and character devices.

When ueventd starts, it regenerates uevents for all currently registered devices by traversing
/sys and writing 'add' to each 'uevent' file that it finds.  This causes the kernel to generate
and resend uevent messages for all of the currently registered devices.  This is done, because
ueventd would not have been running when these devices were registered and therefore was unable
to receive their uevent messages and handle them appropriately.  This process is known as
'cold boot'.
'init' currently waits synchronously on the cold boot process of ueventd before it continues
its boot process.  For this reason, cold boot should be as quick as possible.  One way to achieve
a speed up here is to parallelize the handling of ueventd messages, which consume the bulk of the
time during cold boot.

Handling of uevent messages has two unique properties:
1) It can be done in isolation; it doesn't need to read or write any status once it is started.
2) It uses setegid() and setfscre
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值