linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] O1int for 2.5.73
@ 2003-06-27  8:26 Con Kolivas
  2003-06-28  0:20 ` [PATCH] O1int for 2.5.73 - sched tuning sysctl Roberto Orenstein
  0 siblings, 1 reply; 2+ messages in thread
From: Con Kolivas @ 2003-06-27  8:26 UTC (permalink / raw)
  To: linux kernel mailing list, Felipe Alfaro Solana
  Cc: Mike Galbraith, Marc-Christian Petersen

[-- Attachment #1: Type: text/plain, Size: 510 bytes --]

Here is an updated version of the O1int patch designed to improve 
interactivity.

This change addresses the difficulty of new tasks in heavy load being 
recognised as interactive by decreasing the amount of time considered in the 
interactivity equation, but dropping that decrease exponentially till it gets 
to the MAX_SLEEP_AVG.

This should improve the startup time of new apps in heavy load and lessen 
audio stalls when loads are high _and_ then the audio app is started.

Please test and comment.

Con

[-- Attachment #2: patch-O1int-0306271816 --]
[-- Type: text/x-diff, Size: 3694 bytes --]

diff -Naurp linux-2.5.73/include/linux/sched.h linux-2.5.73-test/include/linux/sched.h
--- linux-2.5.73/include/linux/sched.h	2003-06-26 01:30:42.000000000 +1000
+++ linux-2.5.73-test/include/linux/sched.h	2003-06-26 01:32:34.000000000 +1000
@@ -336,6 +336,7 @@ struct task_struct {
 	prio_array_t *array;
 
 	unsigned long sleep_avg;
+	unsigned long avg_start;
 	unsigned long last_run;
 
 	unsigned long policy;
diff -Naurp linux-2.5.73/kernel/fork.c linux-2.5.73-test/kernel/fork.c
--- linux-2.5.73/kernel/fork.c	2003-06-26 01:30:42.000000000 +1000
+++ linux-2.5.73-test/kernel/fork.c	2003-06-26 01:33:31.000000000 +1000
@@ -863,6 +863,7 @@ struct task_struct *copy_process(unsigne
 	p->array = NULL;
 	p->lock_depth = -1;		/* -1 = no lock */
 	p->start_time = get_jiffies_64();
+	p->avg_start = jiffies;
 	p->security = NULL;
 
 	retval = -ENOMEM;
diff -Naurp linux-2.5.73/kernel/sched.c linux-2.5.73-test/kernel/sched.c
--- linux-2.5.73/kernel/sched.c	2003-06-26 01:30:42.000000000 +1000
+++ linux-2.5.73-test/kernel/sched.c	2003-06-27 18:15:59.000000000 +1000
@@ -313,12 +313,24 @@ static inline void enqueue_task(struct t
  */
 static int effective_prio(task_t *p)
 {
-	int bonus, prio;
+	int bonus, prio, sleep_period;
 
 	if (rt_task(p))
 		return p->prio;
 
-	bonus = MAX_USER_PRIO*PRIO_BONUS_RATIO*p->sleep_avg/MAX_SLEEP_AVG/100 -
+	sleep_period = jiffies - p->avg_start;
+
+	if (sleep_period > MAX_SLEEP_AVG)
+		sleep_period = MAX_SLEEP_AVG;
+	else if (sleep_period < 10)
+		return p->static_prio;
+
+	if (sleep_period < MAX_SLEEP_AVG)
+		sleep_period -= (sleep_period/2) * (MAX_SLEEP_AVG - sleep_period)/MAX_SLEEP_AVG;
+	if (p->sleep_avg > sleep_period)
+		sleep_period = p->sleep_avg;
+
+	bonus = MAX_USER_PRIO*PRIO_BONUS_RATIO*p->sleep_avg/sleep_period/100 -
 			MAX_USER_PRIO*PRIO_BONUS_RATIO/100/2;
 
 	prio = p->static_prio - bonus;
@@ -349,8 +361,12 @@ static inline void activate_task(task_t 
 	long sleep_time = jiffies - p->last_run - 1;
 
 	if (sleep_time > 0) {
-		int sleep_avg;
 
+		if (sleep_time > HZ){
+			p->avg_start = jiffies - HZ;
+			p->sleep_avg = HZ / 2;
+		}
+		else {
 		/*
 		 * This code gives a bonus to interactive tasks.
 		 *
@@ -359,7 +375,7 @@ static inline void activate_task(task_t 
 		 * spends sleeping, the higher the average gets - and the
 		 * higher the priority boost gets as well.
 		 */
-		sleep_avg = p->sleep_avg + sleep_time;
+			p->sleep_avg += sleep_time;
 
 		/*
 		 * 'Overflow' bonus ticks go to the waker as well, so the
@@ -367,12 +383,10 @@ static inline void activate_task(task_t 
 		 * boosting tasks that are related to maximum-interactive
 		 * tasks.
 		 */
-		if (sleep_avg > MAX_SLEEP_AVG)
-			sleep_avg = MAX_SLEEP_AVG;
-		if (p->sleep_avg != sleep_avg) {
-			p->sleep_avg = sleep_avg;
-			p->prio = effective_prio(p);
+			if (p->sleep_avg > MAX_SLEEP_AVG)
+				p->sleep_avg = MAX_SLEEP_AVG;
 		}
+		p->prio = effective_prio(p);
 	}
 	__activate_task(p, rq);
 }
@@ -549,8 +563,6 @@ 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;
 	p->prio = effective_prio(p);
 	set_task_cpu(p, smp_processor_id());
 
@@ -586,13 +598,6 @@ void sched_exit(task_t * p)
 			p->parent->time_slice = MAX_TIMESLICE;
 	}
 	local_irq_restore(flags);
-	/*
-	 * If the child was a (relative-) CPU hog then decrease
-	 * the sleep_avg of the parent as well.
-	 */
-	if (p->sleep_avg < p->parent->sleep_avg)
-		p->parent->sleep_avg = (p->parent->sleep_avg * EXIT_WEIGHT +
-			p->sleep_avg) / (EXIT_WEIGHT + 1);
 }
 
 /**

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

* Re: [PATCH] O1int for 2.5.73 - sched tuning sysctl
  2003-06-27  8:26 [PATCH] O1int for 2.5.73 Con Kolivas
@ 2003-06-28  0:20 ` Roberto Orenstein
  0 siblings, 0 replies; 2+ messages in thread
