diff -urN linux-2.4.19-pre7-ac2-rml/kernel/sched.c linux/kernel/sched.c --- linux-2.4.19-pre7-ac2-rml/kernel/sched.c Sat Apr 20 18:30:02 2002 +++ linux/kernel/sched.c Sat Apr 20 18:30:14 2002 @@ -156,21 +155,21 @@ #define cpu_curr(cpu) (cpu_rq(cpu)->curr) #define rt_task(p) ((p)->prio < MAX_RT_PRIO) -static inline runqueue_t *lock_task_rq(task_t *p, unsigned long *flags) +static inline runqueue_t *task_rq_lock(task_t *p, unsigned long *flags) { - struct runqueue *__rq; + struct runqueue *rq; repeat_lock_task: - __rq = task_rq(p); - spin_lock_irqsave(&__rq->lock, *flags); - if (unlikely(__rq != task_rq(p))) { - spin_unlock_irqrestore(&__rq->lock, *flags); + rq = task_rq(p); + spin_lock_irqsave(&rq->lock, *flags); + if (unlikely(rq != task_rq(p))) { + spin_unlock_irqrestore(&rq->lock, *flags); goto repeat_lock_task; } - return __rq; + return rq; } -static inline void unlock_task_rq(runqueue_t *rq, unsigned long *flags) +static inline void task_rq_unlock(runqueue_t *rq, unsigned long *flags) { spin_unlock_irqrestore(&rq->lock, *flags); } @@ -181,7 +180,7 @@ static inline void dequeue_task(struct task_struct *p, prio_array_t *array) { array->nr_active--; - list_del_init(&p->run_list); + list_del(&p->run_list); if (list_empty(array->queue + p->prio)) __clear_bit(p->prio, array->bitmap); } @@ -277,12 +276,12 @@ cpu_relax(); barrier(); } - rq = lock_task_rq(p, &flags); + rq = task_rq_lock(p, &flags); if (unlikely(rq->curr == p)) { - unlock_task_rq(rq, &flags); + task_rq_unlock(rq, &flags); goto repeat; } - unlock_task_rq(rq, &flags); + task_rq_unlock(rq, &flags); } /* @@ -315,15 +314,15 @@ int success = 0; runqueue_t *rq; - rq = lock_task_rq(p, &flags); + rq = task_rq_lock(p, &flags); p->state = TASK_RUNNING; if (!p->array) { activate_task(p, rq); - if ((rq->curr == rq->idle) || (p->prio < rq->curr->prio)) + if (p->prio < rq->curr->prio) resched_task(rq->curr); success = 1; } - unlock_task_rq(rq, &flags); + task_rq_unlock(rq, &flags); return success; } @@ -406,16 +405,7 @@ mmdrop(oldmm); } - /* - * Here we just switch the register state and the stack. There are - * 3 processes affected by a context switch: - * - * prev ==> .... ==> (last => next) - * - * It's the 'much more previous' 'prev' that is on next's stack, - * but prev is set to (the just run) 'last' process by switch_to(). - * This might sound slightly confusing but makes tons of sense. - */ + /* Here we just switch the register state and the stack. */ switch_to(prev, next, prev); } @@ -510,12 +500,14 @@ busiest = NULL; max_load = 1; for (i = 0; i < smp_num_cpus; i++) { - rq_src = cpu_rq(cpu_logical_map(i)); - if (idle || (rq_src->nr_running < this_rq->prev_nr_running[i])) + int logical = cpu_logical_map(i); + + rq_src = cpu_rq(logical); + if (idle || (rq_src->nr_running < this_rq->prev_nr_running[logical])) load = rq_src->nr_running; else - load = this_rq->prev_nr_running[i]; - this_rq->prev_nr_running[i] = rq_src->nr_running; + load = this_rq->prev_nr_running[logical]; + this_rq->prev_nr_running[logical] = rq_src->nr_running; if ((load > max_load) && (rq_src != this_rq)) { busiest = rq_src; @@ -537,7 +529,7 @@ * Make sure nothing changed since we checked the * runqueue length. */ - if (busiest->nr_running <= this_rq->nr_running + 1) + if (busiest->nr_running <= nr_running + 1) goto out_unlock; /* @@ -582,7 +574,7 @@ #define CAN_MIGRATE_TASK(p,rq,this_cpu) \ ((jiffies - (p)->sleep_timestamp > cache_decay_ticks) && \ ((p) != (rq)->curr) && \ - (tmp->cpus_allowed & (1 << (this_cpu)))) + ((p)->cpus_allowed & (1 << (this_cpu)))) if (!CAN_MIGRATE_TASK(tmp, busiest, this_cpu)) { curr = curr->next; @@ -964,7 +956,7 @@ * We have to be careful, if called from sys_setpriority(), * the task might be in the middle of scheduling on another CPU. */ - rq = lock_task_rq(p, &flags); + rq = task_rq_lock(p, &flags); if (rt_task(p)) { p->static_prio = NICE_TO_PRIO(nice); goto out_unlock; @@ -984,7 +976,7 @@ resched_task(rq->curr); } out_unlock: - unlock_task_rq(rq, &flags); + task_rq_unlock(rq, &flags); } #ifndef __alpha__ @@ -1077,7 +1069,7 @@ * To be able to change p->policy safely, the apropriate * runqueue lock must be held. */ - rq = lock_task_rq(p, &flags); + rq = task_rq_lock(p, &flags); if (policy < 0) policy = p->policy; @@ -1112,7 +1104,7 @@ retval = 0; p->policy = policy; p->rt_priority = lp.sched_priority; - if (rt_task(p)) + if (policy != SCHED_OTHER) p->prio = (MAX_RT_PRIO - 1) - p->rt_priority; else p->prio = p->static_prio; @@ -1120,7 +1112,7 @@ activate_task(p, task_rq(p)); out_unlock: - unlock_task_rq(rq, &flags); + task_rq_unlock(rq, &flags); out_unlock_tasklist: read_unlock_irq(&tasklist_lock); @@ -1375,6 +1367,12 @@ read_unlock(&tasklist_lock); } +/* + * double_rq_lock - safely lock two runqueues + * + * Note this does not disable interrupts like task_rq_lock, + * you need to do so manually before calling. + */ static inline void double_rq_lock(runqueue_t *rq1, runqueue_t *rq2) { if (rq1 == rq2) @@ -1390,6 +1388,12 @@ } } +/* + * double_rq_unlock - safely unlock two runqueues + * + * Note this does not restore interrupts like task_rq_unlock, + * you need to do so manually after calling. + */ static inline void double_rq_unlock(runqueue_t *rq1, runqueue_t *rq2) { spin_unlock(&rq1->lock);