linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] O13int for interactivity
@ 2003-08-04 19:12 Voluspa
  0 siblings, 0 replies; 79+ messages in thread
From: Voluspa @ 2003-08-04 19:12 UTC (permalink / raw)
  To: linux-kernel


On 2003-08-04 18:24:15 Felipe Alfaro Solana wrote:

> Oh, yeah! This is damn good! I've had only a little bit time to try
> it, but I think it rocks. Good work :-)

Can only agree. Wine/wineserver now has the same PRI as in pure A3 on my
game-test, which can be felt and seen. Playability = 8.75 due to there
being slightly more bumps and audio glitches than in A3.

But that (A3) scheduler had other issues. Came home from work and began
typing in an xterm that had been sitting on the screen for more than 8
hours. It woke up... slowly. Took about 3 or 4 seconds before it
accepted my keystrokes without delays. It was not swapped out, but more
like it slowly accelerated from standstill.

Will report faults if I find them. Otherwise will stay silent. No news
is good news, you know.

Mvh
Mats Johannesson

^ permalink raw reply	[flat|nested] 79+ messages in thread
[parent not found: <gQ4n.5oS.7@gated-at.bofh.it>]
* Re: [PATCH] O13int for interactivity
@ 2003-08-06 10:35 Voluspa
  0 siblings, 0 replies; 79+ messages in thread
From: Voluspa @ 2003-08-06 10:35 UTC (permalink / raw)
  To: linux-kernel


Mon, 4 Aug 2003 21:12:47 +0200 I wrote:

> Wine/wineserver now has the same PRI as in pure A3 on my game-test,

I have to make an addendum based on more thorough observations.
Determining which one of wine or wineserver to treat as interactive
seems to be a hard nut for O13int - maybe impossible and irrelevant as
well. Anyway, here's what is happening:

