-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rsockets: Wake-up all waiting threads on poll events
In order to have rpoll() block the calling thread until the desired event occurs, we map rpoll() to poll() on the CQ fd (or the rdma cm fd if the rsocket is not yet connected). However, poll() is waiting on reading an event from the CQ, and not directly on the state of the rsocket. This can result in rpoll() behaving differently than poll() in multi-thread situations. For example, have two threads call rpoll(), one waiting for POLLIN, the other POLLOUT. When a new completion is written to the CQ, an event will be written to the fd. It's possible for one thread (say the POLLOUT one) to wake up, read the CQ event, and process the completion. The completion could report that data is now available to be read from the rsocket, and that POLLIN should be signaled. When the POLLIN thread wakes up, it finds the CQ fd empty, so continues blocking on poll in the kernel. In this case, the thread never exits the kernel. In the above situation, the application will hang. Threads blocking in rpoll() should return based on changes to the state of the rsocket(s) that they are monitoring. And the state of the rsocket may be modified by another thread. To handle this situation, when the state of an rsocket _may_ have changed, we wake up all threads blocked in poll(), so they can re-check the state of their rsocket(s). Note that it's easier to have all threads re-check the rsocket states than perform more complex state tracking because of the difficulty in trying to track which rsockets have been passed into multiple rpoll() calls. Rpoll() is modified as follows. When a thread has processed any event, it halts future calls into poll(). It then writes to an eventfd to signal all threads blocked in poll() to wake-up. Only after all threads return from the kernel are threads allowed to resume calling poll(). Signed-off-by: Sean Hefty <sean.hefty@intel.com>
- Loading branch information
Showing
1 changed file
with
143 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters