[v3,3/8] eal: alarm: close file on cleanup
diff mbox series

Message ID 20200428235827.15383-4-stephen@networkplumber.org
State New
Delegated to: David Marchand
Headers show
Series
  • eal: 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 April 28, 2020, 11:58 p.m. UTC
When rte_eal_cleanup is called, free all the memory
associated with dynamic log levels and types.

Fixes: c1b5fa94a46f ("eal: support dynamic log types")
Cc: olivier.matz@6wind.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/common/eal_private.h |  7 +++++++
 lib/librte_eal/freebsd/eal.c        |  1 +
 lib/librte_eal/freebsd/eal_alarm.c  | 10 ++++++++++
 lib/librte_eal/linux/eal.c          |  1 +
 lib/librte_eal/linux/eal_alarm.c    | 11 +++++++++++
 5 files changed, 30 insertions(+)

Patch
diff mbox series

diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 24ddfc6c53f4..71539dae412f 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -201,6 +201,13 @@  int rte_eal_intr_init(void);
  */
 int rte_eal_alarm_init(void);
 
+/**
+ * Cleanup alarm resources.
+ *
+ * This function is private to EAL.
+ */
+void rte_eal_alarm_cleanup(void);
+
 /**
  * Function is to check if the kernel module(like, vfio, vfio_iommu_type1,
  * etc.) loaded.
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 540b7d38c5b7..582ff0920af4 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -973,6 +973,7 @@  int
 rte_eal_cleanup(void)
 {
 	rte_service_finalize();
+	rte_eal_alarm_cleanup();
 	rte_mp_channel_cleanup();
 	rte_trace_save();
 	eal_trace_fini();
diff --git a/lib/librte_eal/freebsd/eal_alarm.c b/lib/librte_eal/freebsd/eal_alarm.c
index c38b2e04f811..b2089d0b53df 100644
--- a/lib/librte_eal/freebsd/eal_alarm.c
+++ b/lib/librte_eal/freebsd/eal_alarm.c
@@ -61,6 +61,16 @@  rte_eal_alarm_init(void)
 	return 0;
 }
 
+void
+rte_eal_alarm_cleanup(void)
+{
+	if (intr_handle.fd == -1)
+		return;
+
+	close(intr_handle.fd);
+	intr_handle.fd = -1;
+}
+
 static inline int
 timespec_cmp(const struct timespec *now, const struct timespec *at)
 {
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 73d2c98b012b..7458592f4950 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -1333,6 +1333,7 @@  rte_eal_cleanup(void)
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		rte_memseg_walk(mark_freeable, NULL);
 	rte_service_finalize();
+	rte_eal_alarm_cleanup();
 	rte_mp_channel_cleanup();
 	rte_trace_save();
 	eal_trace_fini();
diff --git a/lib/librte_eal/linux/eal_alarm.c b/lib/librte_eal/linux/eal_alarm.c
index 3252c6fa5909..f839626dad7d 100644
--- a/lib/librte_eal/linux/eal_alarm.c
+++ b/lib/librte_eal/linux/eal_alarm.c
@@ -6,6 +6,7 @@ 
 #include <signal.h>
 #include <errno.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/queue.h>
 #include <sys/time.h>
 #include <sys/timerfd.h>
@@ -74,6 +75,16 @@  rte_eal_alarm_init(void)
 	return -1;
 }
 
+void
+rte_eal_alarm_cleanup(void)
+{
+	if (intr_handle.fd == -1)
+		return;
+
+	close(intr_handle.fd);
+	intr_handle.fd = -1;
+}
+
 static void
 eal_alarm_callback(void *arg __rte_unused)
 {