From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id A99151B445 for ; Wed, 19 Dec 2018 17:27:45 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2018 08:27:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,373,1539673200"; d="scan'208";a="285037205" Received: from irsmsx105.ger.corp.intel.com ([163.33.3.28]) by orsmga005.jf.intel.com with ESMTP; 19 Dec 2018 08:27:43 -0800 Received: from irsmsx106.ger.corp.intel.com ([169.254.8.227]) by irsmsx105.ger.corp.intel.com ([169.254.7.247]) with mapi id 14.03.0415.000; Wed, 19 Dec 2018 16:27:42 +0000 From: "Ananyev, Konstantin" To: Honnappa Nagarahalli , "dev@dpdk.org" CC: nd , "Gavin Hu (Arm Technology China)" , nd Thread-Topic: [dpdk-dev] [PATCH 1/2] rwlock: introduce 'try' semantics for RD and WR locking Thread-Index: AQHUl2Vivm9vJQwvFEOiztSJI2zTxKWGK2kAgAAU44A= Date: Wed, 19 Dec 2018 16:27:42 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258010D8BC9AE@IRSMSX106.ger.corp.intel.com> References: <1542130061-3702-1-git-send-email-konstantin.ananyev@intel.com> <1542130061-3702-2-git-send-email-konstantin.ananyev@intel.com> In-Reply-To: Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMzc3MWJiN2YtODE4Ny00M2YwLThiOTYtOTU0MGY5MzgyMGY2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoielRPczFwTUZtcmZkQmt5TWdIXC9iYTdoY1dEXC9OcW00UW9JdEdFaGtIZFdoSTF4c1dxZjNFMHRHeEl0VHlTMmVXIn0= x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 1/2] rwlock: introduce 'try' semantics for RD and WR locking 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: Wed, 19 Dec 2018 16:27:46 -0000 > > > + * try to take a write lock. > > > + * > > > + * @param rwl > > > + * A pointer to a rwlock structure. > > > + * @return > > > + * - zero if the lock is successfully taken > > > + * - -EBUSY if lock could not be acquired for writing because > > > + * it was already locked for reading or writing > > > + */ > > > +static inline __rte_experimental int > > > +rte_rwlock_write_trylock(rte_rwlock_t *rwl) { > > > + int32_t x; > > > + int success =3D 0; > > > + > > > + while (success =3D=3D 0) { > (Apologies for not thinking through all my comments earlier) > I am wondering if the 'while' loop is required for the write lock. >=20 > > > + x =3D rwl->cnt; > > > + /* a lock is held */ > > > + if (x !=3D 0) > > > + return -EBUSY; > > > + success =3D rte_atomic32_cmpset((volatile uint32_t *)&rwl->cnt, > > > + 0, (uint32_t)-1); > This might fail as the lock was taken (either reader or writer). We shoul= d return from here as it already indicates that the lock is not > available for the writer to take. Otherwise, there is a possibility that = the while loop will run for multiple iterations. I would think, from the > user's expectation, it might not be correct. Good point - it will also save us extra read in case of failure. Will change in v2. Konstantin >=20 > In the read_trylock, the while loop should be fine because the write lock= itself is not held. The failure could be because some other reader > incremented the counter before we did. i.e. the reader lock itself may be= available to take in the next iteration. >=20 > > > + } > > > + return 0; > > > +} > > > + >