DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal/windows: fix invalid thread handle
@ 2020-05-22  0:11 Tasnim Bashar
  2020-05-22  0:55 ` Dmitry Kozlyuk
  2020-06-02  2:00 ` [dpdk-dev] [PATCH v3] " Tasnim Bashar
  0 siblings, 2 replies; 17+ messages in thread
From: Tasnim Bashar @ 2020-05-22  0:11 UTC (permalink / raw)
  To: dev
  Cc: harini.ramakrishnan, pallavi.kadam, ranjit.menon, ocardona,
	navasile, dmitry.kozliuk, talshn, fady, ophirmu, thomas

Casting thread ID to handle is not accurate way to get thread handle.
Need to use OpenThread function to get thread handle from thread ID.

pthread_setaffinity_np and pthread_getaffinity_np functions
for Windows are affected because of it.

Signed-off-by: Tasnim Bashar <tbashar@mellanox.com>
---
 lib/librte_eal/windows/include/pthread.h | 40 +++++++++++++++++++++---
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/lib/librte_eal/windows/include/pthread.h b/lib/librte_eal/windows/include/pthread.h
index 0bbed5c3b8..d2a986f8fd 100644
--- a/lib/librte_eal/windows/include/pthread.h
+++ b/lib/librte_eal/windows/include/pthread.h
@@ -18,6 +18,7 @@ extern "C" {
 
 #include <windows.h>
 #include <rte_common.h>
+#include <rte_windows.h>
 
 #define PTHREAD_BARRIER_SERIAL_THREAD TRUE
 
@@ -50,7 +51,19 @@ typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 static inline int
 eal_set_thread_affinity_mask(pthread_t threadid, unsigned long *cpuset)
 {
-	SetThreadAffinityMask((HANDLE) threadid, *cpuset);
+	HANDLE thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE, threadid);
+	if (thread_handle == NULL) {
+		RTE_LOG_WIN32_ERR("OpenThread()");
+		return -1;
+	}
+
+	DWORD ret = SetThreadAffinityMask(thread_handle, *cpuset);
+	if (ret == 0) {
+		RTE_LOG_WIN32_ERR("SetThreadAffinityMask()");
+		CloseHandle(thread_handle);
+		return -1;
+	}
+	CloseHandle(thread_handle);
 	return 0;
 }
 
@@ -60,12 +73,29 @@ eal_get_thread_affinity_mask(pthread_t threadid, unsigned long *cpuset)
 	/* Workaround for the lack of a GetThreadAffinityMask()
 	 *API in Windows
 	 */
-		/* obtain previous mask by setting dummy mask */
-	DWORD dwprevaffinitymask =
-		SetThreadAffinityMask((HANDLE) threadid, 0x1);
+	HANDLE thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE, threadid);
+	if (thread_handle == NULL) {
+		RTE_LOG_WIN32_ERR("OpenThread()");
+		return -1;
+	}
+
+	/* obtain previous mask by setting dummy mask */
+	DWORD dwprevaffinitymask = SetThreadAffinityMask(thread_handle, 0x1);
+	if (dwprevaffinitymask == 0) {
+		RTE_LOG_WIN32_ERR("SetThreadAffinityMask()");
+		CloseHandle(thread_handle);
+		return -1;
+	}
+
 	/* set it back! */
-	SetThreadAffinityMask((HANDLE) threadid, dwprevaffinitymask);
+	DWORD ret = SetThreadAffinityMask(thread_handle, dwprevaffinitymask);
+	if (ret == 0) {
+		RTE_LOG_WIN32_ERR("SetThreadAffinityMask()");
+		CloseHandle(thread_handle);
+		return -1;
+	}
 	*cpuset = dwprevaffinitymask;
+	CloseHandle(thread_handle);
 	return 0;
 }
 
-- 
2.19.1.windows.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-06-29 23:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-22  0:11 [dpdk-dev] [PATCH] eal/windows: fix invalid thread handle Tasnim Bashar
2020-05-22  0:55 ` Dmitry Kozlyuk
2020-06-02  2:00 ` [dpdk-dev] [PATCH v3] " Tasnim Bashar
2020-06-11 14:35   ` Thomas Monjalon
2020-06-12 16:22     ` Tasnim Bashar
2020-06-12 21:33       ` Thomas Monjalon
2020-06-15  8:16   ` Thomas Monjalon
2020-06-16 18:53     ` Tasnim Bashar
2020-06-16 19:17       ` Thomas Monjalon
2020-06-16 19:59         ` Tasnim Bashar
2020-06-15  9:42   ` Thomas Monjalon
2020-06-16 19:00     ` Tasnim Bashar
2020-06-24 23:10   ` [dpdk-dev] [PATCH v4] eal/windows: fix " Tasnim Bashar
2020-06-25  0:38     ` Ranjit Menon
2020-06-25 19:11       ` Tasnim Bashar
2020-06-25 19:25     ` [dpdk-dev] [PATCH v5] " Tasnim Bashar
2020-06-29 23:09       ` Thomas Monjalon

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).