aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2016-05-23 17:24:56 -0400
committerDavid S. Miller <davem@davemloft.net>2016-05-24 17:49:14 -0400
commita9efad8b24bd22616f6c749a6c029957dc76542b (patch)
tree20ab7182ee4b4fef2afebd14c960c0a3d9920c56
parent3275c0c6c522ab04afa14f80efdac6213c3883d6 (diff)
net_sched: avoid too many hrtimer_start() calls
I found a serious performance bug in packet schedulers using hrtimers. sch_htb and sch_fq are definitely impacted by this problem. We constantly rearm high resolution timers if some packets are throttled in one (or more) class, and other packets are flying through qdisc on another (non throttled) class. hrtimer_start() does not have the mod_timer() trick of doing nothing if expires value does not change : if (timer_pending(timer) && timer->expires == expires) return 1; This issue is particularly visible when multiple cpus can queue/dequeue packets on the same qdisc, as hrtimer code has to lock a remote base. I used following fix : 1) Change htb to use qdisc_watchdog_schedule_ns() instead of open-coding it. 2) Cache watchdog prior expiration. hrtimer might provide this, but I prefer to not rely on some hrtimer internal. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/pkt_sched.h1
-rw-r--r--net/sched/sch_api.c4
-rw-r--r--net/sched/sch_htb.c13
3 files changed, 8 insertions, 10 deletions
diff --git a/include/net/pkt_sched.h b/include/net/pkt_sched.h
index 401038d2f9b8..fea53f4d92ca 100644
--- a/include/net/pkt_sched.h
+++ b/include/net/pkt_sched.h
@@ -61,6 +61,7 @@ psched_tdiff_bounded(psched_time_t tv1, psched_time_t tv2, psched_time_t bound)
61} 61}
62 62
63struct qdisc_watchdog { 63struct qdisc_watchdog {
64 u64 last_expires;
64 struct hrtimer timer; 65 struct hrtimer timer;
65 struct Qdisc *qdisc; 66 struct Qdisc *qdisc;
66}; 67};
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 64f71a2155f3..ddf047df5361 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -607,6 +607,10 @@ void qdisc_watchdog_schedule_ns(struct qdisc_watchdog *wd, u64 expires, bool thr
607 if (throttle) 607 if (throttle)
608 qdisc_throttled(wd->qdisc); 608 qdisc_throttled(wd->qdisc);
609 609
610 if (wd->last_expires == expires)
611 return;
612
613 wd->last_expires = expires;
610 hrtimer_start(&wd->timer, 614 hrtimer_start(&wd->timer,
611 ns_to_ktime(expires), 615 ns_to_ktime(expires),
612 HRTIMER_MODE_ABS_PINNED); 616 HRTIMER_MODE_ABS_PINNED);
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index f6bf5818ed4d..d4b4218af6b1 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -928,17 +928,10 @@ ok:
928 } 928 }
929 } 929 }
930 qdisc_qstats_overlimit(sch); 930 qdisc_qstats_overlimit(sch);
931 if (likely(next_event > q->now)) { 931 if (likely(next_event > q->now))
932 if (!test_bit(__QDISC_STATE_DEACTIVATED, 932 qdisc_watchdog_schedule_ns(&q->watchdog, next_event, true);
933 &qdisc_root_sleeping(q->watchdog.qdisc)->state)) { 933 else
934 ktime_t time = ns_to_ktime(next_event);
935 qdisc_throttled(q->watchdog.qdisc);
936 hrtimer_start(&q->watchdog.timer, time,
937 HRTIMER_MODE_ABS_PINNED);
938 }
939 } else {
940 schedule_work(&q->work); 934 schedule_work(&q->work);
941 }
942fin: 935fin:
943 return skb; 936 return skb;
944} 937}