git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5994 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2013-07-19 11:48:43 +00:00
parent 75a84bbeae
commit 4245ba7659
4 changed files with 101 additions and 113 deletions

View File

@ -29,6 +29,10 @@
#ifndef _CHSCHD_H_
#define _CHSCHD_H_
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/**
* @name Wakeup status codes
* @{
@ -71,19 +75,23 @@
#define TIME_INFINITE ((systime_t)-1)
/** @} */
/**
* @brief Returns the priority of the first thread on the given ready list.
*
* @notapi
*/
#define firstprio(rlp) ((rlp)->p_next->p_prio)
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
/**
* @extends threads_queue_t
*
* @brief Ready list header.
*/
#if !defined(PORT_OPTIMIZED_READYLIST_STRUCT) || defined(__DOXYGEN__)
typedef struct {
threads_queue_t r_queue; /**< @brief Threads queue. */
tprio_t r_prio; /**< @brief This field must be
@ -97,12 +105,18 @@ typedef struct {
/* End of the fields shared with the Thread structure.*/
Thread *r_current; /**< @brief The currently running
thread. */
} ReadyList;
#endif /* !defined(PORT_OPTIMIZED_READYLIST_STRUCT) */
} ready_list_t;
#if !defined(PORT_OPTIMIZED_RLIST_EXT) && !defined(__DOXYGEN__)
extern ReadyList rlist;
#endif /* !defined(PORT_OPTIMIZED_RLIST_EXT) */
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
/**
* @brief Returns the priority of the first thread on the given ready list.
*
* @notapi
*/
#define firstprio(rlp) ((rlp)->p_next->p_prio)
/**
* @brief Current thread pointer access macro.
@ -111,9 +125,7 @@ extern ReadyList rlist;
* @note It is forbidden to use this macro in order to change the pointer
* (currp = something), use @p setcurrp() instead.
*/
#if !defined(PORT_OPTIMIZED_CURRP) || defined(__DOXYGEN__)
#define currp rlist.r_current
#endif /* !defined(PORT_OPTIMIZED_CURRP) */
/**
* @brief Current thread pointer change macro.
@ -122,9 +134,15 @@ extern ReadyList rlist;
*
* @notapi
*/
#if !defined(PORT_OPTIMIZED_SETCURRP) || defined(__DOXYGEN__)
#define setcurrp(tp) (currp = (tp))
#endif /* !defined(PORT_OPTIMIZED_SETCURRP) */
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#if !defined(__DOXYGEN__)
extern ready_list_t rlist;
#endif
/*
* Scheduler APIs.
@ -133,41 +151,23 @@ extern ReadyList rlist;
extern "C" {
#endif
void _scheduler_init(void);
#if !defined(PORT_OPTIMIZED_READYI)
Thread *chSchReadyI(Thread *tp);
#endif
#if !defined(PORT_OPTIMIZED_GOSLEEPS)
void chSchGoSleepS(tstate_t newstate);
#endif
#if !defined(PORT_OPTIMIZED_GOSLEEPTIMEOUTS)
msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time);
#endif
#if !defined(PORT_OPTIMIZED_WAKEUPS)
void chSchWakeupS(Thread *tp, msg_t msg);
#endif
#if !defined(PORT_OPTIMIZED_RESCHEDULES)
void chSchRescheduleS(void);
#endif
#if !defined(PORT_OPTIMIZED_ISPREEMPTIONREQUIRED)
bool_t chSchIsPreemptionRequired(void);
#endif
#if !defined(PORT_OPTIMIZED_DORESCHEDULEBEHIND) || defined(__DOXYGEN__)
bool chSchIsPreemptionRequired(void);
void chSchDoRescheduleBehind(void);
#endif
#if !defined(PORT_OPTIMIZED_DORESCHEDULEAHEAD) || defined(__DOXYGEN__)
void chSchDoRescheduleAhead(void);
#endif
#if !defined(PORT_OPTIMIZED_DORESCHEDULE)
void chSchDoReschedule(void);
#endif
#ifdef __cplusplus
}
#endif
/**
* @name Macro Functions
* @{
*/
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
/**
* @brief Determines if the current thread must reschedule.
* @details This function returns @p TRUE if there is a ready thread with
@ -175,9 +175,12 @@ extern "C" {
*
* @iclass
*/
#if !defined(PORT_OPTIMIZED_ISRESCHREQUIREDI) || defined(__DOXYGEN__)
#define chSchIsRescRequiredI() (firstprio(&rlist.r_queue) > currp->p_prio)
#endif /* !defined(PORT_OPTIMIZED_ISRESCHREQUIREDI) */
static inline bool chSchIsRescRequiredI(void) {
chDbgCheckClassI();
return firstprio(&rlist.r_queue) > currp->p_prio;
}
/**
* @brief Determines if yielding is possible.
@ -186,9 +189,12 @@ extern "C" {
*
* @sclass
*/
#if !defined(PORT_OPTIMIZED_CANYIELDS) || defined(__DOXYGEN__)
#define chSchCanYieldS() (firstprio(&rlist.r_queue) >= currp->p_prio)
#endif /* !defined(PORT_OPTIMIZED_CANYIELDS) */
static inline bool chSchCanYieldS(void) {
chDbgCheckClassI();
return firstprio(&rlist.r_queue) >= currp->p_prio;
}
/**
* @brief Yields the time slot.
@ -197,12 +203,13 @@ extern "C" {
*
* @sclass
*/
#if !defined(PORT_OPTIMIZED_DOYIELDS) || defined(__DOXYGEN__)
#define chSchDoYieldS() { \
if (chSchCanYieldS()) \
chSchDoRescheduleBehind(); \
static inline void chSchDoYieldS(void) {
chDbgCheckClassS();
if (chSchCanYieldS())
chSchDoRescheduleBehind();
}
#endif /* !defined(PORT_OPTIMIZED_DOYIELDS) */
/**
* @brief Inline-able preemption code.
@ -211,26 +218,24 @@ extern "C" {
*
* @special
*/
#if (CH_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
#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(); \
} \
}
static inline void chSchPreemption(void) {
tprio_t p1 = firstprio(&rlist.r_queue);
tprio_t p2 = currp->p_prio;
#if CH_TIME_QUANTUM > 0
if (currp->p_preempt) {
if (p1 > p2)
chSchDoRescheduleAhead();
}
else {
if (p1 >= p2)
chSchDoRescheduleBehind();
}
#else /* CH_TIME_QUANTUM == 0 */
#define chSchPreemption() { \
if (p1 >= p2) \
chSchDoRescheduleAhead(); \
}
if (p1 >= p2)
chSchDoRescheduleAhead();
#endif /* CH_TIME_QUANTUM == 0 */
/** @} */
}
#endif /* _CHSCHD_H_ */

