On Sun, Aug 16, 2009 at 8:23 PM, shankarGanesh <[email protected]>wrote:
> Chetan Nanda wrote: > >> >> >> On Thu, Aug 13, 2009 at 6:30 PM, Shankar Ganesh >> <[email protected]<mailto: >> [email protected]>> wrote: >> >> >> >> On Thu, Aug 13, 2009 at 5:23 PM, Daniel Baluta >> <[email protected] <mailto:[email protected]>> wrote: >> >> On Thu, Aug 13, 2009 at 2:17 PM, Shankar >> Ganesh<[email protected] >> <mailto:[email protected]>> wrote: >> > Hi , >> > >> > I have a doubt regarding poll function in char driver . Let >> us consider >> > following code >> > >> > >> >> >> -------------------------------------------------------------------------------------- >> > static unsigned int random_poll(struct file *file, >> poll_table * wait) >> > { >> > unsigned int mask; >> > poll_wait(file, &random_read_wait, wait); >> > poll_wait(file, &random_write_wait, wait); >> > mask = 0; >> > ........ >> > return mask; >> > } >> > >> > >> > read() / write() >> > { >> > wait_event_interuptable() >> > } >> > >> >> >> -------------------------------------------------------------------------------------- >> > >> > Does the above code (poll function) is in sleep state until both >> > random_read_wait & random_write_wait are awakened ? . If i >> have use case If >> > i want my user space application to poll only for read , >> then can i remove >> > one of the above ? >> t beautiful thing we can experience is the mysterious. It is the >> > source of all true art and science." >> > >> AFAIK your actual random_poll function nevers sleeps. The >> calls for >> poll_wait just inform the VFS layer >> about the existence of random_read_wait and random_write_wait wait >> queues. An upper layer will use the return mask >> to actual put your current process to sleep if there are no data >> available for reading/writing. >> >> >> Thanks. How do VFS know which of the queue is woke-up (read -WQ or >> write - WQ ) ? . As any ISR or relevant function wil wake-up the >> wait-queue. >> >> It is decided by value return by drivers poll function. e.g. if driver >> detects that device is ready for reading then poll function should return >> 'POLLRDNORM' to VFS layer. Similarly 'POLLWRNORM' for writable case. >> >> Thanks Chetan . > Return Value - POLLRDNORM & POLLWRNORM describes the operations that > could be immediately performed without blocking. I would like to know the > case where there is blocking > Hi Shankar, Driver need to return a bitmask from its poll function, if value of this bitmask is zero then kernel VFS layer automatically put calling process into sleep state on waitqueue passed in 'poll_wait'. Rest of the handiling is done inside the kernel and driver writers just need to detect the conditions and to return a proper values from their polll function. For better understanding have a look at section 6.3 of LDD3. Thanks, Chetan Nanda > > > >> >> I think you should not care about what type of operation a >> user space >> application is watching for. >> >> Daniel. >> >> >> >> >> -- With Regards, >> ShankarGanesh K . >> >> >> Thanks, >> Chetan Nanda >> >> >> >> >> >> >> "The most beautiful thing we can experience is the mysterious. It >> is the source of all true art and science." >> >> >> >
