public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* scheduler interactivity: timeslice calculation seem wrong
@ 2003-08-19  2:54 Eric St-Laurent
  2003-08-19  3:06 ` Nick Piggin
  2003-08-19  4:13 ` Con Kolivas
  0 siblings, 2 replies; 26+ messages in thread
From: Eric St-Laurent @ 2003-08-19  2:54 UTC (permalink / raw)
  To: linux-kernel

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

currently, nicer tasks (nice value toward -20) get larger timeslices,
and less nice tasks (nice value toward 19) get small timeslices.

this is contrary to all process scheduling theory i've read, and also
contrary to my intuition.

maybe it was done this way for fairness reasons, but that's another
story...

high priority (interactive) tasks should get small timeslices for best
interactive feeling, and low priority (cpu hog) tasks should get large
timeslices for best efficiency, anyway they can be preempted by higher
priority tasks if needed.

also, i think dynamic priority should be used for timeslice calculation
instead of static priority. the reason is, if a low priority task get a
priority boost (to prevent starvation, for example) it should use the
small timeslice corresponding to it's new priority level, instead of
using it's original large timeslice that can ruin the interactive feel.

something like this: (Sorry, not tested...)

PS: i've attached a small program to calculate and print the timeslices
length from code ripped from linux-2.6.0-test3



--- sched-orig.c	Sat Aug 09 00:39:34 2003
+++ sched.c	Mon Aug 18 10:52:22 2003
@@ -126,8 +126,8 @@
  * task_timeslice() is the interface that is used by the scheduler.
  */
 
-#define BASE_TIMESLICE(p) (MIN_TIMESLICE + \
-	((MAX_TIMESLICE - MIN_TIMESLICE)
*(MAX_PRIO-1-(p)->static_prio)/(MAX_USER_PRIO - 1)))
+#define BASE_TIMESLICE(p)	((p)->prio < MAX_RT_PRIO ? MIN_TIMESLICE :
(MAX_TIMESLICE - \
+	((MAX_TIMESLICE - MIN_TIMESLICE) *
(MAX_PRIO-1-(p)->prio)/(MAX_USER_PRIO - 1))))
 
 static inline unsigned int task_timeslice(task_t *p)
 {



Best regards,

Eric St-Laurent


[-- Attachment #2: diff.txt --]
[-- Type: text/plain, Size: 541 bytes --]

--- sched-orig.c	Sat Aug 09 00:39:34 2003
+++ sched.c	Mon Aug 18 10:52:22 2003
@@ -126,8 +126,8 @@
  * task_timeslice() is the interface that is used by the scheduler.
  */
 
-#define BASE_TIMESLICE(p) (MIN_TIMESLICE + \
-	((MAX_TIMESLICE - MIN_TIMESLICE) * (MAX_PRIO-1-(p)->static_prio)/(MAX_USER_PRIO - 1)))
+#define BASE_TIMESLICE(p)	((p)->prio < MAX_RT_PRIO ? MIN_TIMESLICE : (MAX_TIMESLICE - \
+	((MAX_TIMESLICE - MIN_TIMESLICE) * (MAX_PRIO-1-(p)->prio)/(MAX_USER_PRIO - 1))))
 
 static inline unsigned int task_timeslice(task_t *p)
 {

[-- Attachment #3: ts26.cpp --]
[-- Type: text/x-c++, Size: 1370 bytes --]

#include <stdio.h>

#define HZ			1000
#define MIN_TIMESLICE		( 10 * HZ / 1000)
#define MAX_TIMESLICE		(200 * HZ / 1000)
#define MAX_USER_RT_PRIO	100
#define MAX_RT_PRIO		MAX_USER_RT_PRIO
#define MAX_PRIO		(MAX_RT_PRIO + 40)
#define NICE_TO_PRIO(nice)	(MAX_RT_PRIO + (nice) + 20)
#define USER_PRIO(p)		((p)-MAX_RT_PRIO)
#define MAX_USER_PRIO		(USER_PRIO(MAX_PRIO))

#define BASE_TIMESLICE(p)	(MIN_TIMESLICE + \
	((MAX_TIMESLICE - MIN_TIMESLICE) * (MAX_PRIO-1-p)/(MAX_USER_PRIO - 1)))

#define BASE_TIMESLICE2(p)	(MAX_TIMESLICE - \
	((MAX_TIMESLICE - MIN_TIMESLICE) * (MAX_PRIO-1-p)/(MAX_USER_PRIO - 1)))

#define BASE_TIMESLICE3(p)	(prio < MAX_RT_PRIO ? MIN_TIMESLICE : (MAX_TIMESLICE - \
	((MAX_TIMESLICE - MIN_TIMESLICE) * (MAX_PRIO-1-p)/(MAX_USER_PRIO - 1))))

int main(int argc, char *argv[])
{
	// original timeslice calculation
	for (int nice = -20; nice <= 19; nice++)
		printf("nice: %d, timeslice: %d ms\n", nice, BASE_TIMESLICE(NICE_TO_PRIO(nice)) * 1000 / HZ);

	printf("\n");

	// reversed timeslice calculation
	for (int nice = -20; nice <= 19; nice++)
		printf("nice: %d, timeslice: %d ms\n", nice, BASE_TIMESLICE2(NICE_TO_PRIO(nice)) * 1000 / HZ);

	printf("\n");

	// dynamic priority based timeslice calculation
	for (int prio = 0; prio < MAX_PRIO; prio++)
		printf("prio: %d, timeslice: %d ms\n", prio, BASE_TIMESLICE3(prio) * 1000 / HZ);

	return 0;
}

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

end of thread, other threads:[~2003-08-20 18:45 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-19  2:54 scheduler interactivity: timeslice calculation seem wrong Eric St-Laurent
2003-08-19  3:06 ` Nick Piggin
2003-08-19  4:07   ` Eric St-Laurent
2003-08-19  5:23     ` Nick Piggin
2003-08-19  6:54       ` Eric St-Laurent
2003-08-19 19:18         ` bill davidsen
2003-08-19 23:48           ` Eric St-Laurent
2003-08-19 23:54           ` Eric St-Laurent
2003-08-19 19:01       ` bill davidsen
2003-08-20  0:15         ` Eric St-Laurent
2003-08-20  0:32           ` David Lang
2003-08-20  0:48             ` William Lee Irwin III
2003-08-20  4:11               ` Bill Davidsen
2003-08-20  4:36                 ` William Lee Irwin III
2003-08-20 13:59                 ` Andrew Theurer
2003-08-20 16:18                   ` Bill Davidsen
2003-08-20  2:52         ` Nick Piggin
2003-08-19 19:02     ` Mike Fedyk
2003-08-19 17:51   ` Mike Fedyk
2003-08-20  2:41     ` Nick Piggin
2003-08-20 18:45       ` Mike Fedyk
2003-08-19  4:13 ` Con Kolivas
2003-08-19  4:23   ` Eric St-Laurent
2003-08-19  4:29     ` Con Kolivas
2003-08-19  5:06       ` Eric St-Laurent
2003-08-19  6:18         ` William Lee Irwin III

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox