From: Con Kolivas Here is a diff against the O3int patch in 2.5.74-mm3 trying to decrease audio skips and improve X smoothness. It is easier to become interactive with this one to try and decrease application startup and wakeup time, while hopefully still preventing cpu hogs from starving the machine. Changes: Child penalty increased to 95 as in early 2.5 O(1) implementations. This fixes the "parent spinning madly waiting for child to spawn and in the process it is the parent that starves the child"; 80 wasn't enough. The sleep buffer has returned much smaller currently set at 50ms which prevents fully interactive tasks from dropping down a priority for short bursts of cpu activity (eg X). Idle tasks now get a small priority boost so they "rest" at a dynamic priority just below interactive. They now wake up to an interactive state more rapidly, and spawn more interactive children. The variable boost when a process has been running less than MAX_SLEEP_AVG has been tweaked and consequently is more aggressive. Slight code rearrangement to have one less if.. branch. kernel/sched.c | 58 +++++++++++++++++++++++++++++++++------------------------ 1 files changed, 34 insertions(+), 24 deletions(-) diff -puN kernel/sched.c~o4int kernel/sched.c --- 25/kernel/sched.c~o4int 2003-07-10 01:01:05.000000000 -0700 +++ 25-akpm/kernel/sched.c 2003-07-10 01:01:05.000000000 -0700 @@ -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)){ _