From: Roberto Orenstein @ 2003-06-28  0:20 UTC (permalink / raw)
  To: Con Kolivas; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1236 bytes --]

On Fri, 2003-06-27 at 05:26, Con Kolivas wrote:
> Here is an updated version of the O1int patch designed to improve 
> interactivity.
> 
> This change addresses the difficulty of new tasks in heavy load being 
> recognised as interactive by decreasing the amount of time considered in the 
> interactivity equation, but dropping that decrease exponentially till it gets 
> to the MAX_SLEEP_AVG.
> 
> This should improve the startup time of new apps in heavy load and lessen 
> audio stalls when loads are high _and_ then the audio app is started.
> 
> Please test and comment.
> 
> Con

Well, I've just been following this thread and I choose to make a small
patch against your O1 int to export the scheduler tuning knobs via
sysctl. This patch will create /proc/sys/kernel/sched_tuning and expose
all the knobs, sou you guys don't have to recompile and reboot just to
change, say, max_sleep_avg. Don't know if anybody will find it useful,
but at least it doesn't hurts :-) 
It should apply cleanly against plain 2.5.73, altough I didn't tested.

wrt your patch, I must admit I didn't feel any difference from vanilla
2.5.73, but this feeling isn't much scientific 8). I will do some
serious tests tomorrow if I find any time.

Roberto

[-- Attachment #2: patch-sched_tuning --]
[-- Type: text/x-patch, Size: 6217 bytes --]

diff -Nur -X dontdiff linux-2.5.73-O1int/include/linux/sysctl.h linux-2.5.73-test/include/linux/sysctl.h
--- linux-2.5.73-O1int/include/linux/sysctl.h	2003-06-27 19:35:11.000000000 -0300
+++ linux-2.5.73-test/include/linux/sysctl.h	2003-06-27 20:45:59.000000000 -0300
@@ -130,6 +130,7 @@
 	KERN_PIDMAX=55,		/* int: PID # limit */
   	KERN_CORE_PATTERN=56,	/* string: pattern for core-file names */
 	KERN_PANIC_ON_OOPS=57,  /* int: whether we will panic on an oops */
+	KERN_SCHED_TUNING=58	/* dir: scheduler tuning */
 };
 
 
