From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150078.outbound.protection.outlook.com [40.107.15.78]) by dpdk.org (Postfix) with ESMTP id 86DBC5920 for ; Wed, 19 Dec 2018 09:30:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F1dzPmo24qT2RuxPyXVyNIQDOfOxNqYZyVuWn7zQ+Mo=; b=VybbvkStwtRXyOAPKrGgijZRkhNU/oz+3Kh1okQqTNWqMCR5cCEcNUW4mxEKmYflorAxgWylAN/VlrodzFqKUBatn+OpScmevz4gyjSZBAo8GQAJZ2C4exCzkblVmUp04nm4K263QbjQ145AwgdbaTOCmXQBj+KdJYBxajprr0U= Received: from VI1PR08MB3167.eurprd08.prod.outlook.com (52.133.15.142) by VI1PR08MB4160.eurprd08.prod.outlook.com (20.178.204.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1446.17; Wed, 19 Dec 2018 08:30:32 +0000 Received: from VI1PR08MB3167.eurprd08.prod.outlook.com ([fe80::b5a5:e179:34f1:7d21]) by VI1PR08MB3167.eurprd08.prod.outlook.com ([fe80::b5a5:e179:34f1:7d21%5]) with mapi id 15.20.1446.018; Wed, 19 Dec 2018 08:30:32 +0000 From: "Gavin Hu (Arm Technology China)" To: Honnappa Nagarahalli , Konstantin Ananyev , "dev@dpdk.org" CC: nd Thread-Topic: [dpdk-dev] [PATCH 1/2] rwlock: introduce 'try' semantics for RD and WR locking Thread-Index: AQHUe3Y4HvQhiFjHN0a0fJdFjQiXNqWF072AgAAfK5A= Date: Wed, 19 Dec 2018 08:30:32 +0000 Message-ID: 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-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Gavin.Hu@arm.com; x-originating-ip: [113.29.88.7] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR08MB4160; 6:gpaBIPv9grMOQn+D5YJCKOXLz5LbLyzpdQTtgu+T2wdpWAgusB/9lCjFb4wnmLBz/8E8govzII2l+chDvQD+VRuB+QD1EiMht5F81zbkEVZpRhJ2PDTV314ErscqxOLKdEuY0rjuf27kFWHJzCgWqoZNwyPQWmnEeM0CxzxyLEgwRzsQv2AMTKOWDSWenWCkEQqo+obixa6LcmsGFrxlDzbWeUW+22yrW2sCqX/hY3+ROV5xroZmxKBU8SH34UJ0VG30/f5yBSs5JVXomCZivXvs257AKs1g4aPPjDyIbvDOKkRj3ZzgVX5vze3u+nKpH2I0Y5RRNrGcfUap87pYnDMa1+WfEFOoI1UjPAKLsQxRTxD8meuK7saPLXEeTHBiq7ZjXxdBsZiox/NTAs/0ePhMmV10bScgkB85dFKPnO8gEFA3bE9QTcwDf/XpuwYhaoJ81ikQkvQGL60CA9iy3A==; 5:Jw5lcSd48A16+g6zueb7O1t5OBxp1Pjr9sQhLY08SPpD0ZB+DEzVwtksqdg5+mNAddx3TaSxsAee7JxV+APUNDoIs05ZsUYSr45p1EoXCTwEzhdRNdeocRyeq6UMDO1nlTGodbHuVe9xqGLRYQruF97G2dnhz6CacolJt59+vJ0=; 7:JuUAMqnd8bDQ+r35SLW30evGocnWeHD1yPBAUh2wooTI6g42+Dh6wmUCC7aZ4f+B3R/Pz8CqQAWFBXCKP6KVgzRJV5d6zzx2yPFNW66wwAZPAfEEbXFk4dC8xzBJncqsqWjLD0P8MEi97XL9DqAhUw== x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-ms-office365-filtering-correlation-id: 3e77b07d-bc07-45c3-65ac-08d6658c3d8f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR08MB4160; x-ms-traffictypediagnostic: VI1PR08MB4160: nodisclaimer: True x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231475)(944501520)(52105112)(3002001)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:VI1PR08MB4160; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB4160; x-forefront-prvs: 0891BC3F3D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(366004)(396003)(39860400002)(376002)(346002)(13464003)(189003)(199004)(71200400001)(106356001)(71190400001)(105586002)(7696005)(76176011)(81156014)(55016002)(8936002)(81166006)(6116002)(99286004)(53546011)(55236004)(6506007)(256004)(53936002)(316002)(14444005)(25786009)(7736002)(478600001)(2501003)(74316002)(72206003)(14454004)(5660300001)(9686003)(97736004)(305945005)(3846002)(6436002)(33656002)(26005)(6246003)(4326008)(446003)(11346002)(229853002)(476003)(66066001)(186003)(102836004)(86362001)(68736007)(110136005)(575784001)(2906002)(486006); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB4160; H:VI1PR08MB3167.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: aXSFrU1fpFhLixcHnAAV48tS8T5UyD1g+9458PSvc+y+MO2zqFsosXvot0ovUuxc0nOXuVXa6kkKDa6iIsZ1zY9Xo38OXVCwp0mJLS7nQdNuRo5PzGTvCAmllqFGeQTXlZdvPCy8KSpnwAZzYUo1hlHR5GQ+eIoU06xGqUF3xeAGdLBxYOzmyCBj+a1la8A8wAJfJv4NgvFnUJEILrDWhgAo4ypr3h+WAOyZMt9gG7C8W4oTj5tQ78g4+HTW9PSLa2CWVmjyMyeHyVAznNKLWfVcQks++eB0z4GJ3LDm3qtAfrXvsoMmRdU5UHMFQl6X spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e77b07d-bc07-45c3-65ac-08d6658c3d8f X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2018 08:30:32.0467 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4160 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 08:30:36 -0000 > -----Original Message----- > From: Honnappa Nagarahalli > Sent: Wednesday, December 19, 2018 2:38 PM > To: Konstantin Ananyev ; dev@dpdk.org > Cc: nd ; Honnappa Nagarahalli > ; Gavin Hu (Arm Technology China) > ; nd > Subject: RE: [dpdk-dev] [PATCH 1/2] rwlock: introduce 'try' semantics for= RD > and WR locking >=20 > > > > This patch targets 19.02 release. > > > > Introduce rte_rwlock_read_trylock() and rte_rwlock_write_trylock(). > > Signed-off-by: Konstantin Ananyev > > --- > > .../common/include/generic/rte_rwlock.h | 54 +++++++++++++++++++ > > lib/librte_eal/rte_eal_version.map | 2 + > > 2 files changed, 56 insertions(+) > > > > diff --git a/lib/librte_eal/common/include/generic/rte_rwlock.h > > b/lib/librte_eal/common/include/generic/rte_rwlock.h > > index 5751a0e6d..7e395781e 100644 > > --- a/lib/librte_eal/common/include/generic/rte_rwlock.h > > +++ b/lib/librte_eal/common/include/generic/rte_rwlock.h > > @@ -75,6 +75,33 @@ rte_rwlock_read_lock(rte_rwlock_t *rwl) > > } > > } > > > > +/** > Please add the experimental API warning >=20 > > + * try to take a read 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 reading because a > > + * writer holds the lock > > + */ > > +static inline __rte_experimental int > > +rte_rwlock_read_trylock(rte_rwlock_t *rwl) { > > + int32_t x; > > + int success =3D 0; > > + > > + while (success =3D=3D 0) { > > + x =3D rwl->cnt; > > + /* write lock is held */ > > + if (x < 0) > > + return -EBUSY; > > + success =3D rte_atomic32_cmpset((volatile uint32_t *)&rwl- > >cnt, > > + (uint32_t)x, (uint32_t)(x + 1)); > > + } > > + return 0; > > +} > > + > > /** > > * Release a read lock. > > * > > @@ -87,6 +114,33 @@ rte_rwlock_read_unlock(rte_rwlock_t *rwl) > > rte_atomic32_dec((rte_atomic32_t *)(intptr_t)&rwl->cnt); } > > > > +/** > Please add the experimental API warning >=20 > > + * 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) { > > + 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); > > + } > > + return 0; > > +} > > + > > /** > > * Take a write lock. Loop until the lock is held. > > * > > diff --git a/lib/librte_eal/rte_eal_version.map > > b/lib/librte_eal/rte_eal_version.map > > index 3fe78260d..8b1593dd8 100644 > > --- a/lib/librte_eal/rte_eal_version.map > > +++ b/lib/librte_eal/rte_eal_version.map > > @@ -355,6 +355,8 @@ EXPERIMENTAL { > > rte_mp_request_async; > > rte_mp_sendmsg; > > rte_option_register; > > + rte_rwlock_read_trylock; > > + rte_rwlock_write_trylock; > I do not see the other RW lock APIs in this file. >=20 > > rte_service_lcore_attr_get; > > rte_service_lcore_attr_reset_all; > > rte_service_may_be_active; > > -- > > 2.17.1 >=20 > Other than the minor comments, > Reviewed-by: Honnappa Nagarahalli Same comments as Honnappa, experimental warning is required in new code. Reviewed-by: Gavin Hu