Skip to content

Commit 1598f7c

Browse files
Yang Yingliangdavem330
authored andcommitted
net: sched: htb: fix the calculation of quantum
Now, 32bit rates may be not the true rate. So use rate_bytes_ps which is from max(rate32, rate64) to calcualte quantum. Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cc106e4 commit 1598f7c

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎net/sched/sch_htb.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,11 +1477,22 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
14771477
sch_tree_lock(sch);
14781478
}
14791479

1480+
rate64 = tb[TCA_HTB_RATE64] ? nla_get_u64(tb[TCA_HTB_RATE64]) : 0;
1481+
1482+
ceil64 = tb[TCA_HTB_CEIL64] ? nla_get_u64(tb[TCA_HTB_CEIL64]) : 0;
1483+
1484+
psched_ratecfg_precompute(&cl->rate, &hopt->rate, rate64);
1485+
psched_ratecfg_precompute(&cl->ceil, &hopt->ceil, ceil64);
1486+
14801487
/* it used to be a nasty bug here, we have to check that node
14811488
* is really leaf before changing cl->un.leaf !
14821489
*/
14831490
if (!cl->level) {
1484-
cl->quantum = hopt->rate.rate / q->rate2quantum;
1491+
u64 quantum = cl->rate.rate_bytes_ps;
1492+
1493+
do_div(quantum, q->rate2quantum);
1494+
cl->quantum = min_t(u64, quantum, INT_MAX);
1495+
14851496
if (!hopt->quantum && cl->quantum < 1000) {
14861497
pr_warning(
14871498
"HTB: quantum of class %X is small. Consider r2q change.\n",
@@ -1500,13 +1511,6 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
15001511
cl->prio = TC_HTB_NUMPRIO - 1;
15011512
}
15021513

1503-
rate64 = tb[TCA_HTB_RATE64] ? nla_get_u64(tb[TCA_HTB_RATE64]) : 0;
1504-
1505-
ceil64 = tb[TCA_HTB_CEIL64] ? nla_get_u64(tb[TCA_HTB_CEIL64]) : 0;
1506-
1507-
psched_ratecfg_precompute(&cl->rate, &hopt->rate, rate64);
1508-
psched_ratecfg_precompute(&cl->ceil, &hopt->ceil, ceil64);
1509-
15101514
cl->buffer = PSCHED_TICKS2NS(hopt->buffer);
15111515
cl->cbuffer = PSCHED_TICKS2NS(hopt->cbuffer);
15121516

0 commit comments

Comments
 (0)