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, Harman Kalra <hkalra@marvell.com>,
	Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>,
	Dmitry Malloy <dmitrym@microsoft.com>,
	Pallavi Kadam <pallavi.kadam@intel.com>
Subject: [dpdk-stable] [PATCH 2/3] eal/windows: fix interrupt thread handle leakage
Date: Sun,  2 May 2021 05:33:32 +0300	[thread overview]
Message-ID: <20210502023333.30351-2-dmitry.kozliuk@gmail.com> (raw)
In-Reply-To: <20210502023333.30351-1-dmitry.kozliuk@gmail.com>

Each time a work was scheduled in the interrupt thread,
usually an alarm, a handle was opened but not closed.

Opening a handle is a system call, which harms alarm precision.
Instead of opening and closing a handle each time, open it
when interrupt thread starts and close it when the thread finishes.

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_interrupts.c | 34 +++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c
index 9cde02b003..f24ed6e54e 100644
--- a/lib/eal/windows/eal_interrupts.c
+++ b/lib/eal/windows/eal_interrupts.c
@@ -10,6 +10,7 @@
 static pthread_t intr_thread;
 
 static HANDLE intr_iocp;
+static HANDLE intr_thread_handle;
 
 static void
 eal_intr_process(const OVERLAPPED_ENTRY *event)
@@ -17,9 +18,27 @@ eal_intr_process(const OVERLAPPED_ENTRY *event)
 	RTE_SET_USED(event);
 }
 
+static int
+eal_intr_thread_handle_init(void)
+{
+	DWORD thread_id = GetCurrentThreadId();
+
+	intr_thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE, thread_id);
+	if (intr_thread_handle == NULL) {
+		RTE_LOG_WIN32_ERR("OpenThread(%lu)", thread_id);
+		return -1;
+	}
+	return 0;
+}
+
 static void *
 eal_intr_thread_main(LPVOID arg __rte_unused)
 {
+	if (eal_intr_thread_handle_init() < 0) {
+		RTE_LOG(ERR, EAL, "Cannot open interrupt thread handle\n");
+		goto cleanup;
+	}
+
 	while (1) {
 		OVERLAPPED_ENTRY events[16];
 		ULONG event_count, i;
@@ -46,6 +65,10 @@ eal_intr_thread_main(LPVOID arg __rte_unused)
 			eal_intr_process(&events[i]);
 	}
 
+	CloseHandle(intr_thread_handle);
+	intr_thread_handle = NULL;
+
+cleanup:
 	intr_thread = 0;
 
 	CloseHandle(intr_iocp);
@@ -93,15 +116,8 @@ rte_intr_rx_ctl(__rte_unused struct rte_intr_handle *intr_handle,
 int
 eal_intr_thread_schedule(void (*func)(void *arg), void *arg)
 {
-	HANDLE handle;
-
-	handle = OpenThread(THREAD_ALL_ACCESS, FALSE, intr_thread);
-	if (handle == NULL) {
-		RTE_LOG_WIN32_ERR("OpenThread(%llu)", intr_thread);
-		return -ENOENT;
-	}
-
-	if (!QueueUserAPC((PAPCFUNC)(ULONG_PTR)func, handle, (ULONG_PTR)arg)) {
+	if (!QueueUserAPC((PAPCFUNC)(ULONG_PTR)func,
+			intr_thread_handle, (ULONG_PTR)arg)) {
 		RTE_LOG_WIN32_ERR("QueueUserAPC()");
 		return -EINVAL;
 	}
-- 
2.29.3


  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 ` Dmitry Kozlyuk [this message]
2021-05-13  1:15   ` [dpdk-stable] [PATCH 2/3] eal/windows: fix interrupt thread handle leakage Kadam, Pallavi
2021-05-02  2:33 ` [dpdk-stable] [PATCH 3/3] eal/windows: cleanup interrupt resources Dmitry Kozlyuk
2021-05-11  7:41   ` 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-2-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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).