Skip to content

Commit 75426cc

Browse files
pmachatadavem330
authored andcommitted
mlxsw: spectrum_router: Do not query MAX_VRS on each iteration
MLXSW_CORE_RES_GET involves a call to spectrum_core, a separate module. Instead of making the call on every iteration, cache it up front, and use the value. Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Amit Cohen <amcohen@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3903249 commit 75426cc

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,11 @@ static bool mlxsw_sp_vr_is_used(const struct mlxsw_sp_vr *vr)
748748

749749
static struct mlxsw_sp_vr *mlxsw_sp_vr_find_unused(struct mlxsw_sp *mlxsw_sp)
750750
{
751+
int max_vrs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_VRS);
751752
struct mlxsw_sp_vr *vr;
752753
int i;
753754

754-
for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_VRS); i++) {
755+
for (i = 0; i < max_vrs; i++) {
755756
vr = &mlxsw_sp->router->vrs[i];
756757
if (!mlxsw_sp_vr_is_used(vr))
757758
return vr;
@@ -792,12 +793,13 @@ static u32 mlxsw_sp_fix_tb_id(u32 tb_id)
792793
static struct mlxsw_sp_vr *mlxsw_sp_vr_find(struct mlxsw_sp *mlxsw_sp,
793794
u32 tb_id)
794795
{
796+
int max_vrs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_VRS);
795797
struct mlxsw_sp_vr *vr;
796798
int i;
797799

798800
tb_id = mlxsw_sp_fix_tb_id(tb_id);
799801

800-
for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_VRS); i++) {
802+
for (i = 0; i < max_vrs; i++) {
801803
vr = &mlxsw_sp->router->vrs[i];
802804
if (mlxsw_sp_vr_is_used(vr) && vr->tb_id == tb_id)
803805
return vr;
@@ -959,6 +961,7 @@ static int mlxsw_sp_vrs_lpm_tree_replace(struct mlxsw_sp *mlxsw_sp,
959961
struct mlxsw_sp_fib *fib,
960962
struct mlxsw_sp_lpm_tree *new_tree)
961963
{
964+
int max_vrs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_VRS);
962965
enum mlxsw_sp_l3proto proto = fib->proto;
963966
struct mlxsw_sp_lpm_tree *old_tree;
964967
u8 old_id, new_id = new_tree->id;
@@ -968,7 +971,7 @@ static int mlxsw_sp_vrs_lpm_tree_replace(struct mlxsw_sp *mlxsw_sp,
968971
old_tree = mlxsw_sp->router->lpm.proto_trees[proto];
969972
old_id = old_tree->id;
970973

971-
for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_VRS); i++) {
974+
for (i = 0; i < max_vrs; i++) {
972975
vr = &mlxsw_sp->router->vrs[i];
973976
if (!mlxsw_sp_vr_lpm_tree_should_replace(vr, proto, old_id))
974977
continue;
@@ -7298,9 +7301,10 @@ static void mlxsw_sp_vr_fib_flush(struct mlxsw_sp *mlxsw_sp,
72987301

72997302
static void mlxsw_sp_router_fib_flush(struct mlxsw_sp *mlxsw_sp)
73007303
{
7304+
int max_vrs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_VRS);
73017305
int i, j;
73027306

7303-
for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_VRS); i++) {
7307+
for (i = 0; i < max_vrs; i++) {
73047308
struct mlxsw_sp_vr *vr = &mlxsw_sp->router->vrs[i];
73057309

73067310
if (!mlxsw_sp_vr_is_used(vr))

0 commit comments

Comments
 (0)