dynamic sched timeslices

From: Kurt Garloff
Date: Mon Mar 15 2004 - 17:50:16 EST


Hi,

attached patch allows userspace to tune the scheduling timeslices.
It can be used for a couple of things:
* Tune a workload for batch processing:
You'd probably wnat to use long timeslices in order to not reschedule
as often to make good use of your CPU caches
* Tune a workload for interactive use:
Under load, you may want to reduce the scedulilng latencies by using
shorter timeslices (and there are situations where the interactiviy
tweak -- even if they were perfect -- can't save you).
* Tune the ration betweeen maximum and minimum timeslices to make
nice much nicer e.g.

The patch exports /proc/sys/kernel/max_timeslice and min_timeslice,
unites are us. It also exports HZ (readonly).
The patch implementes the desktop boot parameter which introduces
shorter timeslices.

Patch is from andrea and is in our 2.4 tree; 2.6 port was done by me and
straightforward.

Regards,
--
Kurt Garloff <garloff@xxxxxxx> Cologne, DE
SUSE LINUX AG, Nuernberg, DE SUSE Labs (Head)
diff -uNrp linux-2.6.4/include/linux/sched.h linux-2.6.4.sched/include/linux/sched.h
--- linux-2.6.4/include/linux/sched.h 2004-03-11 21:01:41.746772792 +0100
+++ linux-2.6.4.sched/include/linux/sched.h 2004-03-11 21:24:41.208062800 +0100
@@ -176,6 +176,7 @@ extern unsigned long cache_decay_ticks;
#define MAX_SCHEDULE_TIMEOUT LONG_MAX
extern signed long FASTCALL(schedule_timeout(signed long timeout));
asmlinkage void schedule(void);
+extern int max_timeslice, min_timeslice;

struct namespace;

diff -uNrp linux-2.6.4/include/linux/sysctl.h linux-2.6.4.sched/include/linux/sysctl.h
--- linux-2.6.4/include/linux/sysctl.h 2004-03-11 21:01:41.747772640 +0100
+++ linux-2.6.4.sched/include/linux/sysctl.h 2004-03-11 21:32:32.968344336 +0100
@@ -134,6 +134,9 @@ enum
KERN_KDB=64, /* int: kdb on/off */
KERN_S390_HZ_TIMER=65, /* int: hz timer on or off */
KERN_DUMP=66, /* directory: dump parameters */
+ KERN_MAXTIMESLICE=67, /* int: nice -20 max timeslice */
+ KERN_MINTIMESLICE=68, /* int: nice +19 min timeslice */
+ KERN_HZ=69, /* unsigned long: interal kernel HZ */
};


diff -uNrp linux-2.6.4/kernel/sched.c linux-2.6.4.sched/kernel/sched.c
--- linux-2.6.4/kernel/sched.c 2004-03-11 21:01:41.752771880 +0100
+++ linux-2.6.4.sched/kernel/sched.c 2004-03-11 22:06:26.166251272 +0100
@@ -79,12 +79,19 @@ EXPORT_SYMBOL(dump_oncpu);
/*
* These are the 'tuning knobs' of the scheduler:
*
- * Minimum timeslice is 10 msecs, default timeslice is 100 msecs,
- * maximum timeslice is 200 msecs. Timeslices get refilled after
- * they expire.
- */
-#define MIN_TIMESLICE ( 10 * HZ / 1000)
-#define MAX_TIMESLICE (200 * HZ / 1000)
+ * Minimum timeslice is 10 msecs, default timeslice is 150 msecs,
+ * maximum timeslice is 300 msecs. Timeslices get refilled after
+ * they expire.
+ */
+#define __MIN_TIMESLICE 10000
+#define __MAX_TIMESLICE 300000
+#define __MIN_TIMESLICE_DESKTOP 2000
+#define __MAX_TIMESLICE_DESKTOP 60000
+/* the sysctl values are exported in usec units to userspace */
+int max_timeslice = __MAX_TIMESLICE, min_timeslice = __MIN_TIMESLICE;
+#define MAX_TIMESLICE ((max_timeslice * HZ + 999999) / 1000000)
+#define MIN_TIMESLICE ((min_timeslice * HZ + 999999) / 1000000)
+
#define ON_RUNQUEUE_WEIGHT 30
#define CHILD_PENALTY 95
#define PARENT_PENALTY 100
@@ -2965,3 +2972,13 @@ task_t *kdb_cpu_curr(int cpu)
return(cpu_curr(cpu));
}
#endif
+
+static int __init init_desktop(char *str)
+{
+ min_timeslice = __MIN_TIMESLICE_DESKTOP;
+ max_timeslice = __MAX_TIMESLICE_DESKTOP;
+ return 1;
+}
+__setup("desktop", init_desktop);
+
+
diff -uNrp linux-2.6.4/kernel/sysctl.c linux-2.6.4.sched/kernel/sysctl.c
--- linux-2.6.4/kernel/sysctl.c 2004-03-11 21:01:37.983344920 +0100
+++ linux-2.6.4.sched/kernel/sysctl.c 2004-03-11 21:36:26.253879544 +0100
@@ -167,6 +167,7 @@ static void register_proc_table(ctl_tabl
static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
#endif

+static unsigned long __HZ = HZ;
/* The default sysctl tables: */

static ctl_table root_table[] = {
@@ -642,6 +643,30 @@ static ctl_table kern_table[] = {
.mode = 0444,
.proc_handler = &proc_dointvec,
},
+ {
+ .ctl_name = KERN_MAXTIMESLICE,
+ .procname = "max-timeslice",
+ .data = &max_timeslice,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec,
+ },
+ {
+ .ctl_name = KERN_MINTIMESLICE,
+ .procname = "min-timeslice",
+ .data = &min_timeslice,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = &proc_dointvec,
+ },
+ {
+ .ctl_name = KERN_HZ,
+ .procname = "HZ",
+ .data = &__HZ,
+ .maxlen = sizeof(long),
+ .mode = 0444,
+ .proc_handler = &proc_dointvec,
+ },
{ .ctl_name = 0 }
};

Attachment: pgp00000.pgp
Description: PGP signature