mlxsw: spectrum_router: Only query neighbour activity when necessary
authorIdo Schimmel <idosch@nvidia.com>
Wed, 4 May 2022 06:29:09 +0000 (09:29 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 May 2022 10:21:33 +0000 (11:21 +0100)
The driver periodically queries the device for activity of neighbour
entries in order to report it to the kernel's neighbour table.

Avoid unnecessary activity query when no neighbours are installed. Use
an atomic variable to track the number of neighbours, as it is read
without any locks.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h

index dc820d9f2696af6679d1fc509ce966c957e4430b..9ac4f3c003499afb7e0ad88b97232efb22964ba3 100644 (file)
@@ -2360,6 +2360,7 @@ mlxsw_sp_neigh_entry_create(struct mlxsw_sp *mlxsw_sp, struct neighbour *n)
                goto err_neigh_entry_insert;
 
        mlxsw_sp_neigh_counter_alloc(mlxsw_sp, neigh_entry);
+       atomic_inc(&mlxsw_sp->router->neighs_update.neigh_count);
        list_add(&neigh_entry->rif_list_node, &rif->neigh_list);
 
        return neigh_entry;
@@ -2374,6 +2375,7 @@ mlxsw_sp_neigh_entry_destroy(struct mlxsw_sp *mlxsw_sp,
                             struct mlxsw_sp_neigh_entry *neigh_entry)
 {
        list_del(&neigh_entry->rif_list_node);
+       atomic_dec(&mlxsw_sp->router->neighs_update.neigh_count);
        mlxsw_sp_neigh_counter_free(mlxsw_sp, neigh_entry);
        mlxsw_sp_neigh_entry_remove(mlxsw_sp, neigh_entry);
        mlxsw_sp_neigh_entry_free(neigh_entry);
@@ -2571,6 +2573,9 @@ static int mlxsw_sp_router_neighs_update_rauhtd(struct mlxsw_sp *mlxsw_sp)
        char *rauhtd_pl;
        int err;
 
+       if (!atomic_read(&mlxsw_sp->router->neighs_update.neigh_count))
+               return 0;
+
        rauhtd_pl = kmalloc(MLXSW_REG_RAUHTD_LEN, GFP_KERNEL);
        if (!rauhtd_pl)
                return -ENOMEM;
@@ -2950,6 +2955,7 @@ static int mlxsw_sp_neigh_init(struct mlxsw_sp *mlxsw_sp)
                          mlxsw_sp_router_neighs_update_work);
        INIT_DELAYED_WORK(&mlxsw_sp->router->nexthop_probe_dw,
                          mlxsw_sp_router_probe_unresolved_nexthops);
+       atomic_set(&mlxsw_sp->router->neighs_update.neigh_count, 0);
        mlxsw_core_schedule_dw(&mlxsw_sp->router->neighs_update.dw, 0);
        mlxsw_core_schedule_dw(&mlxsw_sp->router->nexthop_probe_dw, 0);
        return 0;
index fa829658a11b80d03c49622360bbc44191690aa0..6e704d807a78cec419771ee1a4eaea1ab5cf478d 100644 (file)
@@ -56,6 +56,7 @@ struct mlxsw_sp_router {
        struct {
                struct delayed_work dw;
                unsigned long interval; /* ms */
+               atomic_t neigh_count;
        } neighs_update;
        struct delayed_work nexthop_probe_dw;
 #define MLXSW_SP_UNRESOLVED_NH_PROBE_INTERVAL 5000 /* ms */