From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDBD4C43387 for ; Thu, 17 Jan 2019 20:44:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A4D7D20851 for ; Thu, 17 Jan 2019 20:44:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k3txG2r3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbfAQUoi (ORCPT ); Thu, 17 Jan 2019 15:44:38 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38509 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbfAQUoi (ORCPT ); Thu, 17 Jan 2019 15:44:38 -0500 Received: by mail-pf1-f194.google.com with SMTP id q1so5396483pfi.5 for ; Thu, 17 Jan 2019 12:44:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3ic6lHu7sjoEjyMOh1T1YvH5DMzrGL8N7DwSmgMexb0=; b=k3txG2r3UheQAzFU49uAqJI4eed0YzCSnFfQ7aQKKfEbht/xqoEn5eXZH+JJEUuPFl uIb1cM4D3RMublZ6uSDwAxwE8qWKeKEgvkiQEHMGWmuMR/8gFgxhRYuyPyKig4CHdY5e yh8LQoabbZ0osGBP/zQ3lhvmRXq3DkrMPO10Ew//K/1/ogo+uHz926WsVm/qCQZXqU5S EAzV1B7tz2rd+DL/PqoLEV1kz7GlbS3imRE3upf32qdrTx/gY7yczKJ7d+ufXE4hz6Ev 1YQBJmpWDePCILAplzrHEks4gzQCQws6YDv07QxNGDSCCiUOlonYjBQnJ9h1UsnDzFBS ynuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3ic6lHu7sjoEjyMOh1T1YvH5DMzrGL8N7DwSmgMexb0=; b=cm4iFsThMW46HDWHsFUDv+J5LjEjihvZFSBixgQBIeaKkzE+tRArnCXG8parE6Crel 5QOQ0JehPP5jhLfx/ctuIaH/rG3b75yfD3JD8Jy2QS5NvzfymDxORWxTaccnVqtL14jE NpgPCOppXjmZN+Gg1+i4d1s+fGlFDu+X61oNylikPGzdzMO0G6Ax7DtCgiJVK5htM5jF zopHABR0Ds51Wt++vGq9YIhFJFsqkUY73mTU5WOPE1rdzKBA+iLg2XOhUf8FBiwzCRLP X96P4jxjMM3rofdnOT/9F63uA/plfudtn1YKl2pS+czR+FvsnVmh/ocCoi3t1DGCrZ3d le4A== X-Gm-Message-State: AJcUuke9nPbtINbU7WW/ULfaIktcd4AzFLYDxAhqcMTAzHrgBW1GZkSq DT95m3J9gxF/XAuazG9SqAUC0bz2 X-Google-Smtp-Source: ALg8bN7Z5ug4fkb1QlNToSnFt/5OgK7uZN1lFN8guJ1xrY4Ew2yC6rDykijRBjeFd2jO03CdIYpSsg== X-Received: by 2002:a63:7512:: with SMTP id q18mr13790146pgc.231.1547757876919; Thu, 17 Jan 2019 12:44:36 -0800 (PST) Received: from tw-172-25-17-123.office.twttr.net ([8.25.197.27]) by smtp.gmail.com with ESMTPSA id q7sm2522214pgp.40.2019.01.17.12.44.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Jan 2019 12:44:36 -0800 (PST) From: Cong Wang To: netdev@vger.kernel.org Cc: Cong Wang , Martin Olsson , Jamal Hadi Salim , Jiri Pirko Subject: [Patch net-next] net_sched: add hit counter for matchall Date: Thu, 17 Jan 2019 12:44:25 -0800 Message-Id: <20190117204425.27750-1-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Reported-by: Martin Olsson Cc: Jamal Hadi Salim Cc: Jiri Pirko Signed-off-by: Cong Wang --- include/uapi/linux/pkt_cls.h | 6 ++++++ net/sched/cls_matchall.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h index 95d0db2a8350..32a3416b51c3 100644 --- a/include/uapi/linux/pkt_cls.h +++ b/include/uapi/linux/pkt_cls.h @@ -527,11 +527,17 @@ enum { /* Match-all classifier */ +struct tc_matchall_pcnt { + __u64 rhit; +}; + enum { TCA_MATCHALL_UNSPEC, TCA_MATCHALL_CLASSID, TCA_MATCHALL_ACT, TCA_MATCHALL_FLAGS, + TCA_MATCHALL_PCNT, + TCA_MATCHALL_PAD, __TCA_MATCHALL_MAX, }; diff --git a/net/sched/cls_matchall.c b/net/sched/cls_matchall.c index 0e408ee9dcec..a1b803fd372e 100644 --- a/net/sched/cls_matchall.c +++ b/net/sched/cls_matchall.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -22,6 +23,7 @@ struct cls_mall_head { u32 handle; u32 flags; unsigned int in_hw_count; + struct tc_matchall_pcnt __percpu *pf; struct rcu_work rwork; }; @@ -34,6 +36,7 @@ static int mall_classify(struct sk_buff *skb, const struct tcf_proto *tp, return -1; *res = head->res; + __this_cpu_inc(head->pf->rhit); return tcf_exts_exec(skb, &head->exts, res); } @@ -46,6 +49,7 @@ static void __mall_destroy(struct cls_mall_head *head) { tcf_exts_destroy(&head->exts); tcf_exts_put_net(&head->exts); + free_percpu(head->pf); kfree(head); } @@ -192,6 +196,11 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, handle = 1; new->handle = handle; new->flags = flags; + new->pf = alloc_percpu(struct tc_matchall_pcnt); + if (!new->pf) { + err = -ENOMEM; + goto err_alloc_percpu; + } err = mall_set_parms(net, tp, new, base, tb, tca[TCA_RATE], ovr, extack); @@ -214,6 +223,8 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, err_replace_hw_filter: err_set_parms: + free_percpu(new->pf); +err_alloc_percpu: tcf_exts_destroy(&new->exts); err_exts_init: kfree(new); @@ -270,8 +281,10 @@ static int mall_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb, static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh, struct sk_buff *skb, struct tcmsg *t) { + struct tc_matchall_pcnt gpf = {}; struct cls_mall_head *head = fh; struct nlattr *nest; + int cpu; if (!head) return skb->len; @@ -289,6 +302,17 @@ static int mall_dump(struct net *net, struct tcf_proto *tp, void *fh, if (head->flags && nla_put_u32(skb, TCA_MATCHALL_FLAGS, head->flags)) goto nla_put_failure; + for_each_possible_cpu(cpu) { + struct tc_matchall_pcnt *pf = per_cpu_ptr(head->pf, cpu); + + gpf.rhit += pf->rhit; + } + + if (nla_put_64bit(skb, TCA_MATCHALL_PCNT, + sizeof(struct tc_matchall_pcnt), + &gpf, TCA_MATCHALL_PAD)) + goto nla_put_failure; + if (tcf_exts_dump(skb, &head->exts)) goto nla_put_failure; -- 2.20.1