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 760F1A0C45; Tue, 24 Aug 2021 22:03:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E89A4406A3; Tue, 24 Aug 2021 22:03:20 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (unknown [40.107.6.64]) by mails.dpdk.org (Postfix) with ESMTP id 0A52140687 for ; Tue, 24 Aug 2021 22:03:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wXlYZMFGeD6Gcv3Kvtr5AxM4uw3RPoud/oJaa7+qiHU=; b=2P1qj9lqLWhgE/lz4iJzQzQuSp0h/asZK/QPs49A9YSIktlqLj0j8r6oWekwIEtglMyggsbkBezJ43bD7uXjlLd/xXNRhBTIl1xWWPeXETALGaodTNdD2R9BS3liKrRG17UIjlDv9PkzQbSZqmVuZqJlwYEbDrrQb3tNIy2gwEE= Received: from AM6PR05CA0033.eurprd05.prod.outlook.com (2603:10a6:20b:2e::46) by PAXPR08MB7043.eurprd08.prod.outlook.com (2603:10a6:102:1db::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.22; Tue, 24 Aug 2021 20:03:18 +0000 Received: from VE1EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2e:cafe::ba) by AM6PR05CA0033.outlook.office365.com (2603:10a6:20b:2e::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Tue, 24 Aug 2021 20:03:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dpdk.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dpdk.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT043.mail.protection.outlook.com (10.152.19.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.17 via Frontend Transport; Tue, 24 Aug 2021 20:03:17 +0000 Received: ("Tessian outbound 19a632698c93:v103"); Tue, 24 Aug 2021 20:03:17 +0000 X-CR-MTA-TID: 64aa7808 Received: from fe1915906907.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 80B3F4C7-6039-4165-9D5F-5F72DAA50626.1; Tue, 24 Aug 2021 20:03:07 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id fe1915906907.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 24 Aug 2021 20:03:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fkFPOaBr0DHr5oMzFxJc2sDVqt9X978+0eOnQOBVWVupXu1dKo03kBo0/FrkrwS6djJkOn+Uk/GYnOog+a8kqNykD2+UHK3zNjcHZbKeSgH4VPPNWpWmlTwDy2Ui9HCWtqnzGpc6EwrzaCj0PjT0U4j84FwZzyxDbI2XuX+ko74bTq37XkdmA+PVpk2Bj3J4P8QxORyVx5yUuhVxprXzeFAjeL9HjteqlOQkYVDdvEo0rdRw9huLBLFlGv9bmksJ2B5+SZHcw0oB53Ot1A8+/0szrlu/9K3oyDMVpcoYAwRrkgq4PkVT/b6OJFOBkGioIO+3pRD4S3LEYqckF2fDnw== 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-SenderADCheck; bh=wXlYZMFGeD6Gcv3Kvtr5AxM4uw3RPoud/oJaa7+qiHU=; b=jZn1tpfJsbUVNWe40n0WXFeOTJrdDBJpjIDsEJQUtOrXmtSEV4vFunCjq78YfKXnatKX1f6/rl0bZ7+MXAv1Z/3rXaRem/3mG/PCjB9hw/a+FUhZjTiG0mYtXEHg0J5czEGJsaGp0jQlOVoZEXSrDK/rdzXPq2DH4Z6AP4D5mHoizN6cks/CaBO+p8TlpP9zsrqJSgSwU0BexMwGfSHHzukA7wFTqb/I//mf2ix4jYQQeKxzshnhqaXtWS1ILWyd2QW6Cq6qVuHWm3ZOWN2bsfsbSIPjMEti5IT5FfMhZzJqdL/5GwDUBgGKBzaAdU6Xf8d9vXudAKir5b2yIIoz+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wXlYZMFGeD6Gcv3Kvtr5AxM4uw3RPoud/oJaa7+qiHU=; b=2P1qj9lqLWhgE/lz4iJzQzQuSp0h/asZK/QPs49A9YSIktlqLj0j8r6oWekwIEtglMyggsbkBezJ43bD7uXjlLd/xXNRhBTIl1xWWPeXETALGaodTNdD2R9BS3liKrRG17UIjlDv9PkzQbSZqmVuZqJlwYEbDrrQb3tNIy2gwEE= Received: from DBAPR08MB5814.eurprd08.prod.outlook.com (2603:10a6:10:1b1::6) by DBAPR08MB5734.eurprd08.prod.outlook.com (2603:10a6:10:1aa::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Tue, 24 Aug 2021 20:03:03 +0000 Received: from DBAPR08MB5814.eurprd08.prod.outlook.com ([fe80::ac8f:622:c2d4:9e6d]) by DBAPR08MB5814.eurprd08.prod.outlook.com ([fe80::ac8f:622:c2d4:9e6d%9]) with mapi id 15.20.4436.025; Tue, 24 Aug 2021 20:03:03 +0000 From: Honnappa Nagarahalli To: Olivier Matz CC: "dev@dpdk.org" , "lucp.at.work@gmail.com" , "david.marchand@redhat.com" , "thomas@monjalon.net" , Ruifeng Wang , nd , nd Thread-Topic: [RFC v2] eal: simplify the implementation of rte_ctrl_thread_create Thread-Index: AQHXmAf2H4CM5JFQ9Uaq02hO5DyJ6quDDf+w Date: Tue, 24 Aug 2021 20:03:03 +0000 Message-ID: References: <20210730213709.19400-1-honnappa.nagarahalli@arm.com> <20210802051652.3611-1-honnappa.nagarahalli@arm.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 49EBE9808A2BF0428481C52A67D0362E.0 x-checkrecipientchecked: true Authentication-Results-Original: 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=arm.com; x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: ea0fa65a-2169-422a-c0db-08d9673a36ff x-ms-traffictypediagnostic: DBAPR08MB5734:|PAXPR08MB7043: x-ld-processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:2449;OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: k4K3FfkLP1cWARZ8Kx5N5rQV2VMarg6OF4K/B5cK23zShKMBcnAekm5jnuGYiKTWxA5yK5q/7YVQS6rAjqzCjZbWjvvJnT+6FZIz8ZyVdCWJejWYMY3e3zbmuYwRoTfiX+eue02xuudcVPVF7aVq8d1PVWxx8tPh+q6haiXp+E6a2u/tlunzdEKBP8zjkn21B3zpOlznyKp/luOx7EuLfKD7Lip97BDDHlObhzUe+r86QW2Cm2EAATLoOBOWuky+lddWTb/wM0EjSqIp6rrMdVvQCfRhD+KyXM1532JyXqtU9fBdbfc1HTcGemiKs89dgxIPv9SbpUGwz2FDCZey59GtFLwPrcRSb+jlkkZNV62WZvUZ/A/8pMtewm/Vs+/MHnGLESq0VNQ6fEMj88tzXn77o/aC5C5ZMFTElOpg18Lq4Mm/mCq5tAo0K4uwODoZmmxABCgHR2xIogHWF6VlK3dDI1sQzlsADf0o8da3NTmanWLbBSAQjn9WvbCspTRlzYaAsD6fKu1SvWnjUc1z+pFfniCatPX3ty9Ev+CciX1OcYbFenLwEMAe7qUey/cVvjZfhFFTCJeOv0DXgoh0RaqD2t6dhhbzHVGAKtrlXazbxN58nB91cm8zlaCkxMZVRrj3A6EgBbz/ddBM64PodoqfeJXiP0gtsN+U9ID9AWBzvcvrdn81Fxhn+3i56EFs/utZaYz/2vTrvbCln1ugMQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBAPR08MB5814.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(396003)(346002)(376002)(39850400004)(366004)(66476007)(86362001)(66946007)(478600001)(66446008)(8676002)(64756008)(66556008)(76116006)(186003)(54906003)(38100700002)(8936002)(26005)(122000001)(2906002)(316002)(4326008)(6916009)(33656002)(71200400001)(9686003)(5660300002)(52536014)(38070700005)(6506007)(83380400001)(55016002)(7696005); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?szxFhFz5EynFMM+zwFLU0TkGul3y3hjPGdUb7PazhytJEXUeGrXuObYd3qhW?= =?us-ascii?Q?i/vRd6Ju3UI2u24nhoAVWloPlkNEOehMpPDCHmhbrstDhSyq7BpYprhX8PkL?= =?us-ascii?Q?sELpERyAxyJZVBPhjOwue+2hGotgc1yKcrEW7zLQGJf1khCX9T1zqvlsUSbj?= =?us-ascii?Q?CRlWwwWWce8BKmxdT7CMkWonh+k7xVvbsTXCouhQOqnIaSUZSp08RGt5mOFg?= =?us-ascii?Q?g4ZgCsYeOazIyoBGEtGtfDqGjig2BiduKmGluAiePf9VZAOSDRKBKAS9qW/H?= =?us-ascii?Q?DCpew8Tj/wnqgj/Q6Fm+xEQei5g6iIBxlRbIBJ/UY0zMG0CSE1T2HzOkFxpC?= =?us-ascii?Q?OmYm9ljf2r4MRD84CldOmZW7pRZKYnWq0YbXPw4Dl9gZVfD27IMlM9US8D4v?= =?us-ascii?Q?RuWlFAUnG8U/lc10lOw1cCwdbJdnLR69ol+1ULoLFUCwtrEnZWVUZFBG1dUU?= =?us-ascii?Q?6uQDnRKbj/pYT6CE4NsNV/7e6wYydvO27QEC03ilGflRFhO6MkuOBbn8kXV+?= =?us-ascii?Q?rAAyarWyAeFYXlVYSN+Czj3c4rpxnLvw/WUHPy04vskgi/HOTR5la554an0C?= =?us-ascii?Q?ZbM8shmdq03V37/vNN3s4tdly5wubAZz4wGudpbsO1nSqJJUtrIwcJ58KzMX?= =?us-ascii?Q?IHpugw4q5UQk96cUCVxsNDAEIBMj5e7xKZV6n06F4AqzZsEZHo3RWeI30hLf?= =?us-ascii?Q?YO6yJSaT7x2SBUS1cusk1ON0+7Obc9mdYFOwJThQOpx2uVnfWKC3/e+QarT3?= =?us-ascii?Q?u6LH4T8PKJVWPx/d4RsJa6n56xIE35yYW37/L7+H/jCaMDelUeM/0+9J34Bh?= =?us-ascii?Q?JsWbfsVpQrI3jq3/bBoTyh0qH/yUUKSwZqjfd34ZQXN1qS1DL6/VcyliqqTA?= =?us-ascii?Q?GwMoiOGyFaPcLfUlcbK2LYwAzRfeFbkHWptUPREdI2QgYmwtgaXUQv4FsaGv?= =?us-ascii?Q?qBIiTIdRPVBFSSEwAwj1Z2yLlBZZCcdr8bJATPvBTZIgXKDHTDmoqJf+Cuj3?= =?us-ascii?Q?M9n0mfT/7XgfGc1U9YaAnTcqRGGT6qz+vc6MMJbFX14+Qr8L/T2Iz3+XsXWh?= =?us-ascii?Q?eDfB3XbqS4q/vNQCX+7GZevY7Ps43or2MCcxr5/bb3PaniKh3XxaeIt2PzY9?= =?us-ascii?Q?LEfJ/cqQkOMfLrz23+5YGxTh5Ekuw9/p2I1gOG+fSN0wEqWXnV5veoeEVvdq?= =?us-ascii?Q?URieKS4cfkRh1DRSrCtb97jPJay4i7erPC582WHG9KZVBBJNLPn8nD2dqrM6?= =?us-ascii?Q?INGIxYf6BcGr8x4II8IYjrRUcaDKi4sVzH5PpvZACin9Le6gKEJrVfp8L4zZ?= =?us-ascii?Q?Z5hDTJvzUiErx7hNaqmULIuR?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR08MB5734 Original-Authentication-Results: 6wind.com; dkim=none (message not signed) header.d=none;6wind.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 4d36f2df-b8f9-4f3d-7eec-08d9673a2e66 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o9bp5x4Th56wA6f8NZVe7N1BKld95HeMq+c4dkh5ZcQpDuxKQmDoXKAQbXW+Ud6AHSOAx96bJLAgjptI1d/ZQXJ8TGZnKLgU4cB1CqWnaoCmtxkpwIbSsZOWKNPGAlHKo24h/dQuKtMFWTX8HxZr+aQ6AADya9bUn11JtmLvEVTaMwATyFMw5UTJuvb566RRWn/TcNDkDzwYQB982v0Ha6qDZMJ07puPRN9N8L7uFwvjOwEJ1KzECcUhUD2ouPxWUfRAGSKMdPXRXG6J1jhaFGV+74PaxCg5gUQmhx+UTeElk1otViQVKaZiefXkFiiiPTMkOyt/eY74ZUvrOQb2eaMINOo2pLSH8rodO+yfwmIkl9/HtRIkC1fUxr6KfjQwc6LFsyQLmJg9cyq8lC9Sgt5nA38dyRG4dT2E65qm6Zeel7HOBHFGt2EU2P/k7u+6UOEUEt2n1CpyxupBX1BRc81/6dS2sc5hiOM7tlh0wDGmtV78tPjUy1xChsENqz6JsiIWXlGZAAqadLAsPpuZ9iZLGuVKDOKCxwpXDJuHFHvKSSYN63WP414YB4nn87WWVhcYkEe04fte8V4NJnwsVutgrmZCOaw4M5vCOVzSjZNgUwQN0HWCRwWs/HpGJ/h0jnqsvfz2LCCHK+gpCPy+pQ5d0bUih6qtbrpYoqsy/vVAwaevAEV25LyQc6zzTKMoJMyx5J9242cKYGPcnenMCg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(186003)(26005)(70586007)(6506007)(8676002)(8936002)(83380400001)(82310400003)(54906003)(70206006)(316002)(7696005)(81166007)(47076005)(336012)(2906002)(508600001)(9686003)(52536014)(4326008)(55016002)(86362001)(356005)(36860700001)(33656002)(6862004)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2021 20:03:17.6731 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ea0fa65a-2169-422a-c0db-08d9673a36ff X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB7043 Subject: Re: [dpdk-dev] [RFC v2] eal: simplify the implementation of rte_ctrl_thread_create 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 Sender: "dev" >=20 > Hi Honnappa, >=20 > On Mon, Aug 02, 2021 at 12:16:52AM -0500, Honnappa Nagarahalli wrote: > > The current described behaviour of rte_ctrl_thread_create is rigid > > which makes the implementation of the function complex. > > The behavior is abstracted to allow for simplified implementation. >=20 > I agree that the behavior description should not reference the pthread > functions, however I don't think the current description prevents from re= writing > the code as you do. Ok >=20 > I think it would be better to explain in commit log why the proposed code= is > simpler than the current one. >=20 > > Signed-off-by: Honnappa Nagarahalli > > --- > > v2: Used compiler's C++11 atomic built-ins to access the shared variabl= e. > > > > lib/eal/common/eal_common_thread.c | 65 +++++++++++++----------------- > > lib/eal/include/rte_lcore.h | 8 ++-- > > 2 files changed, 32 insertions(+), 41 deletions(-) > > > > diff --git a/lib/eal/common/eal_common_thread.c > > b/lib/eal/common/eal_common_thread.c > > index 1a52f42a2b..e3e0bf4bff 100644 > > --- a/lib/eal/common/eal_common_thread.c > > +++ b/lib/eal/common/eal_common_thread.c > > @@ -169,35 +169,35 @@ __rte_thread_uninit(void) struct > > rte_thread_ctrl_params { > > void *(*start_routine)(void *); > > void *arg; > > - pthread_barrier_t configured; > > - unsigned int refcnt; > > + int ret; > > + /* Synchronization variable between the control thread > > + * and the thread calling rte_ctrl_thread_create function. > > + * 0 - Initialized > > + * 1 - Control thread is running successfully > > + * 2 - Control thread encountered an error. 'ret' has the > > + * error code. > > + */ > > + unsigned int sync; >=20 > what do you think about using an enum or defines? Will use defines >=20 > > }; > > > > -static void ctrl_params_free(struct rte_thread_ctrl_params *params) > > -{ > > - if (__atomic_sub_fetch(¶ms->refcnt, 1, __ATOMIC_ACQ_REL) =3D=3D > 0) { > > - (void)pthread_barrier_destroy(¶ms->configured); > > - free(params); > > - } > > -} > > - > > static void *ctrl_thread_init(void *arg) { > > struct internal_config *internal_conf =3D > > eal_get_internal_configuration(); > > rte_cpuset_t *cpuset =3D &internal_conf->ctrl_cpuset; > > struct rte_thread_ctrl_params *params =3D arg; > > - void *(*start_routine)(void *); > > + void *(*start_routine)(void *) =3D params->start_routine; > > void *routine_arg =3D params->arg; > > > > __rte_thread_init(rte_lcore_id(), cpuset); > > - > > - pthread_barrier_wait(¶ms->configured); > > - start_routine =3D params->start_routine; > > - ctrl_params_free(params); > > - > > - if (start_routine =3D=3D NULL) > > + params->ret =3D pthread_setaffinity_np(pthread_self(), > > + sizeof(*cpuset), cpuset); > > + if (params->ret !=3D 0) { > > + __atomic_store_n(¶ms->sync, 2, __ATOMIC_RELEASE); > > return NULL; > > + } >=20 > Sorry if the question is stupid (I'm still not familiar with C++11 atomic= built-ins), > but do we have the assurance that params->ret is set in memory before > params->sync is set? See below at [1]. Yes, the '__ATOMIC_RELEASE' store ensures that all prior memory operations = are completed before 'sync' is updated. >=20 > > + > > + __atomic_store_n(¶ms->sync, 1, __ATOMIC_RELEASE); > > > > return start_routine(routine_arg); > > } > > @@ -207,9 +207,6 @@ rte_ctrl_thread_create(pthread_t *thread, const cha= r > *name, > > const pthread_attr_t *attr, > > void *(*start_routine)(void *), void *arg) { > > - struct internal_config *internal_conf =3D > > - eal_get_internal_configuration(); > > - rte_cpuset_t *cpuset =3D &internal_conf->ctrl_cpuset; > > struct rte_thread_ctrl_params *params; > > int ret; > > > > @@ -219,15 +216,12 @@ rte_ctrl_thread_create(pthread_t *thread, const > > char *name, > > > > params->start_routine =3D start_routine; > > params->arg =3D arg; > > - params->refcnt =3D 2; > > - > > - ret =3D pthread_barrier_init(¶ms->configured, NULL, 2); > > - if (ret !=3D 0) > > - goto fail_no_barrier; > > + params->ret =3D 0; > > + params->sync =3D 0; > > > > ret =3D pthread_create(thread, attr, ctrl_thread_init, (void *)params= ); > > if (ret !=3D 0) > > - goto fail_with_barrier; > > + goto thread_create_failed; > > > > if (name !=3D NULL) { > > ret =3D rte_thread_setname(*thread, name); @@ -236,24 > +230,21 @@ > > rte_ctrl_thread_create(pthread_t *thread, const char *name, > > "Cannot set name for ctrl thread\n"); > > } > > > > - ret =3D pthread_setaffinity_np(*thread, sizeof(*cpuset), cpuset); > > - if (ret !=3D 0) > > - params->start_routine =3D NULL; > > + /* Wait for the control thread to initialize successfully */ > > + while (!__atomic_load_n(¶ms->sync, __ATOMIC_ACQUIRE)) > > + rte_pause(); >=20 > One difference between this implementation and the previous one is this b= usy > loop. rte_pause() relaxes the cpu, but will not make the calling thread t= o sleep > and wait for the sync event. So here we can spin a quite long time until = the > other thread is scheduled by the OS. Yes, this is a difference. We could add a microsleep to allow for the OS to= un-schedule the current thread. >=20 > > + ret =3D params->ret; >=20 > [1] >=20 > Here, it is expected that when params->ret is seen as set before > param->sync. Yes, the __ATOMIC_ACQUIRE load ensures that the params->ret is loaded only = after params->sync is loaded. >=20 > > > > - pthread_barrier_wait(¶ms->configured); > > - ctrl_params_free(params); > > + free(params); > > > > - if (ret !=3D 0) > > - /* start_routine has been set to NULL above; */ > > - /* ctrl thread will exit immediately */ > > + if (__atomic_load_n(¶ms->sync, __ATOMIC_ACQUIRE) !=3D 1) >=20 > it suggest =3D=3D instead of !=3D, like this: >=20 > if (__atomic_load_n(¶ms->sync, __ATOMIC_ACQUIRE) =3D=3D > CTRL_THREAD_ERR) Ok >=20 >=20 > > + /* ctrl thread is exiting */ > > pthread_join(*thread, NULL); > > > > return -ret; > > > > -fail_with_barrier: > > - (void)pthread_barrier_destroy(¶ms->configured); > > +thread_create_failed: > > > > -fail_no_barrier: > > free(params); > > > > return -ret; > > diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h > > index 1550b75da0..f1cc5e38dc 100644 > > --- a/lib/eal/include/rte_lcore.h > > +++ b/lib/eal/include/rte_lcore.h > > @@ -420,10 +420,10 @@ rte_thread_unregister(void); > > /** > > * Create a control thread. > > * > > - * Wrapper to pthread_create(), pthread_setname_np() and > > - * pthread_setaffinity_np(). The affinity of the new thread is based > > - * on the CPU affinity retrieved at the time rte_eal_init() was > > called, > > - * the dataplane and service lcores are then excluded. > > + * Creates a control thread with the given name and attributes. The > > + * affinity of the new thread is based on the CPU affinity retrieved > > + * at the time rte_eal_init() was called, the dataplane and service > > + * lcores are then excluded. >=20 > The description is indeed better. Maybe it is the opportunity to highligh= t that if > the name cannot be set, no error is returned, see commit 368a91d6bdc8 ("e= al: > ignore failure of naming a control thread") Makes sense, will add. >=20 > > * > > * @param thread > > * Filled with the thread id of the new created thread. > > -- > > 2.17.1 > >