From patchwork Thu May 4 22:00:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 98587 Delivered-To: patch@linaro.org Received: by 10.140.89.200 with SMTP id v66csp831835qgd; Thu, 4 May 2017 15:01:27 -0700 (PDT) X-Received: by 10.200.34.162 with SMTP id f31mr41442291qta.65.1493935287253; Thu, 04 May 2017 15:01:27 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o71si2820171qke.72.2017.05.04.15.01.27; Thu, 04 May 2017 15:01:27 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id DC1E760A35; Thu, 4 May 2017 22:01:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id EC74360747; Thu, 4 May 2017 22:00:37 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3CDBD6095C; Thu, 4 May 2017 22:00:29 +0000 (UTC) Received: from forward2o.cmail.yandex.net (forward2o.cmail.yandex.net [37.9.109.243]) by lists.linaro.org (Postfix) with ESMTPS id 920BF6091D for ; Thu, 4 May 2017 22:00:27 +0000 (UTC) Received: from smtp1o.mail.yandex.net (smtp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::25]) by forward2o.cmail.yandex.net (Yandex) with ESMTP id 294E1207F7 for ; Fri, 5 May 2017 01:00:26 +0300 (MSK) Received: from smtp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp1o.mail.yandex.net (Yandex) with ESMTP id 07299130099E for ; Fri, 5 May 2017 01:00:25 +0300 (MSK) Received: by smtp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id GWvRAGZNCj-0OHuL8NT; Fri, 05 May 2017 01:00:24 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Fri, 5 May 2017 01:00:08 +0300 Message-Id: <1493935208-7891-3-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493935208-7891-1-git-send-email-odpbot@yandex.ru> References: <1493935208-7891-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 19 Subject: [lng-odp] [PATCH v1 1/2] linux-generic: rwlock: fix odp_rwlock_read_trylock() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov odp_rwlock_read_trylock() currently works only if there are no readers (and writers) as it compares counter with 0. Make it actually work in case there are other active readers. Fixes: https://bugs.linaro.org/show_bug.cgi?id=2974 Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 19 (lumag:fix-rwlock) ** https://github.com/Linaro/odp/pull/19 ** Patch: https://github.com/Linaro/odp/pull/19.patch ** Base sha: 79ba737a404d2833ad33d8f84ed6ce82c9a8c18e ** Merge commit sha: 8448157882fac03287253bf54c19284b6d52246e **/ platform/linux-generic/odp_rwlock.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/odp_rwlock.c b/platform/linux-generic/odp_rwlock.c index 13c17a2..5bef13a 100644 --- a/platform/linux-generic/odp_rwlock.c +++ b/platform/linux-generic/odp_rwlock.c @@ -33,9 +33,14 @@ void odp_rwlock_read_lock(odp_rwlock_t *rwlock) int odp_rwlock_read_trylock(odp_rwlock_t *rwlock) { - uint32_t zero = 0; + uint32_t cnt = odp_atomic_load_u32(&rwlock->cnt); + + while (cnt != (uint32_t)-1) { + if (odp_atomic_cas_acq_u32(&rwlock->cnt, &cnt, cnt + 1)) + return 1; + } - return odp_atomic_cas_acq_u32(&rwlock->cnt, &zero, (uint32_t)1); + return 0; } void odp_rwlock_read_unlock(odp_rwlock_t *rwlock) From patchwork Thu May 4 22:00:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 98586 Delivered-To: patch@linaro.org Received: by 10.140.89.200 with SMTP id v66csp831555qgd; Thu, 4 May 2017 15:00:59 -0700 (PDT) X-Received: by 10.55.119.5 with SMTP id s5mr10078091qkc.32.1493935259290; Thu, 04 May 2017 15:00:59 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 46si2833879qte.210.2017.05.04.15.00.58; Thu, 04 May 2017 15:00:59 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id D1F4260950; Thu, 4 May 2017 22:00:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id A3EB360609; Thu, 4 May 2017 22:00:34 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B13AB6095E; Thu, 4 May 2017 22:00:28 +0000 (UTC) Received: from forward2m.cmail.yandex.net (forward2m.cmail.yandex.net [5.255.216.20]) by lists.linaro.org (Postfix) with ESMTPS id 430EF60880 for ; Thu, 4 May 2017 22:00:27 +0000 (UTC) Received: from smtp1o.mail.yandex.net (smtp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::25]) by forward2m.cmail.yandex.net (Yandex) with ESMTP id 8C65421699 for ; Fri, 5 May 2017 01:00:24 +0300 (MSK) Received: from smtp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp1o.mail.yandex.net (Yandex) with ESMTP id 298811300AAE for ; Fri, 5 May 2017 01:00:23 +0300 (MSK) Received: by smtp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id GWvRAGZNCj-0NHWufHK; Fri, 05 May 2017 01:00:23 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Suid-Status: 1 0 From: Github ODP bot To: lng-odp@lists.linaro.org Date: Fri, 5 May 2017 01:00:07 +0300 Message-Id: <1493935208-7891-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493935208-7891-1-git-send-email-odpbot@yandex.ru> References: <1493935208-7891-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 19 Subject: [lng-odp] [PATCH v1 2/2] test: lock: expand rwlock tests X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Expand testsuite for rwlocks: - always verify _trylock return code - always unlock after successful _trylock return - try calling _trylock when holding write lock Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 19 (lumag:fix-rwlock) ** https://github.com/Linaro/odp/pull/19 ** Patch: https://github.com/Linaro/odp/pull/19.patch ** Base sha: 79ba737a404d2833ad33d8f84ed6ce82c9a8c18e ** Merge commit sha: 8448157882fac03287253bf54c19284b6d52246e **/ test/common_plat/validation/api/lock/lock.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/common_plat/validation/api/lock/lock.c b/test/common_plat/validation/api/lock/lock.c index bd9a2aa..f8a1d8c 100644 --- a/test/common_plat/validation/api/lock/lock.c +++ b/test/common_plat/validation/api/lock/lock.c @@ -257,7 +257,7 @@ static int ticketlock_api_tests(void *arg UNUSED) static void rwlock_api_test(odp_rwlock_t *rw_lock) { - int rc; + int rc = 0; odp_rwlock_init(rw_lock); /* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 0); */ @@ -265,23 +265,40 @@ static void rwlock_api_test(odp_rwlock_t *rw_lock) odp_rwlock_read_lock(rw_lock); rc = odp_rwlock_read_trylock(rw_lock); - CU_ASSERT(rc == 0); + CU_ASSERT(rc != 0); + if (rc == 1) + odp_rwlock_read_unlock(rw_lock); + rc = odp_rwlock_write_trylock(rw_lock); CU_ASSERT(rc == 0); + if (rc == 1) + odp_rwlock_write_unlock(rw_lock); odp_rwlock_read_unlock(rw_lock); rc = odp_rwlock_read_trylock(rw_lock); + CU_ASSERT(rc != 0); if (rc == 1) odp_rwlock_read_unlock(rw_lock); odp_rwlock_write_lock(rw_lock); /* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 1); */ + rc = odp_rwlock_read_trylock(rw_lock); + CU_ASSERT(rc == 0); + if (rc == 1) + odp_rwlock_read_unlock(rw_lock); + + rc = odp_rwlock_write_trylock(rw_lock); + CU_ASSERT(rc == 0); + if (rc == 1) + odp_rwlock_write_unlock(rw_lock); + odp_rwlock_write_unlock(rw_lock); /* CU_ASSERT(odp_rwlock_is_locked(rw_lock) == 0); */ rc = odp_rwlock_write_trylock(rw_lock); + CU_ASSERT(rc != 0); if (rc == 1) odp_rwlock_write_unlock(rw_lock); }