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 54EAE43EDA; Mon, 22 Apr 2024 15:49:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C02C640265; Mon, 22 Apr 2024 15:49:32 +0200 (CEST) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2073.outbound.protection.outlook.com [40.107.95.73]) by mails.dpdk.org (Postfix) with ESMTP id 011CB4021F for ; Mon, 22 Apr 2024 15:49:31 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c2gkO09hcl1FS1sGmHglVWmx9+NtFmQq0HlPENhBr0SYzfyKsS2NVaNjM6wwz+vAc7Zew6/9MpuvPxE33N0eZJnGDxAvHWyGDkir8t5uzyI9k6Qcp1ZuT1GFJbuq/RWgk/67s5nu4xinZRrfrQlkHXOC3uM4nR7fBFDzWeSL/2yWWhHMcJ8EsM8EZM5MZfgRojIEGZXJMZ2F+cuCvUNT+EuxGmVoaTSyn1dvU44+3XNXqZUmSKkjMbH50yaPKaFig4qV5cjXpCAlHxmVs1P6AM4GUhy42eKyLQk7UyBZh1nxECzmCgJKqX3cZi9rRcLGJrW0dIGha8OL8+/iFH1yjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=v+82ixKL0vi2YW9vy+bUHJulfWCY+MV4D7ZjXNr44yc=; b=PbZHLoLKDhuNfVtU0fp3icTb8W3IJaWAsdbZ3zD9uxVb+6h/fh1lEt/K74cnw9hAiBCbp9vEIRn7oKlJA+VOLpPi5kCzYov0Hbhh55cj4Qvp7dZj/h2POVl5qSXP81z8v3DoYFrqpQZpOFDzBxHZKJXr4tXjFnkKM2AbFTiCyhy4uYCk965rb+YMSLj9p2G+CvjraL3v03uPG9a0Jk2wNZPhkannVbywlU+dCsIFoy9q96vt5GcdXtV/xNWbSpDrw3ZzX16cypDlLptQevw1hNiVkjZXADCTHa//REWhbDb3zYwVpfrVmekjodTROfSVv5fZHV6DMcs4ezqq291AFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=monjalon.net smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v+82ixKL0vi2YW9vy+bUHJulfWCY+MV4D7ZjXNr44yc=; b=w/K/VMZH9Qf760yrpxwXT+h7UDeUA2Zq2GIWgWt/2aDNHfr9Zmvjd4mdkS2BS80WaTd0JT9CS1wElN9z/jttF264HQOF4+xCL96g29SwJ2/E58IQekwCZBy5FuC/ekTDQ63XVvBPw3fDFNEtw9k2S/MvB9L164dx1fdzhZvXujc= Received: from CH0PR03CA0446.namprd03.prod.outlook.com (2603:10b6:610:10e::35) by DM4PR12MB5913.namprd12.prod.outlook.com (2603:10b6:8:66::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Mon, 22 Apr 2024 13:49:26 +0000 Received: from CH1PEPF0000AD81.namprd04.prod.outlook.com (2603:10b6:610:10e:cafe::17) by CH0PR03CA0446.outlook.office365.com (2603:10b6:610:10e::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.33 via Frontend Transport; Mon, 22 Apr 2024 13:49:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000AD81.mail.protection.outlook.com (10.167.244.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Mon, 22 Apr 2024 13:49:26 +0000 Received: from telcodpdk.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 22 Apr 2024 08:49:25 -0500 From: Ferruh Yigit To: Thomas Monjalon CC: , David Marchand , , Jianyue Wu Subject: [PATCH] eal/linux: enhanced error handling for affinity Date: Mon, 22 Apr 2024 14:49:17 +0100 Message-ID: <20240422134917.3740545-1-ferruh.yigit@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD81:EE_|DM4PR12MB5913:EE_ X-MS-Office365-Filtering-Correlation-Id: 679911e3-423b-4475-ad03-08dc62d3066f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?aen6xFlJ8u9aywo8DvrReNcRHu3lmHSIC4+10SABSk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Uw5YglnXWVYmwgopbl5joa9oxYGlMv4rHZbUaY7gDvcorREfUn?= =?us-ascii?Q?agA5Tz83J83iO6AABfY4j45eZtBsleqQjlzVHqW8TR454M3Ao6yFpmntlh8S?= =?us-ascii?Q?9+bz2TFLlpF2Z/1rMEArfj5jsLidZMDbqW/uK+ih/57ucVYLuNCdFINJzvoD?= =?us-ascii?Q?tM7gkDlvliHMt5CaFVvhD6eW9dGH2stQp5GIaa8pcaG9Cfkwn+xMnJ4TbK72?= =?us-ascii?Q?yzULfgWaKrPO2AsTjJGhDGPDLea4OaV8UGVCj8rfedm0psRwKhggCjqjTqaE?= =?us-ascii?Q?uRHyfuqIT9pYlkeIsEwC3nddiWJt4iZCZX6E/e+rODrQ2FpBfBhhDUXj+krk?= =?us-ascii?Q?PHVqfkjCaCO1EnsMF2qJILYPVKxDOeV77NeNKjO8cIIwYD/7S/saZdGn1Ufu?= =?us-ascii?Q?5gKrL6tfmByV0/At7lLKuo1HmH7jhRpl6fR7X8p418cPRs0lObU7E0+WTw66?= =?us-ascii?Q?4Jhuajs=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(36860700004)(82310400014)(1800799015)(376005); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2024 13:49:26.4746 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 679911e3-423b-4475-ad03-08dc62d3066f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000AD81.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5913 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 From: Jianyue Wu Improve the robustness of setting thread affinity in DPDK by adding detailed error logging. Changes: 1. Set `errno` to 0 before calling `pthread_setaffinity_np()` to ensure clean error status. 2. Check the return value of `pthread_setaffinity_np()` and log an error if the call fails. 3. 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 --- .mailmap | 1 + lib/eal/unix/rte_thread.c | 51 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/.mailmap b/.mailmap index 3843868716bd..66cff91f30a9 100644 --- a/.mailmap +++ b/.mailmap @@ -639,6 +639,7 @@ Jianfeng Tan Jiangu Zhao Jianwei Ma Jianwei Mei +Jianyue Wu Jiaqi Min Jiawei Wang Jiawei Zhu diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c index 1b4c73f58e91..56bc7995eb5f 100644 --- a/lib/eal/unix/rte_thread.c +++ b/lib/eal/unix/rte_thread.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -114,6 +115,35 @@ thread_start_wrapper(void *arg) return (void *)(uintptr_t)thread_func(thread_args); } +/* Function to convert cpu_set_t to a string. */ +static void cpuset_to_string(const cpu_set_t *cpuset, + char *cpus_str, size_t cpus_str_size) { + int cpu; + // Track the current position in the string + size_t offset = 0; + + // Clear the string buffer + memset(cpus_str, 0, cpus_str_size); + cpus_str_size = RTE_MAX_LCORE < cpus_str_size ? + RTE_MAX_LCORE : cpus_str_size; + + // Iterate over each CPU core, and check if it is included in the set + for (cpu = 0; cpu < RTE_MAX_LCORE && offset < cpus_str_size - 1; ++cpu) { + if (CPU_ISSET(cpu, cpuset)) { + // Append the current CPU number to the string + int written = snprintf(cpus_str + offset, cpus_str_size - offset, + "%s%d", (offset > 0 ? "," : ""), cpu); + if (written > 0) + offset += written; + if (offset >= cpus_str_size - 1) + break; + } + } + + // Ensure the string is properly terminated + cpus_str[cpus_str_size - 1] = '\0'; +} + int rte_thread_create(rte_thread_t *thread_id, const rte_thread_attr_t *thread_attr, @@ -369,8 +399,25 @@ 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_MAX_LCORE + 1] = {'\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!"); + cpuset_to_string(cpuset, cpus_str, sizeof(cpus_str)); + 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