ChibiOS
20.3.4
|
This module provides the default portable scheduler code.
Macros | |
#define | firstprio(rlp) ((rlp)->next->prio) |
Returns the priority of the first thread on the given ready list. More... | |
#define | currp ch.rlist.current |
Current thread pointer access macro. More... | |
#define | __CH_STRINGIFY(a) #a |
Utility to make the parameter a quoted string. More... | |
Wakeup status codes | |
#define | MSG_OK (msg_t)0 |
Normal wakeup message. More... | |
#define | MSG_TIMEOUT (msg_t)-1 |
Wakeup caused by a timeout condition. More... | |
#define | MSG_RESET (msg_t)-2 |
Wakeup caused by a reset condition. More... | |
Priority constants | |
#define | NOPRIO (tprio_t)0 |
Ready list header priority. More... | |
#define | IDLEPRIO (tprio_t)1 |
Idle priority. More... | |
#define | LOWPRIO (tprio_t)2 |
Lowest priority. More... | |
#define | NORMALPRIO (tprio_t)128 |
Normal priority. More... | |
#define | HIGHPRIO (tprio_t)255 |
Highest priority. More... | |
Thread states | |
#define | CH_STATE_READY (tstate_t)0 |
Waiting on the ready list. More... | |
#define | CH_STATE_CURRENT (tstate_t)1 |
Currently running. More... | |
#define | CH_STATE_WTSTART (tstate_t)2 |
Just created. More... | |
#define | CH_STATE_SUSPENDED (tstate_t)3 |
Suspended state. More... | |
#define | CH_STATE_QUEUED (tstate_t)4 |
On a queue. More... | |
#define | CH_STATE_WTSEM (tstate_t)5 |
On a semaphore. More... | |
#define | CH_STATE_WTMTX (tstate_t)6 |
On a mutex. More... | |
#define | CH_STATE_WTCOND (tstate_t)7 |
On a cond.variable. More... | |
#define | CH_STATE_SLEEPING (tstate_t)8 |
Sleeping. More... | |
#define | CH_STATE_WTEXIT (tstate_t)9 |
Waiting a thread. More... | |
#define | CH_STATE_WTOREVT (tstate_t)10 |
One event. More... | |
#define | CH_STATE_WTANDEVT (tstate_t)11 |
Several events. More... | |
#define | CH_STATE_SNDMSGQ (tstate_t)12 |
Sending a message, in queue. More... | |
#define | CH_STATE_SNDMSG (tstate_t)13 |
Sent a message, waiting answer. More... | |
#define | CH_STATE_WTMSG (tstate_t)14 |
Waiting for a message. More... | |
#define | CH_STATE_FINAL (tstate_t)15 |
Thread terminated. More... | |
#define | CH_STATE_NAMES |
Thread states as array of strings. More... | |
Thread flags and attributes | |
#define | CH_FLAG_MODE_MASK (tmode_t)3U |
Thread memory mode mask. More... | |
#define | CH_FLAG_MODE_STATIC (tmode_t)0U |
Static thread. More... | |
#define | CH_FLAG_MODE_HEAP (tmode_t)1U |
Thread allocated from a Memory Heap. More... | |
#define | CH_FLAG_MODE_MPOOL (tmode_t)2U |
Thread allocated from a Memory Pool. More... | |
#define | CH_FLAG_TERMINATE (tmode_t)4U |
Termination requested flag. More... | |
Typedefs | |
typedef struct ch_delta_list | delta_list_t |
Type of a Virtual Timer structure. More... | |
typedef struct ch_thread | thread_t |
Type of a thread structure. More... | |
typedef thread_t * | thread_reference_t |
Type of a thread reference. More... | |
typedef struct ch_threads_list | threads_list_t |
Type of a generic threads single link list, it works like a stack. More... | |
typedef struct ch_threads_queue | threads_queue_t |
Type of a generic threads bidirectional linked list header and element. More... | |
typedef struct ch_ready_list | ready_list_t |
Type of a ready list header. More... | |
typedef void(* | vtfunc_t) (void *p) |
Type of a Virtual Timer callback function. More... | |
typedef struct ch_virtual_timer | virtual_timer_t |
Type of a Virtual Timer structure. More... | |
typedef struct ch_virtual_timers_list | virtual_timers_list_t |
Type of virtual timers list header. More... | |
typedef struct ch_system_debug | system_debug_t |
Type of a system debug structure. More... | |
typedef struct ch_system | ch_system_t |
Type of system data structure. More... | |
Data Structures | |
struct | ch_threads_queue |
Structure representing a threads queue. More... | |
struct | ch_thread |
Structure representing a thread. More... | |
struct | ch_delta_list |
Virtual Timer delta list element and header structure. More... | |
struct | ch_virtual_timer |
Structure representing a Virtual Timer. More... | |
struct | ch_virtual_timers_list |
Structure representing a virtual timers list header. More... | |
struct | ch_system_debug |
System debug data structure. More... | |
struct | ch_system |
System data structure. More... | |
Functions | |
void | ch_sch_prio_insert (ch_queue_t *tp, ch_queue_t *qp) |
Inserts a thread into a priority ordered queue. More... | |
void | _scheduler_init (void) |
Scheduler initialization. More... | |
thread_t * | chSchReadyI (thread_t *tp) |
Inserts a thread in the Ready List placing it behind its peers. More... | |
thread_t * | chSchReadyAheadI (thread_t *tp) |
Inserts a thread in the Ready List placing it ahead its peers. More... | |
void | chSchGoSleepS (tstate_t newstate) |
Puts the current thread to sleep into the specified state. More... | |
msg_t | chSchGoSleepTimeoutS (tstate_t newstate, sysinterval_t timeout) |
Puts the current thread to sleep into the specified state with timeout specification. More... | |
void | chSchWakeupS (thread_t *ntp, msg_t msg) |
Wakes up a thread. More... | |
void | chSchRescheduleS (void) |
Performs a reschedule if a higher priority thread is runnable. More... | |
bool | chSchIsPreemptionRequired (void) |
Evaluates if preemption is required. More... | |
void | chSchDoRescheduleBehind (void) |
Switches to the first thread on the runnable queue. More... | |
void | chSchDoRescheduleAhead (void) |
Switches to the first thread on the runnable queue. More... | |
void | chSchDoReschedule (void) |
Switches to the first thread on the runnable queue. More... | |
static bool | chSchIsRescRequiredI (void) |
Determines if the current thread must reschedule. More... | |
static bool | chSchCanYieldS (void) |
Determines if yielding is possible. More... | |
static void | chSchDoYieldS (void) |
Yields the time slot. More... | |
static void | chSchPreemption (void) |
Inline-able preemption code. More... | |
Variables | |
ch_system_t | ch |
System data structures. More... | |
#define MSG_TIMEOUT (msg_t)-1 |
#define MSG_RESET (msg_t)-2 |
#define CH_STATE_READY (tstate_t)0 |
#define CH_STATE_SNDMSGQ (tstate_t)12 |
#define CH_STATE_SNDMSG (tstate_t)13 |
#define CH_STATE_NAMES |
Thread states as array of strings.
Each element in an array initialized with this macro can be indexed using the numeric thread state values.
#define CH_FLAG_MODE_MASK (tmode_t)3U |
#define CH_FLAG_MODE_HEAP (tmode_t)1U |
#define CH_FLAG_MODE_MPOOL (tmode_t)2U |
#define CH_FLAG_TERMINATE (tmode_t)4U |
#define firstprio | ( | rlp | ) | ((rlp)->next->prio) |
#define currp ch.rlist.current |
Current thread pointer access macro.
chThdGetSelfX()
instead. #define __CH_STRINGIFY | ( | a | ) | #a |
Utility to make the parameter a quoted string.
Definition at line 110 of file chsystypes.h.
typedef struct ch_delta_list delta_list_t |
Type of a thread structure.
Definition at line 52 of file chsystypes.h.
typedef thread_t* thread_reference_t |
Type of a thread reference.
Definition at line 57 of file chsystypes.h.
typedef struct ch_threads_list threads_list_t |
Type of a generic threads single link list, it works like a stack.
Definition at line 62 of file chsystypes.h.
typedef struct ch_threads_queue threads_queue_t |
Type of a generic threads bidirectional linked list header and element.
Definition at line 69 of file chsystypes.h.
typedef struct ch_ready_list ready_list_t |
Type of a ready list header.
Definition at line 76 of file chsystypes.h.
typedef void(* vtfunc_t) (void *p) |
Type of a Virtual Timer callback function.
Definition at line 81 of file chsystypes.h.
typedef struct ch_virtual_timer virtual_timer_t |
Type of a Virtual Timer structure.
Definition at line 86 of file chsystypes.h.
typedef struct ch_virtual_timers_list virtual_timers_list_t |
Type of virtual timers list header.
Definition at line 91 of file chsystypes.h.
typedef struct ch_system_debug system_debug_t |
Type of a system debug structure.
Definition at line 96 of file chsystypes.h.
typedef struct ch_system ch_system_t |
Type of system data structure.
Definition at line 101 of file chsystypes.h.
|
inline |
Inserts a thread into a priority ordered queue.
[in] | tp | the pointer to the thread to be inserted in the list |
[in] | qp | the pointer to the threads list header |
Definition at line 109 of file chschd.c.
References ch_queue::next.
void _scheduler_init | ( | void | ) |
Scheduler initialization.
Definition at line 128 of file chschd.c.
References ch, ch_pqueue_init(), and ch_system::rlist.
Referenced by chSysInit().
Inserts a thread in the Ready List placing it behind its peers.
The thread is positioned behind all threads with higher or equal priority.
next
and prev
or list corruption would occur. [in] | tp | the thread to be made ready |
Definition at line 153 of file chschd.c.
Referenced by chMtxUnlock(), chMtxUnlockAllS(), chSchDoReschedule(), chSchDoRescheduleBehind(), chSemSignalWait(), chThdCreateI(), chThdDoDequeueNextI(), chThdExitS(), chThdResumeI(), and chThdStartI().
Inserts a thread in the Ready List placing it ahead its peers.
The thread is positioned ahead all threads with higher or equal priority.
next
and prev
or list corruption would occur. [in] | tp | the thread to be made ready |
Definition at line 185 of file chschd.c.
Referenced by chSchDoReschedule(), and chSchDoRescheduleAhead().
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 210 of file chschd.c.
References currp.
Referenced by chEvtWaitAll(), chEvtWaitAny(), chEvtWaitOne(), chThdExitS(), chThdSuspendS(), and chThdWait().
msg_t chSchGoSleepTimeoutS | ( | tstate_t | newstate, |
sysinterval_t | timeout | ||
) |
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 MSG_TIMEOUT
low level message. The possible Thread States are defined into threads.h
.
[in] | newstate | the new thread state |
[in] | timeout | the number of ticks before the operation timeouts, the special values are handled as follow:
|
MSG_TIMEOUT | if a timeout occurs. |
Definition at line 258 of file chschd.c.
Referenced by chEvtWaitAllTimeout(), chEvtWaitAnyTimeout(), chEvtWaitOneTimeout(), chThdEnqueueTimeoutS(), chThdSleepS(), and chThdSuspendTimeoutS().
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.
next
and 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 | the wakeup message |
Definition at line 295 of file chschd.c.
References currp.
Referenced by chCondSignal(), chSemSignal(), chThdCreate(), chThdCreateFromHeap(), chThdCreateFromMemoryPool(), chThdCreateStatic(), chThdResumeS(), and chThdStart().
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 339 of file chschd.c.
Referenced by chBSemSignal(), chCacheReleaseObject(), chCondBroadcast(), chEvtBroadcastFlags(), chEvtSignal(), chGuardedPoolFree(), chGuardedPoolFreeS(), chMBReset(), chMtxUnlock(), chMtxUnlockAllS(), chSemResetWithMessage(), chSemSignal(), chSysRestoreStatusX(), and chThdSetPriority().
bool 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 362 of file chschd.c.
References ch, currp, firstprio, and ch_system::rlist.
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 390 of file chschd.c.
References ch, CH_CFG_IDLE_LEAVE_HOOK, CH_CFG_TIME_QUANTUM, ch_pqueue_remove_highest(), CH_STATE_CURRENT, chSchReadyI(), chSysSwitch, currp, IDLEPRIO, ch_thread::pqueue, ch_system::rlist, and ch_thread::ticks.
Referenced by chSchPreemption().
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 423 of file chschd.c.
References ch, CH_CFG_IDLE_LEAVE_HOOK, ch_pqueue_remove_highest(), CH_STATE_CURRENT, chSchReadyAheadI(), chSysSwitch, currp, IDLEPRIO, ch_thread::pqueue, and ch_system::rlist.
Referenced by chSchPreemption().
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 453 of file chschd.c.
References ch, CH_CFG_IDLE_LEAVE_HOOK, CH_CFG_TIME_QUANTUM, ch_pqueue_remove_highest(), CH_STATE_CURRENT, chSchReadyAheadI(), chSchReadyI(), chSysSwitch, currp, IDLEPRIO, ch_thread::pqueue, ch_system::rlist, and ch_thread::ticks.
|
inlinestatic |
Determines if the current thread must reschedule.
This function returns true
if there is a ready thread with higher priority.
false | if rescheduling is not necessary. |
true | if there is a ready thread at higher priority. |
|
inlinestatic |
Determines if yielding is possible.
This function returns true
if there is a ready thread with equal or higher priority.
false | if yielding is not possible. |
true | if there is a ready thread at equal or higher priority. |
|
inlinestatic |
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 560 of file chschd.h.
Referenced by chThdYield().
|
inlinestatic |
Inline-able preemption code.
This is the common preemption code, this function must be invoked exclusively from the port layer.
Definition at line 576 of file chschd.h.
References ch, chSchDoRescheduleAhead(), chSchDoRescheduleBehind(), currp, firstprio, and ch_system::rlist.
ch_system_t ch |
System data structures.
Definition at line 42 of file chschd.c.
Referenced by _dbg_check_disable(), _dbg_check_enable(), _dbg_check_enter_isr(), _dbg_check_leave_isr(), _dbg_check_lock(), _dbg_check_lock_from_isr(), _dbg_check_suspend(), _dbg_check_unlock(), _dbg_check_unlock_from_isr(), _scheduler_init(), _stats_ctxswc(), _stats_increase_irq(), _stats_init(), _stats_start_measure_crit_isr(), _stats_start_measure_crit_thd(), _stats_stop_measure_crit_isr(), _stats_stop_measure_crit_thd(), _tm_init(), _trace_halt(), _trace_init(), _trace_isr_enter(), _trace_isr_leave(), _trace_switch(), _vt_init(), chDbgCheckClassI(), chDbgCheckClassS(), chRegFirstThread(), chRegNextThread(), chRegSetThreadName(), chSchDoReschedule(), chSchDoRescheduleAhead(), chSchDoRescheduleBehind(), chSchIsPreemptionRequired(), chSchPreemption(), chSysGetIdleThreadX(), chSysHalt(), chSysInit(), chThdGetSelfX(), chVTDoResetI(), chVTDoSetI(), chVTDoTickI(), chVTGetRemainingIntervalI(), chVTGetSystemTimeX(), chVTGetTimersStateI(), and trace_next().