提交 f5d709ff 编写于 作者: J Jakub Kicinski

Merge branch 'mlxsw-update-adjacency-index-more-efficiently'

Ido Schimmel says:

====================
mlxsw: Update adjacency index more efficiently

The device supports an operation that allows the driver to issue one
request to update the adjacency index for all the routes in a given
virtual router (VR) from old index and size to new ones. This is useful
in case the configuration of a certain nexthop group is updated and its
adjacency index changes.

Currently, the driver does not use this operation in an efficient
manner. It iterates over all the routes using the nexthop group and
issues an update request for the VR if it is not the same as the
previous VR.

Instead, this patch set tracks the VRs in which the nexthop group is
used and issues one request for each VR.

Example:

8k IPv6 routes were added in an alternating manner to two VRFs. All the
routes are using the same nexthop object ('nhid 1').

Before:

 Performance counter stats for 'ip nexthop replace id 1 via 2001:db8:1::2 dev swp3':

            16,385      devlink:devlink_hwmsg

       4.255933213 seconds time elapsed

       0.000000000 seconds user
       0.666923000 seconds sys

Number of EMAD transactions corresponds to number of routes using the
nexthop group.

After:

 Performance counter stats for 'ip nexthop replace id 1 via 2001:db8:1::2 dev swp3':

                 3      devlink:devlink_hwmsg

       0.077655094 seconds time elapsed

       0.000000000 seconds user
       0.076698000 seconds sys

Number of EMAD transactions corresponds to number of VRFs / VRs.

Patch set overview:

Patch #1 is a fix for a bug introduced in previous submission. Detected
by Coverity.

Patches #2 and #3 are preparations.

Patch #4 tracks the VRs a nexthop group is member of.

Patch #5 uses the membership tracking from the previous patch to issue
one update request per each VR.
====================

