Skip to contentSkip to conversation

O5int for interactivity

PATCH In review Con Kolivas 2 participants 3 messages Jul 14, 2003

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 O5int for interactivity

More interactivity work for audio and X smoothness. I have fixed all my test
cases and need feedback about others to develop beyond this.

Changes
The idle code now gives just under interactive state based on the runtime
instead of min_sleep_avg - minor startup speed improvement.

Tasks that drop their priority while running are now put to the end of the
queue to continue their timeslice. Fixes a little flutter when tasks are
cpu hogs for short periods (eg mozilla).

Tasks that are complete cpu hogs are put on the expired array every time they
run out of timeslice.

Con

Patch against 2.5.75-mm1 available here:
http://kernel.kolivas.org/2.5

and here:

kernel/sched.c +18 -13
diff -Naurp linux-2.5.75-mm1/kernel/sched.c linux-2.5.75-test/kernel/sched.c
@@ -388,19 +388,19 @@ static inline void __activate_task(task_
 static inline void activate_task(task_t *p, runqueue_t *rq)
 {
 	long sleep_time = jiffies - p->last_run - 1;
+	long runtime = jiffies - p->avg_start;
 
 	if (sleep_time > 0) {
-		unsigned long runtime = jiffies - p->avg_start;
-
 		/*
 		 * Tasks that sleep a long time are categorised as idle and
-		 * will get just under interactive status with a small runtime
-		 * to allow them to become interactive or non-interactive rapidly
+		 * will get just under interactive status
 		 */
 		if (sleep_time > MIN_SLEEP_AVG){
-			p->avg_start = jiffies - MIN_SLEEP_AVG;
-			p->sleep_avg = MIN_SLEEP_AVG * (MAX_BONUS - INTERACTIVE_DELTA - 1) /
-				MAX_BONUS;
+			if (runtime > MAX_SLEEP_AVG){
+				runtime = MAX_SLEEP_AVG;
+				p->avg_start = jiffies - runtime;
+			}
+			p->sleep_avg = runtime * (MAX_BONUS - INTERACTIVE_DELTA - 1) / MAX_BONUS;
 		} else {
 			/*
 			 * This code gives a bonus to interactive tasks.
@@ -1278,11 +1278,7 @@ void scheduler_tick(int user_ticks, int
 	spin_lock(&rq->lock);
 	/*
 	 * The task was running during this tick - update the
-	 * time slice counter and the sleep average. Note: we
-	 * do not update a thread's priority until it either
-	 * goes to sleep or uses up its timeslice. This makes
-	 * it possible for interactive tasks to use up their
-	 * timeslices at their highest priority levels.
+	 * time slice counter and the sleep average.
 	 */
 	if (p->sleep_avg)
 		p->sleep_avg--;
@@ -1309,12 +1305,21 @@ void scheduler_tick(int user_ticks, int 
 		p->time_slice = task_timeslice(p);
 		p->first_time_slice = 0;
 
-		if (!TASK_INTERACTIVE(p) || EXPIRED_STARVING(rq)) {
+		if (!TASK_INTERACTIVE(p) || EXPIRED_STARVING(rq) || !p->sleep_avg) {
 			if (!rq->expired_timestamp)
 				rq->expired_timestamp = jiffies;
 			enqueue_task(p, rq->expired);
 		} else
 			enqueue_task(p, rq->active);
+	} else if (unlikely(p->prio < effective_prio(p))){
+		/*
+		 * Tasks that have lowered their priority are put to the end
+		 * of the active array with their remaining timeslice
+		 */
+		dequeue_task(p, rq->active);
+		set_tsk_need_resched(p);
+		p->prio = effective_prio(p);
+		enqueue_task(p, rq->active);
 	}
 out_unlock:
 	spin_unlock(&rq->lock);
#1 lore raw
Quoted 7 lines · Con Kolivas

More interactivity work for audio and X smoothness. I have fixed all my test
cases and need feedback about others to develop beyond this.

Changes
The idle code now gives just under interactive state based on the runtime
instead of min_sleep_avg - minor startup speed improvement.

Quoted 6 lines

Tasks that drop their priority while running are now put to the end of the
queue to continue their timeslice. Fixes a little flutter when tasks are
cpu hogs for short periods (eg mozilla).

Tasks that are complete cpu hogs are put on the expired array every time they
run out of timeslice.

Hmmm... Starvation is back for me (Pentium III 700Mhz + ACPI):

1. Log on to X/KDE
2. Launch Konqueror
3. Launch XMMS
4. Make XMMS play a song
5. Move the Konqueror window all over the desktop.

Step 5 causes XMMS to completely starve for exactly 5 seconds. After those 5 seconds, the XMMS priority gets adjusted and sound comes back from my speakers.

Another way to starve XMMS for 5 seconds:

1. Launch XMMS
2. Make it play
3. Run a standard CPU hogger: "while true; do a=2; done"

Step 3 will make XMMS starve for exactly 5 seconds. Also, during those 5 seconds, X is completely jerky and moving the mouse makes the pointer goes jumping all over the screen.

Do you want additional information? Any patch trying? Thanks!

#2 lore raw
Quoted 33 lines · Felipe Alfaro Solana
Quoted 7 lines · Con Kolivas

More interactivity work for audio and X smoothness. I have fixed all my test cases and need feedback about others to develop beyond this.

Changes
The idle code now gives just under interactive state based on the runtime
instead of min_sleep_avg - minor startup speed improvement.

Quoted 6 lines

Tasks that drop their priority while running are now put to the end of the queue to continue their timeslice. Fixes a little flutter when tasks are cpu hogs for short periods (eg mozilla).

Tasks that are complete cpu hogs are put on the expired array every time they run out of timeslice.

Hmmm... Starvation is back for me (Pentium III 700Mhz + ACPI):

1. Log on to X/KDE
2. Launch Konqueror
3. Launch XMMS
4. Make XMMS play a song
5. Move the Konqueror window all over the desktop.

Step 5 causes XMMS to completely starve for exactly 5 seconds. After those 5 seconds, the XMMS priority gets adjusted and sound comes back from my speakers.

Another way to starve XMMS for 5 seconds:

1. Launch XMMS
2. Make it play
3. Run a standard CPU hogger: "while true; do a=2; done"

Quoted 6 lines

Step 3 will make XMMS starve for exactly 5 seconds. Also, during those 5 seconds, X is completely jerky and moving the mouse makes the pointer goes jumping all over the screen.

Do you want additional information? Any patch trying? Thanks!

Great thanks for test. Can you try reverting this:

kernel/sched.c +7 -7
diff -Naurp linux-2.5.75-mm1/kernel/sched.c linux-2.5.75-test/kernel/sched.c
@@ -388,19 +388,19 @@ static inline void __activate_task(task_
 static inline void activate_task(task_t *p, runqueue_t *rq)
 {
 	long sleep_time = jiffies - p->last_run - 1;
+	long runtime = jiffies - p->avg_start;
 
 	if (sleep_time > 0) {
-		unsigned long runtime = jiffies - p->avg_start;
-
 		/*
 		 * Tasks that sleep a long time are categorised as idle and
-		 * will get just under interactive status with a small runtime
-		 * to allow them to become interactive or non-interactive rapidly
+		 * will get just under interactive status
 		 */
 		if (sleep_time > MIN_SLEEP_AVG){
-			p->avg_start = jiffies - MIN_SLEEP_AVG;
-			p->sleep_avg = MIN_SLEEP_AVG * (MAX_BONUS - INTERACTIVE_DELTA - 1) /
-				MAX_BONUS;
+			if (runtime > MAX_SLEEP_AVG){
+				runtime = MAX_SLEEP_AVG;
+				p->avg_start = jiffies - runtime;
+			}
+			p->sleep_avg = runtime * (MAX_BONUS - INTERACTIVE_DELTA - 1) / MAX_BONUS;
 		} else {
 			/*
 			 * This code gives a bonus to interactive tasks.