Skip to content

Commit 5bd8cee

Browse files
elic307iSaeed Mahameed
authored andcommitted
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: Eli Cohen <[email protected]> Signed-off-by: Parav Pandit <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 6cdc686 commit 5bd8cee

File tree

1 file changed

+13
-10
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/sf

1 file changed

+13
-10
lines changed

drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,29 @@ static int mlx5_sf_hw_table_id_alloc(struct mlx5_sf_hw_table *table, u32 control
7373
u32 usr_sfnum)
7474
{
7575
struct mlx5_sf_hwc_table *hwc;
76+
int free_idx = -1;
7677
int i;
7778

7879
hwc = mlx5_sf_controller_to_hwc(table->dev, controller);
7980
if (!hwc->sfs)
8081
return -ENOSPC;
8182

82-
/* Check if sf with same sfnum already exists or not. */
8383
for (i = 0; i < hwc->max_fn; i++) {
84+
if (!hwc->sfs[i].allocated && free_idx == -1) {
85+
free_idx = i;
86+
continue;
87+
}
88+
8489
if (hwc->sfs[i].allocated && hwc->sfs[i].usr_sfnum == usr_sfnum)
8590
return -EEXIST;
8691
}
87-
/* Find the free entry and allocate the entry from the array */
88-
for (i = 0; i < hwc->max_fn; i++) {
89-
if (!hwc->sfs[i].allocated) {
90-
hwc->sfs[i].usr_sfnum = usr_sfnum;
91-
hwc->sfs[i].allocated = true;
92-
return i;
93-
}
94-
}
95-
return -ENOSPC;
92+
93+
if (free_idx == -1)
94+
return -ENOSPC;
95+
96+
hwc->sfs[free_idx].usr_sfnum = usr_sfnum;
97+
hwc->sfs[free_idx].allocated = true;
98+
return free_idx;
9699
}
97100

98101
static void mlx5_sf_hw_table_id_free(struct mlx5_sf_hw_table *table, u32 controller, int id)

0 commit comments

Comments
 (0)