From patchwork Wed Apr 19 11:57:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jamal Hadi Salim X-Patchwork-Id: 752222 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3w7L990qZPz9s03 for ; Wed, 19 Apr 2017 21:57:49 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mojatatu-com.20150623.gappssmtp.com header.i=@mojatatu-com.20150623.gappssmtp.com header.b="SuQsifN+"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762793AbdDSL5r (ORCPT ); Wed, 19 Apr 2017 07:57:47 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:35122 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762788AbdDSL5p (ORCPT ); Wed, 19 Apr 2017 07:57:45 -0400 Received: by mail-io0-f193.google.com with SMTP id d203so3156883iof.2 for ; Wed, 19 Apr 2017 04:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rLMrmy20TG+crjpMfWHlOpgcwVbrXWpkPA+hwKWTln4=; b=SuQsifN+3GuoxNL1zUI5Ls0XZ7skTXh6GOKdtE0kR7Uot3bcMfjHpEJFGGI/6UfzSK oXO5BPZyr8R75nQUK58FonVB/4DEnPZmE2K4CxruG21+gBe95vTESmLFwDaVIg22rjmh 3XAkWGYa3WPT0gZ6dQ7omKDngH1iGRv4UAhCewhQ5z93x3lgdLi8EaOFkV5IT66fQwmR Q2ABxqtuncbZ3ZZjmxvRJg521Zz3lvXfcaUr7lalbSi5do4Bl+dPnfkIU/jOvNS8I8CG ISXrSuwp1CvLEllGsGIRx9R2C2YQQs1+IeTxrM4n4e17Mt5BMriloXSfi1RYfSEAjoIu mrLw== 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:in-reply-to :references; bh=rLMrmy20TG+crjpMfWHlOpgcwVbrXWpkPA+hwKWTln4=; b=CLRAhfwBMiXTBoU9Ct+39ugFKArfNjqJ1zl/KMwNzMUD6ZEhSJq8tcUFAKv0FDBbXT x0dfhAC2+mCsIl7hTZNlBiS7ghF4NmEgTrgxniP2yiAQ6dSnB4upmC7G5ueO7oNf/qi+ 9/I3BKeYUvMotWX/+coU2PxqtregZ85sm11d4pgMA13DmTlA95OEzWQfWqDQ8qJtP0J6 oypbNiJ5tqXXDdQybp90SWBZHR3067Yg/KGs/laNpmM0O93VR4JyG3yLjpMBuNkKZhHK SvrUQjq6tk8jwE8pa+zhstaLQuTBYK04x7kEjVGBs91YXmsVNZMAe4wXSKEP2aYUYTzD G09w== X-Gm-Message-State: AN3rC/7LnWtfECo7w3Y1i1EkkpQy41AgMgHfGa/qKb3y2MzCQZjsK2Hb BSjr0mQIGb0kig== X-Received: by 10.107.35.145 with SMTP id j139mr2579703ioj.195.1492603064095; Wed, 19 Apr 2017 04:57:44 -0700 (PDT) Received: from localhost.localdomain (23-233-25-245.cpe.pppoe.ca. [23.233.25.245]) by smtp.gmail.com with ESMTPSA id r70sm1248781iod.37.2017.04.19.04.57.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Apr 2017 04:57:43 -0700 (PDT) From: Jamal Hadi Salim X-Google-Original-From: Jamal Hadi Salim To: davem@davemloft.net Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, jiri@resnulli.us, xiyou.wangcong@gmail.com, Jamal Hadi Salim Subject: [PATCH net-next v4 2/2] net sched actions: add time filter for action dumping Date: Wed, 19 Apr 2017 07:57:30 -0400 Message-Id: <1492603050-9318-2-git-send-email-jhs@emojatatu.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1492603050-9318-1-git-send-email-jhs@emojatatu.com> References: <1492603050-9318-1-git-send-email-jhs@emojatatu.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jamal Hadi Salim This adds support for filtering based on time since last used. When we are dumping a large number of actions it is useful to have the option of filtering based on when the action was last used to reduce the amount of data crossing to user space. With this patch the user space app sets the TCAA_ACT_TIME_FILTER attribute with the value in milliseconds with "time of interest since now". The kernel converts this to jiffies and does the filtering comparison matching entries that have seen activity since then and returns them to user space. Old kernels and old tc continue to work in legacy mode since they dont specify this attribute. Some example (we have 400 actions bound to 400 filters); at installation time using hacked tc which sets the time of interest to 120 seconds: prompt$ hackedtc actions ls action gact | grep index | wc -l 400 go get some coffee and wait for > 120 seconds and try again: prompt$ hackedtc actions ls action gact | grep index | wc -l 0 Lets see a filter bound to one of these actions: .. filter pref 10 u32 filter pref 10 u32 fh 800: ht divisor 1 filter pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:10 (rule hit 2 success 1) match 7f000002/ffffffff at 12 (success 1 ) action order 1: gact action pass random type none pass val 0 index 23 ref 2 bind 1 installed 1145 sec used 802 sec Action statistics: Sent 84 bytes 1 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 .... that coffee took long, no? It was good. Now lets ping -c 1 127.0.0.2, then run the actions again: prompt$ hackedtc actions ls action gact | grep index | wc -l 1 More details please: prompt$ hackedtc -s actions ls action gact action order 0: gact action pass random type none pass val 0 index 23 ref 2 bind 1 installed 1270 sec used 30 sec Action statistics: Sent 168 bytes 2 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 And the filter? filter pref 10 u32 filter pref 10 u32 fh 800: ht divisor 1 filter pref 10 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:10 (rule hit 4 success 2) match 7f000002/ffffffff at 12 (success 2 ) action order 1: gact action pass random type none pass val 0 index 23 ref 2 bind 1 installed 1324 sec used 84 sec Action statistics: Sent 168 bytes 2 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 Signed-off-by: Jamal Hadi Salim --- include/uapi/linux/rtnetlink.h | 1 + net/sched/act_api.c | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index c7080ec..1b36cc0 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -680,6 +680,7 @@ enum { TCAA_ACT_TAB, TCAA_ACT_FLAGS, TCAA_ACT_COUNT, + TCAA_ACT_TIME_FILTER, __TCAA_MAX }; diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 45e1cf7..b03863a 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -84,11 +84,12 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb, { int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; unsigned short act_flags = cb->args[2]; + unsigned long jiffy_filter = cb->args[3]; struct nlattr *nest; spin_lock_bh(&hinfo->lock); - s_i = cb->args[0]; + s_i = cb->args[4]; for (i = 0; i < (hinfo->hmask + 1); i++) { struct hlist_head *head; @@ -101,6 +102,11 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb, if (index < s_i) continue; + if (jiffy_filter && + time_after(jiffy_filter, + (unsigned long)p->tcfa_tm.lastuse)) + continue; + nest = nla_nest_start(skb, n_i); if (nest == NULL) goto nla_put_failure; @@ -118,6 +124,9 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb, } } done: + if (index > 0) + cb->args[4] = index + 1; + spin_unlock_bh(&hinfo->lock); if (n_i) { cb->args[0] += n_i; @@ -1000,6 +1009,7 @@ static int tcf_action_add(struct net *net, struct nlattr *nla, static const struct nla_policy tcaa_policy[TCAA_MAX + 1] = { [TCAA_ACT_FLAGS] = { .type = NLA_U32 }, + [TCAA_ACT_TIME_FILTER] = { .type = NLA_U32 }, }; static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, @@ -1090,13 +1100,14 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) struct tcamsg *t = (struct tcamsg *) nlmsg_data(cb->nlh); struct nlattr *kind = NULL; u32 act_flags = 0; + u32 msecs_filter = 0; + unsigned long jiffy_wanted = 0; ret = nlmsg_parse(cb->nlh, sizeof(struct tcamsg), tcaa, TCAA_MAX, tcaa_policy, NULL); if (ret < 0) return ret; - kind = find_dump_kind(tcaa); if (kind == NULL) { pr_info("tc_dump_action: action bad kind\n"); @@ -1110,12 +1121,22 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) if (tcaa[TCAA_ACT_FLAGS]) act_flags = nla_get_u32(tcaa[TCAA_ACT_FLAGS]); + if (tcaa[TCAA_ACT_TIME_FILTER]) + msecs_filter = nla_get_u32(tcaa[TCAA_ACT_TIME_FILTER]); + nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, cb->nlh->nlmsg_type, sizeof(*t), 0); if (!nlh) goto out_module_put; + if (msecs_filter) { + unsigned long jiffy_msecs = msecs_to_jiffies(msecs_filter); + + jiffy_wanted = jiffies - jiffy_msecs; + } + cb->args[2] = act_flags; + cb->args[3] = jiffy_wanted; t = nlmsg_data(nlh); t->tca_family = AF_UNSPEC;