summaryrefslogtreecommitdiff
path: root/lib/event.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2023-11-02 16:46:27 -0400
committerDonald Sharp <sharpd@nvidia.com>2023-11-08 15:32:56 -0500
commit57ea8ac8c34e347e541239019784167090785850 (patch)
tree822307d69a9a69a14199b950e7c6d09015039819 /lib/event.c
parent6b19e40730c6d331b502171d5cf615f393afff6a (diff)
lib: Modify event system to treat fd access more fairly
Keep track of the last starting spot of where fd's were being handled for read operations. Modify the io read handler to cycle through the list of fd's that need to be handled such that fd's at the front do not take precedence for being handled all the time. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'lib/event.c')
-rw-r--r--lib/event.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/event.c b/lib/event.c
index f5ebd01973..6e55310b65 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -1649,6 +1649,10 @@ static inline void thread_process_io_inner_loop(struct event_loop *m,
* Walks through file descriptor array looking for those pollfds whose .revents
* field has something interesting. Deletes any invalid file descriptors.
*
+ * Try to impart some impartiality to handling of io. The event
+ * system will cycle through the fd's available for io
+ * giving each one a chance to go first.
+ *
* @param m the thread master
* @param num the number of active file descriptors (return value of poll())
*/
@@ -1656,10 +1660,15 @@ static void thread_process_io(struct event_loop *m, unsigned int num)
{
unsigned int ready = 0;
struct pollfd *pfds = m->handler.copy;
+ nfds_t i, last_read = m->last_read % m->handler.copycount;
- for (nfds_t i = 0; i < m->handler.copycount && ready < num; ++i) {
- thread_process_io_inner_loop(m, num, pfds, &i, &ready);
- }
+ for (i = last_read; i < m->handler.copycount && ready < num; ++i)
+ thread_process_io_inner_loop(m, num, pfds, &i, &ready);
+
+ for (i = 0; i < last_read && ready < num; ++i)
+ thread_process_io_inner_loop(m, num, pfds, &i, &ready);
+
+ m->last_read++;
}
/* Add all timers that have popped to the ready list. */