[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210527043609.654854-18-saeed@kernel.org>
Date: Wed, 26 May 2021 21:36:09 -0700
From: Saeed Mahameed <saeed@...nel.org>
To: "David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>
Cc: netdev@...r.kernel.org, Tariq Toukan <tariqt@...dia.com>,
Eli Cohen <elic@...dia.com>, Saeed Mahameed <saeedm@...dia.com>
Subject: [net-next 17/17] net/mlx5: Improve performance in SF allocation
From: Eli Cohen <elic@...dia.com>
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 <elic@...dia.com>
Signed-off-by: Saeed Mahameed <saeedm@...dia.com>
---
.../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 ef5f892aafad..0c1fbf711fe6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
@@ -74,26 +74,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 && 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;
+ free_idx = free_idx == -1 ? i : -1;
+ continue;
}
+
+ if (hwc->sfs[i].usr_sfnum == usr_sfnum)
+ return -EEXIST;
}
- return -ENOSPC;
+
+ if (free_idx == -1)
+ return -ENOSPC;
+
+ hwc->sfs[free_idx].usr_sfnum = usr_sfnum;
+ hwc->sfs[free_idx].allocated = true;
+ return 0;
}
static void mlx5_sf_hw_table_id_free(struct mlx5_sf_hw_table *table, u32 controller, int id)
--
2.31.1
Powered by blists - more mailing lists