From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60074.outbound.protection.outlook.com [40.107.6.74]) by dpdk.org (Postfix) with ESMTP id F05D11BB42 for ; Wed, 19 Dec 2018 07:37:38 +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=Wq/ufFcEMUvb0mrjwhPVLHrZOWRDxmR/lxk07mz5TCs=; b=pVFZHRw+TXZyHSlQucu+3pBOVQQG3vt/s5ZnkLCtVNvSkCbxQdf7Q23eHdSMBYREKhk60svpnXszejBrH+2b5ZQUgBxuJwEYotIIdbF1E+kX8SDz/sn991xAYVriTGOdhVQFl2wkU6BZzkJaxb1F3TEBUSP2+hMr08xm+r2TJUc= Received: from AM6PR08MB3672.eurprd08.prod.outlook.com (20.177.115.29) by AM6PR08MB3416.eurprd08.prod.outlook.com (20.177.113.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.22; Wed, 19 Dec 2018 06:37:37 +0000 Received: from AM6PR08MB3672.eurprd08.prod.outlook.com ([fe80::78ab:2bf4:5476:6c3e]) by AM6PR08MB3672.eurprd08.prod.outlook.com ([fe80::78ab:2bf4:5476:6c3e%2]) with mapi id 15.20.1446.018; Wed, 19 Dec 2018 06:37:37 +0000 From: Honnappa Nagarahalli To: Konstantin Ananyev , "dev@dpdk.org" CC: nd , Honnappa Nagarahalli , "Gavin Hu (Arm Technology China)" , nd Thread-Topic: [dpdk-dev] [PATCH 1/2] rwlock: introduce 'try' semantics for RD and WR locking Thread-Index: AQHUe3Y4LNv3q8oKTkmfFHzLgY5Wn6WFyidQ Date: Wed, 19 Dec 2018 06:37:37 +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: <1542130061-3702-2-git-send-email-konstantin.ananyev@intel.com> 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=Honnappa.Nagarahalli@arm.com; x-originating-ip: [217.140.103.75] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM6PR08MB3416; 6:gY3keo0y1oF5IDNQ1ZdsuLiohBoY0z1gWdRCBFhA3+Tj6RDJNi3psCPb0k43RwpVSGU8kTQZjGsNXK9S0gUK9WEczxmw0Tmpdj6igJY1qo7MjctjFW5MMbriKxlmSt0b2M+3QG+F5L5BnFzYAnm5nbKHxo4hspqjHfxVBduXcCMV7FuwrHHSQ4VX8JD4GEpBCqzcnYN3mupcyMdp0YBCLctLHj3R/d8CQEMA9s8DQdWo0Yut6T1CcR1+tmwgUQ6CXRx9S3muaDoiSL5ANex9QT0rDYsMndxDEZDSsPNJc/rfE2ooOjhsYXX06Q1jAAHLzpk8aSZsn1QtD1GrG2Y2qS18EDjNRGYV7QwnUudSBXJNqoYrysH0FL+Yg+C8GBim2JjcyyUXlTXS6blBFUlpvPjXZ1siruHiEi6wS7ks+NtBKMBs7YM1y9oEq3fZ9IODu9Jf745u7/GNW4hWwpe5ww==; 5:c/A/VPoeqvXM3s+h8DjzLZfoDiKviAEXj2r/pt0KlZysz2b/lU+jSurq2wfkQIN6btJlIqfUxaMSSiC+S/u6Ng7MUq4281Cj5aEXEndQSZboub6PxbEVW/KUi7b3oBSHGsCSpUbpYloxfY9hxSG1+WWSr5fu/UnYrkA3vCb0KZU=; 7:Ms6xW4ppIWC+JQfujBssHZSAvQkjiTo03V52Er+v1Xat6gx2EoMajAdYVmjLEhkHH0nHzqzhU/lT7sLMLBNn7DVIGbTfzT/7M1gL0a9dDUmF7/zS2ETinPt8Jn7cNKRIU22SN/RJ6bxcWT3ezMxv8g== x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-ms-office365-filtering-correlation-id: 75d51d5c-b288-4b42-3025-08d6657c77a0 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:AM6PR08MB3416; x-ms-traffictypediagnostic: AM6PR08MB3416: 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)(5005020)(6040522)(2401047)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231475)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:AM6PR08MB3416; BCL:0; PCL:0; RULEID:; SRVR:AM6PR08MB3416; x-forefront-prvs: 0891BC3F3D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(376002)(366004)(39860400002)(136003)(396003)(199004)(189003)(446003)(229853002)(5660300001)(99286004)(2501003)(33656002)(2906002)(97736004)(3846002)(7696005)(6506007)(11346002)(186003)(76176011)(26005)(486006)(476003)(102836004)(256004)(6116002)(54906003)(316002)(110136005)(7736002)(305945005)(14444005)(74316002)(86362001)(575784001)(81156014)(8936002)(81166006)(71200400001)(71190400001)(14454004)(53936002)(105586002)(106356001)(72206003)(25786009)(4326008)(6436002)(66066001)(6246003)(68736007)(478600001)(9686003)(55016002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR08MB3416; H:AM6PR08MB3672.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: vRpzxcdkqr65khTM6UoEaUpteCCplzK/mhFscBPqBwhH7u5lTcw9E2OfPwP/+lWlMIupY8cITAyaiO5En3WCEsxFp+hxGmTdiPRjvTlXWBm23fYCuJ6I2upGJy7Fclg6fgWqFWE+3Pn0W0RQ/lgK/uKVNwlkTnE2uXQ4tztq/c5/0Dot9vssJJIgr8rIGtV+0xlpTUMMpRg4+ezcbat6x8gawF78yrYY/XklEOsVNcZS6JAyXcl/MmZ1lSifPK3XRIgYV8TmTy+H6pUqJ9V5xUF31cSFq06hZy4XSy99kdKlsvdU+wyA8W6MZb/kTKZB 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: 75d51d5c-b288-4b42-3025-08d6657c77a0 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2018 06:37:37.5739 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3416 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 06:37:39 -0000 >=20 > This patch targets 19.02 release. >=20 > 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(+) >=20 > 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) > } > } >=20 > +/** Please add the experimental API warning > + * 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); } >=20 > +/** Please add the experimental API warning > + * 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. > rte_service_lcore_attr_get; > rte_service_lcore_attr_reset_all; > rte_service_may_be_active; > -- > 2.17.1 Other than the minor comments, Reviewed-by: Honnappa Nagarahalli