|
ChibiOS/RT
2.5.1 |
|
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... | |
Functions | |
| void | _scheduler_init (void) |
| Scheduler initialization. | |
| Thread * | chSchReadyI (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 | chSchRescheduleS (void) |
| Performs a reschedule if a higher priority thread is runnable. | |
| bool_t | chSchIsPreemptionRequired (void) |
| Evaluates if preemption is required. | |
| void | chSchDoRescheduleBehind (void) |
| Switches to the first thread on the runnable queue. | |
| void | chSchDoRescheduleAhead (void) |
| Switches to the first thread on the runnable queue. | |
| void | chSchDoReschedule (void) |
| Switches to the first thread on the runnable queue. | |
Variables | |
| ReadyList | rlist |
| Ready list header. | |
Wakeup status codes | |
| #define | RDY_OK 0 |
| Normal wakeup message. | |
| #define | RDY_TIMEOUT -1 |
| Wakeup caused by a timeout condition. | |
| #define | RDY_RESET -2 |
| Wakeup caused by a reset condition. | |
Priority constants | |
| #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. | |
Special time constants | |
| #define | TIME_IMMEDIATE ((systime_t)0) |
| Zero time specification for some functions with a timeout specification. | |
| #define | TIME_INFINITE ((systime_t)-1) |
| Infinite time specification for all functions with a timeout specification. | |
Macro Functions | |
| #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. | |
| #define | chSchPreemption() |
| Inline-able preemption code. | |
Defines | |
| #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. | |
| void _scheduler_init | ( | void | ) |
Scheduler initialization.
Definition at line 48 of file chschd.c.
References NOPRIO, queue_init, ReadyList::r_newer, ReadyList::r_older, ReadyList::r_prio, and ReadyList::r_queue.
Referenced by chSysInit().
Inserts a thread in the Ready List.
The thread is positioned behind all threads with higher or equal priority.
p_next and p_prev or list corruption would occur. | [in] | tp | the thread to be made ready |
Definition at line 74 of file chschd.c.
References chDbgAssert, chDbgCheckClassI(), Thread::p_next, Thread::p_state, ReadyList::r_queue, THD_STATE_FINAL, and THD_STATE_READY.
Referenced by chCondBroadcastI(), chCondSignalI(), chEvtSignalI(), chIQPutI(), chIQResetI(), chMsgSend(), chMtxLockS(), chMtxUnlockAll(), chMtxUnlockS(), chOQGetI(), chOQResetI(), chSchDoRescheduleBehind(), chSchWakeupS(), chSemAddCounterI(), chSemResetI(), chSemSignalI(), chSemSignalWait(), and chThdExitS().

| void chSchGoSleepS | ( | tstate_t | newstate | ) |
Puts the current thread to sleep into the specified state.
The thread goes into a sleeping state. The possible Thread States are defined into threads.h.
| [in] | newstate | the new thread state |
Definition at line 108 of file chschd.c.
References CH_TIME_QUANTUM, chDbgCheckClassS(), chSysSwitch, currp, fifo_remove(), Thread::p_preempt, ReadyList::r_queue, setcurrp, and THD_STATE_CURRENT.
Referenced by chCondWaitS(), chEvtWaitAll(), chEvtWaitAny(), chEvtWaitOne(), chMsgSend(), chMsgWait(), chMtxLockS(), chSchGoSleepTimeoutS(), chSemSignalWait(), chSemWaitS(), chThdExitS(), and chThdWait().

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 possible Thread States are defined into threads.h.
| [in] | newstate | the new thread state |
| [in] | time | the number of ticks before the operation timeouts, the special values are handled as follow:
|
| RDY_TIMEOUT | if a timeout occurs. |
Definition at line 182 of file chschd.c.
References chDbgCheckClassS(), chSchGoSleepS(), chVTIsArmedI, chVTResetI(), chVTSetI(), currp, and TIME_INFINITE.
Referenced by chCondWaitTimeoutS(), chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), and chSemWaitTimeoutS().

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.
p_next and p_prev or list corruption would occur. chSchReadyI() followed by a chSchRescheduleS() but much more efficient. | [in] | ntp | the Thread to be made ready |
| [in] | msg | message to the awakened thread |
Definition at line 218 of file chschd.c.
References chDbgCheckClassS(), chSchReadyI(), chSysSwitch, currp, Thread::p_prio, Thread::p_state, Thread::rdymsg, setcurrp, and THD_STATE_CURRENT.
Referenced by chCondSignal(), chMtxUnlock(), chSemSignal(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), and chThdResume().

| 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 246 of file chschd.c.
References chDbgCheckClassS(), chSchDoRescheduleAhead(), and chSchIsRescRequiredI.
Referenced by chCondBroadcast(), chEvtBroadcastFlags(), chEvtSignal(), chMBFetchS(), chMBPostAheadS(), chMBPostS(), chMBReset(), chMtxUnlockAll(), chSemReset(), chSemSignalWait(), and chThdSetPriority().

| bool_t chSchIsPreemptionRequired | ( | void | ) |
Evaluates if preemption is required.
The decision is taken by comparing the relative priorities and depending on the state of the round robin timeout counter.
| TRUE | if there is a thread that must go in running state immediately. |
| FALSE | if preemption is not required. |
Definition at line 269 of file chschd.c.
References currp, firstprio, and ReadyList::r_queue.
| void chSchDoRescheduleBehind | ( | void | ) |
Switches to the first thread on the runnable queue.
The current thread is positioned in the ready list behind all threads having the same priority. The thread regains its time quantum.
Definition at line 297 of file chschd.c.
References CH_TIME_QUANTUM, chSchReadyI(), chSysSwitch, currp, fifo_remove(), Thread::p_preempt, ReadyList::r_queue, setcurrp, and THD_STATE_CURRENT.
Referenced by chSchDoReschedule().

