public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Adamushko <dmitry.adamushko@gmail.com>
To: "Con Kolivas" <kernel@kolivas.org>,
	"Andrew Morton" <akpm@linux-foundation.org>
Cc: "Linux Kernel" <linux-kernel@vger.kernel.org>
Subject: [PATCH 2.6.21-rc6-mm1] SD sched: avoid redundant reschedule in set_user_nice()
Date: Tue, 10 Apr 2007 17:16:13 +0200	[thread overview]
Message-ID: <200704101716.14372.dmitry.adamushko@gmail.com> (raw)


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 <dmitry.adamushko@gmail.com>

---

--- linux-2.6.21-rc6-mm1/kernel/sched-orig.c	2007-04-09 10:10:52.000000000 +0200
+++ linux-2.6.21-rc6-mm1/kernel/sched.c	2007-04-09 17:07:12.000000000 +0200
@@ -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_struct
 
 void 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);

                 reply	other threads:[~2007-04-10 21:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200704101716.14372.dmitry.adamushko@gmail.com \
    --to=dmitry.adamushko@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kernel@kolivas.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox