MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sched_idletd

Function sched_idletd

freebsd/kern/sched_ule.c:2808–2887  ·  view source on GitHub ↗

* The actual idle process. */

Source from the content-addressed store, hash-verified

2806 * The actual idle process.
2807 */
2808void
2809sched_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 /*

Callers

nothing calls this directly

Calls 5

mtx_assertFunction · 0.85
tdq_idledFunction · 0.85
mi_switchFunction · 0.70
cpu_idleFunction · 0.50

Tested by

no test coverage detected