From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9889143EF7; Wed, 24 Apr 2024 16:18:27 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6E81D434FA; Wed, 24 Apr 2024 16:18:27 +0200 (CEST) Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) by mails.dpdk.org (Postfix) with ESMTP id 3EC9F40269 for ; Tue, 23 Apr 2024 05:02:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=cEQiN xSsjbWYWzUiprQnnfeZdHUZaKTqvK7M6V4nS08=; b=cKINuEuNTaJI67WZCaaZc Re0ls03fPFKRNda0tb/XJlQsNgarxfzTPB5Lpx8D9jlGNLiSxCD3a7G7lGcPfOxN 7XvnuVaYQkhFFNTG9kdxDB4nwY5k0SHFsJrU81LqUNrfOedHpUOhqA9SE2mtaeta if0W4+Gtf8e1VpCiQskOoU= Received: from ubuntu2204.. (unknown [36.24.144.104]) by gzga-smtp-mta-g1-5 (Coremail) with SMTP id _____wD3XxvWJCdm6yU5CA--.8084S2; Tue, 23 Apr 2024 11:02:46 +0800 (CST) From: Jianyue Wu To: Cc: dev@dpdk.org, Jianyue Wu Subject: [PATCH] eal/linux: enhanced error handling for affinity Date: Tue, 23 Apr 2024 11:02:43 +0800 Message-Id: <20240423030243.59895-1-wujianyue000@163.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wD3XxvWJCdm6yU5CA--.8084S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7WFW5ur47Gr1rKrW7Cr45ZFb_yoW8CF1DpF y0k3sFyrs5ArsFvw13t3W8JFyYyr4xXay7Jr97Aw1fA3y3Wa15Ary5KFy5Xr1rCr48W3s8 JrW7uFWq9r4DJaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRqjgcUUUUU= X-Originating-IP: [36.24.144.104] X-CM-SenderInfo: 5zxmxtpq1xviiqq6il2tof0z/1tbisBfJemV4JBBHlgAAss X-Mailman-Approved-At: Wed, 24 Apr 2024 16:18:26 +0200 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 Improve the robustness of setting thread affinity in DPDK by adding detailed error logging. Changes: 1. Check the return value of pthread_setaffinity_np() and log an error if the call fails. 2. Include the current thread name, the intended CPU set, and a detailed error message in the log. Sample prints: EAL: Cannot set affinity for thread dpdk-test with cpus 0, ret: 22, errno: 0, error description: Success EAL: Cannot set affinity for thread dpdk-worker1 with cpus 1, ret: 22, errno: 0, error description: Success Signed-off-by: Jianyue Wu --- lib/eal/unix/rte_thread.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c index 1b4c73f58e..8f9eaf0dcf 100644 --- a/lib/eal/unix/rte_thread.c +++ b/lib/eal/unix/rte_thread.c @@ -369,8 +369,26 @@ int rte_thread_set_affinity_by_id(rte_thread_t thread_id, const rte_cpuset_t *cpuset) { - return pthread_setaffinity_np((pthread_t)thread_id.opaque_id, - sizeof(*cpuset), cpuset); + int ret; + char cpus_str[RTE_CPU_AFFINITY_STR_LEN] = {'\0'}; + char thread_name[RTE_MAX_THREAD_NAME_LEN] = {'\0'}; + + errno = 0; + ret = pthread_setaffinity_np((pthread_t)thread_id.opaque_id, + sizeof(*cpuset), cpuset); + if (ret != 0) { + if (pthread_getname_np((pthread_t)thread_id.opaque_id, + thread_name, sizeof(thread_name)) != 0) + EAL_LOG(ERR, "pthread_getname_np failed!"); + if (eal_thread_dump_affinity(cpuset, cpus_str, RTE_CPU_AFFINITY_STR_LEN) != 0) + EAL_LOG(ERR, "eal_thread_dump_affinity failed!"); + EAL_LOG(ERR, "Cannot set affinity for thread %s with cpus %s, " + "ret: %d, errno: %d, error description: %s", + thread_name, cpus_str, + ret, errno, strerror(errno)); + } + + return ret; } int -- 2.34.1