setrunqueue (9)
Leading comments
Copyright (c) 2000-2001 John H. Baldwin <jhb@FreeBSD.org> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the ...
NAME
choosethread procrunnable remrunqueue setrunqueue - manage the queue of runnable processesSYNOPSIS
In sys/param.h In sys/proc.h Vt extern struct rq itqueues[] ; Vt extern struct rq rtqueues[] ; Vt extern struct rq queues[] ; Vt extern struct rq idqueues[] ; Ft struct thread * Fn choosethread void Ft int Fn procrunnable void Ft void Fn remrunqueue struct thread *td Ft void Fn setrunqueue struct thread *tdDESCRIPTION
The run queue consists of four priority queues: itqueues for interrupt threads, rtqueues for realtime priority processes, queues for time sharing processes, and idqueues for idle priority processes. Each priority queue consists of an array of NQS queue header structures. Each queue header identifies a list of runnable processes of equal priority. Each queue also has a single word that contains a bit mask identifying non-empty queues to assist in selecting a process quickly. These are named itqueuebits rtqueuebits queuebits and idqueuebits The run queues are protected by the sched_lock mutex.Fn procrunnable returns zero if there are no runnable processes other than the idle process. If there is at least one runnable process other than the idle process, it will return a non-zero value. Note that the sched_lock mutex does not need to be held when this function is called. There is a small race window where one CPU may place a process on the run queue when there are currently no other runnable processes while another CPU is calling this function. In that case the second CPU will simply travel through the idle loop one additional time before noticing that there is a runnable process. This works because idle CPUs are not halted in SMP systems. If idle CPUs are halted in SMP systems, then this race condition might have more serious repercussions in the losing case, and Fn procrunnable may have to require that the sched_lock mutex be acquired.
Fn choosethread returns the highest priority runnable thread. If there are no runnable threads, then the idle thread is returned. This function is called by Fn cpu_switch and Fn cpu_throw to determine which thread to switch to. Fn choosethread must be called with the sched_lock mutex held.
Fn setrunqueue adds the thread Fa td to the tail of the appropriate queue in the proper priority queue. The thread must be runnable, i.e. p_stat must be set to SRUN This function must be called with the sched_lock mutex held.
Fn remrunqueue removes thread Fa td from its run queue. If Fa td is not on a run queue, then the kernel will panic(9). This function must be called with the sched_lock mutex held.