@@ -193,6 +194,21 @@
 	RANDOM_UUID=6
 };
 
+/* /proc/sys/kernel/sched_tuning */
+enum
+{
+	SCHED_TUNING_MIN_TIMESLICE=1,
+	SCHED_TUNING_MAX_TIMESLICE=2,
+	SCHED_TUNING_BONUS_RATIO=3,
+	SCHED_TUNING_MAX_SLEEP_AVG=4,
+	SCHED_TUNING_STARVATION_LIMIT=5,
+	SCHED_TUNING_CHILD_PENALTY=6,
+	SCHED_TUNING_PARENT_PENALTY=7,
+	SCHED_TUNING_EXIT_WEIGHT=8,
+	SCHED_TUNING_INTERACTIVE_DELTA=9,
+	SCHED_TUNING_NODE_THRESHOLD=10
+};
+
 /* /proc/sys/bus/isa */
 enum
 {
diff -Nur -X dontdiff linux-2.5.73-O1int/kernel/sched.c linux-2.5.73-test/kernel/sched.c
--- linux-2.5.73-O1int/kernel/sched.c	2003-06-27 19:57:56.000000000 -0300
+++ linux-2.5.73-test/kernel/sched.c	2003-06-27 20:45:59.000000000 -0300
@@ -65,16 +65,28 @@
  * maximum timeslice is 200 msecs. Timeslices get refilled after
  * they expire.
  */
-#define MIN_TIMESLICE		( 10 * HZ / 1000)
-#define MAX_TIMESLICE		(200 * HZ / 1000)
-#define CHILD_PENALTY		50
-#define PARENT_PENALTY		100
-#define EXIT_WEIGHT		3
-#define PRIO_BONUS_RATIO	25
-#define INTERACTIVE_DELTA	2
-#define MAX_SLEEP_AVG		(10*HZ)
-#define STARVATION_LIMIT	(10*HZ)
-#define NODE_THRESHOLD		125
+int sched_min_timeslice 	= ( 10 * HZ / 1000);
+int sched_max_timeslice 	= (200 * HZ / 1000);
+int sched_prio_bonus_ratio	= 25;
+int sched_max_sleep_avg		= (10*HZ);
+int sched_starvation_limit	= (10*HZ);
+int sched_child_penalty		= 50;
+int sched_parent_penalty	= 100;
+int sched_exit_weight		= 3;
+int sched_interactive_delta 	= 2;
+int sched_node_threshold	= 125;
+
+
+#define MIN_TIMESLICE		sched_min_timeslice
+#define MAX_TIMESLICE		sched_max_timeslice
+#define CHILD_PENALTY		sched_child_penalty
+#define PARENT_PENALTY		sched_parent_penalty
+#define EXIT_WEIGHT		sched_exit_weight
+#define PRIO_BONUS_RATIO	sched_prio_bonus_ratio
+#define INTERACTIVE_DELTA	sched_interactive_delta
+#define MAX_SLEEP_AVG		sched_max_sleep_avg
+#define STARVATION_LIMIT	sched_starvation_limit
+#define NODE_THRESHOLD		sched_node_threshold
 
 /*
  * If a task is 'interactive' then we reinsert it in the active
diff -Nur -X dontdiff linux-2.5.73-O1int/kernel/sysctl.c linux-2.5.73-test/kernel/sysctl.c
--- linux-2.5.73-O1int/kernel/sysctl.c	2003-06-27 19:38:13.000000000 -0300
+++ linux-2.5.73-test/kernel/sysctl.c	2003-06-27 20:45:59.000000000 -0300
@@ -58,6 +58,17 @@
 extern int pid_max;
 extern int sysctl_lower_zone_protection;
 extern int min_free_kbytes;
+/* sched.c */
+extern int sched_min_timeslice;
+extern int sched_max_timeslice;
+extern int sched_prio_bonus_ratio;
+extern int sched_max_sleep_avg;
+extern int sched_starvation_limit;
+extern int sched_child_penalty;
+extern int sched_parent_penalty;
+extern int sched_exit_weight;
+extern int sched_interactive_delta;
+extern int sched_node_threshold;
 
 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
 static int maxolduid = 65535;
@@ -123,6 +134,7 @@
 static ctl_table debug_table[];
 static ctl_table dev_table[];
 extern ctl_table random_table[];
+static ctl_table sched_tuning_table[];
 
 /* /proc declarations: */
 
@@ -551,6 +563,12 @@
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec,
 	},
