From patchwork Sat Jun 26 07:44:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 467954 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=-19.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, URIBL_BLOCKED, USER_AGENT_GIT 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 3E068C49EA5 for ; Sat, 26 Jun 2021 07:44:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 262446186A for ; Sat, 26 Jun 2021 07:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229987AbhFZHrT (ORCPT ); Sat, 26 Jun 2021 03:47:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:35610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbhFZHrS (ORCPT ); Sat, 26 Jun 2021 03:47:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 780476186A; Sat, 26 Jun 2021 07:44:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624693496; bh=LUow8aDu7UyIBr9vl+NV9KscFpX4p3SkIVKvtQSBEcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N2aTOwuHY+hsNdwxAEjvnhwTv6qrY7wZjOpJ2cPThex0DNzGMXyRGIUDGhlXYunbC kmzhye810+FiDCcCtuvcCDDkqyKYCYEeWh4S6AbMwWxWiBBMM3fof+QN1qUutqQ31d UNRtT839GhU29fpOkEM1RiOqsJ2u9e0HD+P7bk7mqgdGA4tP9KTLWzdhUv+Nfs+sS0 sf/h9j8RhPkk5/1asMAsZb3GXux6ruQAqheglp8c8pTMyxkw2jpUSK5iNaqhB6JlLE R39z4DdBS5JoEdh3cKeKU9+0I3/h+ImR6kupfjHAn7OMWWAO1+I60O6xOrOsFQsIhr 6oK8594h72VZQ== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Eli Cohen , Parav Pandit , Saeed Mahameed Subject: [net-next 4/6] net/mlx5: SF, Improve performance in SF allocation Date: Sat, 26 Jun 2021 00:44:15 -0700 Message-Id: <20210626074417.714833-5-saeed@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210626074417.714833-1-saeed@kernel.org> References: <20210626074417.714833-1-saeed@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eli Cohen Avoid second traversal on the SF table by recording the first free entry and using it in case the looked up entry was not found in the table. Signed-off-by: Eli Cohen Signed-off-by: Parav Pandit Signed-off-by: Saeed Mahameed --- .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c index 500c71fb6f6d..d9c69123c1ab 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c @@ -73,26 +73,29 @@ static int mlx5_sf_hw_table_id_alloc(struct mlx5_sf_hw_table *table, u32 control u32 usr_sfnum) { struct mlx5_sf_hwc_table *hwc; + int free_idx = -1; int i; hwc = mlx5_sf_controller_to_hwc(table->dev, controller); if (!hwc->sfs) return -ENOSPC; - /* Check if sf with same sfnum already exists or not. */ for (i = 0; i < hwc->max_fn; i++) { + if (!hwc->sfs[i].allocated && free_idx == -1) { + free_idx = i; + continue; + } + if (hwc->sfs[i].allocated && hwc->sfs[i].usr_sfnum == usr_sfnum) return -EEXIST; } - /* Find the free entry and allocate the entry from the array */ - for (i = 0; i < hwc->max_fn; i++) { - if (!hwc->sfs[i].allocated) { - hwc->sfs[i].usr_sfnum = usr_sfnum; - hwc->sfs[i].allocated = true; - return i; - } - } - return -ENOSPC; + + if (free_idx == -1) + return -ENOSPC; + + hwc->sfs[free_idx].usr_sfnum = usr_sfnum; + hwc->sfs[free_idx].allocated = true; + return free_idx; } static void mlx5_sf_hw_table_id_free(struct mlx5_sf_hw_table *table, u32 controller, int id)