From patchwork Wed Sep 6 16:12:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 131202 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 5028B42529; Wed, 6 Sep 2023 18:23:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C826D4027E; Wed, 6 Sep 2023 18:23:24 +0200 (CEST) Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by mails.dpdk.org (Postfix) with ESMTP id 98363402E2 for ; Wed, 6 Sep 2023 18:23:23 +0200 (CEST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 73D24320096D; Wed, 6 Sep 2023 12:23:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 06 Sep 2023 12:23:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1694017401; x= 1694103801; bh=rxG68et7JQxcK2X0nZ4GmZrJdcC0SauWMLlPbucInN8=; b=j x/GpcZieNepdFXHXoqtAK+c7fwpg3g5yEvjYP78tnoSnq0ifzeJ5AyWV25//68MU cLolvQj+vH6SMmnsZHx4NQqADqNLhKGbkvxuKKuuIkWHGcBk/az5onpKxSq6s6Am EJult3w2jqRfGBxj2CrLMD2Ui6T67XbLPRvk7EZvnVvRhWSbA0rr7mK1EJ/6IFzG f5fRhu28tAvNM7lZznBp7z78sVp23v8EvdlaANxzis7bq71QtT7VtQbIWER2vohi DQnThJB+FjJn3Fo01OhIIyoZxN+flm2zt96pZQ+5Mgp7/nICfQPjXg+8aWl9Ee28 q2QChL7vsxEydnYv5IBuA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1694017401; x= 1694103801; bh=rxG68et7JQxcK2X0nZ4GmZrJdcC0SauWMLlPbucInN8=; b=P ADcsmdtpSBiCEbxaPhIcqp7RLutC2blKTfV9zFyX5EorokF/iNrSrIOVQCJxDpas uPLPZisyZmdps6VGxTdU1HLEvvgpKD7B0XMqJOd1IsM5g4uqV9iQnp5acKMK2ZJn fxY2kbxXTUyiebpl0glpB6kUVyDdUcoAMT1fZRe4Ar2yhrQ0/NmO/eae21jUGrP/ Iu50kOLE65shq41+VRKkvOw1+gS7zR09iUO2rD2uZqsDDABtgnOarKkcPgy1ma6f 6X/CwHIBQ6YZo9BaL637UxK8UrT1rMvVn4rLKPYTmM0MmLM5ZGTHNpYoVo6de4eK kMoErj7suShCG6OklqG8A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudehfedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc ggtffrrghtthgvrhhnpedvjefhudeghedvtdeijeeigeetuedugfejueekieeltdfhteev keehhfeilefhtdenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfh hrohhmpehthhhomhgrshesmhhonhhjrghlohhnrdhnvght X-ME-Proxy: Feedback-ID: i47234305:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 6 Sep 2023 12:23:20 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: Tyler Retzlaff , David Marchand , Ferruh Yigit Subject: [PATCH 05/11] eal: force prefix for internal threads Date: Wed, 6 Sep 2023 18:12:22 +0200 Message-ID: <20230906162226.1618088-6-thomas@monjalon.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230906162226.1618088-1-thomas@monjalon.net> References: <20230906162226.1618088-1-thomas@monjalon.net> 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 In order to make sure all threads created in DPDK drivers and libraries have the same prefix in their name, some wrapper functions are added for internal use when creating a control thread or setting a thread name: - rte_thread_create_internal_control - rte_thread_set_prefixed_name The equivalent public functions are then forbidden for internal use: - rte_thread_create_control - rte_thread_set_name Note: the libraries and drivers conversion is done in next patches, while doing other thread-related changes. Signed-off-by: Thomas Monjalon --- devtools/checkpatches.sh | 8 +++++ lib/eal/common/eal_common_thread.c | 30 ++++++++++++++++ lib/eal/include/rte_thread.h | 57 +++++++++++++++++++++++++++++- lib/eal/version.map | 2 ++ 4 files changed, 96 insertions(+), 1 deletion(-) diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh index 131ffbcebe..18ad6fbb7f 100755 --- a/devtools/checkpatches.sh +++ b/devtools/checkpatches.sh @@ -159,6 +159,14 @@ check_forbidden_additions() { # -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 + # forbid non-internal thread in drivers and libs + awk -v FOLDERS='lib drivers' \ + -v EXPRESSIONS="rte_thread_(set_name|create_control)\\\(" \ + -v RET_ON_FAIL=1 \ + -v MESSAGE='Prefer rte_thread_(set_prefixed_name|create_internal_control) in lib & drivers' \ + -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ + "$1" || res=1 + # forbid inclusion of driver specific headers in apps and examples awk -v FOLDERS='app examples' \ -v EXPRESSIONS='include.*_driver\\.h include.*_pmd\\.h' \ diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 07ac721da1..31c37e3102 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -392,6 +392,36 @@ rte_thread_create_control(rte_thread_t *thread, const char *name, return ret; } +static void +add_internal_prefix(char *prefixed_name, const char *name, size_t size) +{ + const char *prefix = "dpdk-"; + size_t prefixlen; + + prefixlen = strlen(prefix); + strlcpy(prefixed_name, prefix, size); + strlcpy(prefixed_name + prefixlen, name, size - prefixlen); +} + +int +rte_thread_create_internal_control(rte_thread_t *id, const char *name, + rte_thread_func func, void *arg) +{ + char prefixed_name[RTE_THREAD_NAME_SIZE]; + + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); + return rte_thread_create_control(id, prefixed_name, func, arg); +} + +void +rte_thread_set_prefixed_name(rte_thread_t id, const char *name) +{ + char prefixed_name[RTE_THREAD_NAME_SIZE]; + + add_internal_prefix(prefixed_name, name, sizeof(prefixed_name)); + rte_thread_set_name(id, prefixed_name); +} + int rte_thread_register(void) { diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index dd1f62523f..4b1135df4f 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -28,6 +28,9 @@ extern "C" { /* Old definition, aliased for compatibility. */ #define RTE_MAX_THREAD_NAME_LEN RTE_THREAD_NAME_SIZE +/** Maximum internal thread name length (including '\0'). */ +#define RTE_THREAD_INTERNAL_NAME_SIZE 11 + /** * Thread id descriptor. */ @@ -112,7 +115,7 @@ int rte_thread_create(rte_thread_t *thread_id, * @param thread_func * Function to be executed by the new thread. * @param arg - * Argument passed to start_routine. + * Argument passed to thread_func. * @return * On success, returns 0; on error, it returns a negative value * corresponding to the error number. @@ -121,6 +124,36 @@ int rte_thread_create_control(rte_thread_t *thread, const char *name, rte_thread_func thread_func, void *arg); +/** + * Create an internal control thread. + * + * Creates a control thread with the given name prefixed with "dpdk-". + * If setting the name of the thread fails, the error is ignored and logged. + * + * The affinity of the new thread is based on the CPU affinity retrieved + * at the time rte_eal_init() was called, the EAL threads are then excluded. + * + * @param id + * Filled with the thread ID of the new created thread. + * @param name + * The name of the control thread + * (maximum 10 characters excluding terminating '\0'). + * See RTE_THREAD_INTERNAL_NAME_SIZE. + * The name of the driver or library should be first, + * then followed by a hyphen and more details. + * It will be prefixed with "dpdk-" by this function. + * @param func + * Function to be executed by the new thread. + * @param arg + * Argument passed to func. + * @return + * On success, returns 0; a negative value otherwise. + */ +__rte_internal +int +rte_thread_create_internal_control(rte_thread_t *id, const char *name, + rte_thread_func func, void *arg); + /** * Waits for the thread identified by 'thread_id' to terminate * @@ -159,6 +192,7 @@ rte_thread_t rte_thread_self(void); /** * Set the name of the thread. + * * This API is a noop if the underlying platform does not * support setting the thread name or the platform-specific * API used to set the thread name fails. @@ -173,6 +207,27 @@ rte_thread_t rte_thread_self(void); void rte_thread_set_name(rte_thread_t thread_id, const char *thread_name); +/** + * Set the name of an internal thread with adding a "dpdk-" prefix. + * + * This API is a noop if the underlying platform does not support + * setting the thread name, or if it fails. + * + * @param id + * The ID of the thread to set name. + * + * @param name + * The name to set after being prefixed + * (maximum 10 characters excluding terminating '\0'). + * See RTE_THREAD_INTERNAL_NAME_SIZE. + * The name of the driver or library should be first, + * then followed by a hyphen and more details. + * It will be prefixed with "dpdk-" by this function. + */ +__rte_internal +void +rte_thread_set_prefixed_name(rte_thread_t id, const char *name); + /** * Check if 2 thread ids are equal. * diff --git a/lib/eal/version.map b/lib/eal/version.map index 33b853d7be..6d32c19286 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -462,4 +462,6 @@ INTERNAL { rte_mem_map; rte_mem_page_size; rte_mem_unmap; + rte_thread_create_internal_control; + rte_thread_set_prefixed_name; };