From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id C28844C8C for ; Tue, 16 Oct 2018 10:42:46 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2018 01:42:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,387,1534834800"; d="scan'208";a="82954474" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by orsmga006.jf.intel.com with ESMTP; 16 Oct 2018 01:42:44 -0700 Received: from irsmsx106.ger.corp.intel.com ([169.254.8.45]) by IRSMSX103.ger.corp.intel.com ([169.254.3.248]) with mapi id 14.03.0319.002; Tue, 16 Oct 2018 09:42:43 +0100 From: "Ananyev, Konstantin" To: "Yigit, Ferruh" , "Richardson, Bruce" CC: "dev@dpdk.org" , "Yigit, Ferruh" , "stephen@networkplumber.org" Thread-Topic: [dpdk-dev] [PATCH v2 1/2] eal: add API that sleeps while waiting for threads Thread-Index: AQHUZM0Sa+lwrSFHMkmwo2BXkK/MZKUhi8Tg Date: Tue, 16 Oct 2018 08:42:42 +0000 Message-ID: <2601191342CEEE43887BDE71AB9772580102FE7662@IRSMSX106.ger.corp.intel.com> References: <20181011195753.4778-1-ferruh.yigit@intel.com> <20181015222110.61564-1-ferruh.yigit@intel.com> In-Reply-To: <20181015222110.61564-1-ferruh.yigit@intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYjQwOTJjZTUtZmVjMS00NTExLWIwODMtY2RlODllNjVlMGNmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiTEY1N1ZORDVqV2JmZENzTERNOUthaFBjVnRyZ3lvYWJLNHdzaEE4dCsreUhLZnFycE55czdQcUNtaWFZdHZOcyJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2 1/2] eal: add API that sleeps while waiting for threads X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Oct 2018 08:42:47 -0000 HI Ferruh, > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Ferruh Yigit > Sent: Monday, October 15, 2018 11:21 PM > To: Richardson, Bruce > Cc: dev@dpdk.org; Yigit, Ferruh ; stephen@network= plumber.org > Subject: [dpdk-dev] [PATCH v2 1/2] eal: add API that sleeps while waiting= for threads >=20 > It is common that sample applications call rte_eal_wait_lcore() while > waiting for worker threads to be terminated. > Mostly master lcore keeps waiting in this function. >=20 > The waiting app for termination is not a time critical task, app can > prefer a sleep version of the waiting to consume less cycles. >=20 > A sleeping version of the API, rte_eal_wait_lcore_sleep(), has been > added which uses pthread conditions. >=20 > Sample applications will be updated later to use this API. >=20 > Signed-off-by: Ferruh Yigit > --- > v2: > * use pthread cond instead of usleep > --- > lib/librte_eal/bsdapp/eal/eal.c | 3 +++ > lib/librte_eal/bsdapp/eal/eal_thread.c | 7 ++++++ > lib/librte_eal/common/eal_common_launch.c | 22 ++++++++++++++++++ > lib/librte_eal/common/include/rte_launch.h | 26 ++++++++++++++++++++++ > lib/librte_eal/common/include/rte_lcore.h | 3 +++ > lib/librte_eal/linuxapp/eal/eal.c | 3 +++ > lib/librte_eal/linuxapp/eal/eal_thread.c | 7 ++++++ > lib/librte_eal/rte_eal_version.map | 1 + > 8 files changed, 72 insertions(+) >=20 > diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/= eal.c > index 7735194a3..e7d676657 100644 > --- a/lib/librte_eal/bsdapp/eal/eal.c > +++ b/lib/librte_eal/bsdapp/eal/eal.c > @@ -756,6 +756,9 @@ rte_eal_init(int argc, char **argv) > snprintf(thread_name, sizeof(thread_name), > "lcore-slave-%d", i); > rte_thread_setname(lcore_config[i].thread_id, thread_name); > + > + pthread_mutex_init(&rte_eal_thread_mutex[i], NULL); > + pthread_cond_init(&rte_eal_thread_cond[i], NULL); > } >=20 > /* > diff --git a/lib/librte_eal/bsdapp/eal/eal_thread.c b/lib/librte_eal/bsda= pp/eal/eal_thread.c > index 309b58726..60db32d57 100644 > --- a/lib/librte_eal/bsdapp/eal/eal_thread.c > +++ b/lib/librte_eal/bsdapp/eal/eal_thread.c > @@ -28,6 +28,9 @@ RTE_DEFINE_PER_LCORE(unsigned, _lcore_id) =3D LCORE_ID_= ANY; > RTE_DEFINE_PER_LCORE(unsigned, _socket_id) =3D (unsigned)SOCKET_ID_ANY; > RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset); >=20 > +pthread_cond_t rte_eal_thread_cond[RTE_MAX_LCORE]; > +pthread_mutex_t rte_eal_thread_mutex[RTE_MAX_LCORE]; I think would be better to include cond and mutex into struct lcore_config = itself, probably would help to avoid false sharing. Though yeh, it would mean ABI breakage, I suppose.=20 > + > /* > * Send a message to a slave lcore identified by slave_id to call a > * function f with argument arg. Once the execution is done, the > @@ -154,6 +157,10 @@ eal_thread_loop(__attribute__((unused)) void *arg) > lcore_config[lcore_id].ret =3D ret; > rte_wmb(); > lcore_config[lcore_id].state =3D FINISHED; > + > + pthread_mutex_lock(&rte_eal_thread_mutex[lcore_id]); > + pthread_cond_signal(&rte_eal_thread_cond[lcore_id]); > + pthread_mutex_unlock(&rte_eal_thread_mutex[lcore_id]); I understand it would work that way too, but if you introduce mutex and con= d around =20 the state, then it is better to manipulate/access the state after grabbing = the mutex. BTW in that case we don't need wmb: lcore_config[lcore_id].ret =3D ret; pthread_mutex_lock(...); lcore_config[lcore_id].state =3D FINISHED; pthread_cond_signal(..); pthread_mutex_unlock(...); Konstantin