新手上路
- 积分
- 28
- 金钱
- 28
- 注册时间
- 2022-4-6
- 在线时间
- 8 小时
|
1,自己在练习这个章节的编程时,由于自己的理解不到位,遇到了noblockioApp 运行起来后,cpu占用率超过90%的问题。
先给大家看现象:

2,应用程序代码没问题
3,就是驱动源码(缺少poll函数如下图)
/* 设备操作函数 */
static struct file_operations imx6uirq_fops = {
.owner = THIS_MODULE,
.open = imx6uirq_open,
.read = imx6uirq_read,
};
4,自己的理解错误。
一开始不知道noblockioApp.c 里边的select函数会调用驱动里边的poll函数,
在noblockio.c中就没有添加poll函数。才导致图1中的noblockioApp运行时cpu占用率很高的问题。
5,之前是没有注意到下边的内容(52.1.3章节)
当应用程序调
用 select、 epoll 或 poll 函数的时候设备驱动程序中的 poll 函数就会执行,因此需要在设备驱动
程序中编写 poll 函数。
6,在设备驱动程序添加了poll函数之后unsigned int imx6uirq_poll(struct file *filp, struct poll_table_struct *wait)
{
unsigned int mask = 0;
struct imx6uirq_dev *dev = (struct imx6uirq_dev *)filp->private_data;
poll_wait(filp, &dev->r_wait, wait); /* 将等待队列头添加到poll_table中 */
if(atomic_read(&dev->releasekey)) { /* 按键按下 */
mask = POLLIN | POLLRDNORM; /* 返回PLLIN */
}
return mask;
}
static struct file_operations imx6uirq_fops = {
.owner = THIS_MODULE,
.open = imx6uirq_open,
.read = imx6uirq_read,
.poll = imx6uirq_poll,
};
7,现在cpu的占用率恢复正常0%
8,顺便注意以下问题点,如果在modpro noblockio.ko报pin脚冲突考虑屏蔽下图中代码。 /* zuozhongkai dts keys linux自带的key驱动设备树 */
220
221 /*
222
223 gpio-keys {
224 compatible = "gpio-keys";
225 #address-cells = <1>;
226 #size-cells = <0>;
227 autorepeat;
228 key0 {
229 label = "GPIO Key Enter";
230 linux,code = <KEY_ENTER>;
231 gpios = <&gpio1 18 GPIO_ACTIVE_LOW>;
232 };
233 };
234
235 */
|
|