Switching from the game to a text console where "top" is running,
counting to 15 in my head (didn't have a watch on my arm), wine dropps
its PRI from 25 to 16. Wineserver, which has had a PRI of 16, gains a
few points to 18, then shortly after gets elevated to 25 and stays
there. Returning to the game everything is clunky and sound choppy. It
takes a fair amount of work (panning, character movement, menu
selections etc) before wine gets its 25 PRI back. Just waiting doesn't
cut it.

A3 can also be fooled. Not by a mere switch to the text console, but by
deactivating an option which affects the whole graphic handling:

"Software standard BLT [on/off]. Enable this option if graphic anomalies
appear in the game"

After disabling it, but only the first time - on/off thereafter has no
trigger effect - A3 gives wineserver a PRI of 25. It does however
recuperate quickly, within something like 5 seconds. Just waiting is
enough. O13int is also affected by this trigger, that's how I first
experienced the PRI reversing.

Disclaimer: I'm not a gamer, and have no interest in the scheduler
being tuned for this particular scenario. It just happens to be that the
game-test is where I really can observe the differences in scheduler
behaviour.

Mvh
Mats Johannesson

^ permalink raw reply	[flat|nested] 79+ messages in thread
* [PATCH] O13int for interactivity
@ 2003-08-04 16:07 Con Kolivas
  2003-08-04 18:24 ` Felipe Alfaro Solana
                   ` (3 more replies)
  0 siblings, 4 replies; 79+ messages in thread
From: Con Kolivas @ 2003-08-04 16:07 UTC (permalink / raw)
  To: linux kernel mailing list
  Cc: Andrew Morton, Ingo Molnar, Felipe Alfaro Solana

Changes:

Reverted the child penalty to 95 as new changes help this from hurting

Changed the logic behind loss of interactive credits to those that burn off 
all their sleep_avg

Now all tasks get proportionately more sleep as their relative bonus drops 
off. This has the effect of detecting a change from a cpu burner to an 
interactive task more rapidly as in O10. 

The _major_ change in this patch is that tasks on uninterruptible sleep do not 
earn any sleep avg during that sleep; it is not voluntary sleep so they should 
not get it. This has the effect of stopping cpu hogs from gaining dynamic 
priority during periods of heavy I/O. Very good for the jerks you may 
see in X or audio skips when you start a whole swag of disk intensive cpu hogs 
(eg make -j large number). I've simply dropped all their sleep_avg, but 
weighting it may be more appropriate. This has the side effect that pure
disk tasks (eg cp) have relatively low priority which is why weighting may
be better. We shall see.

Please test this one extensively. It should _not_ affect I/O throughput per 
se, but I'd like to see some of the I/O benchmarks on this. I do not want to 
have detrimental effects elsewhere.

patch-O12.3-O13int applies on top of 2.6.0-test2-mm4 that has been 
patched with O12.3int and is available on my site, and a full patch
against 2.6.0-test2 called patch-test2-O13int is here:

http://kernel.kolivas.org/2.5

patch-O12.3-O13int:

--- linux-2.6.0-test2-mm4-O12.3/kernel/sched.c	2003-08-05 01:30:27.000000000 +1000
+++ linux-2.6.0-test2-mm4-O13/kernel/sched.c	2003-08-05 01:36:20.000000000 +1000
@@ -78,7 +78,7 @@
 #define MAX_TIMESLICE		(200 * HZ / 1000)
 #define TIMESLICE_GRANULARITY	(HZ/40 ?: 1)
 #define ON_RUNQUEUE_WEIGHT	30
-#define CHILD_PENALTY		90
+#define CHILD_PENALTY		95
 #define PARENT_PENALTY		100
 #define EXIT_WEIGHT		3
 #define PRIO_BONUS_RATIO	25
@@ -365,6 +365,9 @@ static void recalc_task_prio(task_t *p, 
 	unsigned long long __sleep_time = now - p->timestamp;
 	unsigned long sleep_time;
 
+	if (!p->sleep_avg)
+		p->interactive_credit--;
+
 	if (__sleep_time > NS_MAX_SLEEP_AVG)
 		sleep_time = NS_MAX_SLEEP_AVG;
 	else
@@ -384,17 +387,19 @@ static void recalc_task_prio(task_t *p, 
 					JIFFIES_TO_NS(JUST_INTERACTIVE_SLEEP(p));
 		else {
 			/*
-			 * Tasks with interactive credits get boosted more
-			 * rapidly if their bonus has dropped off. Other
-			 * tasks are limited to one timeslice worth of
-			 * sleep avg.
+			 * The lower the sleep avg a task has the more
+			 * rapidly it will rise with sleep time. Tasks
+			 * without interactive_credit are limited to
+			 * one timeslice worth of sleep avg bonus.
 			 */
-			if (p->interactive_credit > 0)
-				sleep_time *= (MAX_BONUS + 1 -
+			sleep_time *= (MAX_BONUS + 1 -
 					(NS_TO_JIFFIES(p->sleep_avg) *
 					MAX_BONUS / MAX_SLEEP_AVG));
-			else if (sleep_time > JIFFIES_TO_NS(task_timeslice(p)))
-				sleep_time = JIFFIES_TO_NS(task_timeslice(p));
+
+			if (p->interactive_credit < 0 &&
+				sleep_time > JIFFIES_TO_NS(task_timeslice(p)))
+					sleep_time =
+						JIFFIES_TO_NS(task_timeslice(p));
 
 			/*
 			 * This code gives a bonus to interactive tasks.
@@ -435,20 +440,26 @@ static inline void activate_task(task_t 
 	recalc_task_prio(p, now);
 
 	/*
-	 * Tasks which were woken up by interrupts (ie. hw events)
-	 * are most likely of interactive nature. So we give them
-	 * the credit of extending their sleep time to the period
-	 * of time they spend on the runqueue, waiting for execution
-	 * on a CPU, first time around:
+	 * This checks to make sure it's not an uninterruptible task
+	 * that is now waking up.
 	 */
-	if (in_interrupt())
-		p->activated = 2;
-	else
-	/*
-	 * Normal first-time wakeups get a credit too for on-runqueue time,
-	 * but it will be weighted down:
-	 */
-		p->activated = 1;
+	if (!p->activated){
+		/*
+		 * Tasks which were woken up by interrupts (ie. hw events)
+		 * are most likely of interactive nature. So we give them
+		 * the credit of extending their sleep time to the period
+		 * of time they spend on the runqueue, waiting for execution
+		 * on a CPU, first time around:
+		 */
+		if (in_interrupt())
+			p->activated = 2;
+		else
+		/*
+		 * Normal first-time wakeups get a credit too for on-runqueue
+		 * time, but it will be weighted down:
+		 */
+			p->activated = 1;
+	}
 
 	p->timestamp = now;
 
@@ -572,8 +583,15 @@ repeat_lock_task:
 				task_rq_unlock(rq, &flags);
 				goto repeat_lock_task;
 			}
-			if (old_state == TASK_UNINTERRUPTIBLE)
+			if (old_state == TASK_UNINTERRUPTIBLE){
+				/*
+				 * Tasks on involuntary sleep don't earn
+				 * sleep_avg
+				 */
 				rq->nr_uninterruptible--;
+				p->timestamp = sched_clock();
+				p->activated = -1;
+			}
 			if (sync)
 				__activate_task(p, rq);
 			else {
@@ -1326,7 +1344,6 @@ void scheduler_tick(int user_ticks, int 
 		p->prio = effective_prio(p);
 		p->time_slice = task_timeslice(p);
 		p->first_time_slice = 0;
-		p->interactive_credit--;
 
 		if (!rq->expired_timestamp)
 			rq->expired_timestamp = jiffies;
@@ -1459,7 +1476,7 @@ pick_next_task:
 	queue = array->queue + idx;
 	next = list_entry(queue->next, task_t, run_list);
 
-	if (next->activated && next->interactive_credit > 0) {
+	if (next->activated > 0) {
 		unsigned long long delta = now - next->timestamp;
 
 		if (next->activated == 1)


^ permalink raw reply	[flat|nested] 79+ messages in thread
* [PATCH] O10int for interactivity
@ 2003-07-27 15:12 Con Kolivas
  2003-07-28 18:08 ` Valdis.Kletnieks
  0 siblings, 1 reply; 79+ messages in thread
From: Con Kolivas @ 2003-07-27 15:12 UTC (permalink / raw)
  To: linux kernel mailing list; +Cc: Andrew Morton

Here is a fairly rapid evolution of the O*int patches for interactivity thanks
to Ingo's involvement.

Changes:
I've put in some defines to clarify where the numbers for MAX_SLEEP_AVG come 
from now, rather than the number being magic. In the process it increases MSA 
every so slightly so that an average task that runs a full timeslice (102ms) 
will drop exactly one priority in that time.

I've incorporated Ingo's fix for scheduling latency in a form that works for 
my patch, along with the other minor tweaks.

The parent and child sleep avg on forking is set to just on the priority bonus 
value with each fork thus keeping their bonus the same but making them very 
easy to tip to a lower priority.

A tiny addition to ensure any task that runs gets charged one tick of 
sleep_avg.

This patch is against 2.6.0-test1-mm2 patched up to O9int. An updated
O9int with layout corrections was posted on my website. A full O10int patch
against 2.6.0-test1 is available on my website.

Con

http://kernel.kolivas.org/2.5

patch-O10int-0307280030 :

--- linux-2.6.0-test1-mm2/kernel/sched.c	2003-07-27 14:03:16.000000000 +1000
+++ linux-2.6.0-test1ck2/kernel/sched.c	2003-07-28 00:31:39.000000000 +1000
@@ -58,6 +58,8 @@
 #define USER_PRIO(p)		((p)-MAX_RT_PRIO)
 #define TASK_USER_PRIO(p)	USER_PRIO((p)->static_prio)
 #define MAX_USER_PRIO		(USER_PRIO(MAX_PRIO))
+#define AVG_TIMESLICE	(MIN_TIMESLICE + ((MAX_TIMESLICE - MIN_TIMESLICE) *\
+			(MAX_PRIO-1-NICE_TO_PRIO(0))/(MAX_USER_PRIO - 1)))
 
 /*
  * These are the 'tuning knobs' of the scheduler:
@@ -68,16 +70,16 @@
  */
 #define MIN_TIMESLICE		( 10 * HZ / 1000)
 #define MAX_TIMESLICE		(200 * HZ / 1000)
-#define TIMESLICE_GRANULARITY	(HZ / 20 ?: 1)
+#define TIMESLICE_GRANULARITY	(HZ/40 ?: 1)
 #define CHILD_PENALTY		90
 #define PARENT_PENALTY		100
 #define EXIT_WEIGHT		3
 #define PRIO_BONUS_RATIO	25
+#define MAX_BONUS		(MAX_USER_PRIO * PRIO_BONUS_RATIO / 100)
 #define INTERACTIVE_DELTA	2
-#define MAX_SLEEP_AVG		(HZ)
-#define STARVATION_LIMIT	(HZ)
+#define MAX_SLEEP_AVG		(AVG_TIMESLICE * MAX_BONUS)
+#define STARVATION_LIMIT	(MAX_SLEEP_AVG)
 #define NODE_THRESHOLD		125
-#define MAX_BONUS		(MAX_USER_PRIO * PRIO_BONUS_RATIO / 100)
 
 /*
  * If a task is 'interactive' then we reinsert it in the active
@@ -117,6 +119,11 @@
 #define TASK_INTERACTIVE(p) \
 	((p)->prio <= (p)->static_prio - DELTA(p))
 
+#define TASK_PREEMPTS_CURR(p, rq) \
+	((p)->prio < (rq)->curr->prio || \
+		((p)->prio == (rq)->curr->prio && \
+			(p)->time_slice > (rq)->curr->time_slice * 2))
+
 /*
  * BASE_TIMESLICE scales user-nice values [ -20 ... 19 ]
  * to time slice values.
@@ -341,6 +348,42 @@ static inline void __activate_task(task_
 	nr_running_inc(rq);
 }
 
+static void recalc_task_prio(task_t *p)
+{
+	long sleep_time = jiffies - p->last_run - 1;
+
+	if (sleep_time > 0) {
+		p->activated = 0;
+
+		/*
+		 * User tasks that sleep a long time are categorised as
+		 * idle and will get just under interactive status to
+		 * prevent them suddenly becoming cpu hogs and starving
+		 * other processes.
+		 */
+		if (p->mm && sleep_time > HZ)
+			p->sleep_avg = MAX_SLEEP_AVG *
+					(MAX_BONUS - 1) / MAX_BONUS - 1;
+		else {
+
+			/*
+			 * Processes that sleep get pushed to one higher
+			 * priority each time they sleep greater than
+			 * one tick. -ck
+			 */
+			p->sleep_avg = (p->sleep_avg * MAX_BONUS /
+					MAX_SLEEP_AVG + 1) *
+					MAX_SLEEP_AVG / MAX_BONUS;
+
+			if (p->sleep_avg > MAX_SLEEP_AVG)
+				p->sleep_avg = MAX_SLEEP_AVG;
+		}
+	}
+	p->prio = effective_prio(p);
+
+}
+
+
 /*
  * activate_task - move a task to the runqueue and do priority recalculation
  *
@@ -350,37 +393,11 @@ static inline void __activate_task(task_
 static inline void activate_task(task_t *p, runqueue_t *rq)
 {
 	if (likely(p->last_run)){
-		long sleep_time = jiffies - p->last_run - 1;
-
-		if (sleep_time > 0) {
-			/*
-			 * User tasks that sleep a long time are categorised as
-			 * idle and will get just under interactive status to
-			 * prevent them suddenly becoming cpu hogs and starving
-			 * other processes.
-			 */
-			if (p->mm && sleep_time > HZ)
-				p->sleep_avg = MAX_SLEEP_AVG *
-						(MAX_BONUS - 1) / MAX_BONUS - 1;
-			else {
-
-				/*
-				 * Processes that sleep get pushed to one higher
-				 * priority each time they sleep greater than
-				 * one tick. -ck
-				 */
-				p->sleep_avg = (p->sleep_avg * MAX_BONUS /
-						MAX_SLEEP_AVG + 1) *
-						MAX_SLEEP_AVG / MAX_BONUS;
-
-				if (p->sleep_avg > MAX_SLEEP_AVG)
-					p->sleep_avg = MAX_SLEEP_AVG;
-			}
-		}
+		p->activated = 1;
+		recalc_task_prio(p);
 	} else
 		p->last_run = jiffies;
 
-	p->prio = effective_prio(p);
 	__activate_task(p, rq);
 }
 
@@ -507,7 +524,7 @@ repeat_lock_task:
 				__activate_task(p, rq);
 			else {
 				activate_task(p, rq);
-				if (p->prio < rq->curr->prio)
+				if (TASK_PREEMPTS_CURR(p, rq))
 					resched_task(rq->curr);
 			}
 			success = 1;
@@ -556,8 +573,11 @@ void wake_up_forked_process(task_t * p)
 	 * and children as well, to keep max-interactive tasks
 	 * from forking tasks that are max-interactive.
 	 */
-	current->sleep_avg = current->sleep_avg * PARENT_PENALTY / 100;
-	p->sleep_avg = p->sleep_avg * CHILD_PENALTY / 100;
+	current->sleep_avg = current->sleep_avg * MAX_BONUS / MAX_SLEEP_AVG *
+				PARENT_PENALTY / 100 * MAX_SLEEP_AVG /
+				MAX_BONUS;
+	p->sleep_avg = p->sleep_avg * MAX_BONUS / MAX_SLEEP_AVG *
+			CHILD_PENALTY / 100 * MAX_SLEEP_AVG / MAX_BONUS;
 	p->prio = effective_prio(p);
 	p->last_run = 0;
 	set_task_cpu(p, smp_processor_id());
@@ -1254,7 +1274,8 @@ void scheduler_tick(int user_ticks, int 
 		} else
 			enqueue_task(p, rq->active);
 	} else if (!((task_timeslice(p) - p->time_slice) %
-		TIMESLICE_GRANULARITY) && (p->time_slice > MIN_TIMESLICE)) {
+		TIMESLICE_GRANULARITY) && (p->time_slice > MIN_TIMESLICE) &&
+		(p->array == rq->active)) {
 		/*
 		 * Running user tasks get requeued with their remaining
 		 * timeslice after TIMESLICE_GRANULARITY provided they have at
@@ -1302,6 +1323,13 @@ need_resched:
 
 	release_kernel_lock(prev);
 	prev->last_run = jiffies;
+	/*
+	 * If a task has run less than one tick make sure it is still
+	 * charged one sleep_avg for running.
+	 */
+	if (unlikely((task_timeslice(prev) == prev->time_slice) &&
+		prev->sleep_avg))
+			prev->sleep_avg--;
 	spin_lock_irq(&rq->lock);
 
 	/*
@@ -1349,6 +1377,13 @@ pick_next_task:
 	queue = array->queue + idx;
 	next = list_entry(queue->next, task_t, run_list);
 
+	if (next->activated) {
+		next->activated = 0;
+		array = next->array;
+		dequeue_task(next, array);
+		recalc_task_prio(next);
+		enqueue_task(next, array);
+	}
 switch_tasks:
 	prefetch(next);
 	clear_tsk_need_resched(prev);
--- linux-2.6.0-test1-mm2/include/linux/sched.h	2003-07-24 10:31:41.000000000 +1000
+++ linux-2.6.0-test1ck2/include/linux/sched.h	2003-07-27 20:09:04.000000000 +1000
@@ -342,6 +342,7 @@ struct task_struct {
 
 	unsigned long sleep_avg;
 	unsigned long last_run;
+	int activated;
 
 	unsigned long policy;
 	cpumask_t cpus_allowed;


^ permalink raw reply	[flat|nested] 79+ messages in thread

end of thread, other threads:[~2003-08-14 10:49 UTC | newest]

Thread overview: 79+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-04 19:12 [PATCH] O13int for interactivity Voluspa
     [not found] <gQ4n.5oS.7@gated-at.bofh.it>
     [not found] ` <jUl6.5eh.1@gated-at.bofh.it>
     [not found]   ` <jUuT.5kZ.15@gated-at.bofh.it>
     [not found]     ` <jWn1.6K1.11@gated-at.bofh.it>
2003-08-13 13:48       ` Pascal Schmidt
2003-08-13 14:50         ` Gene Heskett
  -- strict thread matches above, loose matches on Subject: below --
2003-08-06 10:35 Voluspa
2003-08-04 16:07 Con Kolivas
2003-08-04 18:24 ` Felipe Alfaro Solana
2003-08-04 19:15 ` Antonio Vargas
2003-08-04 21:32   ` Con Kolivas
2003-08-04 20:11 ` Mike Galbraith
2003-08-04 22:11   ` Con Kolivas
2003-08-05  7:10     ` Mike Galbraith
2003-08-05  2:11 ` Nick Piggin
2003-08-05  2:20   ` Con Kolivas
2003-08-05  2:21     ` Nick Piggin
2003-08-05  3:06       ` Con Kolivas
2003-08-05  3:17         ` Nick Piggin
2003-08-05  3:18       ` Con Kolivas
2003-08-05  3:31         ` Nick Piggin
2003-08-05  5:04           ` Con Kolivas
2003-08-05  5:12             ` Nick Piggin
2003-08-05  5:16               ` Con Kolivas
2003-08-05  5:28                 ` Nick Piggin
2003-08-05 10:22                   ` Con Kolivas
2003-08-05 10:32                     ` Nick Piggin
2003-08-05 10:45                       ` Con Kolivas
2003-08-05 10:48                         ` Nick Piggin
2003-08-05 10:56                           ` Con Kolivas
2003-08-05 11:03                             ` Nick Piggin
2003-08-05 11:12                               ` Con Kolivas
2003-08-05 11:23                                 ` Nick Piggin
2003-08-05 11:34                                   ` Con Kolivas
2003-08-05 10:54                         ` Arjan van de Ven
2003-08-05 11:10                           ` Con Kolivas
2003-08-06 21:33                       ` Timothy Miller
2003-08-06 21:33                         ` Con Kolivas
2003-08-07  0:27                           ` Timothy Miller
2003-08-07  0:27                             ` Con Kolivas
2003-08-07  0:44                               ` Timothy Miller
2003-08-11  6:48                       ` Rob Landley
2003-08-11 15:47                         ` William Lee Irwin III
2003-08-12  2:51                         ` Nick Piggin
2003-08-12  6:16                           ` Mike Galbraith
2003-08-12  7:07                             ` Nick Piggin
2003-08-12  7:18                               ` Nick Piggin
2003-08-12  9:42                                 ` Mike Galbraith
2003-08-12 21:11                                   ` Mike Fedyk
2003-08-13  6:55                                     ` Mike Galbraith
2003-08-12  9:22                               ` Mike Galbraith
2003-08-12  9:37                                 ` Nick Piggin
2003-08-12  9:48                                   ` Mike Galbraith
2003-08-12 10:29                           ` Rob Landley
2003-08-12 11:08                             ` Nick Piggin
2003-08-12 11:35                               ` Rob Landley
2003-08-12 11:58                                 ` Nick Piggin
2003-08-13  2:08                                   ` jw schultz
2003-08-13  3:07                                     ` Gene Heskett
2003-08-13  3:24                                       ` Nick Piggin
2003-08-13  5:24                                         ` Gene Heskett
2003-08-13  5:43                                           ` Andrew McGregor
2003-08-13 12:33                                             ` Gene Heskett
2003-08-14  5:03                                               ` Andrew McGregor
2003-08-14 10:48                                                 ` Gene Heskett
2003-08-12 15:36                           ` Timothy Miller
2003-08-05  6:03             ` Andrew Morton
2003-08-05  7:26               ` Con Kolivas
2003-08-05  8:12                 ` Oliver Neukum
2003-08-05  8:20                   ` Con Kolivas
2003-08-05  8:27                     ` Mike Galbraith
2003-08-05  8:43                       ` Con Kolivas
2003-08-05  9:09                         ` Mike Galbraith
2003-08-05  9:19                           ` Con Kolivas
2003-08-05 10:04                   ` Nick Piggin
2003-08-11  6:57                 ` Rob Landley
2003-08-11 15:58                   ` William Lee Irwin III
2003-08-05  7:53               ` Mike Galbraith
2003-07-27 15:12 [PATCH] O10int " Con Kolivas
2003-07-28 18:08 ` Valdis.Kletnieks
2003-07-28 18:40   ` Andrew Morton
2003-08-04 18:51     ` [PATCH] O13int " Felipe Alfaro Solana
2003-08-04 18:58       ` Felipe Alfaro Solana
2003-08-04 21:46         ` Con Kolivas
2003-08-04 22:16           ` Felipe Alfaro Solana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).