From: Con Kolivas Fine tuning mainly. Smaller timeslice granularity for most interactive tasks and larger for less interactive. Smaller for each extra cpu. Smaller bounds on interactive credit. Idle tasks can gain interactive credits; Idle tasks get more interactivity Uninterruptible sleep wakers are not seen as idle. Kernel threads participate in timeslice granularity requeuing. 25-akpm/kernel/sched.c | 35 ++++++++++++++++++++++++----------- 1 files changed, 24 insertions(+), 11 deletions(-) diff -puN kernel/sched.c~o20int kernel/sched.c --- 25/kernel/sched.c~o20int Wed Sep 3 08:43:26 2003 +++ 25-akpm/kernel/sched.c Wed Sep 3 08:43:26 2003 @@ -76,7 +76,6 @@ */ #define MIN_TIMESLICE ( 10 * HZ / 1000) #define MAX_TIMESLICE (200 * HZ / 1000) -#define TIMESLICE_GRANULARITY (HZ/40 ?: 1) #define ON_RUNQUEUE_WEIGHT 30 #define CHILD_PENALTY 95 #define PARENT_PENALTY 100 @@ -88,6 +87,7 @@ #define STARVATION_LIMIT (MAX_SLEEP_AVG) #define NS_MAX_SLEEP_AVG (JIFFIES_TO_NS(MAX_SLEEP_AVG)) #define NODE_THRESHOLD 125 +#define CREDIT_LIMIT 100 /* * If a task is 'interactive' then we reinsert it in the active @@ -121,6 +121,15 @@ (NS_TO_JIFFIES((p)->sleep_avg) * MAX_BONUS / \ MAX_SLEEP_AVG) +#ifdef CONFIG_SMP +#define TIMESLICE_GRANULARITY(p) \ + (MIN_TIMESLICE * (1 << (MAX_BONUS - CURRENT_BONUS(p))) * \ + num_online_cpus()) +#else +#define TIMESLICE_GRANULARITY(p) \ + (MIN_TIMESLICE * (1 << (MAX_BONUS - CURRENT_BONUS(p)))) +#endif + #define SCALE(v1,v1_max,v2_max) \ (v1) * (v2_max) / (v1_max) @@ -136,10 +145,10 @@ (MAX_BONUS / 2 + DELTA((p)) + 1) / MAX_BONUS - 1)) #define HIGH_CREDIT(p) \ - ((p)->interactive_credit > MAX_SLEEP_AVG) + ((p)->interactive_credit > CREDIT_LIMIT) #define LOW_CREDIT(p) \ - ((p)->interactive_credit < -MAX_SLEEP_AVG) + ((p)->interactive_credit < -CREDIT_LIMIT) #define TASK_PREEMPTS_CURR(p, rq) \ ((p)->prio < (rq)->curr->prio) @@ -383,9 +392,13 @@ static void recalc_task_prio(task_t *p, * prevent them suddenly becoming cpu hogs and starving * other processes. */ - if (p->mm && sleep_time >JUST_INTERACTIVE_SLEEP(p)) - p->sleep_avg = JUST_INTERACTIVE_SLEEP(p) + 1; - else { + if (p->mm && p->activated != -1 && + sleep_time > JUST_INTERACTIVE_SLEEP(p)){ + p->sleep_avg = JIFFIES_TO_NS(MAX_SLEEP_AVG - + AVG_TIMESLICE); + if (!HIGH_CREDIT(p)) + p->interactive_credit++; + } else { /* * The lower the sleep avg a task has the more * rapidly it will rise with sleep time. @@ -1411,12 +1424,12 @@ void scheduler_tick(int user_ticks, int * level, which is in essence a round-robin of tasks with * equal priority. * - * This only applies to user tasks in the interactive - * delta range with at least MIN_TIMESLICE left. + * This only applies to tasks in the interactive + * delta range with at least MIN_TIMESLICE to requeue. */ - if (p->mm && TASK_INTERACTIVE(p) && !((task_timeslice(p) - - p->time_slice) % TIMESLICE_GRANULARITY) && - (p->time_slice > MIN_TIMESLICE) && + if (TASK_INTERACTIVE(p) && !((task_timeslice(p) - + p->time_slice) % TIMESLICE_GRANULARITY(p)) && + (p->time_slice >= (MIN_TIMESLICE * 2)) && (p->array == rq->active)) { dequeue_task(p, rq->active); _