Skip to content

Commit d897a63

Browse files
Jakub Kicinskidavem330
authored andcommitted
sched: add helper for updating statistics on all actions
Forgetting to disable preemption around tcf_action_stats_update() seems to be a common mistake. Add a helper function for updating stats on all actions of a filter. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c380e37 commit d897a63

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,9 +1863,7 @@ int mlx5e_stats_flower(struct mlx5e_priv *priv,
18631863
{
18641864
struct mlx5e_tc_table *tc = &priv->fs.tc;
18651865
struct mlx5e_tc_flow *flow;
1866-
struct tc_action *a;
18671866
struct mlx5_fc *counter;
1868-
LIST_HEAD(actions);
18691867
u64 bytes;
18701868
u64 packets;
18711869
u64 lastuse;
@@ -1884,13 +1882,7 @@ int mlx5e_stats_flower(struct mlx5e_priv *priv,
18841882

18851883
mlx5_fc_query_cached(counter, &bytes, &packets, &lastuse);
18861884

1887-
preempt_disable();
1888-
1889-
tcf_exts_to_list(f->exts, &actions);
1890-
list_for_each_entry(a, &actions, list)
1891-
tcf_action_stats_update(a, bytes, packets, lastuse);
1892-
1893-
preempt_enable();
1885+
tcf_exts_stats_update(f->exts, bytes, packets, lastuse);
18941886

18951887
return 0;
18961888
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,6 @@ int mlxsw_sp_flower_stats(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,
397397
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
398398
struct mlxsw_sp_acl_ruleset *ruleset;
399399
struct mlxsw_sp_acl_rule *rule;
400-
struct tc_action *a;
401-
LIST_HEAD(actions);
402400
u64 packets;
403401
u64 lastuse;
404402
u64 bytes;
@@ -419,13 +417,7 @@ int mlxsw_sp_flower_stats(struct mlxsw_sp_port *mlxsw_sp_port, bool ingress,
419417
if (err)
420418
goto err_rule_get_stats;
421419

422-
preempt_disable();
423-
424-
tcf_exts_to_list(f->exts, &actions);
425-
list_for_each_entry(a, &actions, list)
426-
tcf_action_stats_update(a, bytes, packets, lastuse);
427-
428-
preempt_enable();
420+
tcf_exts_stats_update(f->exts, bytes, packets, lastuse);
429421

430422
mlxsw_sp_acl_ruleset_put(mlxsw_sp, ruleset);
431423
return 0;

drivers/net/ethernet/netronome/nfp/nfp_net_offload.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ static void nfp_net_bpf_stats_reset(struct nfp_net *nn)
8484
static int
8585
nfp_net_bpf_stats_update(struct nfp_net *nn, struct tc_cls_bpf_offload *cls_bpf)
8686
{
87-
struct tc_action *a;
88-
LIST_HEAD(actions);
8987
u64 bytes, pkts;
9088

9189
pkts = nn->rx_filter.pkts - nn->rx_filter_prev.pkts;
@@ -94,13 +92,8 @@ nfp_net_bpf_stats_update(struct nfp_net *nn, struct tc_cls_bpf_offload *cls_bpf)
9492

9593
nn->rx_filter_prev = nn->rx_filter;
9694

97-
preempt_disable();
98-
99-
tcf_exts_to_list(cls_bpf->exts, &actions);
100-
list_for_each_entry(a, &actions, list)
101-
tcf_action_stats_update(a, bytes, pkts, nn->rx_filter_change);
102-
103-
preempt_enable();
95+
tcf_exts_stats_update(cls_bpf->exts,
96+
bytes, pkts, nn->rx_filter_change);
10497

10598
return 0;
10699
}

include/net/pkt_cls.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ static inline void tcf_exts_to_list(const struct tcf_exts *exts,
157157
#endif
158158
}
159159

160+
static inline void
161+
tcf_exts_stats_update(const struct tcf_exts *exts,
162+
u64 bytes, u64 packets, u64 lastuse)
163+
{
164+
#ifdef CONFIG_NET_CLS_ACT
165+
int i;
166+
167+
preempt_disable();
168+
169+
for (i = 0; i < exts->nr_actions; i++) {
170+
struct tc_action *a = exts->actions[i];
171+
172+
tcf_action_stats_update(a, bytes, packets, lastuse);
173+
}
174+
175+
preempt_enable();
176+
#endif
177+
}
178+
160179
/**
161180
* tcf_exts_exec - execute tc filter extensions
162181
* @skb: socket buffer

0 commit comments

Comments
 (0)