Message ID | 1500860146-26970-5-git-send-email-jhs@emojatatu.com |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
Mon, Jul 24, 2017 at 03:35:46AM CEST, jhs@mojatatu.com wrote: >From: Jamal Hadi Salim <jhs@mojatatu.com> > >This patch 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 TCA_ROOT_TIME_DELTA >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. [...] >@@ -128,6 +129,11 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb, > if (index < s_i) > continue; > >+ if (jiffy_since && >+ time_after(jiffy_since, >+ (unsigned long)p->tcfa_tm.lastuse)) You don't need to check jiffy_since==0. Also, nicer ^^ this with a space :) Other than this, looks fine. Thanks.
On 17-07-24 07:34 AM, Jiri Pirko wrote: > Mon, Jul 24, 2017 at 03:35:46AM CEST, jhs@mojatatu.com wrote: >> From: Jamal Hadi Salim <jhs@mojatatu.com> > >> @@ -128,6 +129,11 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb, >> if (index < s_i) >> continue; >> >> + if (jiffy_since && >> + time_after(jiffy_since, >> + (unsigned long)p->tcfa_tm.lastuse)) > > You don't need to check jiffy_since==0. Also, nicer ^^ this with a space :) > Assuming that time_after() would work fine for jiffy_since being zero, but: wouldnt it be more efficient to just not call time_after() altogether? > Other than this, looks fine. Ok, please no more changes - I am exhausted ;-> So speak for this update or send patches afterwards if you dont like something. cheers, jamal
Tue, Jul 25, 2017 at 01:27:03PM CEST, jhs@mojatatu.com wrote: >On 17-07-24 07:34 AM, Jiri Pirko wrote: >> Mon, Jul 24, 2017 at 03:35:46AM CEST, jhs@mojatatu.com wrote: >> > From: Jamal Hadi Salim <jhs@mojatatu.com> > >> >> > @@ -128,6 +129,11 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb, >> > if (index < s_i) >> > continue; >> > >> > + if (jiffy_since && >> > + time_after(jiffy_since, >> > + (unsigned long)p->tcfa_tm.lastuse)) >> >> You don't need to check jiffy_since==0. Also, nicer ^^ this with a space :) >> > >Assuming that time_after() would work fine for jiffy_since being zero, >but: >wouldnt it be more efficient to just not call time_after() altogether? time_after is pretty trivial. But your call. > >> Other than this, looks fine. > >Ok, please no more changes - I am exhausted ;-> So speak for this >update or send patches afterwards if you dont like something. > >cheers, >jamal >
diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index bfa80a6..dab7dad 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -691,6 +691,7 @@ enum { #define TCAA_MAX TCA_ROOT_TAB TCA_ROOT_FLAGS, TCA_ROOT_COUNT, + TCA_ROOT_TIME_DELTA, /* in msecs */ __TCA_ROOT_MAX, #define TCA_ROOT_MAX (__TCA_ROOT_MAX - 1) }; diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 15d6c46..9ffad9c 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -111,6 +111,7 @@ 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; u32 act_flags = cb->args[2]; + unsigned long jiffy_since = cb->args[3]; struct nlattr *nest; spin_lock_bh(&hinfo->lock); @@ -128,6 +129,11 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb, if (index < s_i) continue; + if (jiffy_since && + time_after(jiffy_since, + (unsigned long)p->tcfa_tm.lastuse)) + continue; + nest = nla_nest_start(skb, n_i); if (nest == NULL) goto nla_put_failure; @@ -145,9 +151,11 @@ static int tcf_dump_walker(struct tcf_hashinfo *hinfo, struct sk_buff *skb, } } done: + if (index >= 0) + cb->args[0] = index + 1; + spin_unlock_bh(&hinfo->lock); if (n_i) { - cb->args[0] += n_i; if (act_flags & TCA_FLAG_LARGE_DUMP_ON) cb->args[1] = n_i; } @@ -1077,6 +1085,7 @@ static int tcf_action_add(struct net *net, struct nlattr *nla, static const struct nla_policy tcaa_policy[TCA_ROOT_MAX + 1] = { [TCA_ROOT_FLAGS] = { .type = NLA_BITFIELD_32, .validation_data = &tcaa_root_flags_allowed }, + [TCA_ROOT_TIME_DELTA] = { .type = NLA_U32 }, }; static int tc_ctl_action(struct sk_buff *skb, struct nlmsghdr *n, @@ -1167,7 +1176,9 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) struct nla_bitfield_32 fb; struct nlattr *count_attr = NULL; struct nlattr *tb[TCA_ROOT_MAX + 1]; + unsigned long jiffy_since = 0; struct nlattr *kind = NULL; + u32 msecs_since = 0; u32 act_count = 0; ret = nlmsg_parse(cb->nlh, sizeof(struct tcamsg), tb, TCA_ROOT_MAX, @@ -1188,12 +1199,19 @@ static int tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb) if (tb[TCA_ROOT_FLAGS]) fb = nla_get_bitfield_32(tb[TCA_ROOT_FLAGS]); + if (tb[TCA_ROOT_TIME_DELTA]) + msecs_since = nla_get_u32(tb[TCA_ROOT_TIME_DELTA]); + 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_since) + jiffy_since = jiffies - msecs_to_jiffies(msecs_since); + cb->args[2] = fb.nla_value; + cb->args[3] = jiffy_since; t = nlmsg_data(nlh); t->tca_family = AF_UNSPEC; t->tca__pad1 = 0;