sched: fix tg_has_rt_tasks(), tasklist_lock cleanups
cover sched: fix tg_has_rt_tasks(), tasklist_lock cleanups
This textually depends on
5d07f4202c5d63b73ba1734ed38e08461a689313 "sched: s/do_each_thread/for_each_process_thread/ in core.c" d38e83c715270cc2e137bbf6f25206c8c023896b "sched: s/do_each_thread/for_each_process_thread/ in debug.c"
in -tip tree.
Kirill, you seem to agree with 1/3, I'll appreciate your ack.
Oleg.
PATCH 1/3 sched: fix the task-group check in tg_has_rt_tasks()
tg_has_rt_tasks() wants to find an RT task in this task_group, but task_rq(p)->rt.tg wrongly checks the root rt_rq.
--- kernel/sched/core.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched/core.c +1 -1
@@ -7354,7 +7354,7 @@ static inline int tg_has_rt_tasks(struct task_group *tg)struct task_struct *g, *p;for_each_process_thread (g, p) { -if (rt_task (p) &&task_rq (p)->rt.tg == tg) +if (rt_task (p) &&task_group (p) == tg)return 1 ; }
Signature · 1 line
1.5.5.1
PATCH 3/3 sched: print_rq: don't use tasklist_lock
In reply to Oleg Nesterovread_lock_irqsave(tasklist_lock) in print_rq() looks strange. We do not need to disable irqs, and they are already disabled by the caller.
And afaics this lock buys nothing, we can rely on rcu_read_lock(). In this case it makes sense to also move rcu_read_lock/unlock from the caller to print_rq().
--- kernel/sched/debug.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
kernel/sched/debug.c +2 -5
@@ -150,7 +150,6 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)static void print_rq (struct seq_file *m,struct rq *rq,int rq_cpu) {struct task_struct *g, *p; -unsigned long flags;SEQ_printf (m, "\nrunnable tasks:\n"
@@ -159,14 +158,14 @@ static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)"------------------------------------------------------" "----------------------------------------------------\n"); -read_lock_irqsave (&tasklist_lock, flags); +rcu_read_lock ();for_each_process_thread (g, p) {if (task_cpu (p) != rq_cpu)continue ;print_task (m, rq, p); } -read_unlock_irqrestore (&tasklist_lock, flags); +rcu_read_unlock (); }void print_cfs_rq (struct seq_file *m,int cpu,struct cfs_rq *cfs_rq)
@@ -331,9 +330,7 @@ do { \print_cfs_stats (m, cpu);print_rt_stats (m, cpu); -rcu_read_lock ();print_rq (m, rq, cpu); -rcu_read_unlock ();spin_unlock_irqrestore (&sched_debug_lock, flags);SEQ_printf (m,"\n" ); }
Signature · 1 line
1.5.5.1
PATCH 2/3 sched: normalize_rt_tasks: don't use _irqsave for tasklist_lock, use task_rq_lock()
In reply to Oleg Nesterov1. read_lock(tasklist_lock) does not need to disable irqs.
2. ->mm != NULL is the common mistake, use PF_KTHREAD.
3. The second ->mm check can be simply removed.
4. task_rq_lock() looks better than raw_spin_lock(&p->pi_lock) + __task_rq_lock().
--- kernel/sched/core.c | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-)
kernel/sched/core.c +6 -10
@@ -7137,12 +7137,12 @@ void normalize_rt_tasks(void)unsigned long flags;struct rq *rq; -read_lock_irqsave (&tasklist_lock, flags); +read_lock (&tasklist_lock);for_each_process_thread (g, p) {/* * Only normalize user tasks: */ -if (!p->mm) +if (p->flags &PF_KTHREAD )continue ; p->se.exec_start =0 ;
@@ -7157,20 +7157,16 @@ void normalize_rt_tasks(void)* Renice negative nice level userspace * tasks back to 0: */ -if (task_nice (p) <0 && p->mm) +if (task_nice (p) <0 )set_user_nice (p,0 ); continue; } -raw_spin_lock (&p->pi_lock); - rq =__task_rq_lock (p); - + rq =task_rq_lock (p, &flags);normalize_task (rq, p); - -__task_rq_unlock (rq); -raw_spin_unlock (&p->pi_lock); +task_rq_unlock (rq, p, &flags); } -read_unlock_irqrestore (&tasklist_lock, flags); +read_unlock (&tasklist_lock); }#endif /* CONFIG_MAGIC_SYSRQ */
Signature · 1 line
1.5.5.1
Re: [PATCH 1/3] sched: fix the task-group check in tg_has_rt_tasks()
In reply to Oleg NesterovВ Вс, 21/09/2014 в 21:33 +0200, Oleg Nesterov пишет:
Quoted 4 lines
tg_has_rt_tasks()wants to find an RT task in thistask_group, but task_rq(p)->rt.tg wrongly checks the rootrt_rq.Signed-off-by Oleg Nesterov <[email protected]>
Quoted 17 lines
--- kernel/sched/core.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/sched/core.c +1
-1@@ -7354,7 +7354,7 @@ static inline int tg_has_rt_tasks(struct task_group *tg)struct task_struct *g, *p;for_each_process_thread (g, p) { -if (rt_task (p) &&task_rq (p)->rt.tg == tg) +if (rt_task (p) &&task_group (p) == tg)return 1 ; }
tip-bot for Oleg Nesterov
merge bot[tip:sched/core] sched: print_rq(): Don't use tasklist_lock
In reply to Oleg Nesterovsched: print_rq(): Don't use tasklist_lock
Commit-ID: 5bd96ab6fef66ec6b9f54134364e618fd0f8f2f3 Gitweb: http://git.kernel.org/tip/5bd96ab6fef66ec6b9f54134364e618fd0f8f2f3 Author: Oleg Nesterov <[email protected]> AuthorDate: Sun, 21 Sep 2014 21:33:41 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Sep 2014 14:47:04 +0200
sched: print_rq(): Don't use tasklist_lock
read_lock_irqsave(tasklist_lock) in print_rq() looks strange. We do not need to disable irqs, and they are already disabled by the caller.
And afaics this lock buys nothing, we can rely on rcu_read_lock(). In this case it makes sense to also move rcu_read_lock/unlock from the caller to print_rq().
--- kernel/sched/debug.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/sched/debug.c +2 -5
@@ -150,7 +150,6 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)static void print_rq (struct seq_file *m,struct rq *rq,int rq_cpu) {struct task_struct *g, *p; -unsigned long flags;SEQ_printf (m, "\nrunnable tasks:\n"
@@ -159,14 +158,14 @@ static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)"------------------------------------------------------" "----------------------------------------------------\n"); -read_lock_irqsave (&tasklist_lock, flags); +rcu_read_lock ();for_each_process_thread (g, p) {if (task_cpu (p) != rq_cpu)continue ;print_task (m, rq, p); } -read_unlock_irqrestore (&tasklist_lock, flags); +rcu_read_unlock (); }void print_cfs_rq (struct seq_file *m,int cpu,struct cfs_rq *cfs_rq)
@@ -331,9 +330,7 @@ do { \print_cfs_stats (m, cpu);print_rt_stats (m, cpu); -rcu_read_lock ();print_rq (m, rq, cpu); -rcu_read_unlock ();spin_unlock_irqrestore (&sched_debug_lock, flags);SEQ_printf (m,"\n" ); }
tip-bot for Oleg Nesterov
merge bot[tip:sched/core] sched: normalize_rt_tasks(): Don' t use _irqsave for tasklist_lock, use task_rq_lock()
In reply to Oleg Nesterovsched: normalize_rt_tasks(): Don't use _irqsave for tasklist_lock, use task_rq_lock()
Commit-ID: 3472eaa1f12e217e2b8b0ef658ff861b2308cbbd Gitweb: http://git.kernel.org/tip/3472eaa1f12e217e2b8b0ef658ff861b2308cbbd Author: Oleg Nesterov <[email protected]> AuthorDate: Sun, 21 Sep 2014 21:33:38 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Sep 2014 14:47:03 +0200
sched: normalize_rt_tasks(): Don't use _irqsave for tasklist_lock, use task_rq_lock()
1. read_lock(tasklist_lock) does not need to disable irqs.
2. ->mm != NULL is a common mistake, use PF_KTHREAD.
3. The second ->mm check can be simply removed.
4. task_rq_lock() looks better than raw_spin_lock(&p->pi_lock) + __task_rq_lock().
--- kernel/sched/core.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
kernel/sched/core.c +6 -10
@@ -7220,12 +7220,12 @@ void normalize_rt_tasks(void)unsigned long flags;struct rq *rq; -read_lock_irqsave (&tasklist_lock, flags); +read_lock (&tasklist_lock);for_each_process_thread (g, p) {/* * Only normalize user tasks: */ -if (!p->mm) +if (p->flags &PF_KTHREAD )continue ; p->se.exec_start =0 ;
@@ -7240,20 +7240,16 @@ void normalize_rt_tasks(void)* Renice negative nice level userspace * tasks back to 0: */ -if (task_nice (p) <0 && p->mm) +if (task_nice (p) <0 )set_user_nice (p,0 ); continue; } -raw_spin_lock (&p->pi_lock); - rq =__task_rq_lock (p); - + rq =task_rq_lock (p, &flags);normalize_task (rq, p); - -__task_rq_unlock (rq); -raw_spin_unlock (&p->pi_lock); +task_rq_unlock (rq, p, &flags); } -read_unlock_irqrestore (&tasklist_lock, flags); +read_unlock (&tasklist_lock); }#endif /* CONFIG_MAGIC_SYSRQ */
tip-bot for Oleg Nesterov
merge bot[tip:sched/core] sched: Fix the task-group check in tg_has_rt_tasks()
In reply to Oleg Nesterovsched: Fix the task-group check in tg_has_rt_tasks()
Commit-ID: 8651c65844e93af44554272b7e0d2b142837b244 Gitweb: http://git.kernel.org/tip/8651c65844e93af44554272b7e0d2b142837b244 Author: Oleg Nesterov <[email protected]> AuthorDate: Sun, 21 Sep 2014 21:33:36 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 24 Sep 2014 14:47:00 +0200
sched: Fix the task-group check in tg_has_rt_tasks()
tg_has_rt_tasks() wants to find an RT task in this task_group, but task_rq(p)->rt.tg wrongly checks the root rt_rq.
--- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
@@ -7441,7 +7441,7 @@ static inline int tg_has_rt_tasks(struct task_group *tg)struct task_struct *g, *p;for_each_process_thread (g, p) { -if (rt_task (p) &&task_rq (p)->rt.tg == tg) +if (rt_task (p) &&task_group (p) == tg)return 1 ; }