sched/rt: minimize rq->lock contention in, do_sched_rt_period_timer()
cover sched/rt: minimize rq->lock contention in, do_sched_rt_period_timer()
Peter, Ingo,
I sent this patch about a month ago and got no response.
https://patchwork.kernel.org/patch/9684545/
Does it seem reasonable? I'm not sure if taking rt_runtime_lock is strictly necessary, but it's a big improvement to taking rq->lock every pass through the loop. Is there another way to fix this?
Thanks,
Shaggy
PATCH RESEND 1/1 sched/rt: minimize rq->lock contention in, do_sched_rt_period_timer()
With CONFIG_RT_GROUP_SCHED defined, do_sched_rt_period_timer() sequentially takes each cpu's rq->lock. On a large, busy system, the cumulative time it takes to acquire each lock can be excessive, even triggering a watchdog timeout.
If rt_rq_rt_time and rt_rq->rt_nr_running are both zero, this function does nothing while holding the lock, so don't bother taking it at all.
Orabug: 25491970
--- kernel/sched/rt.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
kernel/sched/rt.c +11 -0
@@ -840,6 +840,17 @@ static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)int enqueue =0 ;struct rt_rq *rt_rq =sched_rt_period_rt_rq (rt_b, i);struct rq *rq =rq_of_rt_rq (rt_rq); +int skip; + +/* +* When span == cpu_online_mask, taking each rq->lock +* can be time-consuming. Try to avoid it when possible. +*/ +raw_spin_lock (&rt_rq->rt_runtime_lock); + skip = !rt_rq->rt_time && !rt_rq->rt_nr_running; +raw_spin_unlock (&rt_rq->rt_runtime_lock); +if (skip) +continue ;raw_spin_lock (&rq->lock);if (rt_rq->rt_time) {
Signature · 1 line
2.12.2
Peter Zijlstra
maintainerQuoted 7 lines · Dave Kleikamp
With
CONFIG_RT_GROUP_SCHEDdefined,do_sched_rt_period_timer()sequentially takes each cpu'srq->lock. On a large, busy system, the cumulative time it takes to acquire each lock can be excessive, even triggering a watchdog timeout.If
rt_rq_rt_timeandrt_rq->rt_nr_runningare both zero, this function does nothing while holding the lock, so don't bother taking it at all.
Indeed, thanks Dave!
tip-bot for Dave Kleikamp
merge bot[tip:sched/core] sched/rt: Minimize rq->lock contention in do_sched_rt_period_timer()
In reply to Dave Kleikampsched/rt: Minimize rq->lock contention in do_sched_rt_period_timer()
Commit-ID: c249f255aab86b9b187ba319b9d2684841ac7c8d Gitweb: http://git.kernel.org/tip/c249f255aab86b9b187ba319b9d2684841ac7c8d Author: Dave Kleikamp <[email protected]> AuthorDate: Mon, 15 May 2017 14:14:13 -0500 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 23 May 2017 10:01:34 +0200
sched/rt: Minimize rq->lock contention in do_sched_rt_period_timer()
With CONFIG_RT_GROUP_SCHED=y, do_sched_rt_period_timer() sequentially takes each CPU's rq->lock. On a large, busy system, the cumulative time it takes to acquire each lock can be excessive, even triggering a watchdog timeout.
If rt_rq->rt_time and rt_rq->rt_nr_running are both zero, this function does nothing while holding the lock, so don't bother taking it at all.
--- kernel/sched/rt.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
kernel/sched/rt.c +11 -0
@@ -840,6 +840,17 @@ static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)int enqueue =0 ;struct rt_rq *rt_rq =sched_rt_period_rt_rq (rt_b, i);struct rq *rq =rq_of_rt_rq (rt_rq); +int skip; + +/* +* When span == cpu_online_mask, taking each rq->lock +* can be time-consuming. Try to avoid it when possible. +*/ +raw_spin_lock (&rt_rq->rt_runtime_lock); + skip = !rt_rq->rt_time && !rt_rq->rt_nr_running; +raw_spin_unlock (&rt_rq->rt_runtime_lock); +if (skip) +continue ;raw_spin_lock (&rq->lock);if (rt_rq->rt_time) {