FreeBSD/sys/kern/sched_ule.c
/*
 * Steals load from a timeshare queue.  Honors the rotating queue head
 * index.
 */
Steals load from a timeshare queue.  Honors the rotating queue head
index.
Steals load from a timeshare queue . Honors the rotating queue head index .
static struct thread *
runq_steal_from(struct runq *rq, int cpu, u_char start)
{
	struct rqbits *rqb;
	struct rqhead *rqh;
	struct thread *td, *first;
	int bit;
	int i;
	rqb = &rq->rq_status;
	bit = start & (RQB_BPW -1);
	first = NULL;
again:
	for (i = RQB_WORD(start); i < RQB_LEN; bit = 0, i++) {
		if (rqb->rqb_bits[i] == 0)
			continue;
		if (bit == 0)
			bit = RQB_FFS(rqb->rqb_bits[i]);
		for (; bit < RQB_BPW; bit++) {
			if ((rqb->rqb_bits[i] & (1ul << bit)) == 0)
				continue;
			rqh = &rq->rq_queues[bit + (i << RQB_L2BPW)];
			TAILQ_FOREACH(td, rqh, td_runq) {
				if (first && THREAD_CAN_MIGRATE(td) &&
				    THREAD_CAN_SCHED(td, cpu))
					return (td);
				first = td;
			}
		}
	}
	if (start != 0) {
		start = 0;
		goto again;
	}
	if (first && THREAD_CAN_MIGRATE(first) &&
	    THREAD_CAN_SCHED(first, cpu))
		return (first);
	return (NULL);
}
static struct thread * runq_steal_from ( struct runq * rq , int cpu , u_char start ) { struct rqbits * rqb ; struct rqhead * rqh ; struct thread * td , * first ; int bit ; int i ; rqb = & rq -> rq_status ; bit = start & ( RQB_BPW - 1 ) ; first = NULL ; again : for ( i = RQB_WORD ( start ) ; i < RQB_LEN ; bit = 0 , i ++ ) { if ( rqb -> rqb_bits [ i ] == 0 ) continue ; if ( bit == 0 ) bit = RQB_FFS ( rqb -> rqb_bits [ i ] ) ; for ( ; bit < RQB_BPW ; bit ++ ) { if ( ( rqb -> rqb_bits [ i ] & ( 1ul << bit ) ) == 0 ) continue ; rqh = & rq -> rq_queues [ bit + ( i << RQB_L2BPW ) ] ; TAILQ_FOREACH ( td , rqh , td_runq ) { if ( first && THREAD_CAN_MIGRATE ( td ) && THREAD_CAN_SCHED ( td , cpu ) ) return ( td ) ; first = td ; } } } if ( start != 0 ) { start = 0 ; goto again ; } if ( first && THREAD_CAN_MIGRATE ( first ) && THREAD_CAN_SCHED ( first , cpu ) ) return ( first ) ; return ( NULL ) ; }
Steals load from a timeshare queue.
Steals load from a timeshare queue .