Skip to contentSkip to conversation

sched: Set correct normal_prio and prio values in sched_fork()

PATCH In review Peter Williams 5 participants 7 messages Sep 24, 2009 – Dec 15, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched: Set correct normal_prio and prio values in sched_fork()

normal_prio should be updated if policy changes from RT to SCHED_MORMAL or if static_prio/nice is changed. Some paths through sched_fork() ignore this requirement and may result in normal_prio having an invalid value.

Fixing this issue allows the call to effective_prio() in wake_up_new_task() to be removed.

kernel/sched.c +9 -11
@@ -2515,22 +2515,17 @@ void sched_fork(struct task_struct *p, i
 	__sched_fork(p);
 
 	/*
-	 * Make sure we do not leak PI boosting priority to the child.
-	 */
-	p->prio = current->normal_prio;
-
-	/*
 	 * Revert to default priority/policy on fork if requested.
 	 */
 	if (unlikely(p->sched_reset_on_fork)) {
-		if (p->policy == SCHED_FIFO || p->policy == SCHED_RR)
+		if (p->policy == SCHED_FIFO || p->policy == SCHED_RR) {
 			p->policy = SCHED_NORMAL;
-
-		if (p->normal_prio < DEFAULT_PRIO)
-			p->prio = DEFAULT_PRIO;
+			p->normal_prio = p->static_prio;
+		}
 
 		if (PRIO_TO_NICE(p->static_prio) < 0) {
 			p->static_prio = NICE_TO_PRIO(0);
+			p->normal_prio = p->static_prio;
 			set_load_weight(p);
 		}
 
@@ -2541,6 +2536,11 @@ void sched_fork(struct task_struct *p, i
 		p->sched_reset_on_fork = 0;
 	}
 
+	/*
+	 * Make sure we do not leak PI boosting priority to the child.
+	 */
+	p->prio = current->normal_prio;
+
 	if (!rt_prio(p->prio))
 		p->sched_class = &fair_sched_class;
 
@@ -2581,8 +2581,6 @@ void wake_up_new_task(struct task_struct
 	BUG_ON(p->state != TASK_RUNNING);
 	update_rq_clock(rq);
 
-	p->prio = effective_prio(p);
-
 	if (!p->sched_class->task_new || !current->se.on_rq) {
 		activate_task(rq, p, 0);
 	} else {
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Peter Williams

normal_prio should be updated if policy changes from RT to SCHED_MORMAL or if static_prio/nice is changed. Some paths through sched_fork() ignore this requirement and may result in normal_prio having an invalid value.

Fixing this issue allows the call to effective_prio() in wake_up_new_task() to be removed.

/me twists his brain into a pretsel, squints his eyes and sees its obvious ;-)

Thank Peter!

#2 lore raw
In reply to Peter Williams
Commit-ID:  f83f9ac2632732bd1678150b5a03d152f912fe72
Gitweb:     http://git.kernel.org/tip/f83f9ac2632732bd1678150b5a03d152f912fe72
Author:     Peter Williams <[email protected]>
AuthorDate: Thu, 24 Sep 2009 06:47:10 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 5 Oct 2009 13:42:20 +0200

sched: Set correct normal_prio and prio values in sched_fork()

normal_prio should be updated if policy changes from RT to SCHED_MORMAL or if static_prio/nice is changed.

Some paths through sched_fork() ignore this requirement and may result in normal_prio having an invalid value.

Fixing this issue allows the call to effective_prio() in wake_up_new_task() to be removed.

LKML-Reference: <[email protected]>

---
 kernel/sched.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
kernel/sched.c +9 -11
index 1535f38..76c0e96 100644
@@ -2515,22 +2515,17 @@ void sched_fork(struct task_struct *p, int clone_flags)
 	__sched_fork(p);
 
 	/*
-	 * Make sure we do not leak PI boosting priority to the child.
-	 */
-	p->prio = current->normal_prio;
-
-	/*
 	 * Revert to default priority/policy on fork if requested.
 	 */
 	if (unlikely(p->sched_reset_on_fork)) {
-		if (p->policy == SCHED_FIFO || p->policy == SCHED_RR)
+		if (p->policy == SCHED_FIFO || p->policy == SCHED_RR) {
 			p->policy = SCHED_NORMAL;
-
-		if (p->normal_prio < DEFAULT_PRIO)
-			p->prio = DEFAULT_PRIO;
+			p->normal_prio = p->static_prio;
+		}
 
 		if (PRIO_TO_NICE(p->static_prio) < 0) {
 			p->static_prio = NICE_TO_PRIO(0);
+			p->normal_prio = p->static_prio;
 			set_load_weight(p);
 		}
 
@@ -2541,6 +2536,11 @@ void sched_fork(struct task_struct *p, int clone_flags)
 		p->sched_reset_on_fork = 0;
 	}
 
+	/*
+	 * Make sure we do not leak PI boosting priority to the child.
+	 */
+	p->prio = current->normal_prio;
+
 	if (!rt_prio(p->prio))
 		p->sched_class = &fair_sched_class;
 
@@ -2581,8 +2581,6 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
 	BUG_ON(p->state != TASK_RUNNING);
 	update_rq_clock(rq);
 
-	p->prio = effective_prio(p);
-
 	if (!p->sched_class->task_new || !current->se.on_rq) {
 		activate_task(rq, p, 0);
 	} else {
#3 lore raw
Quoted 9 lines · tip-bot for Peter Williams

Commit-ID:  f83f9ac2632732bd1678150b5a03d152f912fe72
Gitweb:     http://git.kernel.org/tip/f83f9ac2632732bd1678150b5a03d152f912fe72
Author:     Peter Williams <[email protected]>
AuthorDate: Thu, 24 Sep 2009 06:47:10 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 5 Oct 2009 13:42:20 +0200

sched: Set correct normal_prio and prio values in sched_fork()

Quoted 9 lines

normal_prio should be updated if policy changes from RT to SCHED_MORMAL or if static_prio/nice is changed.

Some paths through sched_fork() ignore this requirement and may result in normal_prio having an invalid value.

Fixing this issue allows the call to effective_prio() in wake_up_new_task() to be removed.

This change causes a lot of threads with a 0 nice value to get a prio value of 140 instead of 120 (at least on my android arm msm build). I don't know if this has any impact on how they are scheduled since the load weight is unaffected, but it at least makes the output of ps more confusing.

Signature · 1 line
Arve Hjønnevåg
#4 lore raw
Quoted 21 lines · Arve Hjønnevåg
Quoted 9 lines · tip-bot for Peter Williams
Commit-ID:  f83f9ac2632732bd1678150b5a03d152f912fe72
Gitweb:     http://git.kernel.org/tip/f83f9ac2632732bd1678150b5a03d152f912fe72
Author:     Peter Williams <[email protected]>
AuthorDate: Thu, 24 Sep 2009 06:47:10 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 5 Oct 2009 13:42:20 +0200

sched: Set correct normal_prio and prio values in sched_fork()

Quoted 9 lines

normal_prio should be updated if policy changes from RT to SCHED_MORMAL or if static_prio/nice is changed.

Some paths through sched_fork() ignore this requirement and may result in normal_prio having an invalid value.

Fixing this issue allows the call to effective_prio() in wake_up_new_task() to be removed.

Quoted 5 lines

This change causes a lot of threads with a 0 nice value to get a prio value of 140 instead of 120 (at least on my android arm msm build). I don't know if this has any impact on how they are scheduled since the load weight is unaffected, but it at least makes the output of ps more confusing.

There's a patch in tip to correct this, hasn't swam upstream yet.

-Mike

#5 lore raw
Quoted 22 lines · Mike Galbraith
Quoted 21 lines · Arve Hj??nnev??g
Quoted 18 lines · tip-bot for Peter Williams
Commit-ID:  f83f9ac2632732bd1678150b5a03d152f912fe72
Gitweb:     http://git.kernel.org/tip/f83f9ac2632732bd1678150b5a03d152f912fe72
Author:     Peter Williams <[email protected]>
AuthorDate: Thu, 24 Sep 2009 06:47:10 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 5 Oct 2009 13:42:20 +0200

sched: Set correct normal_prio and prio values in sched_fork()

normal_prio should be updated if policy changes from RT to SCHED_MORMAL or if static_prio/nice is changed.

Some paths through sched_fork() ignore this requirement and may result in normal_prio having an invalid value.

Fixing this issue allows the call to effective_prio() in wake_up_new_task() to be removed.

Quoted 7 lines
Quoted 5 lines

This change causes a lot of threads with a 0 nice value to get a prio value of 140 instead of 120 (at least on my android arm msm build). I don't know if this has any impact on how they are scheduled since the load weight is unaffected, but it at least makes the output of ps more confusing.

There's a patch in tip to correct this, hasn't swam upstream yet.

just sent the pull request to Linus for the latest scheduler fixes. Meanwhile you can try latest -tip with the fix:

http://people.redhat.com/mingo/tip.git/README

Ingo

#6 lore raw
Quoted 31 lines · Ingo Molnar
Quoted 28 lines · Mike Galbraith
Quoted 26 lines · Arve Hj??nnev??g
Quoted 9 lines · tip-bot for Peter Williams

Commit-ID:  f83f9ac2632732bd1678150b5a03d152f912fe72
Gitweb:     http://git.kernel.org/tip/f83f9ac2632732bd1678150b5a03d152f912fe72
Author:     Peter Williams <[email protected]>
AuthorDate: Thu, 24 Sep 2009 06:47:10 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 5 Oct 2009 13:42:20 +0200

sched: Set correct normal_prio and prio values in sched_fork()

Quoted 9 lines

normal_prio should be updated if policy changes from RT to SCHED_MORMAL or if static_prio/nice is changed.

Some paths through sched_fork() ignore this requirement and may result in normal_prio having an invalid value.

Fixing this issue allows the call to effective_prio() in wake_up_new_task() to be removed.

This change causes a lot of threads with a 0 nice value to get a prio value of 140 instead of 120 (at least on my android arm msm build). I don't know if this has any impact on how they are scheduled since the load weight is unaffected, but it at least makes the output of ps more confusing.

Quoted 9 lines
Quoted 1 line

There's a patch in tip to correct this, hasn't swam upstream yet.

just sent the pull request to Linus for the latest scheduler fixes. Meanwhile you can try latest -tip with the fix:

 http://people.redhat.com/mingo/tip.git/README

       Ingo

Thanks. The fix is upstream now though, so I just cherry-picked it from there.

Signature · 1 line
Arve Hjønnevåg