+	{
+		.ctl_name	= KERN_SCHED_TUNING,
+		.procname	= "sched_tuning",
+		.mode		= 0555,
+		.child		= sched_tuning_table	
+	},
 	{ .ctl_name = 0 }
 };
 
@@ -775,6 +793,100 @@
 
 static ctl_table dev_table[] = {
 	{ .ctl_name = 0 }
+};
+
+/* sched tuning */
+static ctl_table sched_tuning_table[] = {
+	/* min_timeslice */
+	{
+		.ctl_name 	= SCHED_TUNING_MIN_TIMESLICE,
+		.procname	= "min_timeslice",
+		.mode		= 0644,
+		.data		= &sched_min_timeslice,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,		
+	},
+	/*max_timeslice */
+	{
+		.ctl_name	= SCHED_TUNING_MAX_TIMESLICE,
+		.procname	= "max_timeslice",
+		.mode		= 0644,
+		.data		= &sched_max_timeslice,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,
+	},
+	/* prio_bonus_ratio */
+	{
+		.ctl_name 	= SCHED_TUNING_BONUS_RATIO,
+		.procname	= "prio_bonus_ratio",
+		.mode		= 0644,
+		.data		= &sched_prio_bonus_ratio,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,		
+	},
+	/* max_sleep_avg */
+	{
+		.ctl_name	= SCHED_TUNING_MAX_SLEEP_AVG,
+		.procname	= "max_sleep_avg",
+		.mode		= 0644,
+		.data		= &sched_max_sleep_avg,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,
+	},
+	/* starvation_limit */
+	{
+		.ctl_name 	= SCHED_TUNING_STARVATION_LIMIT,
+		.procname	= "starvation_limit",
+		.mode		= 0644,
+		.data		= &sched_starvation_limit,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,		
+	},
+	/* child_penalty */
+	{
+		.ctl_name 	= SCHED_TUNING_CHILD_PENALTY,
+		.procname	= "child_penalty",
+		.mode		= 0644,
+		.data		= &sched_child_penalty,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,		
+	},
+	/* parent_penalty */
+	{
+		.ctl_name	= SCHED_TUNING_PARENT_PENALTY,
+		.procname	= "parent_penalty",
+		.mode		= 0644,
+		.data		= &sched_parent_penalty,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,
+	},
+	/* exit_weight */
+	{
+		.ctl_name 	= SCHED_TUNING_EXIT_WEIGHT,
+		.procname	= "exit_weight",
+		.mode		= 0644,
+		.data		= &sched_exit_weight,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,		
+	},
+	/* interactive_delta */
+	{
+		.ctl_name	= SCHED_TUNING_INTERACTIVE_DELTA,
+		.procname	= "interactive_delta",
+		.mode		= 0644,
+		.data		= &sched_interactive_delta,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,
+	},
+	/* node_threshold */
+	{
+		.ctl_name	= SCHED_TUNING_NODE_THRESHOLD,
+		.procname	= "node_threshold",
+		.mode		= 0644,
+		.data		= &sched_node_threshold,
+		.maxlen		= sizeof(int),
+		.proc_handler	= &proc_dointvec,
+	}
 };  
 
 extern void init_irq_proc (void);

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

end of thread, other threads:[~2003-06-28  2:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-27  8:26 [PATCH] O1int for 2.5.73 Con Kolivas
2003-06-28  0:20 ` [PATCH] O1int for 2.5.73 - sched tuning sysctl Roberto Orenstein

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).