When the shaper holds the next packet back, CAKE arms its watchdog for the exact time that packet may leave. At a few hundred Mbit/s that is a timer interrupt, a softirq and a qdisc run for nearly every packet. Let the timer fire up to four packet times late, capped at 100 us, as sch_fq does with its timer_slack. The shaper keeps its rate, since it sends what it owes once the timer runs. Four packet times of 1514 bytes are 48 us at 1 Gbit/s and 5 us at 10 Gbit/s; below about 480 Mbit/s the cap applies. Signed-off-by: Julius Bairaktaris --- net/sched/sch_cake.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c index f97134522727..89f3c5cbb3de 100644 --- a/net/sched/sch_cake.c +++ b/net/sched/sch_cake.c @@ -229,6 +229,7 @@ struct cake_sched_data { /* time_next = time_this + ((len * rate_ns) >> rate_shft) */ ktime_t time_next_packet; ktime_t failsafe_next_packet; + u64 timer_slack; u64 rate_ns; u16 rate_shft; u16 overflow_timeout; @@ -1618,6 +1619,11 @@ static unsigned int cake_drop(struct Qdisc *sch, struct sk_buff **to_free) return idx + (tin << 16); } +static void cake_watchdog_schedule(struct cake_sched_data *q, u64 next) +{ + qdisc_watchdog_schedule_range_ns(&q->watchdog, next, q->timer_slack); +} + static u8 cake_handle_diffserv(struct sk_buff *skb, bool wash) { const int offset = skb_network_offset(skb); @@ -1797,7 +1803,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch, ktime_to_ns( q->failsafe_next_packet)); sch->qstats.overlimits++; - qdisc_watchdog_schedule_ns(&q->watchdog, next); + cake_watchdog_schedule(q, next); } } } @@ -2071,7 +2077,7 @@ static struct sk_buff *cake_dequeue(struct Qdisc *sch) ktime_to_ns(q->failsafe_next_packet)); sch->qstats.overlimits++; - qdisc_watchdog_schedule_ns(&q->watchdog, next); + cake_watchdog_schedule(q, next); return NULL; } @@ -2281,7 +2287,7 @@ static struct sk_buff *cake_dequeue(struct Qdisc *sch) u64 next = min(ktime_to_ns(q->time_next_packet), ktime_to_ns(q->failsafe_next_packet)); - qdisc_watchdog_schedule_ns(&q->watchdog, next); + cake_watchdog_schedule(q, next); } else if (!sch->q.qlen) { int i; @@ -2636,6 +2642,16 @@ static void cake_configure_rates(struct Qdisc *sch, u64 rate, bool rate_adjust) qd->rate_ns = qd->tins[ft].tin_rate_ns; qd->rate_shft = qd->tins[ft].tin_rate_shft; + + /* Waking the shaper for every packet costs a timer interrupt and a + * softirq each. Letting the timer fire up to four packet times late + * lets it send a few at once, as sch_fq's timer_slack does; the shaper + * still meets its rate, since it catches up on what it owes. Capped so + * that a slow link waits no longer than a fast one would. + */ + qd->timer_slack = min_t(u64, 100 * NSEC_PER_USEC, + (4ULL * psched_mtu(qdisc_dev(sch)) * + qd->rate_ns) >> qd->rate_shft); } static void cake_reconfigure(struct Qdisc *sch) -- 2.53.0