NAME | SYNOPSIS | FEATURES | DESCRIPTION | CLASS_FIFO | CLASS_RR | CLASS_RT | CLASS_TS | RETURN VALUE | ERRORS | ATTRIBUTES | SEE ALSO
#include <exec/chExec.h> #include <sched/chSched.h> #include <sched/chFifo.h> #include <sched/chRr.h> #include <sched/chRt.h>int threadScheduler(KnCap *actorcap, KnThreadLid threadli, void *oldpara, void *newparam);
SCHED_FIFO, SCHED_CLASS
threadScheduler returns and optionally modifies the scheduling parameters of the thread the local identifier of which is threadli in the actor the capability of which is given by actorcap. If actorcap is K_MYACTOR, the thread must belong to the current actor. In this case, if threadli is K_MYSELF, the current thread is affected.
oldparam and newparam point to descriptors of old and new scheduling parameters respectively. The type of the descriptor depends on the scheduler. Generally, there is one type of scheduling parameters per scheduling policy (i.e. scheduling class) implemented by the scheduler.
Two priority-based schedulers are currently supported: SCHED_FIFO and SCHED_CLASS. The SCHED_FIFO scheduler implements the CLASS_FIFO scheduling policy, which manages parameters of type KnFifoThParms. The SCHED_CLASS scheduler implements the CLASS_FIFO, CLASS_RR and CLASS_RT scheduling policies, which respectively manage parameters of type KnFifoThParms, KnRrThParms and KnRtThParms. The SCHED_CLASS also implements the CLASS_TS that is reserved for the implementation of the Chorus/MiX SVR4 subsystem, and therefore should not be used. These policies, as well as the corresponding parameter structures, are described within specific sections below.
If oldparam is not NULL, the thread's current scheduling parameters are stored in the area pointed to by oldparam in the caller's address space.
If newparam is not NULL, it points to an area in the caller's address space containing the new scheduling parameters.
In addition, threadScheduler, as well as the two available schedulers, support the notion of default scheduling class, which defines a normalized scheduling parameters structure, KnThreadDefaultSched. newparms can point to a variable of this type. KnThreadDefaultSched is a structure containing the following fields:
KnSchedClass tdClass ; KnThreadPriority tdPriority ; |
where tdClass must be equal to K_SCHED_DEFAULT. tdPriority establishes the priority of the thread, which may vary between K_PRIOMAX (highest priority) and K_PRIOMIN (lowest priority). The two available schedulers currently map this (virtual) default scheduling class to the CLASS_FIFO policy. This means in particular that they interprete the KnThreadDefaultSched priority field in the same way the CLASS_FIFO interpretes the priority field of a KnFifoThParms structure.
The CLASS_FIFO scheduling class implements a pure priority-based, preemptive, fifo policy. Thread's scheduling parameters are defined by the KnFifoThParms structure, the members of which are the following:
KnSchedClass fifoClass ; KnFifoPriority fifoPriority ; |
fifoClass must be equal to K_SCHED_FIFO. fifoPriority defines the priority of the thread, which may vary between K_FIFO_PRIOMAX (0, highest priority) and K_FIFO_PRIOMIN (255, lowest priority).
CLASS_FIFO uses the full range of priorities (256) in both the SCHED_FIFO and SCHED_CLASS schedulers.
A thread which becomes ready to run after being blocked is always inserted last at the end of its priority ready queue (fifo policy). This means that a running thread is only preempted if a thread of strictly highest priority becomes ready to run. A preempted thread is placed at the head of its priority ready queue. This means that it will be elected first when the preempting thread completes or is blocked.
The CLASS_RR scheduling class is only available within the SCHED_CLASS scheduler. It implements a priority-based, preemptive, round-robin policy. Thread's scheduling parameters are defined by the KnRrThParms structure, the members of which are the following:
KnSchedClass rrClass ; KnRrPriority rrPriority ; |
rrClass must be equal to K_SCHED_RR. rrPriority defines the priority of the thread, which may vary between K_RR_PRIOMAX (0, highest priority) and K_RR_PRIOMIN (255, lowest priority).
CLASS_RR uses the full range of priorities (256) of the SCHED_CLASS scheduler.
The SCHED_RR policy is similar to the SCHED_FIFO policy, except that an elected thread is given a fixed time quantum. If the thread is still running at quantum expiration, it is placed at the end of its priority ready queue, and then may be preempted by threads of equal priority. The thread's quantum is reset when the thread becomes ready after being blocked; it is not reset when the thread is elected again after a preemption.
The time quantum is the same for all priority levels and all threads. It is defined by the K_RR_QUANTUM value (100 milliseconds). It will be turned into a system tunable in a future release.
The CLASS_RT scheduling class is only available within the SCHED_CLASS scheduler. It implements the same policy as the real-time class of UNIX SVR4.0. Refer to the priocntl(2) manual entry of UNIX SVR4.0 for a complete description.
This policy is basically a round-robin policy, with per thread time quanta.
Thread's scheduling parameters are defined by the KnRtThParms structure, the members of which are the following:
KnSchedClass rtClass ; KnRtParms *rtParms ; |
rtClass must be equal to K_SCHED_RT.
The actual parameters are defined by the KnRtParms structure, the members of which are the following:
KnRtPriority rtPriority ; unsigned long rtQSecs ; long rtQNSecs ; |
The fields of this structure map the fields of the rtparms_t of UNIX SVR4. rtPriority defines the priority of the thread, which may vary between K_RT_PRIOMAX (159, highest priority) and K_RT_PRIOMIN (100, lowest priority). Note that the order of priorities is inverted compared to the CLASS_FIFO priorities. CLASS_RT uses only a sub-range of the SCHED_CLASS priorities. This sub-range corresponds to the range [96, 155] of CLASS_FIFO and CLASS_RR.
The rtQSec and rtQNsec define the thread's time quantum, respectively in seconds and nanoseconds.
The rtQNsec field can take the following special values:
The thread's quantum must not be modified, or if the thread enters the CLASS_RT class, the thread's quantum is set to the RT_INFINITE quantum.
The thread's time quantum is infinite.
The thread's time quantum is set to the default for the thread' s priority, as follows:
K_RT_PRIOMIN to K_RT_PRIOMIN+9 |
100 ticks |
K_RT_PRIOMIN+10 to K_RT_PRIOMIN+19 |
80 ticks |
K_RT_PRIOMIN+20 to K_RT_PRIOMIN+29 |
60 ticks |
K_RT_PRIOMIN+30 to K_RT_PRIOMIN+39 |
40 ticks |
K_RT_PRIOMIN+40 to K_RT_PRIOMIN+49 |
20 ticks |
K_RT_PRIOMIN+50 to K_RT_PRIOMIN+59 |
10 ticks |
The default tick period is 10 ms. In this case, the values in the table should be multiplied by ten in order to get the quantum in ms.
The CLASS_RT manages per configurable priority default time quanta.
The CLASS_TS scheduling class is reserved and implements the same policy as the time-sharing class of UNIX SVR4.0.
Upon successful completion, K_OK is returned. Otherwise, a negative error code is returned.
actorcap is an inconsistent actor capability.
actorcap does not specify a reachable actor.
newparam points to a structure containing invalid scheduling parameters.
The system is out of resources.
newparm specifies a non-supported scheduling policy.
Some of the provided data are outside the current actor's address space.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | SYNOPSIS | FEATURES | DESCRIPTION | CLASS_FIFO | CLASS_RR | CLASS_RT | CLASS_TS | RETURN VALUE | ERRORS | ATTRIBUTES | SEE ALSO