| void chSchDoRescheduleAhead | ( | void | ) |
Switches to the first thread on the runnable queue.
The current thread is positioned in the ready list ahead of all threads having the same priority.
Definition at line 322 of file chschd.c.
References currp, fifo_remove(), Thread::p_next, Thread::p_state, ReadyList::r_queue, setcurrp, THD_STATE_CURRENT, and THD_STATE_READY.
Referenced by chSchDoReschedule(), and chSchRescheduleS().

| void chSchDoReschedule | ( | void | ) |
Switches to the first thread on the runnable queue.
The current thread is positioned in the ready list behind or ahead of all threads having the same priority depending on if it used its whole time slice.
Definition at line 355 of file chschd.c.
References chSchDoRescheduleAhead(), chSchDoRescheduleBehind(), and currp.

Ready list header.
Definition at line 40 of file chschd.c.
Referenced by chRegFirstThread(), and chRegNextThread().
| #define RDY_OK 0 |
Normal wakeup message.
Definition at line 36 of file chschd.h.
Referenced by chCondSignal(), chCondSignalI(), chEvtSignalI(), chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), chMBFetchI(), chMBFetchS(), chMBPostAheadI(), chMBPostAheadS(), chMBPostI(), chMBPostS(), chMtxUnlock(), chSemAddCounterI(), chSemSignal(), chSemSignalI(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), and chThdResume().
| #define RDY_TIMEOUT -1 |
Wakeup caused by a timeout condition.
Definition at line 37 of file chschd.h.
Referenced by chCondWaitTimeoutS(), chMBFetchI(), chMBPostAheadI(), chMBPostI(), and chSemWaitTimeoutS().
| #define RDY_RESET -2 |
Wakeup caused by a reset condition.
Definition at line 39 of file chschd.h.
Referenced by chCondBroadcastI(), and chSemResetI().
| #define NOPRIO 0 |
Ready list header priority.
Definition at line 47 of file chschd.h.
Referenced by _scheduler_init().
| #define IDLEPRIO 1 |
| #define NORMALPRIO 64 |
| #define HIGHPRIO 127 |
Highest user priority.
Definition at line 51 of file chschd.h.
Referenced by chThdCreateI(), and chThdSetPriority().
| #define TIME_IMMEDIATE ((systime_t)0) |
Zero time specification for some functions with a timeout specification.
TIME_IMMEDIATE as timeout parameter, see the specific function documentation. Definition at line 65 of file chschd.h.
Referenced by chCondWaitTimeoutS(), chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), chSemWaitTimeoutS(), chThdSleep(), and chVTSetI().
| #define TIME_INFINITE ((systime_t)-1) |
Infinite time specification for all functions with a timeout specification.
Definition at line 71 of file chschd.h.
Referenced by chSchGoSleepTimeoutS().
| #define firstprio | ( | rlp | ) | ((rlp)->p_next->p_prio) |
Returns the priority of the first thread on the given ready list.
Definition at line 79 of file chschd.h.
Referenced by chSchIsPreemptionRequired().
| #define currp rlist.r_current |
Current thread pointer access macro.
chThdSelf() API instead. setcurrp() instead. Definition at line 115 of file chschd.h.
Referenced by chCondWaitS(), chCondWaitTimeoutS(), chEvtAddEvents(), chEvtGetAndClearEvents(), chEvtRegisterMask(), chEvtWaitAll(), chEvtWaitAllTimeout(), chEvtWaitAny(), chEvtWaitAnyTimeout(), chEvtWaitOne(), chEvtWaitOneTimeout(), chMsgSend(), chMsgWait(), chMtxLockS(), chMtxTryLockS(), chMtxUnlock(), chMtxUnlockAll(), chMtxUnlockS(), chSchDoReschedule(), chSchDoRescheduleAhead(), chSchDoRescheduleBehind(), chSchGoSleepS(), chSchGoSleepTimeoutS(), chSchIsPreemptionRequired(), chSchWakeupS(), chSemSignalWait(), chSemWaitS(), chSemWaitTimeoutS(), chSysInit(), chSysTimerHandlerI(), chThdExitS(), chThdSetPriority(), chThdWait(), and dbg_trace().
| #define setcurrp | ( | tp | ) | (currp = (tp)) |
Current thread pointer change macro.
Definition at line 126 of file chschd.h.
Referenced by chSchDoRescheduleAhead(), chSchDoRescheduleBehind(), 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 179 of file chschd.h.
Referenced by chSchRescheduleS().
| #define chSchCanYieldS | ( | ) | (firstprio(&rlist.r_queue) >= currp->p_prio) |
| #define chSchDoYieldS | ( | ) |
{ \
if (chSchCanYieldS()) \
chSchDoRescheduleBehind(); \
}
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 201 of file chschd.h.
Referenced by chThdYield().
| #define chSchPreemption | ( | ) |
{ \
tprio_t p1 = firstprio(&rlist.r_queue); \
tprio_t p2 = currp->p_prio; \
if (currp->p_preempt) { \
if (p1 > p2) \
chSchDoRescheduleAhead(); \
} \
else { \
if (p1 >= p2) \
chSchDoRescheduleBehind(); \
} \
}
Inline-able preemption code.
This is the common preemption code, this function must be invoked exclusively from the port layer.