首页 > 解决方案 > wait_event_interruptible 和 wake_up_interruptible 需要 20 毫秒到 30 毫秒

问题描述

我正在研究 PCIe 卡。当 PCIe 卡引发 MSI 中断时,将调用 ISR 处理程序。在 ISR 例程中,wake_up_interruptible 将唤醒 V4L2 线程。然而,ISR 中的 wake_up_interruptible 和 v4l2 线程中的 wait_event_interruptible 之间的持续时间在 20 毫秒到 30 毫秒之间。时间是使用 linux 内核中的 do_gettimeofday() 函数测量的。下面是代码片段:

文件1.c

struct timeval t0;
irqreturn_t irq_hanlder(int irq, void *data)
{
    ...
    ...
    do_gettimeofday(&t0);
    printk("wake_up_interruptible: Time in micro_sec:%d\n",t0.tv_usec);
    atomic_set (&flag, 1);
    wake_up_interruptible(&my_wq); 
    ...
    ... 
    return IRQ_HANDLED;
}

文件2.c

struct timeval t1; static int v4l2_thread(void *handle) { ... while(1) { ... wait_event_interruptible(my_wq, (atomic_read (&flag))); atomic_set (&flag, 0); do_gettimeofday(&t1); printk("wait_event_interruptible: Time in micro_sec:%d\n",t1.tv_usec); ... } ... return 0;
}

执行上述代码段后,wake_up_interruptible 和 wait_event_interruptible 之间的持续时间约为 20 毫秒到 30 毫秒。我使用了wake_up_interruptible_sync()而不是wake_up_interruptible,那么它也是相同的行为。

查询:

1) 为什么 linux 内核需要大约 20 毫秒到 30 毫秒,只是为了唤醒在 file2.c 中休眠的线程?

2)在linux中有没有其他处理唤醒线程的方法?

3) 如何减少 wake_up_interruptible 和 wait_event_interruptible 之间的时间?

提前致谢。

问候,库尔卡尼。

标签: linuxv4l2

解决方案


推荐阅读