From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D313CC432BE for ; Tue, 31 Aug 2021 12:00:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE69B61008 for ; Tue, 31 Aug 2021 12:00:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbhHaMBG (ORCPT ); Tue, 31 Aug 2021 08:01:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:45672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231628AbhHaMBG (ORCPT ); Tue, 31 Aug 2021 08:01:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5DC9B60698; Tue, 31 Aug 2021 12:00:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630411211; bh=ZFNfZfl6mxHUw1BbBnsrpBxFD/PkIeH8i0iIstK7Ax0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Qwa98a0S/WoF27sbrqu6L5GbtO7FRvnn67IpsP9e51mw5236R/LddXVcCxB6Mr8/1 AvnTXGJQPIG2gxlXoJZJ7Wn8LScNgQVmK5mZbgkEpW6bU5so7HtaNOob0Vtx+pLbxl kjegD7XFZT7p4WtiexRLVBlKDvGf6JFpvmswSet+ppf0uxLEtF+T2nQC20T6dhdZOj U7Ro1riXh95Ku5NOJcRAySwVnYXg7fIminTBWfVw0o1s46WKllEdPTuFUsoNo8sTyD 88S1kGKTQ1+qyxq1LtG47JRmMmJ+NNeL8wtpTiUNbXxvR78Gn5rReSkzMZGvMc4mW4 Wvd5fr6LrQXxQ== Date: Tue, 31 Aug 2021 15:00:07 +0300 From: Leon Romanovsky To: =?utf-8?B?5bq35a6B?= Cc: haakon.bugge@oracle.com, linux-rdma@vger.kernel.org Subject: Re: Re: [PATCH v3] Fix one error in mthca_alloc Message-ID: References: <20210827005228.15671-1-kangning18z@ict.ac.cn> <30f8792b.1e35e.17b9bcbf058.Coremail.kangning18z@ict.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <30f8792b.1e35e.17b9bcbf058.Coremail.kangning18z@ict.ac.cn> Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org On Tue, Aug 31, 2021 at 06:40:38PM +0800, 康宁 wrote: > > > > On Fri, Aug 27, 2021 at 08:52:28AM +0800, kangning wrote: > > > drivers/infiniband/hw/mthca/mthca_allocator.c: alloc->last left unchanged in mthca_alloc, which > > > has impact on performance of function find_next_zero_bit in mthca_alloc. > > > > I don't know what the sentence above means, but the change is unlikely > > to be correct. > > > > When alloc->last starts to be equal to alloc->max, the > > find_next_zero_bit() will always return alloc->max. which will ensure > > that the following code is executed. > > > > 48 if (obj >= alloc->max) { > > 49 alloc->top = (alloc->top + alloc->max) & alloc->mask; > > 50 obj = find_first_zero_bit(alloc->table, alloc->max); > > 51 } > > > > Thanks for your review. > Yes, your analysis is right. However, this is a bitmap allocator for resource id allocation (like QP, and CQ). > We first look at the situation where no resource id is released. > When the value of alloc->last starts to reaches alloc->max, the bitmap will > be full. In this case, it's normal to return an invalid value. > > Now, let's add resource releasing into consideration. > The following code is part of mthca_free: > > 70 spin_lock_irqsave(&alloc->lock, flags); > 71 > 72 clear_bit(obj, alloc->table); > 73 alloc->last = min(alloc->last, obj); > 74 alloc->top = (alloc->top + alloc->max) & alloc->mask; > > mthca_free() is used to release the allocated resource id. It will update alloc->last when obj is freed. > So, if the bitmap has space for allocation, my modification can continuously work. After alloc->last starts to be equal to alloc->max, the bitmap is searches with find_first_zero_bit() call. That will ensure that we look for any bit between 0 and alloc->max. So no, your change can't be right. Thanks > > > > > However the mthca_alloc() function has other error, it returns -1 while > > based on its declaration it needs to be unsigned, > > I think you are right about this. But obj is the return value of u32 type, which is the requirement of resource id > (though it may not fully use 32 bits). I have no idea of how to fix it. > > Thanks. > > > > > Thanks > > > > > > > > Signed-off-by: kangning > > > --- > > > > > > I squashed two commits into one in this version. > > > > > > drivers/infiniband/hw/mthca/mthca_allocator.c | 3 +++ > > > 1 file changed, 3 insertions(+) > > > > > > diff --git a/drivers/infiniband/hw/mthca/mthca_allocator.c b/drivers/infiniband/hw/mthca/mthca_allocator.c > > > index aef1d274a14e..1141695093e7 100644 > > > --- a/drivers/infiniband/hw/mthca/mthca_allocator.c > > > +++ b/drivers/infiniband/hw/mthca/mthca_allocator.c > > > @@ -51,6 +51,9 @@ u32 mthca_alloc(struct mthca_alloc *alloc) > > > } > > > > > > if (obj < alloc->max) { > > > + alloc->last = obj + 1; > > > + if (alloc->last == alloc->max) > > > + alloc->last = 0; > > > set_bit(obj, alloc->table); > > > obj |= alloc->top; > > > } else > > > -- > > > 2.17.1 > > > >