* Steals load from a standard linear queue. */
| 1152 | * Steals load from a standard linear queue. |
| 1153 | */ |
| 1154 | static struct thread * |
| 1155 | runq_steal(struct runq *rq, int cpu) |
| 1156 | { |
| 1157 | struct rqhead *rqh; |
| 1158 | struct rqbits *rqb; |
| 1159 | struct thread *td; |
| 1160 | int word; |
| 1161 | int bit; |
| 1162 | |
| 1163 | rqb = &rq->rq_status; |
| 1164 | for (word = 0; word < RQB_LEN; word++) { |
| 1165 | if (rqb->rqb_bits[word] == 0) |
| 1166 | continue; |
| 1167 | for (bit = 0; bit < RQB_BPW; bit++) { |
| 1168 | if ((rqb->rqb_bits[word] & (1ul << bit)) == 0) |
| 1169 | continue; |
| 1170 | rqh = &rq->rq_queues[bit + (word << RQB_L2BPW)]; |
| 1171 | TAILQ_FOREACH(td, rqh, td_runq) |
| 1172 | if (THREAD_CAN_MIGRATE(td) && |
| 1173 | THREAD_CAN_SCHED(td, cpu)) |
| 1174 | return (td); |
| 1175 | } |
| 1176 | } |
| 1177 | return (NULL); |
| 1178 | } |
| 1179 | |
| 1180 | /* |
| 1181 | * Attempt to steal a thread in priority order from a thread queue. |