--- linux-2.5.74-mm3/kernel/sched.c 2003-07-10 10:23:14.000000000 +1000 +++ linux-2.5.74-test/kernel/sched.c 2003-07-10 10:41:57.000000000 +1000 @@ -68,7 +68,7 @@ */ #define MIN_TIMESLICE ( 10 * HZ / 1000) #define MAX_TIMESLICE (200 * HZ / 1000) -#define CHILD_PENALTY 80 +#define CHILD_PENALTY 95 #define PARENT_PENALTY 100 #define EXIT_WEIGHT 3 #define PRIO_BONUS_RATIO 25 @@ -76,6 +76,7 @@ #define MIN_SLEEP_AVG (HZ) #define MAX_SLEEP_AVG (10*HZ) #define STARVATION_LIMIT (10*HZ) +#define SLEEP_BUFFER (HZ/20) #define NODE_THRESHOLD 125 #define MAX_BONUS ((MAX_USER_PRIO - MAX_RT_PRIO) * PRIO_BONUS_RATIO / 100) @@ -392,33 +393,42 @@ static inline void activate_task(task_t unsigned long runtime = jiffies - p->avg_start; /* - * This code gives a bonus to interactive tasks. - * - * The boost works by updating the 'average sleep time' - * value here, based on ->last_run. The more time a task - * spends sleeping, the higher the average gets - and the - * higher the priority boost gets as well. - */ - p->sleep_avg += sleep_time; - /* - * Give a bonus to tasks that wake early on to prevent - * the problem of the denominator in the bonus equation - * from continually getting larger. - */ - if (runtime < MAX_SLEEP_AVG) - p->sleep_avg += (runtime - p->sleep_avg) * (MAX_SLEEP_AVG - runtime) * - (MAX_BONUS - INTERACTIVE_DELTA) / MAX_BONUS / MAX_SLEEP_AVG; - - if (p->sleep_avg > MAX_SLEEP_AVG) - p->sleep_avg = MAX_SLEEP_AVG; - - /* * Tasks that sleep a long time are categorised as idle and - * get their static priority only + * will get just under interactive status with a small runtime + * to allow them to become interactive or non-interactive rapidly */ if (sleep_time > MIN_SLEEP_AVG){ p->avg_start = jiffies - MIN_SLEEP_AVG; - p->sleep_avg = MIN_SLEEP_AVG / 2; + p->sleep_avg = MIN_SLEEP_AVG * (MAX_BONUS - INTERACTIVE_DELTA - 1) / + MAX_BONUS; + } else { + /* + * This code gives a bonus to interactive tasks. + * + * The boost works by updating the 'average sleep time' + * value here, based on ->last_run. The more time a task + * spends sleeping, the higher the average gets - and the + * higher the priority boost gets as well. + */ + p->sleep_avg += sleep_time; + + /* + * Give a bonus to tasks that wake early on to prevent + * the problem of the denominator in the bonus equation + * from continually getting larger. + */ + if ((runtime - MIN_SLEEP_AVG) < MAX_SLEEP_AVG) + p->sleep_avg += (runtime - p->sleep_avg) * + (MAX_SLEEP_AVG + MIN_SLEEP_AVG - runtime) * + (MAX_BONUS - INTERACTIVE_DELTA) / MAX_BONUS / MAX_SLEEP_AVG; + + /* + * Keep a small buffer of SLEEP_BUFFER sleep_avg to + * prevent fully interactive tasks from becoming + * lower priority with small bursts of cpu usage. + */ + if (p->sleep_avg > (MAX_SLEEP_AVG + SLEEP_BUFFER)) + p->sleep_avg = MAX_SLEEP_AVG + SLEEP_BUFFER; } if (unlikely(p->avg_start > jiffies)){