sch_htb: fix "too many events" situation

HTB is event driven algorithm and part of its work is to apply
scheduled events at proper times. It tried to defend itself from
livelock by processing only limited number of events per dequeue.
Because of faster computers some users already hit this hardcoded
limit.

This patch limits processing up to 2 jiffies (why not 1 jiffie ?
because it might stop prematurely when only fraction of jiffie
remains).

Signed-off-by: Martin Devera <devik@cdi.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Martin Devera 2008-03-23 22:00:38 -07:00 committed by David S. Miller
parent 4b1b366721
commit 8f3ea33a50

View file

@ -711,9 +711,11 @@ static void htb_charge_class(struct htb_sched *q, struct htb_class *cl,
*/ */
static psched_time_t htb_do_events(struct htb_sched *q, int level) static psched_time_t htb_do_events(struct htb_sched *q, int level)
{ {
int i; /* don't run for longer than 2 jiffies; 2 is used instead of
1 to simplify things when jiffy is going to be incremented
for (i = 0; i < 500; i++) { too soon */
unsigned long stop_at = jiffies + 2;
while (time_before(jiffies, stop_at)) {
struct htb_class *cl; struct htb_class *cl;
long diff; long diff;
struct rb_node *p = rb_first(&q->wait_pq[level]); struct rb_node *p = rb_first(&q->wait_pq[level]);
@ -731,9 +733,8 @@ static psched_time_t htb_do_events(struct htb_sched *q, int level)
if (cl->cmode != HTB_CAN_SEND) if (cl->cmode != HTB_CAN_SEND)
htb_add_to_wait_tree(q, cl, diff); htb_add_to_wait_tree(q, cl, diff);
} }
if (net_ratelimit()) /* too much load - let's continue on next jiffie */
printk(KERN_WARNING "htb: too many events !\n"); return q->now + PSCHED_TICKS_PER_SEC / HZ;
return q->now + PSCHED_TICKS_PER_SEC / 10;
} }
/* Returns class->node+prio from id-tree where classe's id is >= id. NULL /* Returns class->node+prio from id-tree where classe's id is >= id. NULL