ChibiOS/RT Logo ChibiOS/RT

Architecture - Reference Manual - Guides

Data Structures | Defines | Functions | Variables

Scheduler
[Base Kernel Services]

Collaboration diagram for Scheduler:


Description

This module provides the default portable scheduler code, scheduler functions can be individually captured by the port layer in order to provide architecture optimized equivalents. When a function is captured its default code is not built into the OS image, the optimized version is included instead.

Data Structures

struct  ReadyList
 Ready list header. More...

Defines

#define RDY_OK   0
 Default thread wakeup low level message.
#define RDY_TIMEOUT   -1
 Low level message sent to a thread awakened by a timeout.
#define RDY_RESET   -2
 Low level message sent to a thread awakened by a reset operation.
#define NOPRIO   0
 Ready list header priority.
#define IDLEPRIO   1
 Idle thread priority.
#define LOWPRIO   2
 Lowest user priority.
#define NORMALPRIO   64
 Normal user priority.
#define HIGHPRIO   127
 Highest user priority.
#define ABSPRIO   255
 Greatest possible priority.
#define TIME_IMMEDIATE   ((systime_t)-1)
 Zero time specification for some syscalls with a timeout specification.
#define TIME_INFINITE   ((systime_t)0)
 Infinite time specification for all the syscalls with a timeout specification.
#define firstprio(rlp)   ((rlp)->p_next->p_prio)
 Returns the priority of the first thread on the given ready list.
#define currp   rlist.r_current
 Current thread pointer access macro.
#define setcurrp(tp)   (currp = (tp))
 Current thread pointer change macro.
#define chSchIsRescRequiredI()   (firstprio(&rlist.r_queue) > currp->p_prio)
 Determines if the current thread must reschedule.
#define chSchCanYieldS()   (firstprio(&rlist.r_queue) >= currp->p_prio)
 Determines if yielding is possible.
#define chSchDoYieldS()
 Yields the time slot.

Functions

void scheduler_init (void)
 Scheduler initialization.
ThreadchSchReadyI (Thread *tp)
 Inserts a thread in the Ready List.
void chSchGoSleepS (tstate_t newstate)
 Puts the current thread to sleep into the specified state.
msg_t chSchGoSleepTimeoutS (tstate_t newstate, systime_t time)
 Puts the current thread to sleep into the specified state with timeout specification.
void chSchWakeupS (Thread *ntp, msg_t msg)
 Wakes up a thread.
void chSchDoRescheduleI (void)
 Switches to the first thread on the runnable queue.
void chSchRescheduleS (void)
 Performs a reschedule if a higher priority thread is runnable.
bool_t chSchIsRescRequiredExI (void)
 Evaluates if a reschedule is required.

Variables

ReadyList rlist
 Ready list header.

Define Documentation

#define RDY_OK   0
#define RDY_TIMEOUT   -1

Low level message sent to a thread awakened by a timeout.

Definition at line 41 of file chschd.h.

Referenced by adcWaitConversion(), chCondWaitTimeoutS(), macWaitReceiveDescriptor(), and macWaitTransmitDescriptor().

#define RDY_RESET   -2

Low level message sent to a thread awakened by a reset operation.

Definition at line 43 of file chschd.h.

#define NOPRIO   0

Ready list header priority.

Definition at line 45 of file chschd.h.

#define IDLEPRIO   1

Idle thread priority.

Definition at line 46 of file chschd.h.

Referenced by chSysInit().

#define LOWPRIO   2

Lowest user priority.

Definition at line 47 of file chschd.h.

Referenced by chThdSetPriority().

#define NORMALPRIO   64

Normal user priority.

Definition at line 48 of file chschd.h.

Referenced by chSysInit().

#define HIGHPRIO   127

Highest user priority.

Definition at line 49 of file chschd.h.

Referenced by chThdCreateI(), and chThdSetPriority().

#define ABSPRIO   255

Greatest possible priority.

Definition at line 50 of file chschd.h.

#define TIME_IMMEDIATE   ((systime_t)-1)

Zero time specification for some syscalls with a timeout specification.

Note:
Not all functions accept TIME_IMMEDIATE as timeout parameter, see the specific function documentation.

