[lkml]   [2021]   [Feb]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[tip: sched/core] sched/deadline: Reduce rq lock contention in dl_add_task_root_domain()
The following commit has been merged into the sched/core branch of tip:

Commit-ID: 3096b6fe494b7b4e45d20cb77aa6b715a3efe344
Author: Dietmar Eggemann <>
AuthorDate: Tue, 19 Jan 2021 09:35:42 +01:00
Committer: Peter Zijlstra <>
CommitterDate: Wed, 10 Feb 2021 14:44:48 +01:00

sched/deadline: Reduce rq lock contention in dl_add_task_root_domain()

dl_add_task_root_domain() is called during sched domain rebuild:

for all top_cpuset descendants:
for all tasks of cpuset:

Change it so that only the task pi lock is taken to check if the task
has a SCHED_DEADLINE (DL) policy. In case that p is a DL task take the
rq lock as well to be able to safely de-reference root domain's DL
bandwidth structure.

Most of the tasks will have another policy (namely SCHED_NORMAL) and
can now bail without taking the rq lock.

One thing to note here: Even in case that there aren't any DL user
tasks, a slow frequency switching system with cpufreq gov schedutil has
a DL task (sugov) per frequency domain running which participates in DL
bandwidth management.

Signed-off-by: Dietmar Eggemann <>
Signed-off-by: Peter Zijlstra (Intel) <>
Reviewed-by: Quentin Perret <>
Reviewed-by: Valentin Schneider <>
Reviewed-by: Daniel Bristot de Oliveira <>
Acked-by: Juri Lelli <>
kernel/sched/deadline.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 1508d12..6f37796 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -2388,9 +2388,13 @@ void dl_add_task_root_domain(struct task_struct *p)
struct rq *rq;
struct dl_bw *dl_b;

- rq = task_rq_lock(p, &rf);
- if (!dl_task(p))
- goto unlock;
+ raw_spin_lock_irqsave(&p->pi_lock, rf.flags);
+ if (!dl_task(p)) {
+ raw_spin_unlock_irqrestore(&p->pi_lock, rf.flags);
+ return;
+ }
+ rq = __task_rq_lock(p, &rf);

dl_b = &rq->rd->dl_bw;
@@ -2399,7 +2403,6 @@ void dl_add_task_root_domain(struct task_struct *p)


task_rq_unlock(rq, p, &rf);

 \ /
  Last update: 2021-02-10 14:56    [W:0.140 / U:2.684 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site