Patchwork [net-next,v2,08/11] tbf: fix value set for q->ptokens

login
register
mail settings
Submitter Jiri Pirko
Date Feb. 8, 2013, 6:59 p.m.
Message ID <1360349981-27801-9-git-send-email-jiri@resnulli.us>
Download mbox | patch
Permalink /patch/219253/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

Jiri Pirko - Feb. 8, 2013, 6:59 p.m.
q->ptokens is in ns and we are assigning q->mtu directly to it. That is
wrong. psched_l2t_ns() should be used to compute correct value.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Acked-by: Eric Dumazet <edumazet@google.com>
---
 net/sched/sch_tbf.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Patch

diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c
index dc562a8..6e8b670 100644
--- a/net/sched/sch_tbf.c
+++ b/net/sched/sch_tbf.c
@@ -165,8 +165,8 @@  static struct sk_buff *tbf_dequeue(struct Qdisc *sch)
 
 		if (q->peak_present) {
 			ptoks = toks + q->ptokens;
-			if (ptoks > (long)q->mtu)
-				ptoks = q->mtu;
+			if (ptoks > (s64) psched_l2t_ns(&q->peak, q->mtu))
+				ptoks = (s64) psched_l2t_ns(&q->peak, q->mtu);
 			ptoks -= (s64) psched_l2t_ns(&q->peak, len);
 		}
 		toks += q->tokens;
@@ -215,7 +215,8 @@  static void tbf_reset(struct Qdisc *sch)
 	sch->q.qlen = 0;
 	q->t_c = ktime_to_ns(ktime_get());
 	q->tokens = q->buffer;
-	q->ptokens = q->mtu;
+	if (q->peak_present)
+		q->ptokens = (s64) psched_l2t_ns(&q->peak, q->mtu);
 	qdisc_watchdog_cancel(&q->watchdog);
 }
 
@@ -296,11 +297,11 @@  static int tbf_change(struct Qdisc *sch, struct nlattr *opt)
 	q->max_size = max_size;
 	q->buffer = PSCHED_TICKS2NS(qopt->buffer);
 	q->tokens = q->buffer;
-	q->ptokens = q->mtu;
 
 	psched_ratecfg_precompute(&q->rate, rtab->rate.rate);
 	if (ptab) {
 		psched_ratecfg_precompute(&q->peak, ptab->rate.rate);
+		q->ptokens = (s64) psched_l2t_ns(&q->peak, q->mtu);
 		q->peak_present = true;
 	} else {
 		q->peak_present = false;