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 61F01459CB; Wed, 18 Sep 2024 13:31:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F0F9F42E5B; Wed, 18 Sep 2024 13:31:07 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by mails.dpdk.org (Postfix) with ESMTP id C2054402BA for ; Wed, 18 Sep 2024 13:31:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726659067; x=1758195067; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=Iw2uIMBGZLQs5a8ig2g08v1dQxpeYf0yoFdvl/Q0VyE=; b=ApJqkkDqRvw7dUOh9FYpjOVpn4sR7HkuG9Nx+h7MwS8L+xw9BZTt2uVP F3APjPu3FeuiebYroA1UL9RXdU5DyJD9liCOfcF8h+AX5vTW2XFjZvk21 bSh3Yt+4dlHE+gD98HXfeqNhTtNAaerjiLpx4h8X9vuKQsK63ZgNOvH19 yopK4ex6sKbu6Bt8cM4s8ov9EOpMcSMQz1FdKoLmsQvXdNL0HENttpBi9 wHPWSOfTGlc42Ry3BIMDCHNORYEwpgah2xTGHldlC2pVNJyPJeprhO1Mx NgMnXaJ7GNUvr4F8X22gnk8Eb8VuxVyKLcOfY5S1pbr6etp+ovGq4xPSR Q==; X-CSE-ConnectionGUID: +SMmzoHjSReMj6cgRRADkA== X-CSE-MsgGUID: ZeuffvRcT2WeLkNMQFvj1w== X-IronPort-AV: E=McAfee;i="6700,10204,11198"; a="25438104" X-IronPort-AV: E=Sophos;i="6.10,238,1719903600"; d="scan'208";a="25438104" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2024 04:31:06 -0700 X-CSE-ConnectionGUID: QVkM5poAQfmYIBE9HcsXCQ== X-CSE-MsgGUID: lvIX5S4iT66ymKiPc5PdBw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,238,1719903600"; d="scan'208";a="69749703" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmviesa010.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 18 Sep 2024 04:31:05 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 18 Sep 2024 04:31:04 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Wed, 18 Sep 2024 04:31:04 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.41) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 18 Sep 2024 04:31:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=C8ZQ4Et/s3Jaw1AtrjFQycKKLCqBe6AtCZ8ZhlRig0aZuxOeVzrHkt+qpFSFtiojhLvycPgXFkL5IM7DBPM6rWhd16aQL+L9u55sz4GoBA5MdElB2vXrxqJ7MLZyKlo4Bey0FBYAQkZFB/5l5QrlYvKszH8HqhhAO52SXccysu+0+aAaKTyOT9V4Vc9MPRcQG6K9GthHtAY1a0L3TwpGyR+ROlVun+CmJ1D++qGxKZgDUf8PCfS/sXi6fIQzPuvg0eIboqKSKI6dsLSeTwFgQDM7oH94poNXCJdwuFxcpcrP0pGQyVCMIBbaAYi9QYAA6GnI9ykZ3JiDPzkSy+5fmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=lOl+Y6kEadMcoHPz2lohr0K+pu+8wBjeGLu1XkiW5N8=; b=aXA8LLoJN7mjBEQxw2dF4cWQ1FfCkiy1zTTKEvEIG8c2DC71ntLoPepZ5+ooDIIRc9AXKzLNh+tb3PDb/IqLMFGmHxfRQFi2ffZWdEmPz4Ojg1fFiFVspS3HJs7knNop8t1dvY/RynqNFFEJn2OGDNerAKgFbLu+sbJylaOzaPXerD9aiqt5KgoWlKtR76jYLXskTYJZS7JnI1/yf+ZI3eWDscFQtmr7FGi6zTzMSietutD9KxFtY6Oj7s8Q50I8KubsUK6qTnDc0aH5+0LWKEvJkHDimXTEhO7GUpXxTEOa85m9ENxmv9k8TCAM/HzJQY7fUNiDTLnAkiKVX/aaZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from MW3PR11MB4521.namprd11.prod.outlook.com (2603:10b6:303:55::13) by PH0PR11MB7472.namprd11.prod.outlook.com (2603:10b6:510:28c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.17; Wed, 18 Sep 2024 11:31:01 +0000 Received: from MW3PR11MB4521.namprd11.prod.outlook.com ([fe80::c706:b86b:2b3:10da]) by MW3PR11MB4521.namprd11.prod.outlook.com ([fe80::c706:b86b:2b3:10da%3]) with mapi id 15.20.7982.016; Wed, 18 Sep 2024 11:31:01 +0000 From: Wojciech Panfil To: CC: , , , , , , Subject: [PATCH] eal/alarm_cancel: Fix thread starvation Date: Wed, 18 Sep 2024 13:39:06 +0200 Message-ID: <20240918113906.64350-1-wojciech.panfil@intel.com> X-Mailer: git-send-email 2.46.0 Organization: Intel Corporation Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: WA2P291CA0008.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1e::21) To MW3PR11MB4521.namprd11.prod.outlook.com (2603:10b6:303:55::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW3PR11MB4521:EE_|PH0PR11MB7472:EE_ X-MS-Office365-Filtering-Correlation-Id: 26bee4ba-ae68-4551-8606-08dcd7d55fdd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?TfMDqBEOqvKKU4V3R9Flg0HzzlLPENPQtTluuMlQUnbxsDZ0f01cz59SCgTW?= =?us-ascii?Q?EPIONSAa+4iL6E4D8QbpNnrylTQPTIHPDiFyPHivHDtmNt5wRA+VQycKXtO7?= =?us-ascii?Q?S9jZObxcqVY8vQvr58sFiLcmm3vjKytb3Rh+Va+5VX+vI+4GZnu8Gpb+lvVs?= =?us-ascii?Q?gwFdWN0zXpgx8x4HR/1P+8OQjP33CPglNMLKG1bkF4TrbTmZ7m941AyqIXkD?= =?us-ascii?Q?5Xpuvn3ABxjQJVIVzi4wUJpFEH/R0SgcFEjTwbec4u8c+z35CtzASnV2nRTa?= =?us-ascii?Q?RPcvmu5ImhPoODXK0Poz8xP1WNMqxC0GLrUNC0ioatvErLjchmCYF3JC4vTl?= =?us-ascii?Q?M83GV2deNljlwvBQg1WaBOEMA6oeBJWO1/n1S2m3vfRs2oT4A2ENZi9k8SRt?= =?us-ascii?Q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Yn8v9CmB/T7cuTsiPp5Ah2yN9Hg?= =?us-ascii?Q?DukFyHLwrR7l+J//xqL34zwGfmk71rXtPPisAU8ozPFTAw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW3PR11MB4521.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(366016)(376014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?nX92KOJbNWIkqpRI8k4uU4oaSv9Xzn3Ygn0Y8UjM0V9QXxLK1fB6fnmhD+bU?= =?us-ascii?Q?JF14c1pCFVG8HX+MPAwwtURl8HptBw1Apm/LnWobNWgwGyubTHJngJHyqg01?= =?us-ascii?Q?f49oB/8272G3UuHw+uwKBi6EeuvYSY64rx8fajIrr3rtuttSBGR21c/ZojJw?= =?us-ascii?Q?cVXVJje++fEhup6fzcv3+TYJ+Xk+3w393lu+Tp/StJYciykk5Jwb7juYHe+B?= =?us-ascii?Q?bznwa6I6NK/xsiZvhP5oEWxq7ofVb9At39stI2o0kzDCkrpPKSCvwNE9SUVw?= =?us-ascii?Q?+uQxfafB6lqvTU7spEoMimiQm79WrscBWy9ZvstoJNUiR7DURZm+4mrRK+IT?= =?us-ascii?Q?Yi3k2WDHl8PGUD6WAYMRWRUBi7tcQlKrYZpfZ+Z1/6D+iP9VVSexfWwCAhFB?= =?us-ascii?Q?llz1VFNXHPT/6cTx9l5sFlNrjMVkjiDhPvx86OrQmbvWzSbGtAnl9buZqFJS?= =?us-ascii?Q?1fpfbKcEvevIToQDuLAxczjXh6KSLW4nxNrhJAUQS5Mvm/ZxFvgpnCQO6OQw?= =?us-ascii?Q?Uz37pmX1ghnewMp4dsUCtU9p4iffbwV5mXS5aTXvrY1U4WSpxXOY1vYKb2DP?= =?us-ascii?Q?BPn8Nhr7U2G7W6HxwY2hf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q?0JyG43LuVMZYdXEm9pstRLWoPtZ3crm9YNFgW+eqio9bwRrvdb4we/2IzbnV?= =?us-ascii?Q?suoIvflDELpEz91RMJKUZJjGHkNlkUdcNdpa2qU88a0okVX43y9NcKepL5+j?= =?us-ascii?Q?MA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 26bee4ba-ae68-4551-8606-08dcd7d55fdd X-MS-Exchange-CrossTenant-AuthSource: MW3PR11MB4521.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2024 11:31:01.7256 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f/PiGpvc8LzDZEv4yxR2OpbKW6UQxnRL8FgNwuGV7ZEJ1Tisx7/FY8svst6AKBFvlRG6InDZHJ8Ze/TpK1KQr3oloPbcx51o6l8VnCsxbuc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB7472 X-OriginatorOrg: intel.com 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 Issue: Two threads: - A, executing rte_eal_alarm_cancel, - B, executing eal_alarm_callback. Such case can cause starvation of thread B. Please see that there is a small time window between lock and unlock in thread A, so thread B must be switched to within a very small time window, so that it can obtain the lock. Solution to this problem is use sched_yield(), which puts current thread (A) at the end of thread execution priority queue and allows thread B to execute. The issue can be observed e.g. on hot-pluggable device detach path. On such path, rte_alarm can used to check if DPDK has completed the detachment. Waiting for completion, rte_eal_alarm_cancel is called, while another thread periodically calls eal_alarm_callback causing the issue to occur. Signed-off-by: Wojciech Panfil --- lib/eal/freebsd/eal_alarm.c | 6 ++++++ lib/eal/linux/eal_alarm.c | 6 ++++++ lib/eal/windows/eal_alarm.c | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c index 94cae5f4b6..3680f5caba 100644 --- a/lib/eal/freebsd/eal_alarm.c +++ b/lib/eal/freebsd/eal_alarm.c @@ -318,7 +318,13 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } ap_prev = ap; } + rte_spinlock_unlock(&alarm_list_lk); + + /* Yield control to a second thread executing eal_alarm_callback to avoid + * its starvation, as it is waiting for the lock we have just released. + */ + sched_yield(); } while (executing != 0); if (count == 0 && err == 0) diff --git a/lib/eal/linux/eal_alarm.c b/lib/eal/linux/eal_alarm.c index eeb096213b..9fe14ade63 100644 --- a/lib/eal/linux/eal_alarm.c +++ b/lib/eal/linux/eal_alarm.c @@ -248,7 +248,13 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } ap_prev = ap; } + rte_spinlock_unlock(&alarm_list_lk); + + /* Yield control to a second thread executing eal_alarm_callback to avoid + * its starvation, as it is waiting for the lock we have just released. + */ + sched_yield(); } while (executing != 0); if (count == 0 && err == 0) diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c index 052af4b21b..9ad530dd31 100644 --- a/lib/eal/windows/eal_alarm.c +++ b/lib/eal/windows/eal_alarm.c @@ -211,6 +211,11 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg) } rte_spinlock_unlock(&alarm_lock); + + /* Yield control to a second thread executing eal_alarm_callback to avoid + * its starvation, as it is waiting for the lock we have just released. + */ + SwitchToThread(); } while (executing); rte_eal_trace_alarm_cancel(cb_fn, cb_arg, removed); -- 2.46.0