Link: https://lore.kernel.org/r/20201125193505.1052466-1-idosch@idosch.orgSigned-off-by: NJakub Kicinski <kuba@kernel.org>
......@@ -2889,6 +2889,18 @@ struct mlxsw_sp_nexthop_group_info {
#define nh_rif nexthops[0].rif
};
struct mlxsw_sp_nexthop_group_vr_key {
u16 vr_id;
enum mlxsw_sp_l3proto proto;
};
struct mlxsw_sp_nexthop_group_vr_entry {
struct list_head list; /* member in vr_list */
struct rhash_head ht_node; /* member in vr_ht */
refcount_t ref_count;
struct mlxsw_sp_nexthop_group_vr_key key;
};
struct mlxsw_sp_nexthop_group {
struct rhash_head ht_node;
struct list_head fib_list; /* list of fib entries that use this group */
......@@ -2901,6 +2913,8 @@ struct mlxsw_sp_nexthop_group {
} obj;
};
struct mlxsw_sp_nexthop_group_info *nhgi;
struct list_head vr_list;
struct rhashtable vr_ht;
enum mlxsw_sp_nexthop_group_type type;
bool can_destroy;
};
......@@ -3017,6 +3031,96 @@ bool mlxsw_sp_nexthop_is_discard(const struct mlxsw_sp_nexthop *nh)
return nh->discard;
}
static const struct rhashtable_params mlxsw_sp_nexthop_group_vr_ht_params = {
.key_offset = offsetof(struct mlxsw_sp_nexthop_group_vr_entry, key),
.head_offset = offsetof(struct mlxsw_sp_nexthop_group_vr_entry, ht_node),
.key_len = sizeof(struct mlxsw_sp_nexthop_group_vr_key),
.automatic_shrinking = true,
};
static struct mlxsw_sp_nexthop_group_vr_entry *
mlxsw_sp_nexthop_group_vr_entry_lookup(struct mlxsw_sp_nexthop_group *nh_grp,
const struct mlxsw_sp_fib *fib)
{
struct mlxsw_sp_nexthop_group_vr_key key;
memset(&key, 0, sizeof(key));
key.vr_id = fib->vr->id;
key.proto = fib->proto;
return rhashtable_lookup_fast(&nh_grp->vr_ht, &key,
mlxsw_sp_nexthop_group_vr_ht_params);
}
static int
mlxsw_sp_nexthop_group_vr_entry_create(struct mlxsw_sp_nexthop_group *nh_grp,
const struct mlxsw_sp_fib *fib)
{
struct mlxsw_sp_nexthop_group_vr_entry *vr_entry;
int err;
vr_entry = kzalloc(sizeof(*vr_entry), GFP_KERNEL);
if (!vr_entry)
return -ENOMEM;
vr_entry->key.vr_id = fib->vr->id;
vr_entry->key.proto = fib->proto;
refcount_set(&vr_entry->ref_count, 1);
err = rhashtable_insert_fast(&nh_grp->vr_ht, &vr_entry->ht_node,
mlxsw_sp_nexthop_group_vr_ht_params);
if (err)
goto err_hashtable_insert;
list_add(&vr_entry->list, &nh_grp->vr_list);
return 0;
err_hashtable_insert:
kfree(vr_entry);
return err;
}
static void
mlxsw_sp_nexthop_group_vr_entry_destroy(struct mlxsw_sp_nexthop_group *nh_grp,
struct mlxsw_sp_nexthop_group_vr_entry *vr_entry)
{
list_del(&vr_entry->list);
rhashtable_remove_fast(&nh_grp->vr_ht, &vr_entry->ht_node,
mlxsw_sp_nexthop_group_vr_ht_params);
kfree(vr_entry);
}
static int
mlxsw_sp_nexthop_group_vr_link(struct mlxsw_sp_nexthop_group *nh_grp,
const struct mlxsw_sp_fib *fib)
{
struct mlxsw_sp_nexthop_group_vr_entry *vr_entry;
vr_entry = mlxsw_sp_nexthop_group_vr_entry_lookup(nh_grp, fib);
if (vr_entry) {
refcount_inc(&vr_entry->ref_count);
return 0;
}
return mlxsw_sp_nexthop_group_vr_entry_create(nh_grp, fib);
}
static void
mlxsw_sp_nexthop_group_vr_unlink(struct mlxsw_sp_nexthop_group *nh_grp,
const struct mlxsw_sp_fib *fib)
{
struct mlxsw_sp_nexthop_group_vr_entry *vr_entry;
vr_entry = mlxsw_sp_nexthop_group_vr_entry_lookup(nh_grp, fib);
if (WARN_ON_ONCE(!vr_entry))
return;
if (!refcount_dec_and_test(&vr_entry->ref_count))
return;
mlxsw_sp_nexthop_group_vr_entry_destroy(nh_grp, vr_entry);
}
struct mlxsw_sp_nexthop_group_cmp_arg {
enum mlxsw_sp_nexthop_group_type type;
union {
......@@ -3243,7 +3347,8 @@ mlxsw_sp_nexthop_lookup(struct mlxsw_sp *mlxsw_sp,
}
static int mlxsw_sp_adj_index_mass_update_vr(struct mlxsw_sp *mlxsw_sp,
const struct mlxsw_sp_fib *fib,
enum mlxsw_sp_l3proto proto,
u16 vr_id,
u32 adj_index, u16 ecmp_size,
u32 new_adj_index,
u16 new_ecmp_size)
......@@ -3251,8 +3356,8 @@ static int mlxsw_sp_adj_index_mass_update_vr(struct mlxsw_sp *mlxsw_sp,
char raleu_pl[MLXSW_REG_RALEU_LEN];
mlxsw_reg_raleu_pack(raleu_pl,
(enum mlxsw_reg_ralxx_protocol) fib->proto,
fib->vr->id, adj_index, ecmp_size, new_adj_index,
(enum mlxsw_reg_ralxx_protocol) proto, vr_id,
adj_index, ecmp_size, new_adj_index,
new_ecmp_size);
return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(raleu), raleu_pl);
}
......@@ -3261,25 +3366,31 @@ static int mlxsw_sp_adj_index_mass_update(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_nexthop_group *nh_grp,
u32 old_adj_index, u16 old_ecmp_size)
{
struct mlxsw_sp_fib_entry *fib_entry;
struct mlxsw_sp_fib *fib = NULL;
int err;
list_for_each_entry(fib_entry, &nh_grp->fib_list, nexthop_group_node) {
struct mlxsw_sp_nexthop_group_info *nhgi = nh_grp->nhgi;
struct mlxsw_sp_nexthop_group_vr_entry *vr_entry;
int err;
if (fib == fib_entry->fib_node->fib)
continue;
fib = fib_entry->fib_node->fib;
err = mlxsw_sp_adj_index_mass_update_vr(mlxsw_sp, fib,
list_for_each_entry(vr_entry, &nh_grp->vr_list, list) {
err = mlxsw_sp_adj_index_mass_update_vr(mlxsw_sp,
vr_entry->key.proto,
vr_entry->key.vr_id,
old_adj_index,
old_ecmp_size,
nhgi->adj_index,
nhgi->ecmp_size);
if (err)
return err;
goto err_mass_update_vr;
}
return 0;
err_mass_update_vr:
list_for_each_entry_continue_reverse(vr_entry, &nh_grp->vr_list, list)
mlxsw_sp_adj_index_mass_update_vr(mlxsw_sp, vr_entry->key.proto,
vr_entry->key.vr_id,
nhgi->adj_index,
nhgi->ecmp_size,
old_adj_index, old_ecmp_size);
return err;
}
static int __mlxsw_sp_nexthop_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
......@@ -3608,10 +3719,8 @@ mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
int i, err2, err = 0;
u32 old_adj_index;
if (!nhgi->gateway) {
mlxsw_sp_nexthop_fib_entries_update(mlxsw_sp, nh_grp);
return 0;
}
if (!nhgi->gateway)
return mlxsw_sp_nexthop_fib_entries_update(mlxsw_sp, nh_grp);
for (i = 0; i < nhgi->count; i++) {
nh = &nhgi->nexthops[i];
......@@ -4366,6 +4475,11 @@ mlxsw_sp_nexthop_obj_group_create(struct mlxsw_sp *mlxsw_sp,
nh_grp = kzalloc(sizeof(*nh_grp), GFP_KERNEL);
if (!nh_grp)
return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&nh_grp->vr_list);
err = rhashtable_init(&nh_grp->vr_ht,
&mlxsw_sp_nexthop_group_vr_ht_params);
if (err)
goto err_nexthop_group_vr_ht_init;
INIT_LIST_HEAD(&nh_grp->fib_list);
nh_grp->type = MLXSW_SP_NEXTHOP_GROUP_TYPE_OBJ;
nh_grp->obj.id = info->id;
......@@ -4379,6 +4493,8 @@ mlxsw_sp_nexthop_obj_group_create(struct mlxsw_sp *mlxsw_sp,
return nh_grp;
err_nexthop_group_info_init:
rhashtable_destroy(&nh_grp->vr_ht);
err_nexthop_group_vr_ht_init:
kfree(nh_grp);
return ERR_PTR(err);
}
......@@ -4391,6 +4507,8 @@ mlxsw_sp_nexthop_obj_group_destroy(struct mlxsw_sp *mlxsw_sp,
return;
mlxsw_sp_nexthop_obj_group_info_fini(mlxsw_sp, nh_grp);
WARN_ON_ONCE(!list_empty(&nh_grp->fib_list));
WARN_ON_ONCE(!list_empty(&nh_grp->vr_list));
rhashtable_destroy(&nh_grp->vr_ht);
kfree(nh_grp);
}
......@@ -4639,6 +4757,11 @@ mlxsw_sp_nexthop4_group_create(struct mlxsw_sp *mlxsw_sp, struct fib_info *fi)
nh_grp = kzalloc(sizeof(*nh_grp), GFP_KERNEL);
if (!nh_grp)
return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&nh_grp->vr_list);
err = rhashtable_init(&nh_grp->vr_ht,
&mlxsw_sp_nexthop_group_vr_ht_params);
if (err)
goto err_nexthop_group_vr_ht_init;
INIT_LIST_HEAD(&nh_grp->fib_list);
nh_grp->type = MLXSW_SP_NEXTHOP_GROUP_TYPE_IPV4;
nh_grp->ipv4.fi = fi;
......@@ -4660,6 +4783,8 @@ mlxsw_sp_nexthop4_group_create(struct mlxsw_sp *mlxsw_sp, struct fib_info *fi)
mlxsw_sp_nexthop4_group_info_fini(mlxsw_sp, nh_grp);
err_nexthop_group_info_init:
fib_info_put(fi);
rhashtable_destroy(&nh_grp->vr_ht);
err_nexthop_group_vr_ht_init:
kfree(nh_grp);
return ERR_PTR(err);
}
......@@ -4673,6 +4798,8 @@ mlxsw_sp_nexthop4_group_destroy(struct mlxsw_sp *mlxsw_sp,
mlxsw_sp_nexthop_group_remove(mlxsw_sp, nh_grp);
mlxsw_sp_nexthop4_group_info_fini(mlxsw_sp, nh_grp);
fib_info_put(nh_grp->ipv4.fi);
WARN_ON_ONCE(!list_empty(&nh_grp->vr_list));
rhashtable_destroy(&nh_grp->vr_ht);
kfree(nh_grp);
}
......@@ -5367,6 +5494,11 @@ mlxsw_sp_fib4_entry_create(struct mlxsw_sp *mlxsw_sp,
if (err)
goto err_nexthop4_group_get;
err = mlxsw_sp_nexthop_group_vr_link(fib_entry->nh_group,
fib_node->fib);
if (err)
goto err_nexthop_group_vr_link;
err = mlxsw_sp_fib4_entry_type_set(mlxsw_sp, fen_info, fib_entry);
if (err)
goto err_fib4_entry_type_set;
......@@ -5382,6 +5514,8 @@ mlxsw_sp_fib4_entry_create(struct mlxsw_sp *mlxsw_sp,
return fib4_entry;
err_fib4_entry_type_set:
mlxsw_sp_nexthop_group_vr_unlink(fib_entry->nh_group, fib_node->fib);
err_nexthop_group_vr_link:
mlxsw_sp_nexthop4_group_put(mlxsw_sp, &fib4_entry->common);
err_nexthop4_group_get:
mlxsw_sp_fib_entry_priv_put(fib_entry->priv);
......@@ -5393,8 +5527,12 @@ mlxsw_sp_fib4_entry_create(struct mlxsw_sp *mlxsw_sp,
static void mlxsw_sp_fib4_entry_destroy(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_fib4_entry *fib4_entry)
{
struct mlxsw_sp_fib_node *fib_node = fib4_entry->common.fib_node;
fib_info_put(fib4_entry->fi);
mlxsw_sp_fib4_entry_type_unset(mlxsw_sp, &fib4_entry->common);
mlxsw_sp_nexthop_group_vr_unlink(fib4_entry->common.nh_group,
fib_node->fib);
mlxsw_sp_nexthop4_group_put(mlxsw_sp, &fib4_entry->common);
mlxsw_sp_fib_entry_priv_put(fib4_entry->common.priv);
kfree(fib4_entry);
......@@ -5971,6 +6109,11 @@ mlxsw_sp_nexthop6_group_create(struct mlxsw_sp *mlxsw_sp,
nh_grp = kzalloc(sizeof(*nh_grp), GFP_KERNEL);
if (!nh_grp)
return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&nh_grp->vr_list);
err = rhashtable_init(&nh_grp->vr_ht,
&mlxsw_sp_nexthop_group_vr_ht_params);
if (err)
goto err_nexthop_group_vr_ht_init;
INIT_LIST_HEAD(&nh_grp->fib_list);
nh_grp->type = MLXSW_SP_NEXTHOP_GROUP_TYPE_IPV6;
......@@ -5989,6 +6132,8 @@ mlxsw_sp_nexthop6_group_create(struct mlxsw_sp *mlxsw_sp,
err_nexthop_group_insert:
mlxsw_sp_nexthop6_group_info_fini(mlxsw_sp, nh_grp);
err_nexthop_group_info_init:
rhashtable_destroy(&nh_grp->vr_ht);
err_nexthop_group_vr_ht_init:
kfree(nh_grp);
return ERR_PTR(err);
}
......@@ -6001,6 +6146,8 @@ mlxsw_sp_nexthop6_group_destroy(struct mlxsw_sp *mlxsw_sp,
return;
mlxsw_sp_nexthop_group_remove(mlxsw_sp, nh_grp);
mlxsw_sp_nexthop6_group_info_fini(mlxsw_sp, nh_grp);
WARN_ON_ONCE(!list_empty(&nh_grp->vr_list));
rhashtable_destroy(&nh_grp->vr_ht);
kfree(nh_grp);
}
......@@ -6060,8 +6207,10 @@ static int mlxsw_sp_nexthop6_group_update(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_fib6_entry *fib6_entry)
{
struct mlxsw_sp_nexthop_group *old_nh_grp = fib6_entry->common.nh_group;
struct mlxsw_sp_fib_node *fib_node = fib6_entry->common.fib_node;
int err;
mlxsw_sp_nexthop_group_vr_unlink(old_nh_grp, fib_node->fib);
fib6_entry->common.nh_group = NULL;
list_del(&fib6_entry->common.nexthop_group_node);
......@@ -6069,6 +6218,11 @@ static int mlxsw_sp_nexthop6_group_update(struct mlxsw_sp *mlxsw_sp,
if (err)
goto err_nexthop6_group_get;
err = mlxsw_sp_nexthop_group_vr_link(fib6_entry->common.nh_group,
fib_node->fib);
if (err)
goto err_nexthop_group_vr_link;
/* In case this entry is offloaded, then the adjacency index
* currently associated with it in the device's table is that
* of the old group. Start using the new one instead.
......@@ -6084,11 +6238,15 @@ static int mlxsw_sp_nexthop6_group_update(struct mlxsw_sp *mlxsw_sp,
return 0;
err_fib_entry_update:
mlxsw_sp_nexthop_group_vr_unlink(fib6_entry->common.nh_group,
fib_node->fib);
err_nexthop_group_vr_link:
mlxsw_sp_nexthop6_group_put(mlxsw_sp, &fib6_entry->common);
err_nexthop6_group_get:
list_add_tail(&fib6_entry->common.nexthop_group_node,
&old_nh_grp->fib_list);
fib6_entry->common.nh_group = old_nh_grp;
mlxsw_sp_nexthop_group_vr_link(old_nh_grp, fib_node->fib);
return err;
}
......@@ -6220,12 +6378,19 @@ mlxsw_sp_fib6_entry_create(struct mlxsw_sp *mlxsw_sp,
if (err)
goto err_nexthop6_group_get;
err = mlxsw_sp_nexthop_group_vr_link(fib_entry->nh_group,
fib_node->fib);
if (err)
goto err_nexthop_group_vr_link;
mlxsw_sp_fib6_entry_type_set(mlxsw_sp, fib_entry, rt_arr[0]);
fib_entry->fib_node = fib_node;
return fib6_entry;
err_nexthop_group_vr_link:
mlxsw_sp_nexthop6_group_put(mlxsw_sp, fib_entry);
err_nexthop6_group_get:
i = nrt6;
err_rt6_create:
......@@ -6245,6 +6410,10 @@ mlxsw_sp_fib6_entry_create(struct mlxsw_sp *mlxsw_sp,
static void mlxsw_sp_fib6_entry_destroy(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_fib6_entry *fib6_entry)
{
struct mlxsw_sp_fib_node *fib_node = fib6_entry->common.fib_node;
mlxsw_sp_nexthop_group_vr_unlink(fib6_entry->common.nh_group,
fib_node->fib);
mlxsw_sp_nexthop6_group_put(mlxsw_sp, &fib6_entry->common);
mlxsw_sp_fib6_entry_rt_destroy_all(fib6_entry);
WARN_ON(fib6_entry->nrt6);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册