Skip to contentSkip to conversation

Thread termination leak fixes

PATCH Superseded David Marchand 5 participants 12 messages May 6, 2021 – May 11, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

cover Thread termination leak fixes

After looking at the control thread API use in recent changes, I noticed that some thread resources are not properly released.
This series fixes two net drivers.

Additional notes:
- I noticed that event/dlb2 never kills/terminates its service thread. It means unplug of this device (if supported) would leak the associated thread resources. I leave it to this driver maintainer to comment/fix.

- The vhost library also lets a service thread in the background but since there is no way to unitialize this library, there is no leak to fix from my pov.

Signature · 12 lines
David Marchand

David Marchand (2):
  net/ark: fix leak on thread termination
  net/ice: fix leak on thread termination

 drivers/net/ark/ark_pktgen.c     | 2 ++
 drivers/net/ice/ice_dcf_parent.c | 2 ++
 2 files changed, 4 insertions(+)

-- 
2.23.0
#1 lore raw

PATCH 1/2 net/ark: fix leak on thread termination

A terminated pthread should be joined or detached so that its associated resources are released.

The "ark-delay-pg" thread is just used to delay some task but it is never joined by the thread that created it.
The easiest solution is to detach the new thread.

Fixes 727b3fe292bc ("net/ark: integrate PMD")
---
 drivers/net/ark/ark_pktgen.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ark/ark_pktgen.c +2 -0
index 28a44f7546..515bfe461c 100644
@@ -3,6 +3,7 @@
  */
 
 #include <unistd.h>
+#include <pthread.h>
 
 #include <rte_string_fns.h>
 #include <rte_malloc.h>
@@ -474,6 +475,7 @@ ark_pktgen_delay_start(void *arg)
 	 * perform a blind sleep here to ensure that the external test
 	 * application has time to setup the test before we generate packets
 	 */
+	pthread_detach(pthread_self());
 	usleep(100000);
 	ark_pktgen_run(inst);
 	return NULL;
Signature · 1 line
2.23.0
Acked-by on v1 1/2
#2 lore raw

Re: [dpdk-dev] [PATCH 1/2] net/ark: fix leak on thread termination

Thank you.

Quoted 40 lines · David Marchand

A terminated pthread should be joined or detached so that its associated resources are released.

The "ark-delay-pg" thread is just used to delay some task but it is never joined by the thread that created it.
The easiest solution is to detach the new thread.

Fixes 727b3fe292bc ("net/ark: integrate PMD")
---
 drivers/net/ark/ark_pktgen.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ark/ark_pktgen.c +1 -0
index 28a44f7546..515bfe461c 100644
@@ -3,6 +3,7 @@
  */
 
 #include <unistd.h>
+#include <pthread.h>
 
 #include <rte_string_fns.h>
 #include <rte_malloc.h>
@@ -474,6 +475,7 @@ ark_pktgen_delay_start(void *arg)
         * perform a blind sleep here to ensure that the external test
         * application has time to setup the test before we generate

packets

         */
+       pthread_detach(pthread_self());
        usleep(100000);
        ark_pktgen_run(inst);
        return NULL;

--
2.23.0

#3 lore raw

PATCH 2/2 net/ice: fix leak on thread termination

In reply to David Marchand

A terminated pthread should be joined or detached so that its associated resources are released.

The "ice-reset-<vf_id>" threads are used to service some reset task in the background, but they are never joined by the thread that created them. The easiest solution is to detach new threads.

Fixes 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")
---
 drivers/net/ice/ice_dcf_parent.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ice/ice_dcf_parent.c +2 -0
index c8e433239b..1d7aa8bc87 100644
@@ -121,6 +121,8 @@ ice_dcf_vsi_update_service_handler(void *param)
 	struct ice_dcf_hw *hw = reset_param->dcf_hw;
 	struct ice_dcf_adapter *adapter;
 
+	pthread_detach(pthread_self());
+
 	rte_delay_us(ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL);
 
 	rte_spinlock_lock(&vsi_update_lock);
Signature · 1 line
2.23.0
Acked-by on v1 2/2
#4 lore raw

Re: [dpdk-dev] [PATCH 2/2] net/ice: fix leak on thread termination