Definition at line 58 of file chschd.h.

Referenced by chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), and chSemWaitTimeoutS().

#define TIME_INFINITE   ((systime_t)0)

Infinite time specification for all the syscalls with a timeout specification.

Definition at line 64 of file chschd.h.

Referenced by chSchGoSleepTimeoutS(), chThdSleep(), chVTSetI(), macWaitReceiveDescriptor(), and macWaitTransmitDescriptor().

#define firstprio (   rlp  )     ((rlp)->p_next->p_prio)

Returns the priority of the first thread on the given ready list.

Definition at line 69 of file chschd.h.

Referenced by chSchIsRescRequiredExI().

#define currp   rlist.r_current

Current thread pointer access macro.

Note:
This macro is not meant to be used in the application code but only from within the kernel, use the chThdSelf() API instead.
It is forbidden to use this macro in order to change the pointer (currp = something), use setcurrp() instead.

Definition at line 111 of file chschd.h.

Referenced by chCondWaitTimeoutS(), chDbgTrace(), chEvtClear(), chEvtPend(), chMsgGet(), chMsgRelease(), chMsgWait(), chMtxTryLockS(), chSchDoRescheduleI(), chSchGoSleepS(), chSchGoSleepTimeoutS(), chSchIsRescRequiredExI(), chSchWakeupS(), chSemWaitS(), chSemWaitTimeoutS(), chSysInit(), chSysTimerHandlerI(), chThdSetPriority(), chThdWait(), and chibios_rt::BaseThread::IsPendingMessage().

#define setcurrp (   tp  )     (currp = (tp))

Current thread pointer change macro.

Note:
This macro is not meant to be used in the application code but only from within the kernel.

Definition at line 123 of file chschd.h.

Referenced by chSchDoRescheduleI(), chSchGoSleepS(), chSchWakeupS(), and chSysInit().

#define chSchIsRescRequiredI (  )     (firstprio(&rlist.r_queue) > currp->p_prio)

Determines if the current thread must reschedule.

This function returns TRUE if there is a ready thread with higher priority.

Definition at line 164 of file chschd.h.

Referenced by chSchRescheduleS().

#define chSchCanYieldS (  )     (firstprio(&rlist.r_queue) >= currp->p_prio)

Determines if yielding is possible.

This function returns TRUE if there is a ready thread with equal or higher priority.

Definition at line 173 of file chschd.h.

#define chSchDoYieldS (  ) 
Value:
{                                                   \
  if (chSchCanYieldS())                                                     \
    chSchDoRescheduleI();                                                   \
}

Yields the time slot.

Yields the CPU control to the next thread in the ready list with equal or higher priority, if any.

Definition at line 182 of file chschd.h.

Referenced by chThdYield().


Function Documentation

void scheduler_init ( void   ) 

Scheduler initialization.

Note:
Internally invoked by the chSysInit(), not an API.

Definition at line 53 of file chschd.c.

References queue_init, ReadyList::r_newer, ReadyList::r_older, ReadyList::r_prio, and ReadyList::r_queue.

Referenced by chSysInit().

Thread * chSchReadyI ( Thread tp  ) 

Inserts a thread in the Ready List.

Note:
The function does not reschedule, the chSchRescheduleS() should be called soon after.
Parameters:
[in] tp the Thread to be made ready
Returns:
The Thread pointer.

Definition at line 78 of file chschd.c.

References Thread::p_next, Thread::p_state, and ReadyList::r_queue.

Referenced by chCondBroadcastI(), chCondSignalI(), chEvtSignalI(), chMsgSend(), chMtxLockS(), chMtxUnlockAll(), chMtxUnlockS(), chSchDoRescheduleI(), chSchWakeupS(), chSemResetI(), chSemSignalI(), chSemSignalWait(), and chThdExit().

void chSchGoSleepS ( tstate_t  newstate  ) 

Puts the current thread to sleep into the specified state.

The thread goes into a sleeping state. The Threads States are described into threads.h.

Parameters:
[in] newstate the new thread state

Definition at line 103 of file chschd.c.

References chDbgTrace(), chSysSwitchI, currp, fifo_remove(), ReadyList::r_queue, and setcurrp.

