SETRUNQUEUE(9)

NAME
setrunqueue, remrunqueue, nextrunqueue - manipulate system run queue

SYNOPSIS
#include <sys/proc.h>
#include <sys/sched.h>
void
setrunqueue(struct lwp *l);
void
remrunqueue(struct lwp *l);
struct lwp *
nextrunqueue(void);

DESCRIPTION
The setrunqueue(), remrunqueue(), and nextrunqueue() functions manipulate the system queue of runnable processes. The system scheduler uses this queue to find the highest-priority process when a process switch occurs. These functions are generally machine-dependent implementations in order to permit efficient implementation of priority-based process selection.

Currently, these functions are scheduler specific and correspond to the default “time-sharing” scheduler in NetBSD. Their implementation is likely to change in the future to cater for different schedulers.

The priority queue consists of an array sched_qs[NQS] of queue header structures each of which identifies a list of runnable processes of equal priority. Lower indices in sched_qs indicate higher priority. A single word sched_whichqs containing a bit mask identifying non-empty queues assists in selecting a process quickly. The running process is on no queue, other processes are on a queue related to p->p_priority, divided by 4 actually to shrink the 0-127 range of priorities into the 32 available queues.

The setrunqueue() function places the given process on the system run queue. It is an error to call setrunqueue() with a process that is not runnable or that is already on the system run queue or sleep queue.

The remrunqueue() function removes the given process from the system run queue. It is an error to call remrunqueue() with a process that is not on the system run queue.

The nextrunqueue() function will make a choice amongst the processes which are ready to run from the priority run queue. nextrunqueue() will remove the first process from the list on the queue with the highest priority a return it.

These functions must be called with the scheduler lock held (see SCHED_LOCK(9)) and at the splsched(9) interrupt protection level,

SEE ALSO
SCHED_LOCK(9), scheduler(9), splsched(9)