Question

I am trying to implement the function

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

in my driver. I've added the file descriptor of my device to the wait queue using

poll_wait(filp, &myqueue, wait);

As soon as the data is copied to kernel buffer an interrupt is generated. How do I wake up the poll_wait() process in ISR?

Was it helpful?

Solution

According to http://tali.admingilde.org/dhwk/vorlesung/ar01s08.html page, driver in interrupt handler should use wake_up(&myqueue); to wake up waiters.

 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);

The LDD3 book describes wake_up in http://www.makelinux.net/ldd3/chp-6-sect-2 "6.2.2. Simple Sleeping"

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.

OTHER TIPS

It is depend on your device. Generally, when some data are available, the device can generate an interrupt, then your interrupt handle function will be called, and in your interrupt handle function, you check the device's registers to verify is there any data available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top