* Enforce affinity settings for a thread. Called after adjustments to * cpumask. */
| 2679 | * cpumask. |
| 2680 | */ |
| 2681 | void |
| 2682 | sched_affinity(struct thread *td) |
| 2683 | { |
| 2684 | #ifdef SMP |
| 2685 | struct td_sched *ts; |
| 2686 | |
| 2687 | THREAD_LOCK_ASSERT(td, MA_OWNED); |
| 2688 | ts = td_get_sched(td); |
| 2689 | if (THREAD_CAN_SCHED(td, ts->ts_cpu)) |
| 2690 | return; |
| 2691 | if (TD_ON_RUNQ(td)) { |
| 2692 | sched_rem(td); |
| 2693 | sched_add(td, SRQ_BORING | SRQ_HOLDTD); |
| 2694 | return; |
| 2695 | } |
| 2696 | if (!TD_IS_RUNNING(td)) |
| 2697 | return; |
| 2698 | /* |
| 2699 | * Force a switch before returning to userspace. If the |
| 2700 | * target thread is not running locally send an ipi to force |
| 2701 | * the issue. |
| 2702 | */ |
| 2703 | td->td_flags |= TDF_NEEDRESCHED; |
| 2704 | if (td != curthread) |
| 2705 | ipi_cpu(ts->ts_cpu, IPI_PREEMPT); |
| 2706 | #endif |
| 2707 | } |
| 2708 | |
| 2709 | /* |
| 2710 | * Bind a thread to a target cpu. |
no test coverage detected