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

View File

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

View File

@ -164,23 +164,6 @@ struct intctx {};
#endif /* defined(__DOXYGEN__) */ #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 /* _FROM_ASM_ */
#endif /* _CHCORE_H_ */ #endif /* _CHCORE_H_ */

View File

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