Skip to content

Commit c8ecebd

Browse files
w1ldptrdavem330
authored andcommitted
net: sched: extract common action counters update code into function
Currently, all implementations of tc_action_ops->stats_update() callback have almost exactly the same implementation of counters update code (besides gact which also updates drop counter). In order to simplify support for using both percpu-allocated and regular action counters depending on run-time flag in following patches, extract action counters update code into standalone function in act API. This commit doesn't change functionality. 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 21d8bd1 commit c8ecebd

7 files changed

Lines changed: 21 additions & 26 deletions

File tree

‎include/net/act_api.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[], int bind,
186186
int ref);
187187
int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
188188
int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
189+
void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
190+
bool drop, bool hw);
189191
int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
190192

191193
int tcf_action_check_ctrlact(int action, struct tcf_proto *tp,

‎net/sched/act_api.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,20 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
989989
return err;
990990
}
991991

992+
void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
993+
bool drop, bool hw)
994+
{
995+
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
996+
997+
if (drop)
998+
this_cpu_ptr(a->cpu_qstats)->drops += packets;
999+
1000+
if (hw)
1001+
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
1002+
bytes, packets);
1003+
}
1004+
EXPORT_SYMBOL(tcf_action_update_stats);
1005+
9921006
int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *p,
9931007
int compat_mode)
9941008
{

‎net/sched/act_ct.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,7 @@ static void tcf_stats_update(struct tc_action *a, u64 bytes, u32 packets,
905905
{
906906
struct tcf_ct *c = to_ct(a);
907907

908-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
909-
910-
if (hw)
911-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
912-
bytes, packets);
908+
tcf_action_update_stats(a, bytes, packets, false, hw);
913909
c->tcf_tm.lastuse = max_t(u64, c->tcf_tm.lastuse, lastuse);
914910
}
915911

‎net/sched/act_gact.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,7 @@ static void tcf_gact_stats_update(struct tc_action *a, u64 bytes, u32 packets,
177177
int action = READ_ONCE(gact->tcf_action);
178178
struct tcf_t *tm = &gact->tcf_tm;
179179

180-
_bstats_cpu_update(this_cpu_ptr(gact->common.cpu_bstats), bytes,
181-
packets);
182-
if (action == TC_ACT_SHOT)
183-
this_cpu_ptr(gact->common.cpu_qstats)->drops += packets;
184-
185-
if (hw)
186-
_bstats_cpu_update(this_cpu_ptr(gact->common.cpu_bstats_hw),
187-
bytes, packets);
188-
180+
tcf_action_update_stats(a, bytes, packets, action == TC_ACT_SHOT, hw);
189181
tm->lastuse = max_t(u64, tm->lastuse, lastuse);
190182
}
191183

‎net/sched/act_mirred.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,7 @@ static void tcf_stats_update(struct tc_action *a, u64 bytes, u32 packets,
318318
struct tcf_mirred *m = to_mirred(a);
319319
struct tcf_t *tm = &m->tcf_tm;
320320

321-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
322-
if (hw)
323-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
324-
bytes, packets);
321+
tcf_action_update_stats(a, bytes, packets, false, hw);
325322
tm->lastuse = max_t(u64, tm->lastuse, lastuse);
326323
}
327324

‎net/sched/act_police.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,7 @@ static void tcf_police_stats_update(struct tc_action *a,
294294
struct tcf_police *police = to_police(a);
295295
struct tcf_t *tm = &police->tcf_tm;
296296

297-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
298-
if (hw)
299-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
300-
bytes, packets);
297+
tcf_action_update_stats(a, bytes, packets, false, hw);
301298
tm->lastuse = max_t(u64, tm->lastuse, lastuse);
302299
}
303300

‎net/sched/act_vlan.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,7 @@ static void tcf_vlan_stats_update(struct tc_action *a, u64 bytes, u32 packets,
307307
struct tcf_vlan *v = to_vlan(a);
308308
struct tcf_t *tm = &v->tcf_tm;
309309

310-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
311-
if (hw)
312-
_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
313-
bytes, packets);
310+
tcf_action_update_stats(a, bytes, packets, false, hw);
314311
tm->lastuse = max_t(u64, tm->lastuse, lastuse);
315312
}
316313

0 commit comments

Comments
 (0)