Quoted 15 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Thursday, May 6, 2021 17:45
To: [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhang, Qi Z <[email protected]>; Wang, Haiyue <[email protected]>
Subject: [PATCH 2/2] net/ice: fix leak on thread termination

A terminated pthread should be joined or detached so that its associated resources are released.

The "ice-reset-<vf_id>" threads are used to service some reset task in the background, but they are never joined by the thread that created them. The easiest solution is to detach new threads.

Quoted 8 lines
Fixes 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")
---
 drivers/net/ice/ice_dcf_parent.c | 2 ++
 1 file changed, 2 insertions(+)

Got it, thanks!

Quoted 2 lines

--
2.23.0

#5 lore raw

Re: [dpdk-dev] [dpdk-stable] [PATCH 2/2] net/ice: fix leak on thread termination

In reply to David Marchand
Quoted 7 lines · David Marchand

A terminated pthread should be joined or detached so that its associated resources are released.

The "ice-reset-<vf_id>" threads are used to service some reset task in the background, but they are never joined by the thread that created them. The easiest solution is to detach new threads.

Not so "easy" for Windows.

I think I'll simply #ifndef WINDOWS my addition. Maybe the leak does not exist on Windows? but if it does, the situation won't change by doing nothing on Windows.

If there is strong objection, I'll need some help to add a pthread_detach() wrapper in windows EAL.
From my quick read at the API, I'd say I need to find the current thread handle (via OpenThread) then CloseHandle it.
But does it work from "pthread_self()" ?

Since a new API thread is in preparation, the "thread detaching" from the pthread API is something to consider.
I could not find it in Narcissa series.

Signature · 1 line
David Marchand
#6 lore raw

Re: [dpdk-dev] [dpdk-stable] [PATCH 2/2] net/ice: fix leak on thread termination

2021-05-07 10:13 (UTC+0200), David Marchand:

Quoted 23 lines
Quoted 7 lines · David Marchand

A terminated pthread should be joined or detached so that its associated resources are released.

The "ice-reset-<vf_id>" threads are used to service some reset task in the background, but they are never joined by the thread that created them. The easiest solution is to detach new threads.

Not so "easy" for Windows.

I think I'll simply #ifndef WINDOWS my addition. Maybe the leak does not exist on Windows? but if it does, the situation won't change by doing nothing on Windows.

If there is strong objection, I'll need some help to add a pthread_detach() wrapper in windows EAL.
From my quick read at the API, I'd say I need to find the current thread handle (via OpenThread) then CloseHandle it.
But does it work from "pthread_self()" ?

Quoted 3 lines

Since a new API thread is in preparation, the "thread detaching" from the pthread API is something to consider.
I could not find it in Narcissa series.

There is no leak.
On Windows, pthread_t is just a number, not a handle. pthread_detach can be implemented as a no-op and added to new API. See also: https://devblogs.microsoft.com/oldnewthing/20100827-00/?p=13023

#7 lore raw

v2 cover Thread termination leak fixes

In reply to David Marchand

After looking at the control thread API use in recent changes, I noticed that some thread resources are not properly released.
This series fixes two net drivers.

Additional notes:
- I noticed that event/dlb2 never kills/terminates its service thread. It means unplug of this device (if supported) would leak the associated thread resources. I leave it to this driver maintainer to comment/fix.

- The vhost library also lets a service thread in the background but since there is no way to unitialize this library, there is no leak to fix from my pov.

Signature · 16 lines
David Marchand

Changes since v1:
- fixed build for net/ice on Windows

David Marchand (2):
  net/ark: fix leak on thread termination
  net/ice: fix leak on thread termination

 drivers/net/ark/ark_pktgen.c      | 2 ++
 drivers/net/ice/ice_dcf_parent.c  | 2 ++
 lib/eal/windows/include/pthread.h | 6 ++++++
 3 files changed, 10 insertions(+)

-- 
2.23.0
#8 lore raw

PATCH v2 1/2 net/ark: fix leak on thread termination

A terminated pthread should be joined or detached so that its associated resources are released.

The "ark-delay-pg" thread is just used to delay some task but it is never joined by the thread that created it.
The easiest solution is to detach the new thread.

Fixes 727b3fe292bc ("net/ark: integrate PMD")
---
 drivers/net/ark/ark_pktgen.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ark/ark_pktgen.c +2 -0
index 28a44f7546..515bfe461c 100644
@@ -3,6 +3,7 @@
  */
 
 #include <unistd.h>
+#include <pthread.h>
 
 #include <rte_string_fns.h>
 #include <rte_malloc.h>
@@ -474,6 +475,7 @@ ark_pktgen_delay_start(void *arg)
 	 * perform a blind sleep here to ensure that the external test
 	 * application has time to setup the test before we generate packets
 	 */
+	pthread_detach(pthread_self());
 	usleep(100000);
 	ark_pktgen_run(inst);
 	return NULL;
Signature · 1 line
2.23.0
#9 lore raw

PATCH v2 2/2 net/ice: fix leak on thread termination

In reply to David Marchand

A terminated pthread should be joined or detached so that its associated resources are released.

The "ice-reset-<vf_id>" threads are used to service some reset task in the background, but they are never joined by the thread that created them. The easiest solution is to detach new threads.

The Windows EAL did not provide a pthread_detach wrapper but there is no resource to release for Windows threads, so add an empty wrapper.

Fixes 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")

---
Changes since v1:
- fixed build for net/ice on Windows

---
 drivers/net/ice/ice_dcf_parent.c  | 2 ++
 lib/eal/windows/include/pthread.h | 6 ++++++
 2 files changed, 8 insertions(+)
drivers/net/ice/ice_dcf_parent.c +2 -0
index c8e433239b..1d7aa8bc87 100644
@@ -121,6 +121,8 @@ ice_dcf_vsi_update_service_handler(void *param)
 	struct ice_dcf_hw *hw = reset_param->dcf_hw;
 	struct ice_dcf_adapter *adapter;
 
+	pthread_detach(pthread_self());
+
 	rte_delay_us(ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL);
 
 	rte_spinlock_lock(&vsi_update_lock);
lib/eal/windows/include/pthread.h +6 -0
index 1939b0121c..27fd2cca52 100644
@@ -143,6 +143,12 @@ pthread_create(void *threadid, const void *threadattr, void *threadfunc,
 	return ((hThread != NULL) ? 0 : E_FAIL);
 }
 
+static inline int
+pthread_detach(__rte_unused pthread_t thread)
+{
+	return 0;
+}
+
 static inline int
 pthread_join(__rte_unused pthread_t thread,
 	__rte_unused void **value_ptr)
Signature · 1 line
2.23.0
Acked-by on v2 2/2
#10 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] net/ice: fix leak on thread termination

2021-05-11 13:33 (UTC+0200), David Marchand:

Quoted 44 lines

A terminated pthread should be joined or detached so that its associated resources are released.

The "ice-reset-<vf_id>" threads are used to service some reset task in the background, but they are never joined by the thread that created them. The easiest solution is to detach new threads.

The Windows EAL did not provide a pthread_detach wrapper but there is no resource to release for Windows threads, so add an empty wrapper.

Fixes 3b3757bda3c3 ("net/ice: get VF hardware index in DCF")

---
Changes since v1:
- fixed build for net/ice on Windows

---
 drivers/net/ice/ice_dcf_parent.c  | 2 ++
 lib/eal/windows/include/pthread.h | 6 ++++++
 2 files changed, 8 insertions(+)
drivers/net/ice/ice_dcf_parent.c +2 -0
index c8e433239b..1d7aa8bc87 100644
@@ -121,6 +121,8 @@ ice_dcf_vsi_update_service_handler(void *param)
 	struct ice_dcf_hw *hw = reset_param->dcf_hw;
 	struct ice_dcf_adapter *adapter;
 
+	pthread_detach(pthread_self());
+
 	rte_delay_us(ICE_DCF_VSI_UPDATE_SERVICE_INTERVAL);
 
 	rte_spinlock_lock(&vsi_update_lock);
lib/eal/windows/include/pthread.h +0 -0
index 1939b0121c..27fd2cca52 100644
@@ -143,6 +143,12 @@ pthread_create(void *threadid, const void *threadattr, void *threadfunc,
 	return ((hThread != NULL) ? 0 : E_FAIL);
 }

lib/eal/windows/include/pthread.h pthread_create(void *threadid, const void *threadattr, void *threadfunc, · line 154

Quoted 10 lines
lib/eal/windows/include/pthread.h +6 -0
 
+static inline int
+pthread_detach(__rte_unused pthread_t thread)
+{
+	return 0;
+}
+
 static inline int
 pthread_join(__rte_unused pthread_t thread,
 	__rte_unused void **value_ptr)

For Windows part,

#11 lore raw
In reply to David Marchand
Quoted 4 lines · David Marchand

After looking at the control thread API use in recent changes, I noticed that some thread resources are not properly released.
This series fixes two net drivers.

Series applied to dpdk-next-net/main, thanks.

Quoted 9 lines

Additional notes:
- I noticed that event/dlb2 never kills/terminates its service thread. It means unplug of this device (if supported) would leak the associated thread resources. I leave it to this driver maintainer to comment/fix.

- The vhost library also lets a service thread in the background but since there is no way to unitialize this library, there is no leak to fix from my pov.