From patchwork Wed Nov 24 21:40:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12637933 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 014CFC433EF for ; Wed, 24 Nov 2021 21:40:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235640AbhKXVnl (ORCPT ); Wed, 24 Nov 2021 16:43:41 -0500 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:49560 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbhKXVnk (ORCPT ); Wed, 24 Nov 2021 16:43:40 -0500 Received: from pop-os.home ([86.243.171.122]) by smtp.orange.fr with ESMTPA id q00BmS3woBazoq00CmFPjq; Wed, 24 Nov 2021 22:40:29 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Wed, 24 Nov 2021 22:40:29 +0100 X-ME-IP: 86.243.171.122 From: Christophe JAILLET To: bharat@chelsio.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 1/3] RDMA/cxgb4: Use bitmap_zalloc() when applicable Date: Wed, 24 Nov 2021 22:40:24 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Use 'bitmap_zalloc()' to simplify code, improve the semantic and avoid some open-coded arithmetic in allocator arguments. Using the 'zalloc' version of the allocator also saves a now useless 'bitmap_zero()' call. Also change the corresponding 'kfree()' into 'bitmap_free()' to keep consistency. While at it, remove an extra space in a statement just a few lines above. Signed-off-by: Christophe JAILLET --- drivers/infiniband/hw/cxgb4/id_table.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/cxgb4/id_table.c b/drivers/infiniband/hw/cxgb4/id_table.c index 724d23297b35..9d08a48c4926 100644 --- a/drivers/infiniband/hw/cxgb4/id_table.c +++ b/drivers/infiniband/hw/cxgb4/id_table.c @@ -90,14 +90,12 @@ int c4iw_id_table_alloc(struct c4iw_id_table *alloc, u32 start, u32 num, alloc->last = prandom_u32() % RANDOM_SKIP; else alloc->last = 0; - alloc->max = num; + alloc->max = num; spin_lock_init(&alloc->lock); - alloc->table = kmalloc_array(BITS_TO_LONGS(num), sizeof(long), - GFP_KERNEL); + alloc->table = bitmap_zalloc(num, GFP_KERNEL); if (!alloc->table) return -ENOMEM; - bitmap_zero(alloc->table, num); if (!(alloc->flags & C4IW_ID_TABLE_F_EMPTY)) for (i = 0; i < reserved; ++i) set_bit(i, alloc->table); @@ -107,5 +105,5 @@ int c4iw_id_table_alloc(struct c4iw_id_table *alloc, u32 start, u32 num, void c4iw_id_table_free(struct c4iw_id_table *alloc) { - kfree(alloc->table); + bitmap_free(alloc->table); } From patchwork Wed Nov 24 21:40:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12637935 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00410C433EF for ; Wed, 24 Nov 2021 21:40:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242430AbhKXVnn (ORCPT ); Wed, 24 Nov 2021 16:43:43 -0500 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:56187 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241959AbhKXVnm (ORCPT ); Wed, 24 Nov 2021 16:43:42 -0500 Received: from pop-os.home ([86.243.171.122]) by smtp.orange.fr with ESMTPA id q00BmS3woBazoq00FmFPk9; Wed, 24 Nov 2021 22:40:31 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Wed, 24 Nov 2021 22:40:31 +0100 X-ME-IP: 86.243.171.122 From: Christophe JAILLET To: bharat@chelsio.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 2/3] RDMA/cxgb4: Use bitmap_set() when applicable Date: Wed, 24 Nov 2021 22:40:25 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The 'alloc->table' bitmap has just been allocated, so this is safe to use the faster and non-atomic 'bitmap_set()' function. There is no need to hand-write it. Signed-off-by: Christophe JAILLET --- drivers/infiniband/hw/cxgb4/id_table.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/cxgb4/id_table.c b/drivers/infiniband/hw/cxgb4/id_table.c index 9d08a48c4926..e09faa659d68 100644 --- a/drivers/infiniband/hw/cxgb4/id_table.c +++ b/drivers/infiniband/hw/cxgb4/id_table.c @@ -82,8 +82,6 @@ void c4iw_id_free(struct c4iw_id_table *alloc, u32 obj) int c4iw_id_table_alloc(struct c4iw_id_table *alloc, u32 start, u32 num, u32 reserved, u32 flags) { - int i; - alloc->start = start; alloc->flags = flags; if (flags & C4IW_ID_TABLE_F_RANDOM) @@ -97,8 +95,7 @@ int c4iw_id_table_alloc(struct c4iw_id_table *alloc, u32 start, u32 num, return -ENOMEM; if (!(alloc->flags & C4IW_ID_TABLE_F_EMPTY)) - for (i = 0; i < reserved; ++i) - set_bit(i, alloc->table); + bitmap_set(alloc->table, 0, reserved); return 0; } From patchwork Wed Nov 24 21:40:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12637937 X-Patchwork-Delegate: jgg@ziepe.ca Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77D0BC433F5 for ; Wed, 24 Nov 2021 21:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243542AbhKXVnr (ORCPT ); Wed, 24 Nov 2021 16:43:47 -0500 Received: from smtp02.smtpout.orange.fr ([80.12.242.124]:52768 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242390AbhKXVnn (ORCPT ); Wed, 24 Nov 2021 16:43:43 -0500 Received: from pop-os.home ([86.243.171.122]) by smtp.orange.fr with ESMTPA id q00BmS3woBazoq00GmFPkK; Wed, 24 Nov 2021 22:40:32 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Wed, 24 Nov 2021 22:40:32 +0100 X-ME-IP: 86.243.171.122 From: Christophe JAILLET To: bharat@chelsio.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 3/3] RDMA/cxgb4: Use non-atomic bitmap functions when possible Date: Wed, 24 Nov 2021 22:40:26 +0100 Message-Id: <0c1c4505ca32f5ba4126e3e324041da191513ef2.1637789139.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The accesses to the 'alloc->table' bitmap are protected by the 'alloc->lock' spinlock, so no concurrent accesses can happen. So prefer the non-atomic '__[set|clear]_bit()' functions to save a few cycles. Signed-off-by: Christophe JAILLET --- drivers/infiniband/hw/cxgb4/id_table.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/cxgb4/id_table.c b/drivers/infiniband/hw/cxgb4/id_table.c index e09faa659d68..f64e7e02b129 100644 --- a/drivers/infiniband/hw/cxgb4/id_table.c +++ b/drivers/infiniband/hw/cxgb4/id_table.c @@ -59,7 +59,7 @@ u32 c4iw_id_alloc(struct c4iw_id_table *alloc) alloc->last = obj + 1; if (alloc->last >= alloc->max) alloc->last = 0; - set_bit(obj, alloc->table); + __set_bit(obj, alloc->table); obj += alloc->start; } else obj = -1; @@ -75,7 +75,7 @@ void c4iw_id_free(struct c4iw_id_table *alloc, u32 obj) obj -= alloc->start; spin_lock_irqsave(&alloc->lock, flags); - clear_bit(obj, alloc->table); + __clear_bit(obj, alloc->table); spin_unlock_irqrestore(&alloc->lock, flags); }