* The actual idle process. */
| 2806 | * The actual idle process. |
| 2807 | */ |
| 2808 | void |
| 2809 | sched_idletd(void *dummy) |
| 2810 | { |
| 2811 | struct thread *td; |
| 2812 | struct tdq *tdq; |
| 2813 | int oldswitchcnt, switchcnt; |
| 2814 | int i; |
| 2815 | |
| 2816 | mtx_assert(&Giant, MA_NOTOWNED); |
| 2817 | td = curthread; |
| 2818 | tdq = TDQ_SELF(); |
| 2819 | THREAD_NO_SLEEPING(); |
| 2820 | oldswitchcnt = -1; |
| 2821 | for (;;) { |
| 2822 | if (tdq->tdq_load) { |
| 2823 | thread_lock(td); |
| 2824 | mi_switch(SW_VOL | SWT_IDLE); |
| 2825 | } |
| 2826 | switchcnt = tdq->tdq_switchcnt + tdq->tdq_oldswitchcnt; |
| 2827 | #ifdef SMP |
| 2828 | if (always_steal || switchcnt != oldswitchcnt) { |
| 2829 | oldswitchcnt = switchcnt; |
| 2830 | if (tdq_idled(tdq) == 0) |
| 2831 | continue; |
| 2832 | } |
| 2833 | switchcnt = tdq->tdq_switchcnt + tdq->tdq_oldswitchcnt; |
| 2834 | #else |
| 2835 | oldswitchcnt = switchcnt; |
| 2836 | #endif |
| 2837 | /* |
| 2838 | * If we're switching very frequently, spin while checking |
| 2839 | * for load rather than entering a low power state that |
| 2840 | * may require an IPI. However, don't do any busy |
| 2841 | * loops while on SMT machines as this simply steals |
| 2842 | * cycles from cores doing useful work. |
| 2843 | */ |
| 2844 | if (TDQ_IDLESPIN(tdq) && switchcnt > sched_idlespinthresh) { |
| 2845 | for (i = 0; i < sched_idlespins; i++) { |
| 2846 | if (tdq->tdq_load) |
| 2847 | break; |
| 2848 | cpu_spinwait(); |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | /* If there was context switch during spin, restart it. */ |
| 2853 | switchcnt = tdq->tdq_switchcnt + tdq->tdq_oldswitchcnt; |
| 2854 | if (tdq->tdq_load != 0 || switchcnt != oldswitchcnt) |
| 2855 | continue; |
| 2856 | |
| 2857 | /* Run main MD idle handler. */ |
| 2858 | tdq->tdq_cpu_idle = 1; |
| 2859 | /* |
| 2860 | * Make sure that tdq_cpu_idle update is globally visible |
| 2861 | * before cpu_idle() read tdq_load. The order is important |
| 2862 | * to avoid race with tdq_notify. |
| 2863 | */ |
| 2864 | atomic_thread_fence_seq_cst(); |
| 2865 | /* |
nothing calls this directly
no test coverage detected