Kernel 信号量不会在Ioctl上下文中唤醒
我有一个正在使用的设备驱动程序。它是这样工作的:Kernel 信号量不会在Ioctl上下文中唤醒,kernel,driver,semaphore,ioctl,ldd,Kernel,Driver,Semaphore,Ioctl,Ldd,我有一个正在使用的设备驱动程序。它是这样工作的: 1. User app sends ioctl cmd 0x01 to driver that puts it to sleep. 2. User app sends another ioctl cmd 0x02 to driver that wakes it up. 我这样做是因为我的硬件还没有准备好,所以我还没有一个设备可以与之通话 问题:当我发送ioctl cmd 0x01以使驱动程序进入睡眠状态时,我的用户应用程序会休眠/挂起,但当我发
1. User app sends ioctl cmd 0x01 to driver that puts it to sleep.
2. User app sends another ioctl cmd 0x02 to driver that wakes it up.
我这样做是因为我的硬件还没有准备好,所以我还没有一个设备可以与之通话
问题:当我发送ioctl cmd 0x01以使驱动程序进入睡眠状态时,我的用户应用程序会休眠/挂起,但当我发送ioctl cmd 0x02时,它不会收到唤醒的信号。我打印出信号量计数以查看发生了什么,并注意到对于每种情况,在调用down()/up()之前,my_sem.count==0
总的来说,我不了解的司机是什么?似乎我的ioctl处理程序对于我随用户应用程序发送的每个ioctl cmd都有一个不同的\u sem副本。当我为up()发送几个连续的cmd时,我希望看到调用up()的每个ioctl cmd的计数都会增加,但它总是在up()之前输出零,在up()之后输出一
看起来每次调用foo_CharIoctl()时都在重新初始化信号量。sema_init()应该放在驱动程序初始化中
/* PSEUDO CODE */
// global defn
DEFINE_SEMAPHORE(my_sem);
.
.
.
// file ops ioctl handler
int foo_CharIoctl(struct file * file,
unsigned int cmd,
unsigned long arg)
{
sema_init(&my_sem, 0);
.
.
.
switch(cmd)
{
case 0x01:
printf my_sem.count;
down_killable(&my_sem);
printf my_sem.count;
case 0x02:
printf my_sem.count;
up(&my_sem);
printf my_sem.count;
...
}
}