From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id D1C9A46073;
	Mon, 13 Jan 2025 17:40:22 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id A14BF40E12;
	Mon, 13 Jan 2025 17:40:22 +0100 (CET)
Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com
 [209.85.214.177])
 by mails.dpdk.org (Postfix) with ESMTP id 2196A402A7
 for <dev@dpdk.org>; Mon, 13 Jan 2025 17:40:21 +0100 (CET)
Received: by mail-pl1-f177.google.com with SMTP id
 d9443c01a7336-21649a7bcdcso76979765ad.1
 for <dev@dpdk.org>; Mon, 13 Jan 2025 08:40:21 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1736786420;
 x=1737391220; darn=dpdk.org; 
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:subject:cc:to:from:date:from:to:cc:subject:date
 :message-id:reply-to;
 bh=sM7RCr9BLX9ENqiQL/5rDK5U72pA40ohMn6IXG5p4CI=;
 b=z+O6lZuNu9PzDWzktD4emAJf3k7CG+5goFI3swpcMCN+NdBbD378KkicV9UevTyVgv
 /885mYkFRdZKKaX3N4BY992SM+/1PL/HsNz3snacM1axi9QB+0ZBOCPGGDuogzqLF0Qx
 0731i6bR0aBTCAB0QwkDzhN0AqK1iESWFUiQtYaWPfZbL0H5K1TPXUwWBBC3ZbywN8rl
 JvkglmapKqZRYfTVhF6di6kgJFpPSDuyZAB1x7p7OEJgBFDt97TCPT7orKpRZ5LjGRbo
 bZRMdfE4r9FY7qE45MblOPm4TLieQGMJLRqt4ItiKYhharZ4ttgnlqXQ+Ah+07xZk5Qu
 rlVg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1736786420; x=1737391220;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=sM7RCr9BLX9ENqiQL/5rDK5U72pA40ohMn6IXG5p4CI=;
 b=Sw5DqbS7hJ0n+NFfsxkVuINFZjzDNVbZna8HIULucuZ8K4llM0n80G56ItydjBwVm1
 8DB2BgVhG48PDydghuLnOxke6NmwussFwnbsm8/o4ESvYfjkNXqEhydtK/2qHncNY6sf
 /+/OP4rBLJVD2edaziNJoClp++s2KLwi1FH/0sdzkieXRawDecuex6g3Qyc1ldFxrKbq
 Qqoja7v05rYOcGGMGTEWPCHriQg+jOZKZ0bsLtu/wTF7QRH8E2zPpA6SuDI+qlopm4Yq
 xZxpKmG6/KzkR7XeTTb3ob1qnDXuisyQblqYGVe0fKlLYYzjPj88CKW/0lrTqgl9nkt/
 Mqrg==
X-Gm-Message-State: AOJu0YzCQQX9CNXmBoRAJlyWuMnhQDMiFlCs9YT8Eul68q4Qg5916lyK
 6vwh5wxYKl7ZGFf1iFmROPQLLNjIb1BiJ4OCxLMKRyT38x62BLqy06mN+wRn+zNnNZBeJ5R9BqV
 y
X-Gm-Gg: ASbGncs6V7Um7E0xxuWIXiLswE3J5vtSR467oRe3rgogBoVa52oc5pXv22Huea18VK9
 9ktO5HF4mQOsI4+cP0nDVt0euuvmAek9ySx2MjWzmMCe9AhPbmh5RXSidC1jBT4bl/waKnhpgSu
 9VCwiyw+HGfvxTsteExQGqdg1vcs5p3YQ6YrOJ7YZBuUrmbNOE0TUtzi6SXkmBFqLVs/WXNPUa2
 AVyI7iSNnMNiqp407ra/l8LfmQvz84DjijkqjJBN+573P22XlOHpEox7LmkyQaWRyHwmu0dgoot
 Zy6nk3xsPyGyE4ceKrXSvhsaBKdUnumIKg==
X-Google-Smtp-Source: AGHT+IEqr2VOkBS3zqNwjmTTCrUQUEvNRmiT55BZzS7a40fOczJj9TsgUpdLRZLk2mOPNh6WcOAFCQ==
X-Received: by 2002:a17:902:ea09:b0:216:527b:5413 with SMTP id
 d9443c01a7336-21a83f67c04mr296193855ad.26.1736786420207; 
 Mon, 13 Jan 2025 08:40:20 -0800 (PST)
Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226])
 by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-21a9f21bd3esm55579365ad.122.2025.01.13.08.40.19
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 13 Jan 2025 08:40:19 -0800 (PST)
Date: Mon, 13 Jan 2025 08:40:17 -0800
From: Stephen Hemminger <stephen@networkplumber.org>
To: Gagandeep Singh <G.Singh@nxp.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [PATCH] eal: add worker threads cleanup in rte_eal_cleanup()
Message-ID: <20250113084017.6fe7edc3@hermes.local>
In-Reply-To: <AS8PR04MB81986B239B742A86D9E7F82EE11F2@AS8PR04MB8198.eurprd04.prod.outlook.com>
References: <20250110064717.1372216-1-g.singh@nxp.com>
 <20250110091902.5139f8b2@hermes.local>
 <AS8PR04MB81986B239B742A86D9E7F82EE11F2@AS8PR04MB8198.eurprd04.prod.outlook.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

On Mon, 13 Jan 2025 05:13:01 +0000
Gagandeep Singh <G.Singh@nxp.com> wrote:

> Hi,
> 
> > -----Original Message-----
> > From: Stephen Hemminger <stephen@networkplumber.org>
> > Sent: Friday, January 10, 2025 10:49 PM
> > To: Gagandeep Singh <G.Singh@nxp.com>
> > Cc: dev@dpdk.org
> > Subject: Re: [PATCH] eal: add worker threads cleanup in rte_eal_cleanup()
> > 
> > On Fri, 10 Jan 2025 12:17:17 +0530
> > Gagandeep Singh <g.singh@nxp.com> wrote:
> >   
> > > 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>
> > > ---  
> > 
> > What problem is this trying to solve?
> > 
> > Canceling threads sends signals and can be problematic.
> > Many of the operations done in drivers are not signal safe.  
> 
> To ensure the proper cleanup of thread-specific resources, the DPAA driver initializes pthread-specific destructors using pthread_key_create(). These destructors are executed only when a thread terminates or the key is deleted. However, since threads are not terminated when the application is killed, these destructors are not executed, resulting in resource leaks.
> To address this issue, we propose adding thread termination code to rte_eal_cleanup() to ensure that threads are properly terminated, thereby triggering the execution of pthread-specific destructors
> 
> Any alternate suggestion in case pthread_cancel is not a better solution? We can add pthread join timeout to avoid blocking on thread stuck or
> May be any way to call pthread_exit?

The DPAA driver is the problem here. It should not be using pthread_key.
Other drivers don't do this. Other drivers do setup on probe and cleanup on close.

An application doing a clean shutdown should do what existing testpmd, l3fwd, do
	- wait for worker threads to go idle
	- stop all ports
	- close all ports
	- call eal cleanup

If DPAA driver needs pthread_key it should handling that in the close.
But it really should be using DPDK thread local storage for this.