Skip to content

Commit 961d0e5

Browse files
Zh-yuan Yedavem330
authored andcommitted
net: cbs: Fix software cbs to consider packet sending time
Currently the software CBS does not consider the packet sending time when depleting the credits. It caused the throughput to be Idleslope[kbps] * (Port transmit rate[kbps] / |Sendslope[kbps]|) where Idleslope * (Port transmit rate / (Idleslope + |Sendslope|)) = Idleslope is expected. In order to fix the issue above, this patch takes the time when the packet sending completes into account by moving the anchor time variable "last" ahead to the send completion time upon transmission and adding wait when the next dequeue request comes before the send completion time of the previous packet. changelog: V2->V3: - remove unnecessary whitespace cleanup - add the checks if port_rate is 0 before division V1->V2: - combine variable "send_completed" into "last" - add the comment for estimate of the packet sending Fixes: 585d763 ("net/sched: Introduce Credit Based Shaper (CBS) qdisc") Signed-off-by: Zh-yuan Ye <[email protected]> Reviewed-by: Vinicius Costa Gomes <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 81573b1 commit 961d0e5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

net/sched/sch_cbs.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch)
181181
s64 credits;
182182
int len;
183183

184+
/* The previous packet is still being sent */
185+
if (now < q->last) {
186+
qdisc_watchdog_schedule_ns(&q->watchdog, q->last);
187+
return NULL;
188+
}
184189
if (q->credits < 0) {
185190
credits = timediff_to_credits(now - q->last, q->idleslope);
186191

@@ -212,7 +217,12 @@ static struct sk_buff *cbs_dequeue_soft(struct Qdisc *sch)
212217
credits += q->credits;
213218

214219
q->credits = max_t(s64, credits, q->locredit);
215-
q->last = now;
220+
/* Estimate of the transmission of the last byte of the packet in ns */
221+
if (unlikely(atomic64_read(&q->port_rate) == 0))
222+
q->last = now;
223+
else
224+
q->last = now + div64_s64(len * NSEC_PER_SEC,
225+
atomic64_read(&q->port_rate));
216226

217227
return skb;
218228
}

0 commit comments

Comments
 (0)