Skip to contentSkip to conversation

fs/epoll: Enable non-blocking busypoll when epoll timeout is 0

PATCH In review Sridhar Samudrala 2 participants 2 messages Jul 11, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 fs/epoll: Enable non-blocking busypoll when epoll timeout is 0

This patch triggers non-blocking busy poll when busy_poll is enabled, epoll is called with a timeout of 0 and is associated with a napi_id. This enables an app thread to go through napi poll routine once by calling epoll with a 0 timeout.

poll/select with a 0 timeout behave in a similar manner.

v4:
- Fix a typo (Andy)
v3:
- reset napi_id if no event available after busy poll (Alex) v2:
- Added net_busy_loop_on() check (Eric)

---
 fs/eventpoll.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
fs/eventpoll.c +16 -0
index 12eebcdea9c8..10da7a8e1c2b 100644
@@ -1847,6 +1847,22 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
 		eavail = ep_events_available(ep);
 		write_unlock_irq(&ep->lock);
 
+		/*
+		 * Trigger non-blocking busy poll if timeout is 0 and there are
+		 * no events available. Passing timed_out(1) to ep_busy_loop
+		 * will make sure that busy polling is triggered only once.
+		 */
+		if (!eavail && net_busy_loop_on()) {
+			ep_busy_loop(ep, timed_out);
+
+			write_lock_irq(&ep->lock);
+			eavail = ep_events_available(ep);
+			write_unlock_irq(&ep->lock);
+
+			if (!eavail)
+				ep_reset_busy_poll_napi_id(ep);
+		}
+
 		goto send_events;
 	}
 
Signature · 1 line
2.25.4
Reviewed-by on v4 1/1
#1 lore raw
Quoted 37 lines · Sridhar Samudrala

This patch triggers non-blocking busy poll when busy_poll is enabled, epoll is called with a timeout of 0 and is associated with a napi_id. This enables an app thread to go through napi poll routine once by calling epoll with a 0 timeout.

poll/select with a 0 timeout behave in a similar manner.

v4:
- Fix a typo (Andy)
v3:
- reset napi_id if no event available after busy poll (Alex) v2:
- Added net_busy_loop_on() check (Eric)

---
 fs/eventpoll.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
fs/eventpoll.c +9 -0
index 12eebcdea9c8..10da7a8e1c2b 100644
@@ -1847,6 +1847,22 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
                eavail = ep_events_available(ep);
                write_unlock_irq(&ep->lock);
 
+               /*
+                * Trigger non-blocking busy poll if timeout is 0 and there are
+                * no events available. Passing timed_out(1) to ep_busy_loop
+                * will make sure that busy polling is triggered only once.
+                */
+               if (!eavail && net_busy_loop_on()) {
+                       ep_busy_loop(ep, timed_out);
+
+                       write_lock_irq(&ep->lock);

fs/eventpoll.c static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, · line 1868

Quoted 10 lines
fs/eventpoll.c +7 -0
+                       eavail = ep_events_available(ep);
+                       write_unlock_irq(&ep->lock);
+
+                       if (!eavail)
+                               ep_reset_busy_poll_napi_id(ep);
+               }
+
                goto send_events;
        }
 

This addresses the concern that I had.