add support for per action hw stats
Subsystems (6)
v4 cover add support for per action hw stats
There are currently two mechanisms for populating hardware stats:
1. Using flow_offload api to query the flow's statistics. The api assumes that the same stats values apply to all the flow's actions.
This assumption breaks when action drops or jumps over following actions.
2. Using hw_action api to query specific action stats via a driver callback method. This api assures the correct action stats for the offloaded action, however, it does not apply to the rest of the actions in the flow's actions array, as elaborated below.
The current hw_action api does not apply to the following use cases:
1. Actions that are implicitly created by filters (aka bind actions). In the following example only one counter will apply to the rule:
tc filter add dev $DEV prio 2 protocol ip parent ffff: \
flower ip_proto tcp dst_ip $IP2 \
action police rate 1mbit burst 100k conform-exceed drop/pipe \
action mirred egress redirect dev $DEV22. Action preceding a hw action.
In the following example the same flow stats will apply to the sample and mirred actions:
tc action add police rate 1mbit burst 100k conform-exceed drop / pipe
tc filter add dev $DEV prio 2 protocol ip parent ffff: \
flower ip_proto tcp dst_ip $IP2 \
action sample rate 1 group 10 trunc 60 pipe \
action police index 1 \
action mirred egress redirect dev $DEV23. Meter action using jump control.
In the following example the same flow stats will apply to both mirred actions:
tc action add police rate 1mbit burst 100k conform-exceed jump 2 / pipe tc filter add dev $DEV prio 2 protocol ip parent ffff: \
flower ip_proto tcp dst_ip $IP2 \
action police index 1 \
action mirred egress redirect dev $DEV2
action mirred egress redirect dev $DEV3
This series provides the platform to query per action stats for in_hw flows.
The first four patches are preparation patches with no functionality change. The fifth patch re-uses the existing flow action stats api to query action stats for both classifier and action dumps.
The rest of the patches add per action stats support to the Mellanox driver.
Oz Shlomo (9):
net/sched: optimize action stats api calls
net/sched: act_pedit, setup offload action for action stats query net/sched: pass flow_stats instead of multiple stats args net/sched: introduce flow_offload action cookie net/sched: support per action hw stats
net/mlx5e: TC, add hw counter to branching actions net/mlx5e: TC, store tc action cookies per attr net/mlx5e: TC, map tc action cookie to a hw counter net/mlx5e: TC, support per action stats
drivers/net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 2 +- .../ethernet/mellanox/mlx5/core/en/tc/act_stats.c | 197 +++++++++++++++++++++ .../ethernet/mellanox/mlx5/core/en/tc/act_stats.h | 27 +++ .../net/ethernet/mellanox/mlx5/core/en/tc_priv.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_rep.h | 3 + drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 91 ++++++++-- drivers/net/ethernet/mellanox/mlx5/core/en_tc.h | 4 + .../net/ethernet/mellanox/mlx5/core/fs_counters.c | 10 ++ include/linux/mlx5/fs.h | 2 + include/net/flow_offload.h | 3 + include/net/pkt_cls.h | 30 ++-- net/sched/act_api.c | 14 +- net/sched/act_pedit.c | 23 ++- net/sched/cls_api.c | 1 + net/sched/cls_flower.c | 7 +- net/sched/cls_matchall.c | 6 +- 17 files changed, 375 insertions(+), 48 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.h
Signature · 1 line
1.8.3.1
PATCH v4 1/9 net/sched: optimize action stats api calls
Currently the hw action stats update is called from tcf_exts_hw_stats_update, when a tc filter is dumped, and from tcf_action_copy_stats, when a hw action is dumped.
However, the tcf_action_copy_stats is also called from tcf_action_dump. As such, the hw action stats update cb is called 3 times for every tc flower filter dump.
Move the tc action hw stats update from tcf_action_copy_stats to tcf_dump_walker to update the hw action stats when tc action is dumped.
--- net/sched/act_api.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/sched/act_api.c +2 -3
@@ -539,6 +539,8 @@ static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb, (unsigned long)p->tcfa_tm.lastuse))continue ; +tcf_action_update_hw_stats (p); + nest =nla_nest_start_noflag (skb, n_i);if (!nest) { index--;
@@ -1539,9 +1541,6 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *p,if (p ==NULL ) goto errout; -/* update hw stats for this action */ -tcf_action_update_hw_stats (p); -/* compat_mode being true specifies a call that is supposed * to add additional backward compatibility statistic TLVs. */
Signature · 1 line
1.8.3.1
Re: [PATCH net-next v4 1/9] net/sched: optimize action stats api calls
Quoted 8 lines · Oz Shlomo
Currently the hw action stats update is called from
tcf_exts_hw_stats_update, when a tc filter is dumped, and fromtcf_action_copy_stats, when a hw action is dumped.
However, thetcf_action_copy_statsis also called fromtcf_action_dump. As such, the hw action stats update cb is called 3 times for every tc flower filter dump.
Quoted 6 lines
Move the tc action hw stats update from
tcf_action_copy_statstotcf_dump_walkerto update the hw action stats when tc action is dumped.Signed-off-by Oz Shlomo <[email protected]>Reviewed-by Simon Horman <[email protected]>Reviewed-by Marcelo Ricardo Leitner <[email protected]>
This patch is trivial, but if an ACK is needed, then:
cheers,
jamal
Quoted 30 lines
--- net/sched/act_api.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)net/sched/act_api.c +2
-4@@ -539,6 +539,8 @@ static int tcf_dump_walker(struct tcf_idrinfo *idrinfo, struct sk_buff *skb, (unsigned long)p->tcfa_tm.lastuse))continue ; +tcf_action_update_hw_stats (p); + nest =nla_nest_start_noflag (skb, n_i);if (!nest) { index--;@@ -1539,9 +1541,6 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *p,if (p ==NULL ) goto errout; -/* update hw stats for this action */ -tcf_action_update_hw_stats (p); -/* compat_mode being true specifies a call that is supposed * to add additional backward compatibility statistic TLVs. */ --1.8.3.1
PATCH v4 2/9 net/sched: act_pedit, setup offload action for action stats query
In reply to Oz ShlomoA single tc pedit action may be translated to multiple flow_offload actions.
Offload only actions that translate to a single pedit command value.
---
Change log:
V1 -> V2:
- Add extack message on error
- Assign the flow action id outside the for loop. Ensure the rest of the pedit actions follow the assigned id.
V2 -> V3:
- Fix last_cmd initialization
V3 -> V4:
- Compare all action types to the first action
--- net/sched/act_pedit.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
net/sched/act_pedit.c +22 -1
@@ -545,7 +545,28 @@ static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data, } *index_inc = k; }else { -return -EOPNOTSUPP ; +struct flow_offload_action *fl_action = entry_data; +u32 cmd =tcf_pedit_cmd (act,0 ); +int k; + +switch (cmd) { +case TCA_PEDIT_KEY_EX_CMD_SET : + fl_action->id =FLOW_ACTION_MANGLE ; +break ; +case TCA_PEDIT_KEY_EX_CMD_ADD : + fl_action->id =FLOW_ACTION_ADD ; +break ; +default : +NL_SET_ERR_MSG_MOD (extack,"Unsupported pedit command offload" ); +return -EOPNOTSUPP ; + } + +for (k =1 ; k <tcf_pedit_nkeys (act); k++) { +if (cmd !=tcf_pedit_cmd (act, k)) { +NL_SET_ERR_MSG_MOD (extack,"Unsupported pedit command offload" ); +return -EOPNOTSUPP ; + } + } }return 0 ;
Signature · 1 line
1.8.3.1
Re: [PATCH net-next v4 2/9] net/sched: act_pedit, setup offload action for action stats query
Quoted 8 lines · Oz Shlomo
A single tc pedit action may be translated to multiple
flow_offloadactions.
Offload only actions that translate to a single pedit command value.Signed-off-by Oz Shlomo <[email protected]>Reviewed-by Simon Horman <[email protected]>Reviewed-by Marcelo Ricardo Leitner <[email protected]>
cheers,
jamal
Quoted 54 lines
---
Change log:V1 -> V2:
- Add extack message on error
- Assign the flow action id outside the for loop. Ensure the rest of the pedit actions follow the assigned id.V2 -> V3:
- Fixlast_cmdinitializationV3 -> V4:
- Compare all action types to the first action--- net/sched/act_pedit.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)net/sched/act_pedit.c +22
-2@@ -545,7 +545,28 @@ static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data, } *index_inc = k; }else { -return -EOPNOTSUPP ; +struct flow_offload_action *fl_action = entry_data; +u32 cmd =tcf_pedit_cmd (act,0 ); +int k; + +switch (cmd) { +case TCA_PEDIT_KEY_EX_CMD_SET : + fl_action->id =FLOW_ACTION_MANGLE ; +break ; +case TCA_PEDIT_KEY_EX_CMD_ADD : + fl_action->id =FLOW_ACTION_ADD ; +break ; +default : +NL_SET_ERR_MSG_MOD (extack,"Unsupported pedit command offload" ); +return -EOPNOTSUPP ; + } + +for (k =1 ; k <tcf_pedit_nkeys (act); k++) { +if (cmd !=tcf_pedit_cmd (act, k)) { +NL_SET_ERR_MSG_MOD (extack,"Unsupported pedit command offload" ); +return -EOPNOTSUPP ; + } + } }return 0 ; --1.8.3.1
PATCH v4 3/9 net/sched: pass flow_stats instead of multiple stats args
In reply to Oz ShlomoInstead of passing 6 stats related args, pass the flow_stats.
--- include/net/pkt_cls.h | 11 +++++------ net/sched/cls_flower.c | 7 +------ net/sched/cls_matchall.c | 6 +----- 3 files changed, 7 insertions(+), 17 deletions(-)
include/net/pkt_cls.h +5 -6
@@ -294,8 +294,7 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)static inline void tcf_exts_hw_stats_update (const struct tcf_exts *exts, -u64 bytes,u64 packets,u64 drops,u64 lastuse, -u8 used_hw_stats,bool used_hw_stats_valid) +struct flow_stats *stats) {#ifdef CONFIG_NET_CLS_ACT int i;
@@ -306,12 +305,12 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)/* if stats from hw, just skip */ if (tcf_action_update_hw_stats (a)) {preempt_disable (); -tcf_action_stats_update (a, bytes, packets, drops, - lastuse, true); +tcf_action_stats_update (a, stats->bytes, stats->pkts, stats->drops, + stats->lastused, true);preempt_enable (); - a->used_hw_stats = used_hw_stats; - a->used_hw_stats_valid = used_hw_stats_valid; + a->used_hw_stats = stats->used_hw_stats; + a->used_hw_stats_valid = stats->used_hw_stats_valid; } }#endif
net/sched/cls_flower.c +1 -6
@@ -502,12 +502,7 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f,tc_setup_cb_call (block,TC_SETUP_CLSFLOWER , &cls_flower, false, rtnl_held); -tcf_exts_hw_stats_update (&f->exts, cls_flower.stats.bytes, - cls_flower.stats.pkts, - cls_flower.stats.drops, - cls_flower.stats.lastused, - cls_flower.stats.used_hw_stats, - cls_flower.stats.used_hw_stats_valid); +tcf_exts_hw_stats_update (&f->exts, &cls_flower.stats); }static void __fl_put (struct cls_fl_filter *f)
net/sched/cls_matchall.c +1 -5
@@ -331,11 +331,7 @@ static void mall_stats_hw_filter(struct tcf_proto *tp,tc_setup_cb_call (block,TC_SETUP_CLSMATCHALL , &cls_mall, false, true); -tcf_exts_hw_stats_update (&head->exts, cls_mall.stats.bytes, - cls_mall.stats.pkts, cls_mall.stats.drops, - cls_mall.stats.lastused, - cls_mall.stats.used_hw_stats, - cls_mall.stats.used_hw_stats_valid); +tcf_exts_hw_stats_update (&head->exts, &cls_mall.stats); } static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh,
Signature · 1 line
1.8.3.1
Re: [PATCH net-next v4 3/9] net/sched: pass flow_stats instead of multiple stats args
Quoted 6 lines · Oz Shlomo
Instead of passing 6 stats related args, pass the
flow_stats.Signed-off-by Oz Shlomo <[email protected]>Reviewed-by Simon Horman <[email protected]>Reviewed-by Marcelo Ricardo Leitner <[email protected]>
cheers,
jamal
Quoted 75 lines
--- include/net/pkt_cls.h | 11 +++++------ net/sched/cls_flower.c | 7 +------ net/sched/cls_matchall.c | 6 +----- 3 files changed, 7 insertions(+), 17 deletions(-)include/net/pkt_cls.h +5
-6@@ -294,8 +294,7 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)static inline void tcf_exts_hw_stats_update (const struct tcf_exts *exts, -u64 bytes,u64 packets,u64 drops,u64 lastuse, -u8 used_hw_stats,bool used_hw_stats_valid) +struct flow_stats *stats) {#ifdef CONFIG_NET_CLS_ACT int i;@@ -306,12 +305,12 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)/* if stats from hw, just skip */ if (tcf_action_update_hw_stats (a)) {preempt_disable (); -tcf_action_stats_update (a, bytes, packets, drops, - lastuse, true); +tcf_action_stats_update (a, stats->bytes, stats->pkts, stats->drops, + stats->lastused, true);preempt_enable (); - a->used_hw_stats = used_hw_stats; - a->used_hw_stats_valid = used_hw_stats_valid; + a->used_hw_stats = stats->used_hw_stats; + a->used_hw_stats_valid = stats->used_hw_stats_valid; } }#endif net/sched/cls_flower.c +1
-6@@ -502,12 +502,7 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f,tc_setup_cb_call (block,TC_SETUP_CLSFLOWER , &cls_flower, false, rtnl_held); -tcf_exts_hw_stats_update (&f->exts, cls_flower.stats.bytes, - cls_flower.stats.pkts, - cls_flower.stats.drops, - cls_flower.stats.lastused, - cls_flower.stats.used_hw_stats, - cls_flower.stats.used_hw_stats_valid); +tcf_exts_hw_stats_update (&f->exts, &cls_flower.stats); }static void __fl_put (struct cls_fl_filter *f)net/sched/cls_matchall.c +1
-6@@ -331,11 +331,7 @@ static void mall_stats_hw_filter(struct tcf_proto *tp,tc_setup_cb_call (block,TC_SETUP_CLSMATCHALL , &cls_mall, false, true); -tcf_exts_hw_stats_update (&head->exts, cls_mall.stats.bytes, - cls_mall.stats.pkts, cls_mall.stats.drops, - cls_mall.stats.lastused, - cls_mall.stats.used_hw_stats, - cls_mall.stats.used_hw_stats_valid); +tcf_exts_hw_stats_update (&head->exts, &cls_mall.stats); } static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh, --1.8.3.1
PATCH v4 4/9 net/sched: introduce flow_offload action cookie
In reply to Oz ShlomoCurrently a hardware action is uniquely identified by the <id, hw_index> tuple. However, the id is set by the flow_act_setup callback and tc core cannot enforce this, and it is possible that a future change could break this. In addition, <id, hw_index> are not unique across network namespaces.
Uniquely identify the action by setting an action cookie by the tc core. Use the unique action cookie to query the action's hardware stats.
--- include/net/flow_offload.h | 2 ++ net/sched/act_api.c | 1 + net/sched/cls_api.c | 1 + 3 files changed, 4 insertions(+)
include/net/flow_offload.h +2 -0
@@ -228,6 +228,7 @@ struct flow_action_cookie *flow_action_cookie_create(void *data,struct flow_action_entry {enum flow_action_id id;u32 hw_index; +unsigned long act_cookie;enum flow_action_hw_stats hw_stats;action_destr destructor;void *destructor_priv;
@@ -610,6 +611,7 @@ struct flow_offload_action {enum offload_act_command command;enum flow_action_id id;u32 index; +unsigned long cookie;struct flow_stats stats;struct flow_action action; };
net/sched/act_api.c +1 -0
@@ -192,6 +192,7 @@ static int offload_action_init(struct flow_offload_action *fl_action, fl_action->extack = extack; fl_action->command = cmd; fl_action->index = act->tcfa_index; + fl_action->cookie = (unsigned long )act;if (act->ops->offload_act_setup) {spin_lock_bh (&act->tcfa_lock);
net/sched/cls_api.c +1 -0
@@ -3577,6 +3577,7 @@ int tc_setup_action(struct flow_action *flow_action,for (k =0 ; k < index ; k++) { entry[k].hw_stats =tc_act_hw_stats (act->hw_stats); entry[k].hw_index = act->tcfa_index; + entry[k].act_cookie = (unsigned long )act; } j += index;
Signature · 1 line
1.8.3.1
Re: [PATCH net-next v4 4/9] net/sched: introduce flow_offload action cookie
Quoted 6 lines · Oz Shlomo
Currently a hardware action is uniquely identified by the <id,
hw_index> tuple. However, the id is set by theflow_act_setupcallback and tc core cannot enforce this, and it is possible that a future change could break this. In addition, <id,hw_index> are not unique across network namespaces.
Quoted 6 lines
Uniquely identify the action by setting an action cookie by the tc core. Use the unique action cookie to query the action's hardware stats.
Signed-off-by Oz Shlomo <[email protected]>Reviewed-by Simon Horman <[email protected]>Reviewed-by Marcelo Ricardo Leitner <[email protected]>
LGTM.
cheers,
jamal
Quoted 53 lines
--- include/net/flow_offload.h | 2 ++ net/sched/act_api.c | 1 + net/sched/cls_api.c | 1 + 3 files changed, 4 insertions(+)include/net/flow_offload.h +2
-0@@ -228,6 +228,7 @@ struct flow_action_cookie *flow_action_cookie_create(void *data,struct flow_action_entry {enum flow_action_id id;u32 hw_index; +unsigned long act_cookie;enum flow_action_hw_stats hw_stats;action_destr destructor;void *destructor_priv;@@ -610,6 +611,7 @@ struct flow_offload_action {enum offload_act_command command;enum flow_action_id id;u32 index; +unsigned long cookie;struct flow_stats stats;struct flow_action action; };net/sched/act_api.c +1
-0@@ -192,6 +192,7 @@ static int offload_action_init(struct flow_offload_action *fl_action, fl_action->extack = extack; fl_action->command = cmd; fl_action->index = act->tcfa_index; + fl_action->cookie = (unsigned long )act;if (act->ops->offload_act_setup) {spin_lock_bh (&act->tcfa_lock);net/sched/cls_api.c +1
-1@@ -3577,6 +3577,7 @@ int tc_setup_action(struct flow_action *flow_action,for (k =0 ; k < index ; k++) { entry[k].hw_stats =tc_act_hw_stats (act->hw_stats); entry[k].hw_index = act->tcfa_index; + entry[k].act_cookie = (unsigned long )act; } j += index; --1.8.3.1
PATCH v4 5/9 net/sched: support per action hw stats
In reply to Oz ShlomoThere are currently two mechanisms for populating hardware stats:
1. Using flow_offload api to query the flow's statistics. The api assumes that the same stats values apply to all the flow's actions.
This assumption breaks when action drops or jumps over following actions.
2. Using hw_action api to query specific action stats via a driver callback method. This api assures the correct action stats for the offloaded action, however, it does not apply to the rest of the actions in the flow's actions array.
Extend the flow_offload stats callback to indicate that a per action stats update is required.
Use the existing flow_offload_action api to query the action's hw stats. In addition, currently the tc action stats utility only updates hw actions. Reuse the existing action stats cb infrastructure to query any action stats.
---
Change log:
V1 -> V2
- Fix static function without inline keyword in header file
- Rearrange flow_cls_offload members such that stats and use_act stats will be on the same cache line
- Fall-through to flow stats when hw_stats update returns an error (this aligns with current behavior).
--- include/net/flow_offload.h | 1 + include/net/pkt_cls.h | 29 +++++++++++++++++++---------- net/sched/act_api.c | 8 -------- net/sched/cls_flower.c | 2 +- net/sched/cls_matchall.c | 2 +- 5 files changed, 22 insertions(+), 20 deletions(-)
include/net/flow_offload.h +1 -0
@@ -594,6 +594,7 @@ struct flow_cls_common_offload {struct flow_cls_offload {struct flow_cls_common_offload common;enum flow_cls_command command; +bool use_act_stats;unsigned long cookie;struct flow_rule *rule;struct flow_stats stats;
include/net/pkt_cls.h +19 -10
@@ -292,9 +292,15 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)#define tcf_act_for_each_action (i, a, actions) \ for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = actions[i]); i++) +static inline bool tc_act_in_hw (struct tc_action *act) +{ +return !!act->in_hw_count; +} +static inline void tcf_exts_hw_stats_update (const struct tcf_exts *exts, -struct flow_stats *stats) +struct flow_stats *stats, +bool use_act_stats) {#ifdef CONFIG_NET_CLS_ACT int i;
@@ -302,16 +308,18 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)for (i =0 ; i < exts->nr_actions; i++) {struct tc_action *a = exts->actions[i]; -/* if stats from hw, just skip */ -if (tcf_action_update_hw_stats (a)) { -preempt_disable (); -tcf_action_stats_update (a, stats->bytes, stats->pkts, stats->drops, - stats->lastused, true); -preempt_enable (); - - a->used_hw_stats = stats->used_hw_stats; - a->used_hw_stats_valid = stats->used_hw_stats_valid; +if (use_act_stats ||tc_act_in_hw (a)) { +if (!tcf_action_update_hw_stats (a)) +continue ; } + +preempt_disable (); +tcf_action_stats_update (a, stats->bytes, stats->pkts, stats->drops, + stats->lastused, true); +preempt_enable (); + + a->used_hw_stats = stats->used_hw_stats; + a->used_hw_stats_valid = stats->used_hw_stats_valid; }#endif }
@@ -769,6 +777,7 @@ struct tc_cls_matchall_offload {enum tc_matchall_command command;struct flow_rule *rule;struct flow_stats stats; +bool use_act_stats;unsigned long cookie; };
net/sched/act_api.c +0 -8
@@ -169,11 +169,6 @@ static bool tc_act_skip_sw(u32 flags)return (flags &TCA_ACT_FLAGS_SKIP_SW ) ? true : false; } -static bool tc_act_in_hw (struct tc_action *act) -{ -return !!act->in_hw_count; -} -/* SKIP_HW and SKIP_SW are mutually exclusive flags. */ static bool tc_act_flags_valid (u32 flags) {
@@ -308,9 +303,6 @@ int tcf_action_update_hw_stats(struct tc_action *action)struct flow_offload_action fl_act = {};int err; -if (!tc_act_in_hw (action)) -return -EOPNOTSUPP ; - err =offload_action_init (&fl_act, action,FLOW_ACT_STATS ,NULL );if (err)return err;
net/sched/cls_flower.c +1 -1
@@ -502,7 +502,7 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f,tc_setup_cb_call (block,TC_SETUP_CLSFLOWER , &cls_flower, false, rtnl_held); -tcf_exts_hw_stats_update (&f->exts, &cls_flower.stats); +tcf_exts_hw_stats_update (&f->exts, &cls_flower.stats, cls_flower.use_act_stats); }static void __fl_put (struct cls_fl_filter *f)
net/sched/cls_matchall.c +1 -1
@@ -331,7 +331,7 @@ static void mall_stats_hw_filter(struct tcf_proto *tp,tc_setup_cb_call (block,TC_SETUP_CLSMATCHALL , &cls_mall, false, true); -tcf_exts_hw_stats_update (&head->exts, &cls_mall.stats); +tcf_exts_hw_stats_update (&head->exts, &cls_mall.stats, cls_mall.use_act_stats); } static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh,
Signature · 1 line
1.8.3.1
Re: [PATCH net-next v4 5/9] net/sched: support per action hw stats
Quoted 19 lines · Oz Shlomo
There are currently two mechanisms for populating hardware stats:
1. Usingflow_offloadapi to query the flow's statistics. The api assumes that the same stats values apply to all the flow's actions.
This assumption breaks when action drops or jumps over following actions.
2. Usinghw_actionapi to query specific action stats via a driver callback method. This api assures the correct action stats for the offloaded action, however, it does not apply to the rest of the actions in the flow's actions array.Extend the
flow_offloadstats callback to indicate that a per action stats update is required.
Use the existingflow_offload_actionapi to query the action's hw stats. In addition, currently the tc action stats utility only updates hw actions. Reuse the existing action stats cb infrastructure to query any action stats.
Quoted 3 lines
Signed-off-by Oz Shlomo <[email protected]>Reviewed-by Simon Horman <[email protected]>Reviewed-by Marcelo Ricardo Leitner <[email protected]>
I just looked for functional equivalency and it LGTM.
cheers,
jamal
Quoted 141 lines
---
Change log:V1 -> V2
- Fix static function without inline keyword in header file
- Rearrangeflow_cls_offloadmembers such that stats anduse_actstats will be on the same cache line
- Fall-through to flow stats whenhw_statsupdate returns an error (this aligns with current behavior).--- include/net/flow_offload.h | 1 + include/net/pkt_cls.h | 29 +++++++++++++++++++---------- net/sched/act_api.c | 8 -------- net/sched/cls_flower.c | 2 +- net/sched/cls_matchall.c | 2 +- 5 files changed, 22 insertions(+), 20 deletions(-)include/net/flow_offload.h +1
-0@@ -594,6 +594,7 @@ struct flow_cls_common_offload {struct flow_cls_offload {struct flow_cls_common_offload common;enum flow_cls_command command; +bool use_act_stats;unsigned long cookie;struct flow_rule *rule;struct flow_stats stats;include/net/pkt_cls.h +19
-10@@ -292,9 +292,15 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)#define tcf_act_for_each_action (i, a, actions) \ for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = actions[i]); i++) +static inline bool tc_act_in_hw (struct tc_action *act) +{ +return !!act->in_hw_count; +} +static inline void tcf_exts_hw_stats_update (const struct tcf_exts *exts, -struct flow_stats *stats) +struct flow_stats *stats, +bool use_act_stats) {#ifdef CONFIG_NET_CLS_ACT int i;@@ -302,16 +308,18 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts)for (i =0 ; i < exts->nr_actions; i++) {struct tc_action *a = exts->actions[i]; -/* if stats from hw, just skip */ -if (tcf_action_update_hw_stats (a)) { -preempt_disable (); -tcf_action_stats_update (a, stats->bytes, stats->pkts, stats->drops, - stats->lastused, true); -preempt_enable (); - - a->used_hw_stats = stats->used_hw_stats; - a->used_hw_stats_valid = stats->used_hw_stats_valid; +if (use_act_stats ||tc_act_in_hw (a)) { +if (!tcf_action_update_hw_stats (a)) +continue ; } + +preempt_disable (); +tcf_action_stats_update (a, stats->bytes, stats->pkts, stats->drops, + stats->lastused, true); +preempt_enable (); + + a->used_hw_stats = stats->used_hw_stats; + a->used_hw_stats_valid = stats->used_hw_stats_valid; }#endif }@@ -769,6 +777,7 @@ struct tc_cls_matchall_offload {enum tc_matchall_command command;struct flow_rule *rule;struct flow_stats stats; +bool use_act_stats;unsigned long cookie; };net/sched/act_api.c +0
-8@@ -169,11 +169,6 @@ static bool tc_act_skip_sw(u32 flags)return (flags &TCA_ACT_FLAGS_SKIP_SW ) ? true : false; } -static bool tc_act_in_hw (struct tc_action *act) -{ -return !!act->in_hw_count; -} -/* SKIP_HW and SKIP_SW are mutually exclusive flags. */ static bool tc_act_flags_valid (u32 flags) {@@ -308,9 +303,6 @@ int tcf_action_update_hw_stats(struct tc_action *action)struct flow_offload_action fl_act = {};int err; -if (!tc_act_in_hw (action)) -return -EOPNOTSUPP ; - err =offload_action_init (&fl_act, action,FLOW_ACT_STATS ,NULL );if (err)return err;net/sched/cls_flower.c +1
-1@@ -502,7 +502,7 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f,tc_setup_cb_call (block,TC_SETUP_CLSFLOWER , &cls_flower, false, rtnl_held); -tcf_exts_hw_stats_update (&f->exts, &cls_flower.stats); +tcf_exts_hw_stats_update (&f->exts, &cls_flower.stats, cls_flower.use_act_stats); }static void __fl_put (struct cls_fl_filter *f)net/sched/cls_matchall.c +1
-2@@ -331,7 +331,7 @@ static void mall_stats_hw_filter(struct tcf_proto *tp,tc_setup_cb_call (block,TC_SETUP_CLSMATCHALL , &cls_mall, false, true); -tcf_exts_hw_stats_update (&head->exts, &cls_mall.stats); +tcf_exts_hw_stats_update (&head->exts, &cls_mall.stats, cls_mall.use_act_stats); } static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh, --1.8.3.1
PATCH v4 6/9 net/mlx5e: TC, add hw counter to branching actions
In reply to Oz ShlomoCurrently a hw count action is appended to the last action of the action list. However, a branching action may terminate the action list before reaching the last action.
Append a count action to a branching action.
In the next patches, filters with branching actions will read this counter when reporting stats per action.
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +5 -0
@@ -3785,6 +3785,7 @@ bool mlx5e_same_hw_devs(struct mlx5e_priv *priv, struct mlx5e_priv *peer_priv)INIT_LIST_HEAD (&attr2->list); parse_attr->filter_dev = attr->parse_attr->filter_dev; attr2->action =0 ; + attr2->counter =NULL ; attr2->flags =0 ; attr2->parse_attr = parse_attr; attr2->dest_chain =0 ;
@@ -4084,6 +4085,10 @@ struct mlx5_flow_attr * jump_state->jumping_attr = attr->branch_false; jump_state->jump_count = jump_count; + +/* branching action requires its own counter */ + attr->action |=MLX5_FLOW_CONTEXT_ACTION_COUNT ; +return 0 ; err_branch_false:
Signature · 1 line
1.8.3.1
PATCH v4 7/9 net/mlx5e: TC, store tc action cookies per attr
In reply to Oz ShlomoThe tc parse action phase translates the tc actions to mlx5 flow attributes data structure that is used during the flow offload phase. Currently, the flow offload stage instantiates hw counters while associating them to flow cookie. However, flows with branching actions are required to associate a hardware counter with its action cookies.
Store the parsed tc action cookies on the flow attribute.
Use the list of cookies in the next patch to associate a tc action cookie with its allocated hw counter.
---
Change log:
V1 -> V2:
- Reduce tc_act_cookies_count size from int to u16
- Rearange mlx5_flow_attr attributes for better cache alignment
--- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 3 +++ drivers/net/ethernet/mellanox/mlx5/core/en_tc.h | 2 ++ 2 files changed, 5 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +3 -0
@@ -3786,6 +3786,7 @@ bool mlx5e_same_hw_devs(struct mlx5e_priv *priv, struct mlx5e_priv *peer_priv) parse_attr->filter_dev = attr->parse_attr->filter_dev; attr2->action =0 ; attr2->counter =NULL ; + attr->tc_act_cookies_count =0 ; attr2->flags =0 ; attr2->parse_attr = parse_attr; attr2->dest_chain =0 ;
@@ -4149,6 +4150,8 @@ struct mlx5_flow_attr * goto out_free; parse_state->actions |= attr->action; +if (!tc_act->stats_action) + attr->tc_act_cookies[attr->tc_act_cookies_count++] = act->act_cookie;/* Split attr for multi table act if not the last act. */ if (jump_state.jump_target ||
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +2 -0
@@ -69,6 +69,7 @@ struct mlx5_nic_flow_attr {struct mlx5_flow_attr {u32 action; +unsigned long tc_act_cookies[TCA_ACT_MAX_PRIO ];struct mlx5_fc *counter;struct mlx5_modify_hdr *modify_hdr;struct mlx5e_mod_hdr_handle *mh;/* attached mod header instance */
@@ -79,6 +80,7 @@ struct mlx5_flow_attr {struct mlx5e_tc_flow_parse_attr *parse_attr;u32 chain;u16 prio; +u16 tc_act_cookies_count;u32 dest_chain;struct mlx5_flow_table *ft;struct mlx5_flow_table *dest_ft;
Signature · 1 line
1.8.3.1
PATCH v4 8/9 net/mlx5e: TC, map tc action cookie to a hw counter
In reply to Oz ShlomoCurrently 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.
---
Change log:
V2 -> V3:
- Change commit message title
--- drivers/net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../ethernet/mellanox/mlx5/core/en/tc/act_stats.c | 153 +++++++++++++++++++++ .../ethernet/mellanox/mlx5/core/en/tc/act_stats.h | 23 ++++ drivers/net/ethernet/mellanox/mlx5/core/en_rep.h | 3 + drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 44 ++++++ 5 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.h
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
@@ -47,7 +47,7 @@ mlx5_core-$(CONFIG_MLX5_CLS_ACT) += en_tc.o en/rep/tc.o en/rep/neigh.o \ en/tc_tun_vxlan.o en/tc_tun_gre.o en/tc_tun_geneve.o \ en/tc_tun_mplsoudp.o diag/en_tc_tracepoint.o \ en/tc/post_act.o en/tc/int_port.o en/tc/meter.o \ - en/tc/post_meter.o + en/tc/post_meter.o en/tc/act_stats.o mlx5_core-$(CONFIG_MLX5_CLS_ACT) += en/tc/act/act.o en/tc/act/drop.o en/tc/act/trap.o \ en/tc/act/accept.o en/tc/act/mark.o en/tc/act/goto.o \
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.c new file +153 -0
153 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.h new file +23 -0
@@ -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__ */
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +3 -0
@@ -100,6 +100,9 @@ struct mlx5_rep_uplink_priv {struct mlx5e_tc_int_port_priv *int_port_priv;struct mlx5e_flow_meters *flow_meters; + +/* tc action stats */ +struct mlx5e_tc_act_stats_handle *action_stats_handle; };struct mlx5e_rep_priv {
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +44 -0
102 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 9/9 net/mlx5e: TC, support per action stats
In reply to Oz ShlomoExtend the action stats callback implementation to update stats for actions that are associated with hw counters.
Note that the callback may be called from tc action utility or from tc flower. Both apis expect the driver to return the stats difference from the last update. As such, query the raw counter value and maintain the diff from the last api call in the tc layer, instead of the fs_core layer.
---
Change log:
V2 -> V3:
- Change commit message title
--- .../net/ethernet/mellanox/mlx5/core/en/rep/tc.c | 2 +- .../ethernet/mellanox/mlx5/core/en/tc/act_stats.c | 44 ++++++++++++++++++++++ .../ethernet/mellanox/mlx5/core/en/tc/act_stats.h | 4 ++ .../net/ethernet/mellanox/mlx5/core/en/tc_priv.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 39 +++++++++++++------ drivers/net/ethernet/mellanox/mlx5/core/en_tc.h | 2 + .../net/ethernet/mellanox/mlx5/core/fs_counters.c | 10 +++++ include/linux/mlx5/fs.h | 2 + 8 files changed, 91 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +1 -1
@@ -589,7 +589,7 @@ static bool mlx5e_rep_macvlan_mode_supported(const struct net_device *dev) act =mlx5e_tc_act_get (fl_act->id, ns_type);if (!act || !act->stats_action) -return -EOPNOTSUPP ; +return mlx5e_tc_fill_action_stats (priv, fl_act);return act->stats_action (priv, fl_act); }
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.c +44 -0
59 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/tc/act_stats.h +4 -0
@@ -20,4 +20,8 @@ mlx5e_tc_act_stats_del_flow(struct mlx5e_tc_act_stats_handle *handle, struct mlx5e_tc_flow *flow); +int +mlx5e_tc_act_stats_fill_stats (struct mlx5e_tc_act_stats_handle *handle, +struct flow_offload_action *fl_act); +#endif /* __MLX5_EN_ACT_STATS_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en/tc_priv.h +1 -0
@@ -30,6 +30,7 @@ enum {MLX5E_TC_FLOW_FLAG_TUN_RX =MLX5E_TC_FLOW_BASE +9 ,MLX5E_TC_FLOW_FLAG_FAILED =MLX5E_TC_FLOW_BASE +10 ,MLX5E_TC_FLOW_FLAG_SAMPLE =MLX5E_TC_FLOW_BASE +11 , + MLX5E_TC_FLOW_FLAG_USE_ACT_STATS = MLX5E_TC_FLOW_BASE + 12, }; struct mlx5e_tc_flow_parse_attr {
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +27 -12
@@ -4117,6 +4117,7 @@ struct mlx5_flow_attr */* branching action requires its own counter */ attr->action |=MLX5_FLOW_CONTEXT_ACTION_COUNT ; +flow_flag_set (flow,USE_ACT_STATS );return 0 ;
@@ -4967,6 +4968,12 @@ int mlx5e_delete_flower(struct net_device *dev, struct mlx5e_priv *priv,return err; } +int mlx5e_tc_fill_action_stats (struct mlx5e_priv *priv, +struct flow_offload_action *fl_act) +{ +return mlx5e_tc_act_stats_fill_stats (get_act_stats_handle (priv), fl_act); +} +int mlx5e_stats_flower (struct net_device *dev,struct mlx5e_priv *priv,struct flow_cls_offload *f,unsigned long flags) {
@@ -4993,11 +5000,15 @@ int mlx5e_stats_flower(struct net_device *dev, struct mlx5e_priv *priv, }if (mlx5e_is_offloaded_flow (flow) ||flow_flag_test (flow,CT )) { - counter =mlx5e_tc_get_counter (flow); -if (!counter) - goto errout; +if (flow_flag_test (flow,USE_ACT_STATS )) { + f->use_act_stats = true; + }else { + counter =mlx5e_tc_get_counter (flow); +if (!counter) + goto errout; -mlx5_fc_query_cached (counter, &bytes, &packets, &lastuse); +mlx5_fc_query_cached (counter, &bytes, &packets, &lastuse); + } }/* Under multipath it's possible for one rule to be currently
@@ -5013,14 +5024,18 @@ int mlx5e_stats_flower(struct net_device *dev, struct mlx5e_priv *priv,u64 packets2;u64 lastuse2; - counter =mlx5e_tc_get_counter (flow->peer_flow); -if (!counter) - goto no_peer_counter; -mlx5_fc_query_cached (counter, &bytes2, &packets2, &lastuse2); - - bytes += bytes2; - packets += packets2; - lastuse =max_t (u64, lastuse, lastuse2); +if (flow_flag_test (flow,USE_ACT_STATS )) { + f->use_act_stats = true; + }else { + counter =mlx5e_tc_get_counter (flow->peer_flow); +if (!counter) + goto no_peer_counter; +mlx5_fc_query_cached (counter, &bytes2, &packets2, &lastuse2); + + bytes += bytes2; + packets += packets2; + lastuse =max_t (u64, lastuse, lastuse2); + } } no_peer_counter:
drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +2 -0
@@ -199,6 +199,8 @@ int mlx5e_delete_flower(struct net_device *dev, struct mlx5e_priv *priv,int mlx5e_stats_flower (struct net_device *dev,struct mlx5e_priv *priv,struct flow_cls_offload *f,unsigned long flags); +int mlx5e_tc_fill_action_stats (struct mlx5e_priv *priv, +struct flow_offload_action *fl_act);int mlx5e_tc_configure_matchall (struct mlx5e_priv *priv,struct tc_cls_matchall_offload *f);
drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +10 -0
@@ -504,6 +504,16 @@ void mlx5_fc_query_cached(struct mlx5_fc *counter, counter->lastpackets = c.packets; } +void mlx5_fc_query_cached_raw (struct mlx5_fc *counter, +u64 *bytes,u64 *packets,u64 *lastuse) +{ +struct mlx5_fc_cache c = counter->cache; + + *bytes = c.bytes; + *packets = c.packets; + *lastuse = c.lastuse; +} +void mlx5_fc_queue_stats_work (struct mlx5_core_dev *dev,struct delayed_work *dwork,unsigned long delay)
include/linux/mlx5/fs.h +2 -0
@@ -296,6 +296,8 @@ int mlx5_modify_rule_destination(struct mlx5_flow_handle *handler,u64 mlx5_fc_query_lastuse (struct mlx5_fc *counter);void mlx5_fc_query_cached (struct mlx5_fc *counter,u64 *bytes,u64 *packets,u64 *lastuse); +void mlx5_fc_query_cached_raw (struct mlx5_fc *counter, +u64 *bytes,u64 *packets,u64 *lastuse);int mlx5_fc_query (struct mlx5_core_dev *dev,struct mlx5_fc *counter,u64 *packets,u64 *bytes);u32 mlx5_fc_id (struct mlx5_fc *counter);
Signature · 1 line
1.8.3.1
This series was applied to netdev/net-next.git (master) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Sun, 12 Feb 2023 15:25:11 +0200 you wrote:
There are currently two mechanisms for populating hardware stats:
1. Usingflow_offloadapi to query the flow's statistics. The api assumes that the same stats values apply to all the flow's actions.
This assumption breaks when action drops or jumps over following actions.
2. Usinghw_actionapi to query specific action stats via a driver callback method. This api assures the correct action stats for the offloaded action, however, it does not apply to the rest of the actions in the flow's actions array, as elaborated below.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v4,1/9] net/sched: optimize action stats api calls
https://git.kernel.org/netdev/net-next/c/8f2ca70c07f4 - [net-next,v4,2/9] net/sched: act_pedit, setup offload action for action stats query https://git.kernel.org/netdev/net-next/c/3320f36fd8ad - [net-next,v4,3/9] net/sched: pass flow_stats instead of multiple stats args https://git.kernel.org/netdev/net-next/c/ac7d27907d54 - [net-next,v4,4/9] net/sched: introduce flow_offload action cookie https://git.kernel.org/netdev/net-next/c/d307b2c6f962 - [net-next,v4,5/9] net/sched: support per action hw stats https://git.kernel.org/netdev/net-next/c/5246c896b805 - [net-next,v4,6/9] net/mlx5e: TC, add hw counter to branching actions https://git.kernel.org/netdev/net-next/c/e9d1061d8727 - [net-next,v4,7/9] net/mlx5e: TC, store tc action cookies per attr https://git.kernel.org/netdev/net-next/c/cca7eac13856 - [net-next,v4,8/9] net/mlx5e: TC, map tc action cookie to a hw counter https://git.kernel.org/netdev/net-next/c/d13674b1d14c - [net-next,v4,9/9] net/mlx5e: TC, support per action stats https://git.kernel.org/netdev/net-next/c/2b68d659a704
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html