Skip to content

Commit 5e174d5

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: modify stats helper functions to support regular stats
Modify stats update helper functions introduced in previous patches in this series to fallback to regular tc_action->tcfa_{b|q}stats if cpu stats are not allocated for the action argument. If regular non-percpu allocated counters are in use, then obtain action tcfa_lock while modifying them. Signed-off-by: Vlad Buslov <vladbu@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ef816f3 commit 5e174d5

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

‎include/net/act_api.h‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,35 @@ int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
190190
static inline void tcf_action_update_bstats(struct tc_action *a,
191191
struct sk_buff *skb)
192192
{
193-
bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), skb);
194-
}
195-
196-
static inline struct gnet_stats_queue *
197-
tcf_action_get_qstats(struct tc_action *a)
198-
{
199-
return this_cpu_ptr(a->cpu_qstats);
193+
if (likely(a->cpu_bstats)) {
194+
bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), skb);
195+
return;
196+
}
197+
spin_lock(&a->tcfa_lock);
198+
bstats_update(&a->tcfa_bstats, skb);
199+
spin_unlock(&a->tcfa_lock);
200200
}
201201

202202
static inline void tcf_action_inc_drop_qstats(struct tc_action *a)
203203
{
204-
qstats_drop_inc(this_cpu_ptr(a->cpu_qstats));
204+
if (likely(a->cpu_qstats)) {
205+
qstats_drop_inc(this_cpu_ptr(a->cpu_qstats));
206+
return;
207+
}
208+
spin_lock(&a->tcfa_lock);
209+
qstats_drop_inc(&a->tcfa_qstats);
210+
spin_unlock(&a->tcfa_lock);
205211
}
206212

207213
static inline void tcf_action_inc_overlimit_qstats(struct tc_action *a)
208214
{
209-
qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats));
215+
if (likely(a->cpu_qstats)) {
216+
qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats));
217+
return;
218+
}
219+
spin_lock(&a->tcfa_lock);
220+
qstats_overlimit_inc(&a->tcfa_qstats);
221+
spin_unlock(&a->tcfa_lock);
210222
}
211223

212224
void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,

‎net/sched/act_api.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,14 +992,23 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
992992
void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
993993
bool drop, bool hw)
994994
{
995-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
995+
if (a->cpu_bstats) {
996+
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
996997

997-
if (drop)
998-
this_cpu_ptr(a->cpu_qstats)->drops += packets;
998+
if (drop)
999+
this_cpu_ptr(a->cpu_qstats)->drops += packets;
1000+
1001+
if (hw)
1002+
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
1003+
bytes, packets);
1004+
return;
1005+
}
9991006

1007+
_bstats_update(&a->tcfa_bstats, bytes, packets);
1008+
if (drop)
1009+
a->tcfa_qstats.drops += packets;
10001010
if (hw)
1001-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
1002-
bytes, packets);
1011+
_bstats_update(&a->tcfa_bstats_hw, bytes, packets);
10031012
}
10041013
EXPORT_SYMBOL(tcf_action_update_stats);
10051014

0 commit comments

Comments
 (0)