net: sched: extract common action counters update code into function
authorVlad Buslov <vladbu@mellanox.com>
Wed, 30 Oct 2019 14:09:00 +0000 (16:09 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 31 Oct 2019 01:07:50 +0000 (18:07 -0700)
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>
include/net/act_api.h
net/sched/act_api.c
net/sched/act_ct.c
net/sched/act_gact.c
net/sched/act_mirred.c
net/sched/act_police.c
net/sched/act_vlan.c

index b18c699681ca81b4d5163a42d2dcf7123505f5c2..f6f66c692385ecf37ca2f4c9bd3cbb4a4ce096e6 100644 (file)
@@ -186,6 +186,8 @@ int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[], int bind,
                    int ref);
 int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
 int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
+void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
+                            bool drop, bool hw);
 int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
 
 int tcf_action_check_ctrlact(int action, struct tcf_proto *tp,
index 69d4676a402f54ac0d03999b5c73e572c1f06447..0638afa2fc3f2e01aedc712bc0d0233a61b4bbd4 100644 (file)
@@ -989,6 +989,20 @@ err:
        return err;
 }
 
+void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
+                            bool drop, bool hw)
+{
+       _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
+
+       if (drop)
+               this_cpu_ptr(a->cpu_qstats)->drops += packets;
+
+       if (hw)
+               _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
+                                  bytes, packets);
+}
+EXPORT_SYMBOL(tcf_action_update_stats);
+
 int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *p,
                          int compat_mode)
 {
index fcc46025e79086bffb21b4c9db451d92003872eb..ba76857754e56d6b670ae7b0df01356be51005ec 100644 (file)
@@ -905,11 +905,7 @@ static void tcf_stats_update(struct tc_action *a, u64 bytes, u32 packets,
 {
        struct tcf_ct *c = to_ct(a);
 
-       _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
-
-       if (hw)
-               _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
-                                  bytes, packets);
+       tcf_action_update_stats(a, bytes, packets, false, hw);
        c->tcf_tm.lastuse = max_t(u64, c->tcf_tm.lastuse, lastuse);
 }
 
index 324f1d1f6d477973596fe334ce682587610a30a7..569cec63d4c39391eccc70f732a56f5796ce668b 100644 (file)
@@ -177,15 +177,7 @@ static void tcf_gact_stats_update(struct tc_action *a, u64 bytes, u32 packets,
        int action = READ_ONCE(gact->tcf_action);
        struct tcf_t *tm = &gact->tcf_tm;
 
-       _bstats_cpu_update(this_cpu_ptr(gact->common.cpu_bstats), bytes,
-                          packets);
-       if (action == TC_ACT_SHOT)
-               this_cpu_ptr(gact->common.cpu_qstats)->drops += packets;
-
-       if (hw)
-               _bstats_cpu_update(this_cpu_ptr(gact->common.cpu_bstats_hw),
-                                  bytes, packets);
-
+       tcf_action_update_stats(a, bytes, packets, action == TC_ACT_SHOT, hw);
        tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
index 08923b21e56607f4b163dafa4e2f97d348a34061..621686a6b5be90b0c8373625397b7f5e449aef58 100644 (file)
@@ -318,10 +318,7 @@ static void tcf_stats_update(struct tc_action *a, u64 bytes, u32 packets,
        struct tcf_mirred *m = to_mirred(a);
        struct tcf_t *tm = &m->tcf_tm;
 
-       _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
-       if (hw)
-               _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
-                                  bytes, packets);
+       tcf_action_update_stats(a, bytes, packets, false, hw);
        tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
index 981a9eca0c524ac7a18c98630c0bc7d087fadfdc..51d34b1a61d52715e1da5fe76642ffae25a32a57 100644 (file)
@@ -294,10 +294,7 @@ static void tcf_police_stats_update(struct tc_action *a,
        struct tcf_police *police = to_police(a);
        struct tcf_t *tm = &police->tcf_tm;
 
-       _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
-       if (hw)
-               _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
-                                  bytes, packets);
+       tcf_action_update_stats(a, bytes, packets, false, hw);
        tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }
 
index 08aaf719a70fbbc1577705712f2cf6d3d5b0202e..9e68edb22e5374e32d643b34b688edaecef545fd 100644 (file)
@@ -307,10 +307,7 @@ static void tcf_vlan_stats_update(struct tc_action *a, u64 bytes, u32 packets,
        struct tcf_vlan *v = to_vlan(a);
        struct tcf_t *tm = &v->tcf_tm;
 
-       _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
-       if (hw)
-               _bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
-                                  bytes, packets);
+       tcf_action_update_stats(a, bytes, packets, false, hw);
        tm->lastuse = max_t(u64, tm->lastuse, lastuse);
 }