[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.63.0705250923210.27351@ranjit.corp.google.com>
Date: Fri, 25 May 2007 10:11:05 -0700 (PDT)
From: Ranjit Manomohan <ranjitm@...gle.com>
To: netdev@...r.kernel.org
cc: ranjitm@...gle.com
Subject: [PATCH][NET_SCHED] Update htb rate when stats are polled.
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@...gle.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));
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists