-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/mlx5e: TC, map tc action cookie to a hw counter
Currently a hardware counter is associated with a flow cookie. This does not apply to flows using branching action which are required to return per action stats. A single counter may apply to multiple actions. Scan the flow actions in reverse (from the last to the first action) while caching the last counter. Associate all the flow attribute tc action cookies with the current cached counter. Signed-off-by: Oz Shlomo <ozsh@nvidia.com> Reviewed-by: Roi Dayan <roid@nvidia.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
- Loading branch information
Oz Shlomo
authored and
Paolo Abeni
committed
Feb 14, 2023
1 parent
cca7eac
commit d13674b
Showing
5 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB | ||
// Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
|
||
#include <linux/rhashtable.h> | ||
#include <net/flow_offload.h> | ||
#include "en/tc_priv.h" | ||
#include "act_stats.h" | ||
#include "en/fs.h" | ||
|
||
struct mlx5e_tc_act_stats_handle { | ||
struct rhashtable ht; | ||
spinlock_t ht_lock; /* protects hashtable */ | ||
}; | ||
|
||
struct mlx5e_tc_act_stats { | ||
unsigned long tc_act_cookie; | ||
|
||
struct mlx5_fc *counter; | ||
u64 lastpackets; | ||
u64 lastbytes; | ||
|
||
struct rhash_head hash; | ||
struct rcu_head rcu_head; | ||
}; | ||
|
||
static const struct rhashtable_params act_counters_ht_params = { | ||
.head_offset = offsetof(struct mlx5e_tc_act_stats, hash), | ||
.key_offset = 0, | ||
.key_len = offsetof(struct mlx5e_tc_act_stats, counter), | ||
.automatic_shrinking = true, | ||
}; | ||
|
||
struct mlx5e_tc_act_stats_handle * | ||
mlx5e_tc_act_stats_create(void) | ||
{ | ||
struct mlx5e_tc_act_stats_handle *handle; | ||
int err; | ||
|
||
handle = kvzalloc(sizeof(*handle), GFP_KERNEL); | ||
if (IS_ERR(handle)) | ||
return ERR_PTR(-ENOMEM); | ||
|
||
err = rhashtable_init(&handle->ht, &act_counters_ht_params); | ||
if (err) | ||
goto err; | ||
|
||
spin_lock_init(&handle->ht_lock); | ||
return handle; | ||
err: | ||
kvfree(handle); | ||
return ERR_PTR(err); | ||
} | ||
|
||
void mlx5e_tc_act_stats_free(struct mlx5e_tc_act_stats_handle *handle) | ||
{ | ||
rhashtable_destroy(&handle->ht); | ||
kvfree(handle); | ||
} | ||
|
||
static int | ||
mlx5e_tc_act_stats_add(struct mlx5e_tc_act_stats_handle *handle, | ||
unsigned long act_cookie, | ||
struct mlx5_fc *counter) | ||
{ | ||
struct mlx5e_tc_act_stats *act_stats, *old_act_stats; | ||
struct rhashtable *ht = &handle->ht; | ||
int err = 0; | ||
|
||
act_stats = kvzalloc(sizeof(*act_stats), GFP_KERNEL); | ||
if (!act_stats) | ||
return -ENOMEM; | ||
|
||
act_stats->tc_act_cookie = act_cookie; | ||
act_stats->counter = counter; | ||
|
||
rcu_read_lock(); | ||
old_act_stats = rhashtable_lookup_get_insert_fast(ht, | ||
&act_stats->hash, | ||
act_counters_ht_params); | ||
if (IS_ERR(old_act_stats)) { | ||
err = PTR_ERR(old_act_stats); | ||
goto err_hash_insert; | ||
} else if (old_act_stats) { | ||
err = -EEXIST; | ||
goto err_hash_insert; | ||
} | ||
rcu_read_unlock(); | ||
|
||
return 0; | ||
|
||
err_hash_insert: | ||
rcu_read_unlock(); | ||
kvfree(act_stats); | ||
return err; | ||
} | ||
|
||
void | ||
mlx5e_tc_act_stats_del_flow(struct mlx5e_tc_act_stats_handle *handle, | ||
struct mlx5e_tc_flow *flow) | ||
{ | ||
struct mlx5_flow_attr *attr; | ||
struct mlx5e_tc_act_stats *act_stats; | ||
int i; | ||
|
||
list_for_each_entry(attr, &flow->attrs, list) { | ||
for (i = 0; i < attr->tc_act_cookies_count; i++) { | ||
struct rhashtable *ht = &handle->ht; | ||
|
||
spin_lock(&handle->ht_lock); | ||
act_stats = rhashtable_lookup_fast(ht, | ||
&attr->tc_act_cookies[i], | ||
act_counters_ht_params); | ||
if (act_stats && | ||
rhashtable_remove_fast(ht, &act_stats->hash, | ||
act_counters_ht_params) == 0) | ||
kvfree_rcu(act_stats, rcu_head); | ||
|
||
spin_unlock(&handle->ht_lock); | ||
} | ||
} | ||
} | ||
|
||
int | ||
mlx5e_tc_act_stats_add_flow(struct mlx5e_tc_act_stats_handle *handle, | ||
struct mlx5e_tc_flow *flow) | ||
{ | ||
struct mlx5_fc *curr_counter = NULL; | ||
unsigned long last_cookie = 0; | ||
struct mlx5_flow_attr *attr; | ||
int err; | ||
int i; | ||
|
||
list_for_each_entry(attr, &flow->attrs, list) { | ||
if (attr->counter) | ||
curr_counter = attr->counter; | ||
|
||
for (i = 0; i < attr->tc_act_cookies_count; i++) { | ||
/* jump over identical ids (e.g. pedit)*/ | ||
if (last_cookie == attr->tc_act_cookies[i]) | ||
continue; | ||
|
||
err = mlx5e_tc_act_stats_add(handle, attr->tc_act_cookies[i], curr_counter); | ||
if (err) | ||
goto out_err; | ||
last_cookie = attr->tc_act_cookies[i]; | ||
} | ||
} | ||
|
||
return 0; | ||
out_err: | ||
mlx5e_tc_act_stats_del_flow(handle, flow); | ||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ | ||
/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ | ||
|
||
#ifndef __MLX5_EN_ACT_STATS_H__ | ||
#define __MLX5_EN_ACT_STATS_H__ | ||
|
||
#include <net/flow_offload.h> | ||
#include "en/tc_priv.h" | ||
|
||
struct mlx5e_tc_act_stats_handle; | ||
|
||
struct mlx5e_tc_act_stats_handle *mlx5e_tc_act_stats_create(void); | ||
void mlx5e_tc_act_stats_free(struct mlx5e_tc_act_stats_handle *handle); | ||
|
||
int | ||
mlx5e_tc_act_stats_add_flow(struct mlx5e_tc_act_stats_handle *handle, | ||
struct mlx5e_tc_flow *flow); | ||
|
||
void | ||
mlx5e_tc_act_stats_del_flow(struct mlx5e_tc_act_stats_handle *handle, | ||
struct mlx5e_tc_flow *flow); | ||
|
||
#endif /* __MLX5_EN_ACT_STATS_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters