Index: linux-2.6.7-ck2pre/kernel/sched.c =================================================================== --- linux-2.6.7-ck2pre.orig/kernel/sched.c 2004-06-25 23:06:57.000000000 +1000 +++ linux-2.6.7-ck2pre/kernel/sched.c 2004-06-27 21:39:40.182630568 +1000 @@ -231,8 +231,8 @@ static void enqueue_task(struct task_struct *p, runqueue_t *rq) { - if (rq->curr->flags & PF_PREEMPTED) { - rq->curr->flags &= ~PF_PREEMPTED; + if (p->flags & PF_PREEMPTED) { + p->flags &= ~PF_PREEMPTED; list_add(&p->run_list, rq->queue + p->prio); } else list_add_tail(&p->run_list, rq->queue + p->prio); @@ -268,7 +268,10 @@ rq->nr_running++; } -// burst - extra intervals an interactive task can run for at best priority +/* + * burst - extra intervals an interactive task can run for at best priority + * instead of descending priorities. + */ static unsigned int burst(task_t *p) { unsigned int task_user_prio; @@ -297,7 +300,10 @@ p->burst--; } -// slice - the duration a task runs before losing burst +/* + * slice - the duration a task runs before getting requeued at it's best + * priority and has it's burst decremented. + */ static unsigned int slice(task_t *p) { unsigned int slice = RR_INTERVAL; @@ -308,7 +314,9 @@ return slice; } -// interactive - interactive tasks get longer intervals at best priority +/* + * interactive - sysctl which allows interactive tasks to have bursts + */ int interactive = 1; /* @@ -346,20 +354,25 @@ return prio; } +/* + * recalc_task_prio - this checks for tasks that run ultra short timeslices + * or have just forked a thread/process and make them continue their old + * slice instead of starting a new one at high priority. + */ static void recalc_task_prio(task_t *p, unsigned long long now) { unsigned long sleep_time = now - p->timestamp; - unsigned long run_time = NS_TO_JIFFIES(p->runtime); - unsigned long total_run = NS_TO_JIFFIES(p->totalrun) + run_time; - if ((!run_time && NS_TO_JIFFIES(p->runtime + sleep_time) < - rr_interval(p)) || p->flags & PF_FORKED) { + unsigned long ns_totalrun = p->totalrun + p->runtime; + unsigned long total_run = NS_TO_JIFFIES(ns_totalrun); + if (p->flags & PF_FORKED || (!(NS_TO_JIFFIES(p->runtime)) && + NS_TO_JIFFIES(p->runtime + sleep_time) < rr_interval(p))) { p->flags &= ~PF_FORKED; if (p->slice - total_run < 1) { p->totalrun = 0; dec_burst(p); } else { - p->totalrun += p->runtime; - p->slice -= NS_TO_JIFFIES(p->totalrun); + p->totalrun = ns_totalrun; + p->slice -= total_run; } } else { inc_burst(p); @@ -786,7 +799,9 @@ unsigned long flags; runqueue_t *rq = task_rq_lock(current, &flags); - //Forked process gets no burst to prevent fork bombs. + /* + * Forked process gets no burst to prevent fork bombs. + */ p->burst = 0; BUG_ON(p->state != TASK_RUNNING); @@ -1768,11 +1783,15 @@ cpustat->system += sys_ticks; spin_lock(&rq->lock); - // SCHED_FIFO tasks never run out of timeslice. + /* + * SCHED_FIFO tasks never run out of timeslice. + */ if (unlikely(p->policy == SCHED_FIFO)) goto out_unlock; rq->cache_ticks++; - // Tasks lose burst each time they use up a full slice(). + /* + * Tasks lose burst each time they use up a full slice(). + */ if (!--p->slice) { set_tsk_need_resched(p); dequeue_task(p, rq); @@ -3601,7 +3620,9 @@ for (j = 0; j <= MAX_PRIO; j++) INIT_LIST_HEAD(&rq->queue[j]); memset(rq->bitmap, 0, BITS_TO_LONGS(MAX_PRIO+1)*sizeof(long)); - // delimiter for bitsearch + /* + * delimiter for bitsearch + */ __set_bit(MAX_PRIO, rq->bitmap); } /*