PKT_SCHED: Use gnet_stats for actions and policer
Subsystems (3)
cover PKT_SCHED: Use gnet_stats for actions and policer
Dave,
This is the last patchset in my attempt to clean up traffic control statistics. It converts the action and policer code to the gnet_stats API.
I decided to not provide backward compatibility for action statistics and introduce a new TLV type TCA_ACT_STATS for them in order to get some consistency and be prepared if we ever introduce statistics to classifiers. This was approved by Jamal.
Shall I mark the old estimator and statistic API as __deprecated or remove it right away?
Cheers
PATCH 1/8 tcf_action: copy generic stats via TCA_ACT_STATS
Dumps the statistic common to all action modules via the newly introduced TLV type TCA_ACT_STATS in tcf_action_copy_stats but allows the corresponding module to dump its own statistic by implementing the get_stats callback.
include/linux/rtnetlink.h +1 -0
@@ -699,6 +699,7 @@TCA_RATE ,TCA_FCNT ,TCA_STATS2 , +TCA_ACT_STATS , __TCA_MAX };
include/net/act_api.h +7 -1
@@ -44,10 +44,16 @@u32 capab; \int action; \struct tcf_t tm; \ -struct tc_stats stats; \ +struct gnet_stats_basic bstats; \ +struct gnet_stats_queue qstats; \ +struct gnet_stats_rate_est rate_est; \spinlock_t *stats_lock; \ spinlock_t lock +struct tcf_act_hdr +{ +tca_gen (act_hdr); +};struct tc_action {
include/net/pkt_act.h +3 -4
@@ -60,7 +60,7 @@ *p1p = p->next;write_unlock_bh (&tcf_t_lock);#ifdef CONFIG_NET_ESTIMATOR -qdisc_kill_estimator (&p->stats); +gen_kill_estimator (&p->bstats, &p->rate_est);#endif kfree (p);return ;
@@ -256,9 +256,8 @@ p->tm.install = jiffies; p->tm.lastuse = jiffies;#ifdef CONFIG_NET_ESTIMATOR -if (est) { -qdisc_new_estimator (&p->stats, p->stats_lock, est); - } +if (est) +gen_new_estimator (&p->bstats, &p->rate_est, p->stats_lock, est);#endif h =tcf_hash (p->index);write_lock_bh (&tcf_t_lock);
net/sched/act_api.c +26 -3
@@ -416,14 +416,37 @@int tcf_action_copy_stats (struct sk_buff *skb,struct tc_action *a) { +struct gnet_dump d; +struct tcf_act_hdr *h = a->priv; +#ifdef CONFIG_KMOD /* place holder */ #endif -if (NULL == a->ops ||NULL == a->ops->get_stats) -return 1 ; +if (NULL == h) + goto errout; + +if (gnet_stats_start_copy (skb,TCA_ACT_STATS , h->stats_lock, &d) <0 ) + goto errout; + +if (NULL != a->ops &&NULL != a->ops->get_stats) +if (a->ops->get_stats (skb, a) <0 ) + goto errout; + + if (gnet_stats_copy_basic(&d, &h->bstats) < 0 || +#ifdef CONFIG_NET_ESTIMATOR +gnet_stats_copy_rate_est (&d, &h->rate_est) <0 || +#endif + gnet_stats_copy_queue(&d, &h->qstats) < 0) + goto errout; + +if (gnet_stats_finish_copy (&d) <0 ) + goto errout; + +return 0 ; -return a->ops->get_stats (skb,a); +errout: + return -1; }
PATCH 2/8 gact: use gnet_stats for action stats
In reply to Thomas Grafnet/sched/gact.c +4 -16
@@ -62,7 +62,7 @@int gact_determ (struct tcf_gact *p) { -if (p->stats.packets%p->pval) +if (p->bstats.packets%p->pval)return p->action;return p->paction; }
@@ -163,10 +163,10 @@#else action = p->action;#endif - p->stats.bytes += skb->len; - p->stats.packets++; + p->bstats.bytes += skb->len; + p->bstats.packets++;if (TC_ACT_SHOT == action) - p->stats.drops++; + p->qstats.drops++; p->tm.lastuse = jiffies;spin_unlock (&p->lock);
@@ -214,17 +214,6 @@return -1 ; } -int -tcf_gact_stats (struct sk_buff *skb,struct tc_action *a) -{ -struct tcf_gact *p; - p =PRIV (a,gact); -if (NULL != p) -return qdisc_copy_stats (skb, &p->stats,p->stats_lock); - -return 1 ; -} -struct tc_action_ops act_gact_ops = { .next =NULL , .kind ="gact" ,
@@ -232,7 +221,6 @@ .capab = TCA_CAP_NONE, .owner = THIS_MODULE, .act = tcf_gact, - .get_stats = tcf_gact_stats, .dump = tcf_gact_dump, .cleanup = tcf_gact_cleanup, .lookup = tcf_hash_search,
PATCH 3/8 ipt: use gnet_stats for action stats
In reply to Thomas Grafnet/sched/ipt.c +5 -18
@@ -218,9 +218,8 @@*/ p->tm.install = jiffies;#ifdef CONFIG_NET_ESTIMATOR -if (est) { -qdisc_new_estimator (&p->stats, p->stats_lock, est); - } +if (est) +gen_new_estimator (&p->bstats, &p->rate_est, p->stats_lock, est);#endif h =tcf_hash (p->index);write_lock_bh (&ipt_lock);
@@ -258,8 +257,8 @@spin_lock (&p->lock); p->tm.lastuse = jiffies; - p->stats.bytes += skb->len; - p->stats.packets++; + p->bstats.bytes += skb->len; + p->bstats.packets++;if (skb_cloned (skb) ) {if (pskb_expand_head (skb,0 ,0 ,GFP_ATOMIC )) {
@@ -278,7 +277,7 @@break ;case NF_DROP : result =TC_ACT_SHOT ; - p->stats.drops++; + p->qstats.drops++;break ;case IPT_CONTINUE : result =TC_ACT_PIPE ;
@@ -346,17 +345,6 @@return -1 ; } -int -tcf_ipt_stats (struct sk_buff *skb,struct tc_action *a) -{ -struct tcf_ipt *p; - p =PRIV (a,ipt); -if (NULL != p) -return qdisc_copy_stats (skb, &p->stats, p->stats_lock); - -return 1 ; -} -struct tc_action_ops act_ipt_ops = { .next =NULL , .kind ="ipt" ,
@@ -364,7 +352,6 @@ .capab = TCA_CAP_NONE, .owner = THIS_MODULE, .act = tcf_ipt, - .get_stats = tcf_ipt_stats, .dump = tcf_ipt_dump, .cleanup = tcf_ipt_cleanup, .lookup = tcf_hash_search,
PATCH 4/8 mirred: use gnet_stats for action stats
In reply to Thomas Grafnet/sched/mirred.c +5 -18
@@ -195,9 +195,9 @@ bad_mirred:if (NULL != skb2)kfree_skb (skb2); - p->stats.overlimits++; - p->stats.bytes += skb->len; - p->stats.packets++; + p->qstats.overlimits++; + p->bstats.bytes += skb->len; + p->bstats.packets++;spin_unlock (&p->lock);/* should we be asking for packet to be dropped? * may make sense for redirect case only
@@ -216,8 +216,8 @@ goto bad_mirred; } - p->stats.bytes += skb2->len; - p->stats.packets++; + p->bstats.bytes += skb2->len; + p->bstats.packets++;if ( !(at &AT_EGRESS )) {if (p->ok_push) {skb_push (skb2, skb2->dev->hard_header_len);
@@ -268,18 +268,6 @@return -1 ; } -int -tcf_mirred_stats (struct sk_buff *skb,struct tc_action *a) -{ -struct tcf_mirred *p; - p =PRIV (a,mirred); - -if (NULL != p) -return qdisc_copy_stats (skb, &p->stats, p->stats_lock); - -return 1 ; -} -static struct tc_action_ops act_mirred_ops = { .next =NULL , .kind ="mirred" ,
@@ -287,7 +275,6 @@ .capab = TCA_CAP_NONE, .owner = THIS_MODULE, .act = tcf_mirred, - .get_stats = tcf_mirred_stats, .dump = tcf_mirred_dump, .cleanup = tcf_mirred_cleanup, .lookup = tcf_hash_search,
PATCH 5/8 pedit: use gnet_stats for action stats
In reply to Thomas Grafnet/sched/pedit.c +3 -15
@@ -183,10 +183,10 @@ } bad: - p->stats.overlimits++; + p->qstats.overlimits++; done: - p->stats.bytes += skb->len; - p->stats.packets++; + p->bstats.bytes += skb->len; + p->bstats.packets++;spin_unlock (&p->lock);return p->action; }
@@ -255,17 +255,6 @@return -1 ; } -int -tcf_pedit_stats (struct sk_buff *skb,struct tc_action *a) -{ -struct tcf_pedit *p; - p =PRIV (a,pedit); -if (NULL != p) -return qdisc_copy_stats (skb, &p->stats, p->stats_lock); - -return 1 ; -} -static struct tc_action_ops act_pedit_ops = { .kind ="pedit" ,
@@ -273,7 +262,6 @@ .capab = TCA_CAP_NONE, .owner = THIS_MODULE, .act = tcf_pedit, - .get_stats = tcf_pedit_stats, .dump = tcf_pedit_dump, .cleanup = tcf_pedit_cleanup, .lookup = tcf_hash_search,
PATCH 6/8 police: use gnet_stats for action policer stats
In reply to Thomas Grafnet/sched/police.c +6 -17
@@ -245,7 +245,7 @@ p->index = parm->index ? :tcf_police_new_index ();#ifdef CONFIG_NET_ESTIMATOR if (est) -qdisc_new_estimator (&p->stats, p->stats_lock, est); +gen_new_estimator (&p->bstats, &p->rate_est, p->stats_lock, est);#endif h =tcf_police_hash (p->index);write_lock_bh (&police_lock);
@@ -275,16 +275,6 @@return 0 ; } -int tcf_act_police_stats (struct sk_buff *skb,struct tc_action *a) -{ -struct tcf_police *p; - p =PRIV (a); -if (NULL != p) -return qdisc_copy_stats (skb, &p->stats, p->stats_lock); - -return 1 ; -} -int tcf_act_police (struct sk_buff **pskb,struct tc_action *a) {psched_time_t now;
@@ -302,12 +292,12 @@spin_lock (&p->lock); - p->stats.bytes += skb->len; - p->stats.packets++; + p->bstats.bytes += skb->len; + p->bstats.packets++;#ifdef CONFIG_NET_ESTIMATOR -if (p->ewma_rate && p->stats.bps >= p->ewma_rate) { - p->stats.overlimits++; +if (p->ewma_rate && p->rate_est.bps >= p->ewma_rate) { + p->qstats.overlimits++;spin_unlock (&p->lock);return p->action; }
@@ -343,7 +333,7 @@ } } - p->stats.overlimits++; + p->qstats.overlimits++;spin_unlock (&p->lock);return p->action; }
@@ -400,7 +390,6 @@ .capab = TCA_CAP_NONE, .owner = THIS_MODULE, .act = tcf_act_police, - .get_stats = tcf_act_police_stats, .dump = tcf_act_police_dump, .cleanup = tcf_act_police_cleanup, .lookup = tcf_hash_search,
PATCH 7/8 police: use gnet_stats for old policer stats
In reply to Thomas GrafTransforms old policer to use generic statistic via TCA_STATS2 and maintain backward compatibility via TCA_STATS. Adds a new API for classifiers to invoke the dumping process.
include/net/act_api.h +4 -1
@@ -28,7 +28,9 @@struct qdisc_rate_table *R_tab;struct qdisc_rate_table *P_tab; -struct tc_stats stats; +struct gnet_stats_basic bstats; +struct gnet_stats_queue qstats; +struct gnet_stats_rate_est rate_est;spinlock_t *stats_lock; };
@@ -101,6 +103,7 @@extern void tcf_police_destroy (struct tcf_police *p);extern struct tcf_police *tcf_police_locate (struct rtattr *rta,struct rtattr *est);extern int tcf_police_dump (struct sk_buff *skb,struct tcf_police *p); +extern int tcf_police_dump_stats (struct sk_buff *skb,struct tcf_police *p);static inline int tcf_police_release (struct tcf_police *p,int bind)
net/sched/police.c +32 -7
@@ -149,7 +149,7 @@ *p1p = p->next;write_unlock_bh (&police_lock);#ifdef CONFIG_NET_ESTIMATOR -qdisc_kill_estimator (&p->stats); +gen_kill_estimator (&p->bstats, &p->rate_est);#endif if (p->R_tab)qdisc_put_rtab (p->R_tab);
@@ -469,7 +469,7 @@ p->action = parm->action;#ifdef CONFIG_NET_ESTIMATOR if (est) -qdisc_new_estimator (&p->stats, p->stats_lock, est); +gen_new_estimator (&p->bstats, &p->rate_est, p->stats_lock, est);#endif h =tcf_police_hash (p->index);write_lock_bh (&police_lock);
@@ -493,12 +493,12 @@spin_lock (&p->lock); - p->stats.bytes += skb->len; - p->stats.packets++; + p->bstats.bytes += skb->len; + p->bstats.packets++;#ifdef CONFIG_NET_ESTIMATOR -if (p->ewma_rate && p->stats.bps >= p->ewma_rate) { - p->stats.overlimits++; +if (p->ewma_rate && p->rate_est.bps >= p->ewma_rate) { + p->qstats.overlimits++;spin_unlock (&p->lock);return p->action; }
@@ -534,7 +534,7 @@ } } - p->stats.overlimits++; + p->qstats.overlimits++;spin_unlock (&p->lock);return p->action; }
@@ -570,9 +570,34 @@return -1 ; } +int tcf_police_dump_stats (struct sk_buff *skb,struct tcf_police *p) +{ +struct gnet_dump d; + +if (gnet_stats_start_copy_compat (skb,TCA_STATS2 ,TCA_STATS , +TCA_XSTATS , p->stats_lock, &d) <0 ) + +if (gnet_stats_copy_basic (&d, &p->bstats) <0 || +#ifdef CONFIG_NET_ESTIMATOR +gnet_stats_copy_rate_est (&d, &p->rate_est) <0 || +#endif +gnet_stats_copy_queue (&d, &p->qstats) <0 ) + goto errout; + +if (gnet_stats_finish_copy (&d) <0 ) + goto errout; + +return 0 ; + +errout: +return -1 ; +} + +EXPORT_SYMBOL (tcf_police);EXPORT_SYMBOL (tcf_police_destroy);EXPORT_SYMBOL (tcf_police_dump); +EXPORT_SYMBOL (tcf_police_dump_stats);EXPORT_SYMBOL (tcf_police_hash);EXPORT_SYMBOL (tcf_police_ht);EXPORT_SYMBOL (tcf_police_locate);
PATCH 8/8 cls_*: use tcf_police_dump_stats to dump via new gnet_stats API
In reply to Thomas Grafnet/sched/cls_fw.c +2 -4
@@ -395,11 +395,9 @@ }#else /* CONFIG_NET_CLS_ACT */ #ifdef CONFIG_NET_CLS_POLICE -if (f->police) { -if (qdisc_copy_stats (skb, &f->police->stats, - f->police->stats_lock)) +if (f->police) +if (tcf_police_dump_stats (skb, f->police) <0 ) goto rtattr_failure; - }#endif /* CONFIG_NET_CLS_POLICE */ #endif /* CONFIG_NET_CLS_ACT */ return skb->len;
net/sched/cls_route.c +2 -4
@@ -566,11 +566,9 @@ rta->rta_len = skb->tail - b;#ifdef CONFIG_NET_CLS_POLICE -if (f->police) { -if (qdisc_copy_stats (skb, &f->police->stats, - f->police->stats_lock)) +if (f->police) +if (tcf_police_dump_stats (skb, f->police) <0 ) goto rtattr_failure; - }#endif return skb->len;
net/sched/cls_rsvp.h +2 -4
@@ -631,11 +631,9 @@ rta->rta_len = skb->tail - b;#ifdef CONFIG_NET_CLS_POLICE -if (f->police) { -if (qdisc_copy_stats (skb, &f->police->stats, - f->police->stats_lock)) +if (f->police) +if (tcf_police_dump_stats (skb, f->police) <0 ) goto rtattr_failure; - }#endif return skb->len;
net/sched/cls_u32.c +2 -4
@@ -775,11 +775,9 @@ }#else #ifdef CONFIG_NET_CLS_POLICE -if (TC_U32_KEY (n->handle) && n->police) { -if (qdisc_copy_stats (skb, &n->police->stats, - n->police->stats_lock)) +if (TC_U32_KEY (n->handle) && n->police) +if (tcf_police_dump_stats (skb, n->police) <0 ) goto rtattr_failure; - }#endif #endif return skb->len;
David S. Miller
maintainerQuoted 8 lines · On Wed, 3 Nov 2004 22:58:16 +0100 Thomas Graf <[email protected]> wrote:
This is the last patchset in my attempt to clean up traffic control statistics. It converts the action and policer code to the
gnet_statsAPI.I decided to not provide backward compatibility for action statistics and introduce a new TLV type
TCA_ACT_STATSfor them in order to get some consistency and be prepared if we ever introduce statistics to classifiers. This was approved by Jamal.
All applied, very nice work Thomas.
Quoted 2 lines
Shall I mark the old estimator and statistic API as
__deprecatedor remove it right away?
Since nothing in the tree uses it any more, let's just kill it outright.
* David S. Miller <[email protected]> 2004-11-03 14:18
Quoted 5 lines
Quoted 2 lines
Shall I mark the old estimator and statistic API as
__deprecatedor remove it right away?Since nothing in the tree uses it any more, let's just kill it outright.
I will come up with a patch tomorrow together with the iproute2 patch which needs some more work. Thanks for the quick applying.