DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] eal: add worker threads cleanup in rte_eal_cleanup()
@ 2025-01-10  6:47 Gagandeep Singh
  0 siblings, 0 replies; only message in thread
From: Gagandeep Singh @ 2025-01-10  6:47 UTC (permalink / raw)
  To: dev

This patch introduces a worker thread cleanup function in the EAL library,
ensuring proper termination of created pthreads and invocation of
registered pthread destructors.
This guarantees the correct cleanup of thread-specific resources,
used by drivers or applications.

Signed-off-by: Gagandeep Singh <g.singh@nxp.com>
---
 lib/eal/linux/eal.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index a6220524a4..a828905783 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -913,6 +913,32 @@ eal_worker_thread_create(unsigned int lcore_id)
 	return ret;
 }
 
+static void
+eal_worker_thread_cleanup(void)
+{
+	unsigned int lcore_id;
+	int ret = 0;
+
+	/* Cancel all the worker pthreads */
+	RTE_LCORE_FOREACH_WORKER(lcore_id) {
+		/* Check for non zero id */
+		if (!lcore_config[lcore_id].thread_id.opaque_id)
+			continue;
+
+		ret = pthread_cancel((pthread_t)lcore_config[lcore_id].thread_id.opaque_id);
+		if (ret != 0) {
+			EAL_LOG(WARNING, "Pthread cancel fails for lcore %d",
+					lcore_id);
+		}
+		ret = pthread_join((pthread_t)lcore_config[lcore_id].thread_id.opaque_id, NULL);
+		if (ret != 0) {
+			EAL_LOG(WARNING, "Pthread join fails for lcore %d",
+					lcore_id);
+		}
+	}
+	EAL_LOG(DEBUG, "Worker thread clean up done");
+}
+
 /* Launch threads, called at application init(). */
 int
 rte_eal_init(int argc, char **argv)
@@ -1321,6 +1347,7 @@ rte_eal_cleanup(void)
 #endif
 	rte_mp_channel_cleanup();
 	eal_bus_cleanup();
+	eal_worker_thread_cleanup();
 	rte_trace_save();
 	eal_trace_fini();
 	eal_mp_dev_hotplug_cleanup();
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-10  6:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-10  6:47 [PATCH] eal: add worker threads cleanup in rte_eal_cleanup() Gagandeep Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).