Re: Char device. poll() function question.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/9/30 Chetan Nanda <chetannanda@xxxxxxxxx>:
>
>
> On Wed, Sep 30, 2009 at 6:38 PM, Denis Borisevich <dennisfen@xxxxxxxxx>
> wrote:
>>
>> Hi!
>> I want to use poll() functionality (to properly handle select() and
>> poll() syscalls) in my char-device driver. The code for my kernel-side
>> poll() function is (a little bit simplified):
>>
>> unsigned int my_poll(struct file *filp, struct poll_table_struct *wait)
>> {
>>        unsigned int mask=0;
>>        unsigned long flags;
>>
>>        poll_wait(filp, my_wait_queue, wait);
>>
>>        if ( any_data_available > 0)
>>                mask |= POLLIN | POLLRDNORM;
>>
>>        return mask;
>> }
>>
>> Where "my_wait_queue" is of "wait_queue_head_t" type,
>> "any_data_available" if the flag which tells if any data is available
>> within internal buffer.
>>
> When you are setting 'any_data_available' variable to some positive values
> at the same place you have to wakeup process that is waiting in wait-queue.
> May be this part is missing in your current code and because of that select
> is not retuning before timeout.
Thank you for the answer. I got the point. I used this approach when I
was implementing read() function in this driver. But in that case I've
put the process to sleep manually by wait_event() call. Why do we need
this poll_wait() function if we can use wait_event()? I don't see any
conveniences which it could give. Or do I miss something?
>>
>> When I load this driver and start user-space application wich calls
>> select() with 5 seconds timeout the select() returns after waiting
>> this timeout no matter when the data comes into the port (1,2,3
>> seconds). The return value is positive when the data available and 0
>> when no data comes, as it should be. The question is why select()
>> waits for the timeout even when data is available?
>>
>> --
>> Denis
>>
> Thanks,
> Chetan Nanda

--
Denis

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux