Use wait_event_interruptible_timeout to determine if a device driver has timed out
In my device driver, I’m using wait_event_interruptible_timeout
. How can I tell if a timeout has occurred? The macro only returns an error code on interrupt, but the timeout is not an interrupt, so it returns “0”.
EDIT: Not sure how to tell if a timeout has occurred, but condition
won’t be set, so that sounds like the answer.
Solution
A few weeks ago, I was reading Linux Device Drivers, Third Edition ran into the same confusing problem after the description of the function. However, after reading the comments on various wait functions in the current kernel source tree, I found that the API has changed since the publication of this book. Newer kernels (at least 2.6.34+ and probably earlier than it) return the remaining number of jiffies to a timeout instead of an error code. Therefore, a zero return value indicates that a timeout occurred, and any non-zero value should indicate a successful wake-up through an event condition. The comments in include/linux/wait.h
describe the new API well.