netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][NET_SCHED] Update htb rate when stats are polled.
@ 2007-05-25 17:11 Ranjit Manomohan
  2007-05-26  4:10 ` Ilpo Järvinen
  2007-05-26  7:58 ` Patrick McHardy
  0 siblings, 2 replies; 6+ messages in thread
From: Ranjit Manomohan @ 2007-05-25 17:11 UTC (permalink / raw)
  To: netdev; +Cc: ranjitm

Currently the HTB rate for a class is update very slowly (once
every 16 seconds). This patch updates the rate whenever the stats
are requested from user space. This enables more accurate rate
monitoring.

Signed-off-by: Ranjit Manomohan <ranjitm@google.com>

diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 035788c..1d6ec60 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -92,6 +92,7 @@ struct htb_class {
  	struct gnet_stats_basic bstats;
  	struct gnet_stats_queue qstats;
  	struct gnet_stats_rate_est rate_est;
+	unsigned long rate_est_when;	/* last time rate was calculated */
  	struct tc_htb_xstats xstats;	/* our special stats */
  	int refcnt;		/* usage count of this class */

@@ -679,6 +680,23 @@ static int htb_requeue(struct sk_buff *s

  #ifdef HTB_RATECM
  #define RT_GEN(D,R) R+=D-(R/HTB_EWMAC);D=0
+
+/* Update packet/byte rate for a class. */
+static void calc_rate(struct htb_class *cl)
+{
+	unsigned long now = jiffies;
+	if (time_after(now, (cl->rate_est_when + HZ))) {
+	unsigned int elapsed_secs =
+			(now - cl->rate_est_when)/HZ;
+		cl->sum_bytes /= elapsed_secs;
+		cl->sum_packets /= elapsed_secs;
+		RT_GEN (cl->sum_bytes,cl->rate_bytes);
+		RT_GEN (cl->sum_packets,cl->rate_packets);
+		cl->rate_est_when = now;
+	} else if time_before(now, cl->rate_est_when)
+		cl->rate_est_when = now; /* Wraparound */
+}
+
  static void htb_rate_timer(unsigned long arg)
  {
  	struct Qdisc *sch = (struct Qdisc *)arg;
@@ -697,10 +715,8 @@ static void htb_rate_timer(unsigned long
  	if (++q->recmp_bucket >= HTB_HSIZE)
  		q->recmp_bucket = 0;

-	hlist_for_each_entry(cl,p, q->hash + q->recmp_bucket, hlist) {
-		RT_GEN(cl->sum_bytes, cl->rate_bytes);
-		RT_GEN(cl->sum_packets, cl->rate_packets);
-	}
+	hlist_for_each_entry(cl,p, q->hash + q->recmp_bucket, hlist)
+		calc_rate(cl);
  	spin_unlock_bh(&sch->dev->queue_lock);
  }
  #endif
@@ -1176,8 +1192,9 @@ htb_dump_class_stats(struct Qdisc *sch,
  	struct htb_class *cl = (struct htb_class *)arg;

  #ifdef HTB_RATECM
-	cl->rate_est.bps = cl->rate_bytes / (HTB_EWMAC * HTB_HSIZE);
-	cl->rate_est.pps = cl->rate_packets / (HTB_EWMAC * HTB_HSIZE);
+	calc_rate(cl);
+	cl->rate_est.bps = cl->rate_bytes / HTB_EWMAC;
+	cl->rate_est.pps = cl->rate_packets / HTB_EWMAC;
  #endif

  	if (!cl->level && cl->un.leaf.q)
@@ -1464,6 +1481,7 @@ static int htb_change_class(struct Qdisc
  		cl->mbuffer = 60 * PSCHED_TICKS_PER_SEC;	/* 1min */
  		cl->t_c = psched_get_time();
  		cl->cmode = HTB_CAN_SEND;
+		cl->rate_est_when = jiffies;

  		/* attach to the hash list and parent's family */
  		hlist_add_head(&cl->hlist, q->hash + htb_hash(classid));

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-05-30  7:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-25 17:11 [PATCH][NET_SCHED] Update htb rate when stats are polled Ranjit Manomohan
2007-05-26  4:10 ` Ilpo Järvinen
2007-05-26  7:58 ` Patrick McHardy
2007-05-26 12:55   ` Patrick McHardy
2007-05-29 18:39     ` Ranjit Manomohan
2007-05-30  7:33       ` Patrick McHardy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).