SD sched: avoid redundant reschedule in set_user_nice()
PATCH 1/1 SD sched: avoid redundant reschedule in set_user_nice()
Hello,
This change seems to be pretty logical. OTOH, it's just a micro-optimization. So there is no hurry and we may wait till Con is back (Andrew, if you think it'd be better).
Logically-wise, this is similar to the changes I have sent earlier for the mainline.
There is no need to change TASK_PREEMPTS_CURR() here. All the infrastructure is already in place (task_preempts_curr() already does the necessary checks). And nevertheless, set_user_nice() can be made nicer. So that's what this patch is about.
---
Call for reschedule upon increasing a task's priority in set_user_nice() only if the task may preempt the current one.
Signed-off-by Dmitry Adamushko <[email protected]>
---
kernel/sched.c renamed from kernel/sched-orig.c +9 -6
@@ -4022,14 +4022,14 @@ EXPORT_SYMBOL(sleep_on_timeout);void rt_mutex_setprio (struct task_struct *p,int prio) {unsigned long flags; -int queued, oldprio; +int queued, delta;struct rq *rq;BUG_ON (prio <0 || prio >MAX_PRIO ); rq =task_rq_lock (p, &flags); - oldprio = p->prio; + delta = prio - p->prio; queued =task_queued (p);if (queued)dequeue_task (p, rq);
@@ -4043,7 +4043,7 @@ void rt_mutex_setprio(struct task_struct* this runqueue and our priority is higher than the current's */ if (task_running (rq, p)) { -if (p->prio > oldprio) +if (delta >0 )resched_task (rq->curr); }else try_preempt (p, rq);
@@ -4055,7 +4055,7 @@ void rt_mutex_setprio(struct task_structvoid set_user_nice (struct task_struct *p,long nice) { -int queued, old_prio,delta; +int queued, old_prio, delta;unsigned long flags;struct rq *rq;
@@ -4096,8 +4096,11 @@ void set_user_nice(struct task_struct *p* If the task increased its priority or is running and * lowered its priority, then reschedule its CPU: */ -if (delta <0 || (delta >0 &&task_running (rq, p))) -resched_task (rq->curr); +if (task_running (rq, p)) { +if (delta >0 ) +resched_task (rq->curr); + }else +try_preempt (p, rq); } out_unlock:task_rq_unlock (rq, &flags);