* Add a thread to the actual run-queue. Keeps transferable counts up to * date with what is actually on the run-queue. Selects the correct * queue position for timeshare threads. */
| 457 | * queue position for timeshare threads. |
| 458 | */ |
| 459 | static __inline void |
| 460 | tdq_runq_add(struct tdq *tdq, struct thread *td, int flags) |
| 461 | { |
| 462 | struct td_sched *ts; |
| 463 | u_char pri; |
| 464 | |
| 465 | TDQ_LOCK_ASSERT(tdq, MA_OWNED); |
| 466 | THREAD_LOCK_BLOCKED_ASSERT(td, MA_OWNED); |
| 467 | |
| 468 | pri = td->td_priority; |
| 469 | ts = td_get_sched(td); |
| 470 | TD_SET_RUNQ(td); |
| 471 | if (THREAD_CAN_MIGRATE(td)) { |
| 472 | tdq->tdq_transferable++; |
| 473 | ts->ts_flags |= TSF_XFERABLE; |
| 474 | } |
| 475 | if (pri < PRI_MIN_BATCH) { |
| 476 | ts->ts_runq = &tdq->tdq_realtime; |
| 477 | } else if (pri <= PRI_MAX_BATCH) { |
| 478 | ts->ts_runq = &tdq->tdq_timeshare; |
| 479 | KASSERT(pri <= PRI_MAX_BATCH && pri >= PRI_MIN_BATCH, |
| 480 | ("Invalid priority %d on timeshare runq", pri)); |
| 481 | /* |
| 482 | * This queue contains only priorities between MIN and MAX |
| 483 | * realtime. Use the whole queue to represent these values. |
| 484 | */ |
| 485 | if ((flags & (SRQ_BORROWING|SRQ_PREEMPTED)) == 0) { |
| 486 | pri = RQ_NQS * (pri - PRI_MIN_BATCH) / PRI_BATCH_RANGE; |
| 487 | pri = (pri + tdq->tdq_idx) % RQ_NQS; |
| 488 | /* |
| 489 | * This effectively shortens the queue by one so we |
| 490 | * can have a one slot difference between idx and |
| 491 | * ridx while we wait for threads to drain. |
| 492 | */ |
| 493 | if (tdq->tdq_ridx != tdq->tdq_idx && |
| 494 | pri == tdq->tdq_ridx) |
| 495 | pri = (unsigned char)(pri - 1) % RQ_NQS; |
| 496 | } else |
| 497 | pri = tdq->tdq_ridx; |
| 498 | runq_add_pri(ts->ts_runq, td, pri, flags); |
| 499 | return; |
| 500 | } else |
| 501 | ts->ts_runq = &tdq->tdq_idle; |
| 502 | runq_add(ts->ts_runq, td, flags); |
| 503 | } |
| 504 | |
| 505 | /* |
| 506 | * Remove a thread from a run-queue. This typically happens when a thread |
no test coverage detected