patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: dev@dpdk.org
Cc: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
	stable@dpdk.org,
	Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>,
	Dmitry Malloy <dmitrym@microsoft.com>,
	Pallavi Kadam <pallavi.kadam@intel.com>,
	Harman Kalra <hkalra@marvell.com>
Subject: [dpdk-stable] [PATCH 3/3] eal/windows: cleanup interrupt resources
Date: Sun,  2 May 2021 05:33:33 +0300
Message-ID: <20210502023333.30351-3-dmitry.kozliuk@gmail.com> (raw)
In-Reply-To: <20210502023333.30351-1-dmitry.kozliuk@gmail.com>

Interrupt manager in Windows EAL allocates on IOCP and starts
a control thread that runs indefinitely. At DPDK cleanup
this thread was not stopped and IOCP handle was not closed.

Gracefully stop interrupt-handling in rte_eal_cleanup().
The thread already closes IOCP handle before exiting.

Fixes: 5c016fc0205a ("eal/windows: add interrupt thread skeleton")
Cc: stable@dpdk.org

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/eal/windows/eal.c            |  1 +
 lib/eal/windows/eal_interrupts.c | 26 ++++++++++++++++++++++++--
 lib/eal/windows/eal_windows.h    |  5 +++++
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index 28c787c0b0..25afc42f8e 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -258,6 +258,7 @@ rte_eal_cleanup(void)
 {
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	eal_intr_thread_cancel();
 	/* after this point, any DPDK pointers will become dangling */
 	rte_eal_memory_detach();
 	eal_cleanup_config(internal_conf);
diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c
index f24ed6e54e..bb0585cb34 100644
--- a/lib/eal/windows/eal_interrupts.c
+++ b/lib/eal/windows/eal_interrupts.c
@@ -7,6 +7,8 @@
 #include "eal_private.h"
 #include "eal_windows.h"
 
+#define IOCP_KEY_SHUTDOWN UINT32_MAX
+
 static pthread_t intr_thread;
 
 static HANDLE intr_iocp;
@@ -34,12 +36,14 @@ eal_intr_thread_handle_init(void)
 static void *
 eal_intr_thread_main(LPVOID arg __rte_unused)
 {
+	bool finished = false;
+
 	if (eal_intr_thread_handle_init() < 0) {
 		RTE_LOG(ERR, EAL, "Cannot open interrupt thread handle\n");
 		goto cleanup;
 	}
 
-	while (1) {
+	while (!finished) {
 		OVERLAPPED_ENTRY events[16];
 		ULONG event_count, i;
 		BOOL result;
@@ -61,8 +65,13 @@ eal_intr_thread_main(LPVOID arg __rte_unused)
 			continue;
 		}
 
-		for (i = 0; i < event_count; i++)
+		for (i = 0; i < event_count; i++) {
+			if (events[i].lpCompletionKey == IOCP_KEY_SHUTDOWN) {
+				finished = true;
+				break;
+			}
 			eal_intr_process(&events[i]);
+		}
 	}
 
 	CloseHandle(intr_thread_handle);
@@ -125,6 +134,19 @@ eal_intr_thread_schedule(void (*func)(void *arg), void *arg)
 	return 0;
 }
 
+void
+eal_intr_thread_cancel(void)
+{
+	if (!PostQueuedCompletionStatus(
+			intr_iocp, 0, IOCP_KEY_SHUTDOWN, NULL)) {
+		RTE_LOG_WIN32_ERR("PostQueuedCompletionStatus()");
+		RTE_LOG(ERR, EAL, "Cannot cancel interrupt thread\n");
+		return;
+	}
+
+	WaitForSingleObject(intr_thread_handle, INFINITE);
+}
+
 int
 rte_intr_callback_register(
 	__rte_unused const struct rte_intr_handle *intr_handle,
diff --git a/lib/eal/windows/eal_windows.h b/lib/eal/windows/eal_windows.h
index 478accc1b9..7cc811485d 100644
--- a/lib/eal/windows/eal_windows.h
+++ b/lib/eal/windows/eal_windows.h
@@ -67,6 +67,11 @@ unsigned int eal_socket_numa_node(unsigned int socket_id);
  */
 int eal_intr_thread_schedule(void (*func)(void *arg), void *arg);
 
+/**
+ * Request interrupt thread to stop and wait its termination.
+ */
+void eal_intr_thread_cancel(void);
+
 /**
  * Open virt2phys driver interface device.
  *
-- 
2.29.3


  parent reply	other threads:[~2021-05-02  2:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-02  2:33 [dpdk-stable] [PATCH 1/3] eal/windows: fix use of incorrect thread ID Dmitry Kozlyuk
2021-05-02  2:33 ` [dpdk-stable] [PATCH 2/3] eal/windows: fix interrupt thread handle leakage Dmitry Kozlyuk
2021-05-13  1:15   ` Kadam, Pallavi
2021-05-02  2:33 ` Dmitry Kozlyuk [this message]
2021-05-11  7:41   ` [dpdk-stable] [PATCH 3/3] eal/windows: cleanup interrupt resources Thomas Monjalon
2021-05-11  7:59     ` Dmitry Kozlyuk
2021-05-11 17:21       ` Ranjit Menon
2021-05-12 14:56         ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
2021-05-11 17:24   ` Ranjit Menon
2021-05-28 17:33   ` Jie Zhou
2021-06-23  7:08     ` Thomas Monjalon
2021-05-04  0:08 ` [dpdk-stable] [dpdk-dev] [PATCH 1/3] eal/windows: fix use of incorrect thread ID Tyler Retzlaff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210502023333.30351-3-dmitry.kozliuk@gmail.com \
    --to=dmitry.kozliuk@gmail.com \
    --cc=dev@dpdk.org \
    --cc=dmitrym@microsoft.com \
    --cc=hkalra@marvell.com \
    --cc=navasile@linux.microsoft.com \
    --cc=pallavi.kadam@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

patches for DPDK stable branches

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ https://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git