View File

@ -23,22 +23,40 @@
* @brief Scheduler code.
*
* @addtogroup scheduler
* @details 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.
* @details This module provides the default portable scheduler code.
* @{
*/
#include "ch.h"
/*===========================================================================*/
/* Module local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
/**
* @brief Ready list header.
*/
#if !defined(PORT_OPTIMIZED_RLIST_VAR) || defined(__DOXYGEN__)
ReadyList rlist;
#endif /* !defined(PORT_OPTIMIZED_RLIST_VAR) */
ready_list_t rlist;
/*===========================================================================*/
/* Module local types. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
/**
* @brief Scheduler initialization.
@ -70,7 +88,6 @@ void _scheduler_init(void) {
*
* @iclass
*/
#if !defined(PORT_OPTIMIZED_READYI) || defined(__DOXYGEN__)
Thread *chSchReadyI(Thread *tp) {
Thread *cp;
@ -93,7 +110,6 @@ Thread *chSchReadyI(Thread *tp) {
tp->p_prev->p_next = cp->p_prev = tp;
return tp;
}
#endif /* !defined(PORT_OPTIMIZED_READYI) */
/**
* @brief Puts the current thread to sleep into the specified state.
@ -104,7 +120,6 @@ Thread *chSchReadyI(Thread *tp) {
*
* @sclass
*/
#if !defined(PORT_OPTIMIZED_GOSLEEPS) || defined(__DOXYGEN__)
void chSchGoSleepS(tstate_t newstate) {
Thread *otp;
@ -120,9 +135,7 @@ void chSchGoSleepS(tstate_t newstate) {
currp->p_state = THD_STATE_CURRENT;
chSysSwitch(currp, otp);
}
#endif /* !defined(PORT_OPTIMIZED_GOSLEEPS) */
#if !defined(PORT_OPTIMIZED_GOSLEEPTIMEOUTS) || defined(__DOXYGEN__)
/*
* Timeout wakeup callback.
*/
@ -195,7 +208,6 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) {
chSchGoSleepS(newstate);
return currp->p_u.rdymsg;
}
#endif /* !defined(PORT_OPTIMIZED_GOSLEEPTIMEOUTS) */
/**
* @brief Wakes up a thread.
@ -214,7 +226,6 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) {
*
* @sclass
*/
#if !defined(PORT_OPTIMIZED_WAKEUPS) || defined(__DOXYGEN__)
void chSchWakeupS(Thread *ntp, msg_t msg) {
chDbgCheckClassS();
@ -233,7 +244,6 @@ void chSchWakeupS(Thread *ntp, msg_t msg) {
chSysSwitch(ntp, otp);
}
}
#endif /* !defined(PORT_OPTIMIZED_WAKEUPS) */
/**
* @brief Performs a reschedule if a higher priority thread is runnable.
@ -242,7 +252,6 @@ void chSchWakeupS(Thread *ntp, msg_t msg) {
*
* @sclass
*/
#if !defined(PORT_OPTIMIZED_RESCHEDULES) || defined(__DOXYGEN__)
void chSchRescheduleS(void) {
chDbgCheckClassS();
@ -250,7 +259,6 @@ void chSchRescheduleS(void) {
if (chSchIsRescRequiredI())
chSchDoRescheduleAhead();
}
#endif /* !defined(PORT_OPTIMIZED_RESCHEDULES) */
/**
* @brief Evaluates if preemption is required.
@ -265,8 +273,7 @@ void chSchRescheduleS(void) {
*
* @special
*/
#if !defined(PORT_OPTIMIZED_ISPREEMPTIONREQUIRED) || defined(__DOXYGEN__)
bool_t chSchIsPreemptionRequired(void) {
bool chSchIsPreemptionRequired(void) {
tprio_t p1 = firstprio(&rlist.r_queue);
tprio_t p2 = currp->p_prio;
#if CH_TIME_QUANTUM > 0
@ -281,7 +288,6 @@ bool_t chSchIsPreemptionRequired(void) {
return p1 > p2;
#endif
}
#endif /* !defined(PORT_OPTIMIZED_ISPREEMPTIONREQUIRED) */
/**
* @brief Switches to the first thread on the runnable queue.
@ -293,7 +299,6 @@ bool_t chSchIsPreemptionRequired(void) {
*
* @special
*/
#if !defined(PORT_OPTIMIZED_DORESCHEDULEBEHIND) || defined(__DOXYGEN__)
void chSchDoRescheduleBehind(void) {
Thread *otp;
@ -307,7 +312,6 @@ void chSchDoRescheduleBehind(void) {
chSchReadyI(otp);
chSysSwitch(currp, otp);
}
#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEBEHIND) */
/**
* @brief Switches to the first thread on the runnable queue.
@ -318,7 +322,6 @@ void chSchDoRescheduleBehind(void) {
*
* @special
*/
#if !defined(PORT_OPTIMIZED_DORESCHEDULEAHEAD) || defined(__DOXYGEN__)
void chSchDoRescheduleAhead(void) {
Thread *otp, *cp;
@ -339,7 +342,6 @@ void chSchDoRescheduleAhead(void) {
chSysSwitch(currp, otp);
}
#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEAHEAD) */
/**
* @brief Switches to the first thread on the runnable queue.
@ -351,7 +353,6 @@ void chSchDoRescheduleAhead(void) {
*
* @special
*/
#if !defined(PORT_OPTIMIZED_DORESCHEDULE) || defined(__DOXYGEN__)
void chSchDoReschedule(void) {
#if CH_TIME_QUANTUM > 0
@ -373,6 +374,5 @@ void chSchDoReschedule(void) {
chSchDoRescheduleAhead();
#endif /* !(CH_TIME_QUANTUM > 0) */
}
#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULE) */
/** @} */

View File

@ -164,23 +164,6 @@ struct intctx {};
#endif /* defined(__DOXYGEN__) */
/**
* @brief Excludes the default @p chSchIsPreemptionRequired()implementation.
*/
#define PORT_OPTIMIZED_ISPREEMPTIONREQUIRED
#if (CH_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
/**
* @brief Inline-able version of this kernel function.
*/
#define chSchIsPreemptionRequired() \
(currp->p_preempt ? firstprio(&rlist.r_queue) > currp->p_prio : \
firstprio(&rlist.r_queue) >= currp->p_prio)
#else /* CH_TIME_QUANTUM == 0 */
#define chSchIsPreemptionRequired() \
(firstprio(&rlist.r_queue) > currp->p_prio)
#endif /* CH_TIME_QUANTUM == 0 */
#endif /* _FROM_ASM_ */
#endif /* _CHCORE_H_ */

View File

@ -633,7 +633,7 @@ ROMCONST struct testcase testbmk12 = {
static void bmk13_execute(void) {
test_print("--- System: ");
test_printn(sizeof(ReadyList) + sizeof(VTList) +
test_printn(sizeof(ready_list_t) + sizeof(VTList) +
PORT_IDLE_THREAD_STACK_SIZE +
(sizeof(Thread) + sizeof(struct intctx) +
sizeof(struct extctx) +