On 12/08/07 13:57 +0000, Ming Liu wrote: > Dear all, > I am reading LDD(V3) chapter 6 on the topic of wait_event(queue, condition) > and wake_up(queue) functions. I am quite confused on the sayings. One is > "Until condition evaluates to a true value, the process continues to > sleep", which looks like that 'condition' is the one who wake up the > process from its sleeping. However the other saying is "The basic function > that wakes up sleeping processes is called wake_up, and wake_up wakes up > all processes waiting on the given queue" So who is the exact one to wake > the sleeping process up at all, condition or wake_up? From my > understanding, if the condition becomes true, then the sleeping process > will leave its sleeping status and wake up. Then what's the use of wake_up > function?
I understand it this way: - condition Just checking the condition is one way (if you don't have a wake_up source, like an interrupt), but that's not really what wait_event does. It would be something like while (condition) { msleep(10); } There was some talk on poll_wait(), but I don't know what happened to it. - wake_up Just wake_up isn't enough, you get a race: | interrupt handler | process | ------------------------------------------ | do_something() | | | wake_up() | | | ... | wait on wq | And so you have a process waiting on waitqueue, that just missed the wakeup. Obviously should not be used. - wake_up & condition | interrupt handler | process | ------------------------------------------ | flag = 1 | | | wake_up() | | | ... | wait_event | | ... | flag = 0 | This will work properly and if wait_event misses a wake_up, the condition check (flag) will kick in before putting it to sleep. > > My senario could be described as: in my char device driver, I use one ioctl > command to initiate a DMA transfer. After all related registers are > initiated, this process will be put to sleep for saving CPU cycles. In the > interrupt handler which is for a DMA_done, I wake that process up and > resume its following executing. With this method, in my application program > if I release a DMA initiation command, it is a Blocking operation and it > will wait until the DMA transfer is done. Looks like you should use the "wake_up and condition" option. Domen > > Perhaps my question is quite simple or basic. Thanks for any explanation > and comment on this topic in my senario from you experts. Thanks a lot. > > Br > Ming > > _________________________________________________________________ > 与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn > > _______________________________________________ > Linuxppc-embedded mailing list > Linuxppc-embedded@ozlabs.org > https://ozlabs.org/mailman/listinfo/linuxppc-embedded _______________________________________________ Linuxppc-embedded mailing list Linuxppc-embedded@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-embedded