[07/14] eal: interrupts close epoll fd on shutdown
diff mbox series

Message ID 20200104013341.19809-8-stephen@networkplumber.org
State New
Delegated to: David Marchand
Headers show
Series
  • cleanup resources on shutdown
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Jan. 4, 2020, 1:33 a.m. UTC
Use pthread callbacks to ensure that the epoll fd is closed
when rte_eal_cleanup is called.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/linux/eal/eal_interrupts.c | 26 ++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/lib/librte_eal/linux/eal/eal_interrupts.c b/lib/librte_eal/linux/eal/eal_interrupts.c
index fa08ac4171bd..ae4d3ae3ed60 100644
--- a/lib/librte_eal/linux/eal/eal_interrupts.c
+++ b/lib/librte_eal/linux/eal/eal_interrupts.c
@@ -1032,6 +1032,19 @@  eal_intr_handle_interrupts(int pfd, unsigned totalfds)
 	}
 }
 
+
+/**
+ * Callback at end of intr_thread loop or if thread is cancelled
+ * that closes the epoll file descriptor
+ */
+static void
+eal_intr_thread_close(void *arg)
+{
+	int pfd = (int)(unsigned long)arg;
+
+	close(pfd);
+}
+
 /**
  * It builds/rebuilds up the epoll file descriptor with all the
  * file descriptors being waited on. Then handles the interrupts.
@@ -1061,6 +1074,12 @@  eal_intr_thread_main(__rte_unused void *arg)
 		if (pfd < 0)
 			rte_panic("Cannot create epoll instance\n");
 
+		/* close pfd on thread exit or cancel_pop
+		 * see man page for restrictions on this macro.
+		 */
+		pthread_cleanup_push(eal_intr_thread_close,
+				     (void *)(unsigned long)pfd);
+
 		pipe_event.data.fd = intr_pipe.readfd;
 		/**
 		 * add pipe fd into wait list, this pipe is used to
@@ -1100,11 +1119,8 @@  eal_intr_thread_main(__rte_unused void *arg)
 		/* serve the interrupt */
 		eal_intr_handle_interrupts(pfd, numfds);
 
-		/**
-		 * when we return, we need to rebuild the
-		 * list of fds to monitor.
-		 */
-		close(pfd);
+		/* close pfd and rebuild the list */
+		pthread_cleanup_pop(1);
 	}
 }