gpt4 book ai didi

c - ISR 中的事件通知

转载 作者:太空狗 更新时间:2023-10-29 11:09:14 24 4
gpt4 key购买 nike

我正在尝试实现该功能

unsigned int (*poll) (struct file *filp, poll_table *wait);

在我的驱动程序中。我已经使用

将设备的文件描述符添加到等待队列
poll_wait(filp, &myqueue, wait);

一旦数据被复制到内核缓冲区,就会产生一个中断。如何在 ISR 中唤醒 poll_wait() 进程?

最佳答案

根据 http://tali.admingilde.org/dhwk/vorlesung/ar01s08.html页面,中断处理程序中的驱动程序应使用 wake_up(&myqueue); 唤醒等待者。

 poll_wait(file, q, pt)

register wait queue q for an poll/select system call. The driver should wake up that wait queue when new data is available.

This is best illustrated with an example. The following example_poll function returns the status of the file descriptor (is it possible to read or write) and registers two wait queues that can be used wake the poll/select call.

unsigned int example_poll(struct file * file, poll_table * pt)
{
unsigned int mask = 0;
if (data_avail_to_read) mask |= POLLIN | POLLRDNORM;
if (data_avail_to_write) mask |= POLLOUT | POLLWRNORM;
poll_wait(file, &read_queue, pt);
poll_wait(file, &write_queue, pt);
return mask;
}

Then, when data is available again the driver should call:

 data_avail_to_read = 1;  
wake_up(&read_queue);

LDD3 书在 http://www.makelinux.net/ldd3/chp-6-sect-2 中描述了 wake_up “6.2.2. 简单 sleep ”

The other half of the picture, of course, is waking up. Some other thread of execution (a different process, or an interrupt handler, perhaps) has to perform the wakeup for you, since your process is, of course, asleep. The basic function that wakes up sleeping processes is called wake_up . It comes in several forms (but we look at only two of them now):

void wake_up(wait_queue_head_t *queue);
void wake_up_interruptible(wait_queue_head_t *queue);

wake_up wakes up all processes waiting on the given queue (though the situation is a little more complicated than that, as we will see later). The other form (wake_up_interruptible) restricts itself to processes performing an interruptible sleep. In general, the two are indistinguishable (if you are using interruptible sleeps); in practice, the convention is to use wake_up if you are using wait_event and wake_up_interruptible if you use wait_event_interruptible.

关于c - ISR 中的事件通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22376876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com