Commit 5bd8cee2 authored by Eli Cohen's avatar Eli Cohen Committed by Saeed Mahameed

net/mlx5: SF, Improve performance in SF allocation

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: default avatarEli Cohen <elic@nvidia.com>
Signed-off-by: default avatarParav Pandit <parav@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 6cdc686a
...@@ -73,26 +73,29 @@ static int mlx5_sf_hw_table_id_alloc(struct mlx5_sf_hw_table *table, u32 control ...@@ -73,26 +73,29 @@ static int mlx5_sf_hw_table_id_alloc(struct mlx5_sf_hw_table *table, u32 control
u32 usr_sfnum) u32 usr_sfnum)
{ {
struct mlx5_sf_hwc_table *hwc; struct mlx5_sf_hwc_table *hwc;
int free_idx = -1;
int i; int i;
hwc = mlx5_sf_controller_to_hwc(table->dev, controller); hwc = mlx5_sf_controller_to_hwc(table->dev, controller);
if (!hwc->sfs) if (!hwc->sfs)
return -ENOSPC; return -ENOSPC;
/* Check if sf with same sfnum already exists or not. */
for (i = 0; i < hwc->max_fn; i++) { 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) if (hwc->sfs[i].allocated && hwc->sfs[i].usr_sfnum == usr_sfnum)
return -EEXIST; return -EEXIST;
} }
/* Find the free entry and allocate the entry from the array */
for (i = 0; i < hwc->max_fn; i++) { if (free_idx == -1)
if (!hwc->sfs[i].allocated) { return -ENOSPC;
hwc->sfs[i].usr_sfnum = usr_sfnum;
hwc->sfs[i].allocated = true; hwc->sfs[free_idx].usr_sfnum = usr_sfnum;
return i; hwc->sfs[free_idx].allocated = true;
} return free_idx;
}
return -ENOSPC;
} }
static void mlx5_sf_hw_table_id_free(struct mlx5_sf_hw_table *table, u32 controller, int id) static void mlx5_sf_hw_table_id_free(struct mlx5_sf_hw_table *table, u32 controller, int id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment