From: Con Kolivas <kernel@kolivas.org>

Small error in the just interactive logic has been corrected.

Idle tasks get one higher priority than just interactive so they don't get
swamped under heavy load.

Cosmetic cleanup.



 kernel/sched.c |   31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)

diff -puN kernel/sched.c~o19int kernel/sched.c
--- 25/kernel/sched.c~o19int	2003-08-30 16:01:59.000000000 -0700
+++ 25-akpm/kernel/sched.c	2003-08-30 16:01:59.000000000 -0700
@@ -64,8 +64,8 @@
 /*
  * Some helpers for converting nanosecond timing to jiffy resolution
  */
-#define NS_TO_JIFFIES(TIME)	(TIME / (1000000000 / HZ))
-#define JIFFIES_TO_NS(TIME)	(TIME * (1000000000 / HZ))
+#define NS_TO_JIFFIES(TIME)	((TIME) / (1000000000 / HZ))
+#define JIFFIES_TO_NS(TIME)	((TIME) * (1000000000 / HZ))
 
 /*
  * These are the 'tuning knobs' of the scheduler:
@@ -132,7 +132,8 @@
 	((p)->prio <= (p)->static_prio - DELTA(p))
 
 #define JUST_INTERACTIVE_SLEEP(p) \
-	(MAX_SLEEP_AVG - (DELTA(p) * AVG_TIMESLICE))
+	(JIFFIES_TO_NS(MAX_SLEEP_AVG * \
+		(MAX_BONUS / 2 + DELTA((p)) + 1) / MAX_BONUS - 1))
 
 #define HIGH_CREDIT(p) \
 	((p)->interactive_credit > MAX_SLEEP_AVG)
@@ -382,10 +383,8 @@ static void recalc_task_prio(task_t *p, 
 		 * prevent them suddenly becoming cpu hogs and starving
 		 * other processes.
 		 */
-		if (p->mm && sleep_time >
-			JIFFIES_TO_NS(JUST_INTERACTIVE_SLEEP(p)))
-				p->sleep_avg =
-					JIFFIES_TO_NS(JUST_INTERACTIVE_SLEEP(p));
+		if (p->mm && sleep_time >JUST_INTERACTIVE_SLEEP(p))
+			p->sleep_avg = JUST_INTERACTIVE_SLEEP(p) + 1;
 		else {
 			/*
 			 * The lower the sleep avg a task has the more
@@ -405,16 +404,15 @@ static void recalc_task_prio(task_t *p, 
 			/*
 			 * Non high_credit tasks waking from uninterruptible
 			 * sleep are limited in their sleep_avg rise as they
-			 * are likely to be waiting on I/O
+			 * are likely to be cpu hogs waiting on I/O
 			 */
 			if (p->activated == -1 && !HIGH_CREDIT(p) && p->mm){
-				if (p->sleep_avg >=
-					JIFFIES_TO_NS(JUST_INTERACTIVE_SLEEP(p)))
-						sleep_time = 0;
+				if (p->sleep_avg >= JUST_INTERACTIVE_SLEEP(p))
+					sleep_time = 0;
 				else if (p->sleep_avg + sleep_time >=
-					JIFFIES_TO_NS(JUST_INTERACTIVE_SLEEP(p))){
+					JUST_INTERACTIVE_SLEEP(p)){
 						p->sleep_avg =
-							JIFFIES_TO_NS(JUST_INTERACTIVE_SLEEP(p));
+							JUST_INTERACTIVE_SLEEP(p);
 						sleep_time = 0;
 					}
 			}
@@ -431,7 +429,8 @@ static void recalc_task_prio(task_t *p, 
 
 			if (p->sleep_avg > NS_MAX_SLEEP_AVG){
 				p->sleep_avg = NS_MAX_SLEEP_AVG;
-				p->interactive_credit += !(HIGH_CREDIT(p));
+				if (!HIGH_CREDIT(p))
+					p->interactive_credit++;
 			}
 		}
 	}
@@ -1548,8 +1547,8 @@ switch_tasks:
 	prev->sleep_avg -= run_time;
 	if ((long)prev->sleep_avg <= 0){
 		prev->sleep_avg = 0;
-		prev->interactive_credit -=
-			!(HIGH_CREDIT(prev) || LOW_CREDIT(prev));
+		if (!(HIGH_CREDIT(prev) || LOW_CREDIT(prev)))
+			prev->interactive_credit--;
 	}
 	prev->timestamp = now;
 

_