【问题标题】:Semaphore will not wake up in the context of Ioctl信号量不会在 Ioctl 的上下文中唤醒
【发布时间】:2015-04-21 15:57:57
【问题描述】:

我有一个正在处理的设备驱动程序。它是这样工作的:

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 时,它没有收到唤醒信号。我打印出信号量计数以查看发生了什么,并注意到对于每种情况,my_sem.count == 0 在调用 down()/up() 之前。

一般来说,我不明白的驱动程序是什么?对于我随用户应用程序发送的每个 ioctl cmd,我的 ioctl 处理程序似乎都有不同的 my_sem 副本。当我为 up() 发送多个连续 cmd 时,我希望看到每个调用 up() 的 ioctl cmd 的计数增加,但它总是在 up() 之前打印出零,在 up() 之后打印出 ONE。

/* 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;
        ...
    }
}

【问题讨论】:

    标签: kernel driver semaphore ioctl ldd


    【解决方案1】:

    看起来您每次调用 foo_CharIoctl() 时都在重新初始化信号量。 sema_init() 应该放在你的驱动初始化中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多