Referenced by chCondWaitS(), chEvtWaitAll(), chEvtWaitAny(), chEvtWaitOne(), chMsgSend(), chMsgWait(), chMtxLockS(), chSchGoSleepTimeoutS(), chSemSignalWait(), chSemWaitS(), chThdExit(), and chThdWait().

Here is the call graph for this function:

msg_t chSchGoSleepTimeoutS ( tstate_t  newstate,
systime_t  time 
)

Puts the current thread to sleep into the specified state with timeout specification.

The thread goes into a sleeping state, if it is not awakened explicitly within the specified timeout then it is forcibly awakened with a RDY_TIMEOUT low level message. The Threads States are described into threads.h.

Parameters:
[in] newstate the new thread state
[in] time the number of ticks before the operation timeouts, the special values are handled as follow:

  • TIME_INFINITE the thread enters an infinite sleep state, this is equivalent to invoking chSchGoSleepS() but, of course, less efficient.
  • TIME_IMMEDIATE this value is accepted but interpreted as a normal time specification not as an immediate timeout specification.
Returns:
The wakeup message.
Return values:
RDY_TIMEOUT if a timeout occurs.

Definition at line 167 of file chschd.c.

References chSchGoSleepS(), chVTIsArmedI, chVTResetI(), chVTSetI(), currp, and TIME_INFINITE.

Referenced by chCondWaitTimeoutS(), chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), and chSemWaitTimeoutS().

Here is the call graph for this function:

void chSchWakeupS ( Thread ntp,
msg_t  msg 
)

Wakes up a thread.

The thread is inserted into the ready list or immediately made running depending on its relative priority compared to the current thread.

Note:
It is equivalent to a chSchReadyI() followed by a chSchRescheduleS() but much more efficient.
The function assumes that the current thread has the highest priority.
Parameters:
[in] ntp the Thread to be made ready
[in] msg message to the awakened thread

Definition at line 197 of file chschd.c.

References chDbgTrace(), chSchReadyI(), chSysSwitchI, currp, Thread::p_prio, Thread::p_state, Thread::p_u, Thread::rdymsg, and setcurrp.

Referenced by chCondSignal(), chMsgRelease(), chMtxUnlock(), chSemSignal(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), and chThdResume().

Here is the call graph for this function:

void chSchDoRescheduleI ( void   ) 

Switches to the first thread on the runnable queue.

Note:
It is intended to be called if chSchRescRequiredI() evaluates to TRUE.

Definition at line 225 of file chschd.c.

References chDbgTrace(), chSchReadyI(), chSysSwitchI, currp, fifo_remove(), ReadyList::r_queue, and setcurrp.

Referenced by chSchRescheduleS().

Here is the call graph for this function:

void chSchRescheduleS ( void   ) 

Performs a reschedule if a higher priority thread is runnable.

If a thread with a higher priority than the current thread is in the ready list then make the higher priority thread running.

Definition at line 247 of file chschd.c.

References chSchDoRescheduleI(), and chSchIsRescRequiredI.

Referenced by adcStopConversion(), canSleep(), canStop(), canWakeup(), chCondBroadcast(), chEvtBroadcast(), chEvtSignal(), chMBFetchS(), chMBPostAheadS(), chMBPostS(), chMBReset(), chMtxUnlockAll(), chSemReset(), chSemSignalWait(), chThdSetPriority(), and sdStop().

Here is the call graph for this function:

bool_t chSchIsRescRequiredExI ( void   ) 

Evaluates if a reschedule is required.

The decision is taken by comparing the relative priorities and depending on the state of the round robin timeout counter.

Note:
This function is meant to be used in the timer interrupt handler where chVTDoTickI() is invoked.
Return values:
TRUE if there is a thread that should go in running state.
FALSE if a reschedule is not required.

Definition at line 265 of file chschd.c.

References currp, firstprio, and ReadyList::r_queue.


Variable Documentation

Ready list header.

Definition at line 46 of file chschd.c.

Referenced by chRegFirstThread(), chRegNextThread(), and chSysTimerHandlerI().


Generated on Sun Nov 28 2010 14:09:56 for ChibiOS/RT by doxygen 1.7.1