History

net_sched: add hit counter for matchall

Although matchall always matches packets, however, it still relies on a protocol match first. So it is still useful to have such a counter for matchall. Of course, unlike u32, every time we hit a matchall filter, it is always a success, so we don't have to distinguish them. Sample output: filter protocol 802.1Q pref 100 matchall chain 0 filter protocol 802.1Q pref 100 matchall chain 0 handle 0x1 not_in_hw (rule hit 10) action order 1: vlan pop continue index 1 ref 1 bind 1 installed 40 sec used 1 sec Action statistics: Sent 836 bytes 10 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0

Cong Wang committed 7 years ago

Commit f88c19a1 parent 209f94e2 files · +30 −0Browse files

Unified · Split

2 files
  1. include/uapi/linux/pkt_cls.h +6 −0
  2. net/sched/cls_matchall.c +24 −0
include/uapi/linux/pkt_cls.h+6−0
@@ -527,11 +527,17 @@ enum { · 526 unmodified lines
527527
528528 /* Match-all classifier */
529529
530+struct tc_matchall_pcnt {
531+ __u64 rhit;
532+};
533+
530534 enum {
531535 TCA_MATCHALL_UNSPEC,
532536 TCA_MATCHALL_CLASSID,
533537 TCA_MATCHALL_ACT,
534538 TCA_MATCHALL_FLAGS,
539+ TCA_MATCHALL_PCNT,
540+ TCA_MATCHALL_PAD,
535541 __TCA_MATCHALL_MAX,
536542 };
537543
net/sched/cls_matchall.c+24−0
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include <linux/kernel.h>
1313 #include <linux/init.h>
1414 #include <linux/module.h>
15+#include <linux/percpu.h>
1516
1617 #include <net/sch_generic.h>
1718 #include <net/pkt_cls.h>
@@ -22,6 +23,7 @@ struct cls_mall_head { · 4 unmodified lines
2223 u32 handle;
2324 u32 flags;
2425 unsigned int in_hw_count;
26+ struct tc_matchall_pcnt __percpu *pf;
2527 struct rcu_work rwork;
2628 };
2729
@@ -34,6 +36,7 @@ static int mall_classify(struct sk_buff *skb, const struct tcf_proto *tp, · 6 unmodified lines
3436 return -1;
3537
3638 *res = head->res;
39+ __this_cpu_inc(head->pf->rhit);
3740 return tcf_exts_exec(skb, &head->exts, res);
3841 }
3942
@@ -46,6 +49,7 @@ static void __mall_destroy(struct cls_mall_head *head) · 6 unmodified lines
4649 {
4750 tcf_exts_destroy(&head->exts);
4851 tcf_exts_put_net(&head->exts);
52+ free_percpu(head->pf);
4953 kfree(head);
5054 }
5155
@@ -192,6 +196,11 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, · 140 unmodified lines
192196 handle = 1;
193197 new->handle = handle;
194198 new->flags = flags;
199+ new->pf = alloc_percpu(struct tc_matchall_pcnt);
200+ if (!new->pf) {
201+ err = -ENOMEM;
202+ goto err_alloc_percpu;
203+ }
195204
196205 err = mall_set_parms(net, tp, new, base, tb, tca[TCA_RATE], ovr,
197206 extack);
@@ -214,6 +223,8 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, · 16 unmodified lines
214223
215224 err_replace_hw_filter:
216225 err_set_parms:
226+ free_percpu(new->pf);
227+err_alloc_percpu:
217228 tcf_exts_destroy(&new->exts);
218229 err_exts_init:
219230 kfree(new);
@@ -270,8 +281,10 @@ static int mall_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb, · 50 unmodified lines
270281 static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh,
271282 struct sk_buff *skb, struct tcmsg *t)
272283 {
284+ struct tc_matchall_pcnt gpf = {};
273285 struct cls_mall_head *head = fh;
274286 struct nlattr *nest;
287+ int cpu;
275288
276289 if (!head)
277290 return skb->len;
@@ -289,6 +302,17 @@ static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh, · 11 unmodified lines
289302 if (head->flags && nla_put_u32(skb, TCA_MATCHALL_FLAGS, head->flags))
290303 goto nla_put_failure;
291304
305+ for_each_possible_cpu(cpu) {
306+ struct tc_matchall_pcnt *pf = per_cpu_ptr(head->pf, cpu);
307+
308+ gpf.rhit += pf->rhit;
309+ }
310+
311+ if (nla_put_64bit(skb, TCA_MATCHALL_PCNT,
312+ sizeof(struct tc_matchall_pcnt),
313+ &gpf, TCA_MATCHALL_PAD))
314+ goto nla_put_failure;
315+
292316 if (tcf_exts_dump(skb, &head->exts))
293317 goto nla_put_failure;
294318