From patchwork Tue Dec 18 05:03:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Yanjun X-Patchwork-Id: 10734829 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A2ED6C5 for ; Tue, 18 Dec 2018 04:58:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18C1A2A135 for ; Tue, 18 Dec 2018 04:58:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 095462A16B; Tue, 18 Dec 2018 04:58:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98A862A135 for ; Tue, 18 Dec 2018 04:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726567AbeLRE6S (ORCPT ); Mon, 17 Dec 2018 23:58:18 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:50228 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726312AbeLRE6S (ORCPT ); Mon, 17 Dec 2018 23:58:18 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBI4owCm099957; Tue, 18 Dec 2018 04:58:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id; s=corp-2018-07-02; bh=NNQrXNhaFPgzWg0WwTIpWcnjlN6br6TSnUNsa8nSjqU=; b=CPAi9TnxdYPFxoMN2+9P9ToUXqVmyPpv21RyXTC0oiIdjKFXAhrAJc/bePXSl/OXrG0m xcw9LNuMibo5EoOeE+x6kBhCWmwPrp+q4bUq8FnVy+Q9C/glRfCnfeMLJ+stpdXlwvHo I2mG7zrr3ch8ppkya9JUoNSj37N5L8QwmM4lOaM2bVI8gqnIBvzjEBQnJJeuTX4wfZ1D fbFEgrQ+TCur9H7ZUagJjw1RngNirV7t3fxkNgbtr4DLL+B5cWWBXCKXDYIyWTw1ugyf hKzlbUONp1FrxbFrbxFnX/8AXkAV6bHCZZCairIEjWPSlpHEvSuRliwnBr0HmqstXpOI 8A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2pcq4ds84q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Dec 2018 04:58:11 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wBI4w5j6031642 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Dec 2018 04:58:05 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wBI4w4vv002244; Tue, 18 Dec 2018 04:58:04 GMT Received: from shipboat.cn.oracle.com (/10.182.70.235) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 17 Dec 2018 20:58:04 -0800 From: Zhu Yanjun To: monis@mellanox.com, dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org Subject: [PATCH 1/1] IB: rxe: replace read/write locks with atomic bitops Date: Tue, 18 Dec 2018 00:03:34 -0500 Message-Id: <20181218050334.13459-1-yanjun.zhu@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9110 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=630 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812180042 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In rxe_pool.c, pool state is protected by some read/write locks. Now these read/write locks are replaced with atomic bitops. This can make source code compact. Signed-off-by: Zhu Yanjun --- drivers/infiniband/sw/rxe/rxe_pool.c | 22 +++++++--------------- drivers/infiniband/sw/rxe/rxe_pool.h | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c index 36b53fb94a49..1a7efe0e3bb1 100644 --- a/drivers/infiniband/sw/rxe/rxe_pool.c +++ b/drivers/infiniband/sw/rxe/rxe_pool.c @@ -222,7 +222,7 @@ int rxe_pool_init( pool->key_size = rxe_type_info[type].key_size; } - pool->state = RXE_POOL_STATE_VALID; + set_bit(RXE_POOL_STATE_VALID, &pool->state); out: return err; @@ -232,7 +232,7 @@ static void rxe_pool_release(struct kref *kref) { struct rxe_pool *pool = container_of(kref, struct rxe_pool, ref_cnt); - pool->state = RXE_POOL_STATE_INVALID; + set_bit(RXE_POOL_STATE_INVALID, &pool->state); kfree(pool->table); } @@ -243,14 +243,10 @@ static void rxe_pool_put(struct rxe_pool *pool) int rxe_pool_cleanup(struct rxe_pool *pool) { - unsigned long flags; - - write_lock_irqsave(&pool->pool_lock, flags); - pool->state = RXE_POOL_STATE_INVALID; + set_bit(RXE_POOL_STATE_INVALID, &pool->state); if (atomic_read(&pool->num_elem) > 0) pr_warn("%s pool destroyed with unfree'd elem\n", pool_name(pool)); - write_unlock_irqrestore(&pool->pool_lock, flags); rxe_pool_put(pool); @@ -380,17 +376,13 @@ void rxe_drop_index(void *arg) void *rxe_alloc(struct rxe_pool *pool) { struct rxe_pool_entry *elem; - unsigned long flags; might_sleep_if(!(pool->flags & RXE_POOL_ATOMIC)); - read_lock_irqsave(&pool->pool_lock, flags); - if (pool->state != RXE_POOL_STATE_VALID) { - read_unlock_irqrestore(&pool->pool_lock, flags); + if (!test_bit(RXE_POOL_STATE_VALID, &pool->state)) return NULL; - } + kref_get(&pool->ref_cnt); - read_unlock_irqrestore(&pool->pool_lock, flags); kref_get(&pool->rxe->ref_cnt); @@ -438,7 +430,7 @@ void *rxe_pool_get_index(struct rxe_pool *pool, u32 index) read_lock_irqsave(&pool->pool_lock, flags); - if (pool->state != RXE_POOL_STATE_VALID) + if (!test_bit(RXE_POOL_STATE_VALID, &pool->state)) goto out; node = pool->tree.rb_node; @@ -470,7 +462,7 @@ void *rxe_pool_get_key(struct rxe_pool *pool, void *key) read_lock_irqsave(&pool->pool_lock, flags); - if (pool->state != RXE_POOL_STATE_VALID) + if (!test_bit(RXE_POOL_STATE_VALID, &pool->state)) goto out; node = pool->tree.rb_node; diff --git a/drivers/infiniband/sw/rxe/rxe_pool.h b/drivers/infiniband/sw/rxe/rxe_pool.h index aa4ba307097b..5cc6b01c274d 100644 --- a/drivers/infiniband/sw/rxe/rxe_pool.h +++ b/drivers/infiniband/sw/rxe/rxe_pool.h @@ -94,7 +94,7 @@ struct rxe_pool { size_t elem_size; struct kref ref_cnt; void (*cleanup)(struct rxe_pool_entry *obj); - enum rxe_pool_state state; + unsigned long state; enum rxe_pool_flags flags; enum rxe_elem_type type;