From patchwork Mon Nov 27 09:25:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vodak X-Patchwork-Id: 134618 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 62992433E3; Mon, 27 Nov 2023 10:25:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D6BE040261; Mon, 27 Nov 2023 10:25:22 +0100 (CET) Received: from office2.cesnet.cz (office2.cesnet.cz [78.128.248.237]) by mails.dpdk.org (Postfix) with ESMTP id 37ABB40150 for ; Mon, 27 Nov 2023 10:25:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=office2-2020; t=1701077120; bh=6Y4shkRqErNteqUhepxRTYo4nKM7a8mawTxE2MUrQFE=; h=From:To:Cc:Subject:Date; b=GDKHzM1xQzRP0ru4Z7n4XfFj4ZPoUg8P4z+dzW6q6wtLbqZy33cdy3VMKz5F7wicS QNe0Av0Hb4H39iYmXZmoUAYnpHTY7vuQjbRHqjL8Zj8US0gNZvHzm0fRLu7Wbah7Kj g3B6gnoNFp5L2pcvbSDWbVfSgn5rnUvm4YgkVc+S+beaZRWwWZn313WnhmAUadrfDI 5o3iEKakexnIp0WYb1ij4jfiQxntMPkIOmbjom9Lh/Myvs36+3f7ZKZtaa1EYFVeuQ oS8EHs7MQFfE7pQ9oEdHouOI5h/+7ACMAYRxgdeX/417HYG6FXINOiaQd4gwTebs+t 5ZSXqj2s1gQ1A== Received: from localhost.localdomain (unknown [IPv6:2001:67c:1220:80e:93:a24f:6f5b:26b4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by office2.cesnet.cz (Postfix) with ESMTPSA id E50C21180072; Mon, 27 Nov 2023 10:25:18 +0100 (CET) From: David Vodak To: dev@dpdk.org Cc: David Vodak Subject: [PATCH] eal: introduce missing rte_thread wrappers Date: Mon, 27 Nov 2023 10:25:02 +0100 Message-ID: <20231127092502.18510-1-vodak@cesnet.cz> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Function rte_ctrl_thread_create has been replaced by rte_thread_create_control, encouraging Linux users to switch from the pthread_t API to the rte_thread API. However the rte_thread API does not provide wrappers for all pthread functions. This commit introduces equivalent functions for pthread_timedjoin_np, pthread_getname_np and pthread_cancel. Bugzilla ID: 1330 --- lib/eal/include/rte_thread.h | 49 ++++++++++++++++++++++++++++++++++++ lib/eal/unix/rte_thread.c | 20 +++++++++++++++ lib/eal/version.map | 3 +++ 3 files changed, 72 insertions(+) diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 8da9d4d3fb..49a068eda7 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -463,6 +463,55 @@ int rte_thread_value_set(rte_thread_key key, const void *value); */ void *rte_thread_value_get(rte_thread_key key); +/** + * Try to join with a terminated thread. If thread has not yet terminated, + * then the call blocks until a maximum time, specified in abstime. + * + * @param thread_id + * Id of the thread. + * + * @param retval + * Exit status of the thread. + * + * @param abstime + * Maximum time of call blocking, measured against the CLOCK_REALTIME clock. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +int rte_thread_timedjoin_np(rte_thread_t thread_id, void **retval, const struct timespec *abstime); + +/** + * Get name of the thread. + * + * @param thread_id + * Id of the thread. + * + * @param name + * Name of the thread. + * + * @param size + * The number of bytes available in name. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +int rte_thread_getname_np(rte_thread_t thread_id, char name[], size_t size); + +/** + * Send a cancelation request to a thread. + * + * @param thread_id + * Id of the thread. + * + * @return + * On success, return 0. + * On failure, return a positive errno-style error number. + */ +int rte_thread_cancel(rte_thread_t thread_id); + #ifdef __cplusplus } #endif diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c index 36a21ab2f9..79986bee6a 100644 --- a/lib/eal/unix/rte_thread.c +++ b/lib/eal/unix/rte_thread.c @@ -378,3 +378,23 @@ rte_thread_get_affinity_by_id(rte_thread_t thread_id, return pthread_getaffinity_np((pthread_t)thread_id.opaque_id, sizeof(*cpuset), cpuset); } + +int +rte_thread_timedjoin_np(rte_thread_t thread_id, void **retval, + const struct timespec *abstime) +{ + return pthread_timedjoin_np((pthread_t) thread_id.opaque_id, retval, + abstime); +} + +int +rte_thread_getname_np(rte_thread_t thread_id, char name[], size_t size) +{ + return pthread_getname_np((pthread_t) thread_id.opaque_id, name, size); +} + +int +rte_thread_cancel(rte_thread_t thread_id) +{ + return pthread_cancel((pthread_t) thread_id.opaque_id); +} diff --git a/lib/eal/version.map b/lib/eal/version.map index 5e0cd47c82..66ac45b7de 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -310,6 +310,9 @@ DPDK_24 { rte_thread_unregister; rte_thread_value_get; rte_thread_value_set; + rte_thread_timedjoin_np; # WINDOWS_NO_EXPORT + rte_thread_getname_np; # WINDOWS_NO_EXPORT + rte_thread_cancel; # WINDOWS_NO_EXPORT rte_uuid_compare; rte_uuid_is_null; rte_uuid_parse;