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 8AC1F431FC; Wed, 25 Oct 2023 18:41:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7985B40EF0; Wed, 25 Oct 2023 18:41:18 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 2532D40042 for ; Wed, 25 Oct 2023 18:41:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698252076; x=1729788076; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=0xytzyn0p4SuPdZtT1d4zqwLUC9cBEbena87gbVTkw4=; b=h6tl1ksOsvvap6/2hY2h4GD4cFZBtWF/JGtmeU+/4LrJaxKmreTS58uK tHcrMLRuDdJf7tgbfW9KxYQifk6si4UwGOyic2g0hqx/5TCCpafAXjxcr 2EOGHptGn6I2SdgWJFAWPoU3Vsc7HpBRJcI7ybGTape7r5VaUA9fjUodX 1eEZdthnv7BZXgvdxeZEeKlSKZiOGznMuyh1bNpG/Cg5ahT4FZ1xQEgAk lj4jO8MGLTgEQk/AJc9hDE6YhBV7Zlmy7gn/gtuaVsUUO9AQhOmfMKZut D26DD3xOfxq6WnIJPewM4AgaCQyEXm50FVMTcPv8VOIeaGhkrFkpnUTpI g==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="387169647" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="387169647" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 09:41:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="849589284" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="849589284" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by FMSMGA003.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 25 Oct 2023 09:40:58 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Wed, 25 Oct 2023 09:40:56 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Wed, 25 Oct 2023 09:40:55 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Wed, 25 Oct 2023 09:40:55 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.168) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.32; Wed, 25 Oct 2023 09:40:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hoAqBvIWBjtGD6t6/0CfXMjTgKWJt2+xOYtl6j0h6aUkI+p5lWoQN9nvGzHh4AKZ6/vtM+UOhtLnyOo6za/Srk1VGy/ZuWuZuRP3RmmZf4dmpmlV6hw0d7K6dVgYMYWjhiBynBupLGogKslYB8Mr6Kkpwl1QvABzFml9/Q0uL2OEVJYVV8jpfUrPzsKDIJlGa1a5+Y2o93uxgfkCXAg1xoO5l6jn1/5Cl1KLkNOJsZpxPE5SIDRsd+jU2n5IIOQV3vcYyFfQ5jyok4hIq+cdSp3f97EoDD7zrK12mMaWgLmYDM3pTGwf03ICQrpfc82WAhfhSj2KYY8XkOtZqYgLDw== 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=OMejE3+U4Mp8RKYGG8At83iOgga8CvM8M3Qf75Tltc4=; b=Qekg/dW0JH7QAMCmDvFbjMI53RCpKN5ctWO3pXhsFYcSX1NtSVvgGAbvw1HLh2EcWQRGiiSzJF9hryowE/+lGH9I/ezqtPefkEIZhgbr1GrCPNQTxCSsDNvmoi23EMtG7d62JZp73oBKOOjnZlQa8+nzNTOaYXnaXYu0AYM5AL24Y2nXUkebpqEjZNH0YSqU/Kc7ans7paRZpFtsEMKiRzBZm1bBnN08CxAnBWyn0M4Rkj1E/TLQSa3XgusJolkdk8QE3011V/fiZ4eIEqvk7tF920wVdyBgs1J19mUWfxW5eASyzeotM30PnkHTWEzmJNufX7fmuF+N0X9JKxIrCw== 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 DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) by DS7PR11MB7805.namprd11.prod.outlook.com (2603:10b6:8:ea::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Wed, 25 Oct 2023 16:40:52 +0000 Received: from DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::d70b:11a0:d28f:ec44]) by DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::d70b:11a0:d28f:ec44%6]) with mapi id 15.20.6907.032; Wed, 25 Oct 2023 16:40:52 +0000 Date: Wed, 25 Oct 2023 17:40:45 +0100 From: Bruce Richardson To: Thomas Monjalon CC: , David Marchand , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Subject: Re: [PATCH v3 1/2] eal: add thread yield functions Message-ID: References: <20231024125416.798897-1-thomas@monjalon.net> <20231025163352.1076755-1-thomas@monjalon.net> <20231025163352.1076755-2-thomas@monjalon.net> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20231025163352.1076755-2-thomas@monjalon.net> X-ClientProxiedBy: DU2PR04CA0213.eurprd04.prod.outlook.com (2603:10a6:10:2b1::8) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|DS7PR11MB7805:EE_ X-MS-Office365-Filtering-Correlation-Id: 94f919e4-9266-41dc-4996-08dbd57926a9 X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GA6JdL3Krr+H6MAlJPih2Rxu5VqRX3PO80qu1K27AX8+X5MJyBgUZ+tpQ/OiCMKgJkbuQul3viH4ykQH/CIeKbzbKDJJQGhfhQFoAdHm17uPYYqjsoRdODYrUITilI2RvJrT51pL2VlH6ip2W3F/4/n/luWcVElH5MI3eiDr9TPKdnGHpRTEM9binn1STLlrASKt4boJAqU5VbrfOoj8kGd9tfTyVP03SR7wPeUjD0skEqX077lpnr2cU8XgiaZ+xea9Ht/mpynNlAREgmKzdAQ+ayPv3OZG3r59vAnAq9A3+v5nQ7GQunNgSkG9Y34/Iu+iJ5zWAbqzCRQNkVYOV6estpBhCFWXOjZr10Nr5ziwyKZxOG6NtQnfr7wYMKOYiF40CMqK2wdgNcOBfOGb1Oq3SYa05uTNVjJdOun1SFwEy9zP8T1dDtnJvDA9VdozFplsPpIuva3gw2vW76x/lG/1YV9t6iIqhTgJHtFYYyabp8Hjubh9twziAfqpQ+bV7dq3YirEGZSODZCgpEa+aG3YUFXoLTuNWlXtOrSxp4swGtXF0kKswyP/ValGU/Wq X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376002)(39860400002)(366004)(396003)(346002)(136003)(230922051799003)(451199024)(64100799003)(1800799009)(186009)(107886003)(6506007)(44832011)(2906002)(41300700001)(38100700002)(316002)(66476007)(82960400001)(66946007)(54906003)(6666004)(66556008)(6916009)(6512007)(6486002)(83380400001)(86362001)(4326008)(5660300002)(478600001)(8936002)(8676002)(26005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?hn71bl9DiQ4075CT/lAR5uQKMTiEM1CSXqLv7FC69bCbLqjF2e+gN46q4ACq?= =?us-ascii?Q?36eVFG5HxfWuVbn5KfszAn2RMKDOXfFi8RNPxVRVr5COeSpJsRVw7/6c/8P5?= =?us-ascii?Q?/2rUPE/4skZRscY2dk8NlFLLrLpFruH1athHrizY4BOGc3KaFpu9Zt2vACMz?= =?us-ascii?Q?Gjh0sh6ymJi1bFX/4fA6eCMq6iLiFpOeoYyR6XhfVAK+aJ8+AehKGGiNKSw4?= =?us-ascii?Q?/WYFB4xCxgVi4bk9JGOw8/nOYDSL3K/36ppgydOpbP2faezKbDoPftJWf1l4?= =?us-ascii?Q?DOijnCAV/7kkpPS8Aw+2wOx78iizfU+LzG7Kh/LJOJxT7BfS2hfg1IzmZ7IF?= =?us-ascii?Q?/1So18v62AvVnEfLRnn7qAjGwwrK1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dIthpdufi61M2JNF+OZjBMY08BrRezkRRBY+AMUTY0sgb5?= =?us-ascii?Q?/mq0YOaIP19Td4nDA/mhxgdnEcKrpeBcEsCaarNim2MaOH7I6QyxPAb16htO?= =?us-ascii?Q?P9fmNI7bpFcfrSmfuy+P3hawygyULOLGNVn5DzJfgbAkV0dU3z/cBxPkOxQB?= =?us-ascii?Q?09MgiWqiZL8Rr5S2K8v7EGV7WvlTzN2BT+p5deVU342fIE8wkVov63c1xy3M?= =?us-ascii?Q?8Io9ZdPByYLJ/ekSvSGp1OWbYW5DZL4pDoyEE2O43dCEYlTA8u0r/EBlUXbS?= =?us-ascii?Q?3hn22JY8mHiGUmfKKJKnrK7F/pewU3jK/cj9TwrMe7kU5rY33Jt4vFgRTlW4?= =?us-ascii?Q?AA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 94f919e4-9266-41dc-4996-08dbd57926a9 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 16:40:52.2249 (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: Hp3DYgu9eoFDOWIYYDPb1OfltIbjgwXWXIK4vWo5P4yoLXuq1hP71YRz1bxN2mOlbHWi9OPTZk4JuxEaxwkkRh1caCnkJ6eQSNqJaI+cPig= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR11MB7805 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 On Wed, Oct 25, 2023 at 06:31:10PM +0200, Thomas Monjalon wrote: > When running real-time threads, we may need to force scheduling > kernel threads or other real-time threads. > New functions are added to address these cases. > > The yield functions should not have any interest for normal threads. > Note: other purposes may be addressed with rte_pause() or rte_delay_*(). > > Signed-off-by: Thomas Monjalon > --- > lib/eal/include/rte_thread.h | 22 ++++++++++++++++++++++ > lib/eal/unix/rte_thread.c | 16 ++++++++++++++++ > lib/eal/version.map | 4 ++++ > lib/eal/windows/rte_thread.c | 15 +++++++++++++++ > 4 files changed, 57 insertions(+) > > diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h > index 8da9d4d3fb..139cafac96 100644 > --- a/lib/eal/include/rte_thread.h > +++ b/lib/eal/include/rte_thread.h > @@ -183,6 +183,28 @@ int rte_thread_join(rte_thread_t thread_id, uint32_t *value_ptr); > */ > int rte_thread_detach(rte_thread_t thread_id); > > +/** > + * Allow another thread to run on the same CPU core. > + * > + * Lower priority threads may not be scheduled. > + * > + * Especially useful in real-time thread priority > + * to schedule other real-time threads. > + * @see RTE_THREAD_PRIORITY_REALTIME_CRITICAL > + */ > +__rte_experimental > +void rte_thread_yield(void); > + > +/** > + * Unblock a CPU core running busy in a real-time thread. > + * > + * Especially useful in real-time thread priority > + * to avoid a busy loop blocking vital threads on a core. > + * @see RTE_THREAD_PRIORITY_REALTIME_CRITICAL > + */ > +__rte_experimental > +void rte_thread_yield_realtime(void); > + > /** > * Get the id of the calling thread. > * > diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c > index 36a21ab2f9..92b4e53adb 100644 > --- a/lib/eal/unix/rte_thread.c > +++ b/lib/eal/unix/rte_thread.c > @@ -5,9 +5,11 @@ > > #include > #include > +#include > #include > #include > #include > +#include > > #include > #include > @@ -227,6 +229,20 @@ rte_thread_detach(rte_thread_t thread_id) > return pthread_detach((pthread_t)thread_id.opaque_id); > } > > +void > +rte_thread_yield(void) > +{ > + sched_yield(); > +} > + > +void > +rte_thread_yield_realtime(void) > +{ > + /* A simple yield may not be enough to schedule kernel threads. */ > + struct timespec wait = {.tv_nsec = 1}; > + nanosleep(&wait, NULL); > +} > + While I realise we discussed this earlier, and I also was the original suggester of using sched_yield, I think just having just one function using sleep is probably best after all. /Bruce