Scheduling ========== The scheduler chooses which runnable thread executes on a CPU, coordinates CPU placement and migration, and accounts for execution and priority changes. Its machine-independent implementation is in ``sys/kern`` and its interface is described in ``sys/sys/sched.h``. This checkout contains a scheduler-instance framework. The shim selects a registered implementation during boot and dispatches the scheduler interface to it. ULE and 4BSD provide different queueing and policy implementations behind that interface. .. toctree:: :maxdepth: 1 dispatch run-queues switching-and-locking api/index Finding the implementation -------------------------- .. list-table:: Source map :header-rows: 1 :widths: 35 65 * - Source - Responsibility * - ``sys/sys/sched.h`` - Interface descriptions, dispatch macros, and instance registration. * - ``sys/kern/sched_shim.c`` - Boot selection, interface dispatch, and common scheduler information. * - ``sys/kern/sched_ule.c`` - ULE priorities, per-CPU queues, placement, migration, and balancing. * - ``sys/kern/sched_4bsd.c`` - 4BSD priorities, global/per-CPU queues, and accounting. * - ``sys/kern/kern_synch.c`` - Machine-independent context-switch and runnable-state transitions. * - ``sys/kern/kern_switch.c``, ``sys/sys/runq.h`` - Priority-indexed run-queue primitives used by scheduler implementations. * - ``sys/kern/subr_sleepqueue.c``, ``sys/kern/subr_turnstile.c`` - Waiting and lock-contention mechanisms that interact with scheduling. The execution unit is a thread. Process policy and nice values influence its treatment, but a process can contain multiple independently scheduled threads. A blocked thread is not simply a low-priority runnable thread. The :doc:`../vm/index` and :doc:`../vfs/index` guides show two common reasons for a thread to block. Scheduler and VFS references both select the ``kern`` Doxygen project; their reading topics and canonical API pages remain separate.