aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Adamushko <dmitry.adamushko@gmail.com>2007-05-08 03:33:06 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:17 -0400
commitbd53f96ca54a21c07e7a0ae1886fa623d370b85f (patch)
treec908772406a055fcaa8a8742a36f61014a99b20a
parent4953198b6ce07b008b0f1c2edd41c9d027a118b4 (diff)
sched: redundant reschedule when set_user_nice() boosts a prio of a task from the "expired" array
- Make TASK_PREEMPTS_CURR(task, rq) return "true" only if the task's prio is higher than the current's one and the task is in the "active" array. This ensures we don't make redundant resched_task() calls when the task is in the "expired" array (as may happen now in set_user_prio(), rt_mutex_setprio() and pull_task() ) ; - generalise conditions for a call to resched_task() in set_user_nice(), rt_mutex_setprio() and sched_setscheduler() Signed-off-by: Dmitry Adamushko <dmitry.adamushko@gmail.com> Cc: Con Kolivas <kernel@kolivas.org> Acked-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--kernel/sched.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index e60786eb731c..be2706c885a7 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -169,7 +169,7 @@ unsigned long long __attribute__((weak)) sched_clock(void)
169 (MAX_BONUS / 2 + DELTA((p)) + 1) / MAX_BONUS - 1)) 169 (MAX_BONUS / 2 + DELTA((p)) + 1) / MAX_BONUS - 1))
170 170
171#define TASK_PREEMPTS_CURR(p, rq) \ 171#define TASK_PREEMPTS_CURR(p, rq) \
172 ((p)->prio < (rq)->curr->prio) 172 (((p)->prio < (rq)->curr->prio) && ((p)->array == (rq)->active))
173 173
174#define SCALE_PRIO(x, prio) \ 174#define SCALE_PRIO(x, prio) \
175 max(x * (MAX_PRIO - prio) / (MAX_USER_PRIO / 2), MIN_TIMESLICE) 175 max(x * (MAX_PRIO - prio) / (MAX_USER_PRIO / 2), MIN_TIMESLICE)
@@ -4076,13 +4076,13 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
4076 struct prio_array *array; 4076 struct prio_array *array;
4077 unsigned long flags; 4077 unsigned long flags;
4078 struct rq *rq; 4078 struct rq *rq;
4079 int oldprio; 4079 int delta;
4080 4080
4081 BUG_ON(prio < 0 || prio > MAX_PRIO); 4081 BUG_ON(prio < 0 || prio > MAX_PRIO);
4082 4082
4083 rq = task_rq_lock(p, &flags); 4083 rq = task_rq_lock(p, &flags);
4084 4084
4085 oldprio = p->prio; 4085 delta = prio - p->prio;
4086 array = p->array; 4086 array = p->array;
4087 if (array) 4087 if (array)
4088 dequeue_task(p, array); 4088 dequeue_task(p, array);
@@ -4098,13 +4098,11 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
4098 enqueue_task(p, array); 4098 enqueue_task(p, array);
4099 /* 4099 /*
4100 * Reschedule if we are currently running on this runqueue and 4100 * Reschedule if we are currently running on this runqueue and
4101 * our priority decreased, or if we are not currently running on 4101 * our priority decreased, or if our priority became higher
4102 * this runqueue and our priority is higher than the current's 4102 * than the current's.
4103 */ 4103 */
4104 if (task_running(rq, p)) { 4104 if (TASK_PREEMPTS_CURR(p, rq) ||
4105 if (p->prio > oldprio) 4105 (delta > 0 && task_running(rq, p)))
4106 resched_task(rq->curr);
4107 } else if (TASK_PREEMPTS_CURR(p, rq))
4108 resched_task(rq->curr); 4106 resched_task(rq->curr);
4109 } 4107 }
4110 task_rq_unlock(rq, &flags); 4108 task_rq_unlock(rq, &flags);
@@ -4152,10 +4150,12 @@ void set_user_nice(struct task_struct *p, long nice)
4152 enqueue_task(p, array); 4150 enqueue_task(p, array);
4153 inc_raw_weighted_load(rq, p); 4151 inc_raw_weighted_load(rq, p);
4154 /* 4152 /*
4155 * If the task increased its priority or is running and 4153 * Reschedule if we are currently running on this runqueue and
4156 * lowered its priority, then reschedule its CPU: 4154 * our priority decreased, or if our priority became higher
4155 * than the current's.
4157 */ 4156 */
4158 if (delta < 0 || (delta > 0 && task_running(rq, p))) 4157 if (TASK_PREEMPTS_CURR(p, rq) ||
4158 (delta > 0 && task_running(rq, p)))
4159 resched_task(rq->curr); 4159 resched_task(rq->curr);
4160 } 4160 }
4161out_unlock: 4161out_unlock:
@@ -4382,13 +4382,11 @@ recheck:
4382 __activate_task(p, rq); 4382 __activate_task(p, rq);
4383 /* 4383 /*
4384 * Reschedule if we are currently running on this runqueue and 4384 * Reschedule if we are currently running on this runqueue and
4385 * our priority decreased, or if we are not currently running on 4385 * our priority decreased, or our priority became higher
4386 * this runqueue and our priority is higher than the current's 4386 * than the current's.
4387 */ 4387 */
4388 if (task_running(rq, p)) { 4388 if (TASK_PREEMPTS_CURR(p, rq) ||
4389 if (p->prio > oldprio) 4389 (task_running(rq, p) && p->prio > oldprio))
4390 resched_task(rq->curr);
4391 } else if (TASK_PREEMPTS_CURR(p, rq))
4392 resched_task(rq->curr); 4390 resched_task(rq->curr);
4393 } 4391 }
4394 __task_rq_unlock(rq); 4392 __task_rq_unlock(rq);