/* 131 * This is the function that decides how desirable a process is.. 132 * You can weigh different processes against each other depending 133 * on what CPU they've run on lately etc to try to handle cache 134 * and TLB miss penalties. 135 * 136 * Return values: 137 * -1000: never select this 138 * 0: out of time, recalculate counters (but it might still be 139 * selected) 140 * +ve: "goodness" value (the larger, the better) 141 * +1000: realtime process, select this. 142 */ 143 144 static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm) 145 { 146 int weight; 147 148 /* 149 * select the current process after every other 150 * runnable process, but before the idle thread. 151 * Also, dont trigger a counter recalculation. 152 */ 153 weight = -1; 154 if (p->policy & SCHED_YIELD) 155 goto out; 156 157 /* 158 * Non-RT process - normal case first. 159 */ 160 if (p->policy == SCHED_OTHER) { 161 /* 162 * Give the process a first-approximation goodness value 163 * according to the number of clock-ticks it has left. 164 * 165 * Don't do any other calculations if the time slice is 166 * over.. 167 */ 168 weight = p->counter; 169 if (!weight) 170 goto out; 171 172 #ifdef CONFIG_SMP 173 /* Give a largish advantage to the same processor... */ 174 /* (this is equivalent to penalizing other processors) */ 175 if (p->processor == this_cpu) 176 weight += PROC_CHANGE_PENALTY; 177 #endif 178 179 /* .. and a slight advantage to the current MM */ 180 if (p->mm == this_mm || !p->mm) 181 weight += 1; 182 weight += 20 - p->nice; 183 goto out; 184 } 185 186 /* 187 * Realtime process, select the first one on the 188 * runqueue (taking priorities within processes 189 * into account). 190 */ 191 weight = 1000 + p->rt_priority; 192 out: 193 return weight; 194 }