Skip to content

Commit

Permalink
net/mlx5: SF, Improve performance in SF allocation
Browse files Browse the repository at this point in the history
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@nvidia.com>
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
  • Loading branch information
Eli Cohen authored and Saeed Mahameed committed Jun 26, 2021
1 parent 6cdc686 commit 5bd8cee
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5bd8cee

Please sign in to comment.