From 1ea7355d85e316aadfd90468b3e808bb3dc95ee9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Aug 2009 13:07:24 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1073 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 os/kernel/src/chschd.c (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c new file mode 100644 index 000000000..3ba8b29e9 --- /dev/null +++ b/os/kernel/src/chschd.c @@ -0,0 +1,242 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file chschd.c + * @brief Scheduler code. + * @addtogroup Scheduler + * @{ + */ + +#include + +/** @cond never */ +ReadyList rlist; +/** @endcond */ + +/** + * @brief Scheduler initialization. + * + * @note Internally invoked by the @p chSysInit(). + */ +void scheduler_init(void) { + + queue_init(&rlist); + rlist.r_prio = NOPRIO; +#if CH_USE_ROUNDROBIN + rlist.r_preempt = CH_TIME_QUANTUM; +#endif +} + +/** + * @brief Inserts a thread in the Ready List. + * + * @param[in] tp the Thread to be made ready + * @return The Thread pointer. + * @note The function does not reschedule, the @p chSchRescheduleS() should + * be called soon after. + */ +#if CH_OPTIMIZE_SPEED +/* NOTE: it is inlined in this module only.*/ +INLINE Thread *chSchReadyI(Thread *tp) { +#else +Thread *chSchReadyI(Thread *tp) { +#endif + Thread *cp; + + tp->p_state = PRREADY; + cp = (Thread *)&rlist; + do { + cp = cp->p_next; + } while (cp->p_prio >= tp->p_prio); + /* Insertion on p_prev.*/ + tp->p_prev = (tp->p_next = cp)->p_prev; + tp->p_prev->p_next = cp->p_prev = tp; + return tp; +} + +/** + * @brief Puts the current thread to sleep into the specified state. + * @details The thread goes into a sleeping state. The @ref thread_states are + * described into @p threads.h. + * + * @param[in] newstate the new thread state + */ +void chSchGoSleepS(tstate_t newstate) { + Thread *otp; + + (otp = currp)->p_state = newstate; + (currp = fifo_remove((void *)&rlist))->p_state = PRCURR; +#if CH_USE_ROUNDROBIN + rlist.r_preempt = CH_TIME_QUANTUM; +#endif + chDbgTrace(otp, currp); + chSysSwitchI(otp, currp); +} + +/* + * Timeout wakeup callback. + */ +static void wakeup(void *p) { + Thread *tp = (Thread *)p; + +#if CH_USE_SEMAPHORES || CH_USE_MUTEXES || CH_USE_CONDVARS + switch (tp->p_state) { +#if CH_USE_SEMAPHORES + case PRWTSEM: + chSemFastSignalI(tp->p_wtsemp); + /* Falls into, intentional. */ +#endif +#if CH_USE_MUTEXES + case PRWTMTX: +#endif +#if CH_USE_CONDVARS + case PRWTCOND: +#endif + /* States requiring dequeuing. */ + dequeue(tp); + } +#endif + chSchReadyI(tp)->p_rdymsg = RDY_TIMEOUT; +} + +/** + * @brief Puts the current thread to sleep into the specified state with + * timeout specification. + * @details The thread goes into a sleeping state, if it is not awakened + * explicitly within the specified timeout then it is forcibly + * awakened with a @p RDY_TIMEOUT low level message. The @ref + * thread_states are described into @p threads.h. + * + * @param[in] newstate the new thread state + * @param[in] time the number of ticks before the operation timeouts, the + * special values are handled as follow: + * - @a TIME_INFINITE the thread enters an infinite sleep + * state, this is equivalent to invoking @p chSchGoSleepS() + * but, of course, less efficient. + * - @a TIME_IMMEDIATE this value is accepted but interpreted + * as a normal time specification not as an immediate timeout + * specification. + * . + * @return The wakeup message. + * @retval RDY_TIMEOUT if a timeout occurs. + */ +msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { + + if (TIME_INFINITE != time) { + VirtualTimer vt; + + chVTSetI(&vt, time, wakeup, currp); + chSchGoSleepS(newstate); + if (chVTIsArmedI(&vt)) + chVTResetI(&vt); + } + else + chSchGoSleepS(newstate); + return currp->p_rdymsg; +} + +/** + * @brief Wakes up a thread. + * @details The thread is inserted into the ready list or immediately made + * running depending on its relative priority compared to the current + * thread. + * + * @param[in] ntp the Thread to be made ready + * @param[in] msg message to the awakened thread + * @note It is equivalent to a @p chSchReadyI() followed by a + * @p chSchRescheduleS() but much more efficient. + */ +void chSchWakeupS(Thread *ntp, msg_t msg) { + + ntp->p_rdymsg = msg; + /* If the waken thread has a not-greater priority than the current + * one then it is just inserted in the ready list else it made + * running immediately and the invoking thread goes in the ready + * list instead.*/ + if (ntp->p_prio <= currp->p_prio) + chSchReadyI(ntp); + else { + Thread *otp = currp; + chSchReadyI(otp); + (currp = ntp)->p_state = PRCURR; +#if CH_USE_ROUNDROBIN + rlist.r_preempt = CH_TIME_QUANTUM; +#endif + chDbgTrace(otp, ntp); + chSysSwitchI(otp, ntp); + } +} + +/** + * @brief Switches to the first thread on the runnable queue. + * + * @note It is intended to be called if @p chSchRescRequiredI() evaluates to + * @p TRUE. + */ +void chSchDoRescheduleI(void) { + + Thread *otp = currp; + /* pick the first thread from the ready queue and makes it current */ + (currp = fifo_remove((void *)&rlist))->p_state = PRCURR; + chSchReadyI(otp); +#if CH_USE_ROUNDROBIN + rlist.r_preempt = CH_TIME_QUANTUM; +#endif + chDbgTrace(otp, currp); + chSysSwitchI(otp, currp); +} + +/** + * @brief Performs a reschedulation if a higher priority thread is runnable. + * @details If a thread with a higher priority than the current thread is in + * the ready list then make the higher priority thread running. + */ +void chSchRescheduleS(void) { + /* first thread in the runnable queue has higher priority than the running + * thread? */ + if (firstprio(&rlist) > currp->p_prio) + chSchDoRescheduleI(); +} + +/** + * @brief Evaluates if a reschedulation is required. + * @details The decision is taken by comparing the relative priorities and + * depending on the state of the round robin timeout counter. + * + * @retval TRUE if there is a thread that should go in running state. + * @retval FALSE if a reschedulation is not required. + */ +bool_t chSchRescRequiredI(void) { + tprio_t p1 = firstprio(&rlist); + tprio_t p2 = currp->p_prio; +#if CH_USE_ROUNDROBIN + /* If the running thread has not reached its time quantum, reschedule only + * if the first thread on the ready queue has a higher priority. + * Otherwise, if the running thread has used up its time quantum, reschedule + * if the first thread on the ready queue has equal or higher priority.*/ + return rlist.r_preempt ? p1 > p2 : p1 >= p2; +#else + /* If the round robin feature is not enabled then performs a simpler + * comparison.*/ + return p1 > p2; +#endif +} + +/** @} */ -- cgit v1.2.3 From c4299aa2dac83bfe3cee1bf65bfa4ee9f84233bd Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 28 Aug 2009 11:54:36 +0000 Subject: Fixed bug 2846162. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1110 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 3ba8b29e9..846833286 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -138,18 +138,19 @@ static void wakeup(void *p) { * @retval RDY_TIMEOUT if a timeout occurs. */ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { + Thread *tp = currp; if (TIME_INFINITE != time) { VirtualTimer vt; - chVTSetI(&vt, time, wakeup, currp); + chVTSetI(&vt, time, wakeup, tp); chSchGoSleepS(newstate); if (chVTIsArmedI(&vt)) chVTResetI(&vt); } else chSchGoSleepS(newstate); - return currp->p_rdymsg; + return tp->p_rdymsg; } /** -- cgit v1.2.3 From 1ce340b59e0b68f7bf868914af3701b408bd1820 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 28 Aug 2009 14:53:54 +0000 Subject: Better fix for bug 2846162. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1112 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 846833286..3ba8b29e9 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -138,19 +138,18 @@ static void wakeup(void *p) { * @retval RDY_TIMEOUT if a timeout occurs. */ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { - Thread *tp = currp; if (TIME_INFINITE != time) { VirtualTimer vt; - chVTSetI(&vt, time, wakeup, tp); + chVTSetI(&vt, time, wakeup, currp); chSchGoSleepS(newstate); if (chVTIsArmedI(&vt)) chVTResetI(&vt); } else chSchGoSleepS(newstate); - return tp->p_rdymsg; + return currp->p_rdymsg; } /** -- cgit v1.2.3 From 219d8d1ec90984f9b00dcbad070895577172aee0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 28 Aug 2009 16:10:40 +0000 Subject: Fixed more warnings from GCC 4.4.x. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1116 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 3ba8b29e9..76464d603 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -37,7 +37,7 @@ ReadyList rlist; */ void scheduler_init(void) { - queue_init(&rlist); + queue_init(&rlist.r_queue); rlist.r_prio = NOPRIO; #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; @@ -82,7 +82,7 @@ void chSchGoSleepS(tstate_t newstate) { Thread *otp; (otp = currp)->p_state = newstate; - (currp = fifo_remove((void *)&rlist))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; #endif @@ -194,7 +194,7 @@ void chSchDoRescheduleI(void) { Thread *otp = currp; /* pick the first thread from the ready queue and makes it current */ - (currp = fifo_remove((void *)&rlist))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; chSchReadyI(otp); #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; @@ -211,7 +211,7 @@ void chSchDoRescheduleI(void) { void chSchRescheduleS(void) { /* first thread in the runnable queue has higher priority than the running * thread? */ - if (firstprio(&rlist) > currp->p_prio) + if (firstprio(&rlist.r_queue) > currp->p_prio) chSchDoRescheduleI(); } @@ -224,7 +224,7 @@ void chSchRescheduleS(void) { * @retval FALSE if a reschedulation is not required. */ bool_t chSchRescRequiredI(void) { - tprio_t p1 = firstprio(&rlist); + tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; #if CH_USE_ROUNDROBIN /* If the running thread has not reached its time quantum, reschedule only -- cgit v1.2.3 From 397ccffac55ffd139d0e3e82add83e51413c1347 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 30 Aug 2009 06:59:43 +0000 Subject: Documentation reorganization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1133 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 76464d603..af24f5cf4 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -20,7 +20,7 @@ /** * @file chschd.c * @brief Scheduler code. - * @addtogroup Scheduler + * @addtogroup scheduler * @{ */ -- cgit v1.2.3 From 7dfa36f86d896cdb824a9137a81f324c8243c4d9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 5 Sep 2009 15:31:27 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1148 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index af24f5cf4..6183180bc 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -211,7 +211,7 @@ void chSchDoRescheduleI(void) { void chSchRescheduleS(void) { /* first thread in the runnable queue has higher priority than the running * thread? */ - if (firstprio(&rlist.r_queue) > currp->p_prio) + if (chSchMustRescheduleS()) chSchDoRescheduleI(); } -- cgit v1.2.3 From 5d2ad7ce56f9efaba58104c60690a0d076236004 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 6 Sep 2009 08:52:46 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1151 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 55 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 6183180bc..929f114e5 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -61,7 +61,7 @@ Thread *chSchReadyI(Thread *tp) { Thread *cp; tp->p_state = PRREADY; - cp = (Thread *)&rlist; + cp = (Thread *)&rlist.r_queue; do { cp = cp->p_next; } while (cp->p_prio >= tp->p_prio); @@ -71,6 +71,22 @@ Thread *chSchReadyI(Thread *tp) { return tp; } +#if 0 +INLINE Thread *chSchReadyReverseI(Thread *tp) { + Thread *cp; + + tp->p_state = PRREADY; + cp = (Thread *)&rlist.r_queue; + do { + cp = cp->p_prev; + } while ((cp->p_prio < tp->p_prio) && (cp->p_prio < tp->p_prio)); + /* Insertion on p_next.*/ + tp->p_next = (tp->p_prev = cp)->p_next; + tp->p_next->p_prev = cp->p_next = tp; + return tp; +} +#endif + /** * @brief Puts the current thread to sleep into the specified state. * @details The thread goes into a sleeping state. The @ref thread_states are @@ -109,7 +125,7 @@ static void wakeup(void *p) { #if CH_USE_CONDVARS case PRWTCOND: #endif - /* States requiring dequeuing. */ + /* States requiring dequeuing.*/ dequeue(tp); } #endif @@ -193,7 +209,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { void chSchDoRescheduleI(void) { Thread *otp = currp; - /* pick the first thread from the ready queue and makes it current */ + /* Pick the first thread from the ready queue and makes it current.*/ (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; chSchReadyI(otp); #if CH_USE_ROUNDROBIN @@ -209,8 +225,8 @@ void chSchDoRescheduleI(void) { * the ready list then make the higher priority thread running. */ void chSchRescheduleS(void) { - /* first thread in the runnable queue has higher priority than the running - * thread? */ + /* First thread in the runnable queue has higher priority than the running + * thread?.*/ if (chSchMustRescheduleS()) chSchDoRescheduleI(); } @@ -239,4 +255,33 @@ bool_t chSchRescRequiredI(void) { #endif } +#if CH_USE_ROUNDROBIN +void chSchDoYieldS(void) { + + if (chSchCanYieldS()) { + Thread *cp = (Thread *)&rlist.r_queue; + Thread *otp = currp; + + /* + * Note, the following insertion code works because we know that on the + * ready list there is at least one thread with priority equal or higher + * than the current one. + */ + otp->p_state = PRREADY; + do { + cp = cp->p_prev; + } while (cp->p_prio < otp->p_prio); + /* Insertion on p_next.*/ + otp->p_next = (otp->p_prev = cp)->p_next; + otp->p_next->p_prev = cp->p_next = otp; + + /* Pick the first thread from the ready queue and makes it current.*/ + (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; + rlist.r_preempt = CH_TIME_QUANTUM; + chDbgTrace(otp, currp); + chSysSwitchI(otp, currp); + } +} +#endif /* CH_USE_ROUNDROBIN */ + /** @} */ -- cgit v1.2.3 From 7f7253bec22642ead836cb47fbca3caba57042a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 6 Sep 2009 09:53:29 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1152 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 929f114e5..7ab32f068 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -71,22 +71,6 @@ Thread *chSchReadyI(Thread *tp) { return tp; } -#if 0 -INLINE Thread *chSchReadyReverseI(Thread *tp) { - Thread *cp; - - tp->p_state = PRREADY; - cp = (Thread *)&rlist.r_queue; - do { - cp = cp->p_prev; - } while ((cp->p_prio < tp->p_prio) && (cp->p_prio < tp->p_prio)); - /* Insertion on p_next.*/ - tp->p_next = (tp->p_prev = cp)->p_next; - tp->p_next->p_prev = cp->p_next = tp; - return tp; -} -#endif - /** * @brief Puts the current thread to sleep into the specified state. * @details The thread goes into a sleeping state. The @ref thread_states are -- cgit v1.2.3 From 1f2dd43b3ebca18d849527e1be6f93d473298677 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 6 Sep 2009 16:50:07 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1155 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 7ab32f068..093a1a0c0 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -162,6 +162,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { * @param[in] msg message to the awakened thread * @note It is equivalent to a @p chSchReadyI() followed by a * @p chSchRescheduleS() but much more efficient. + * @note The function assumes that the current thread has the highest priority */ void chSchWakeupS(Thread *ntp, msg_t msg) { @@ -175,10 +176,17 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { else { Thread *otp = currp; chSchReadyI(otp); - (currp = ntp)->p_state = PRCURR; #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; #endif +#if 0 + /* Shortcut for when the round robin scheduling is not enabled.*/ + otp->p_state = PRREADY; + /* Direct insertion on top of the ready list, no scanning.*/ + otp->p_next = rlist.r_queue.p_next->p_next; + otp->p_next->p_prev = rlist.r_queue.p_next = otp; +#endif + (currp = ntp)->p_state = PRCURR; chDbgTrace(otp, ntp); chSysSwitchI(otp, ntp); } -- cgit v1.2.3 From af8d2e36166b5c13f795c361752c6c6988947d11 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 6 Sep 2009 17:54:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1156 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 093a1a0c0..1f7e27c93 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -178,13 +178,6 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { chSchReadyI(otp); #if CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; -#endif -#if 0 - /* Shortcut for when the round robin scheduling is not enabled.*/ - otp->p_state = PRREADY; - /* Direct insertion on top of the ready list, no scanning.*/ - otp->p_next = rlist.r_queue.p_next->p_next; - otp->p_next->p_prev = rlist.r_queue.p_next = otp; #endif (currp = ntp)->p_state = PRCURR; chDbgTrace(otp, ntp); -- cgit v1.2.3 From c5496788e53c99371c2f4a36c67dcbf556176398 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 13 Sep 2009 09:38:59 +0000 Subject: Cortex-M3 related improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1161 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 1f7e27c93..08ecf46a0 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -210,8 +210,7 @@ void chSchDoRescheduleI(void) { * the ready list then make the higher priority thread running. */ void chSchRescheduleS(void) { - /* First thread in the runnable queue has higher priority than the running - * thread?.*/ + if (chSchMustRescheduleS()) chSchDoRescheduleI(); } -- cgit v1.2.3 From d688b84d2585d3bedbd682417313bcb581b1a1fc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 13 Sep 2009 12:06:08 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1162 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 08ecf46a0..7c65e3fd6 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -211,7 +211,7 @@ void chSchDoRescheduleI(void) { */ void chSchRescheduleS(void) { - if (chSchMustRescheduleS()) + if (chSchIsRescRequiredI()) chSchDoRescheduleI(); } @@ -222,8 +222,11 @@ void chSchRescheduleS(void) { * * @retval TRUE if there is a thread that should go in running state. * @retval FALSE if a reschedulation is not required. + * + * @note This function is meant to be used in the timer interrupt handler + * where @p chVTDoTickI() is invoked. */ -bool_t chSchRescRequiredI(void) { +bool_t chSchIsRescRequiredExI(void) { tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; #if CH_USE_ROUNDROBIN -- cgit v1.2.3 From 404fe109397d80016f71c57f42ee6cd0cbfe96d1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 17 Oct 2009 15:42:19 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1236 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 7c65e3fd6..150169481 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -39,7 +39,7 @@ void scheduler_init(void) { queue_init(&rlist.r_queue); rlist.r_prio = NOPRIO; -#if CH_USE_ROUNDROBIN +#if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif } @@ -83,7 +83,7 @@ void chSchGoSleepS(tstate_t newstate) { (otp = currp)->p_state = newstate; (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; -#if CH_USE_ROUNDROBIN +#if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif chDbgTrace(otp, currp); @@ -176,7 +176,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { else { Thread *otp = currp; chSchReadyI(otp); -#if CH_USE_ROUNDROBIN +#if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif (currp = ntp)->p_state = PRCURR; @@ -197,7 +197,7 @@ void chSchDoRescheduleI(void) { /* Pick the first thread from the ready queue and makes it current.*/ (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; chSchReadyI(otp); -#if CH_USE_ROUNDROBIN +#if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif chDbgTrace(otp, currp); @@ -229,7 +229,7 @@ void chSchRescheduleS(void) { bool_t chSchIsRescRequiredExI(void) { tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; -#if CH_USE_ROUNDROBIN +#if CH_TIME_QUANTUM > 0 /* If the running thread has not reached its time quantum, reschedule only * if the first thread on the ready queue has a higher priority. * Otherwise, if the running thread has used up its time quantum, reschedule @@ -242,7 +242,11 @@ bool_t chSchIsRescRequiredExI(void) { #endif } -#if CH_USE_ROUNDROBIN +/** + * @brief Yields the time slot. + * @details Yields the CPU control to the next thread in the ready list with + * equal priority, if any. + */ void chSchDoYieldS(void) { if (chSchCanYieldS()) { @@ -269,6 +273,5 @@ void chSchDoYieldS(void) { chSysSwitchI(otp, currp); } } -#endif /* CH_USE_ROUNDROBIN */ /** @} */ -- cgit v1.2.3 From 43f9fd4180030081daae9122bd57a521ec9c58e1 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 30 Oct 2009 15:45:38 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1258 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 150169481..87c2e2f8c 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -268,7 +268,9 @@ void chSchDoYieldS(void) { /* Pick the first thread from the ready queue and makes it current.*/ (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; +#if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; +#endif chDbgTrace(otp, currp); chSysSwitchI(otp, currp); } -- cgit v1.2.3 From bdb7f4ab20bd3daf261ab93dfe733e0ff11dca0f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Dec 2009 17:37:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1397 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 87c2e2f8c..15f7a1a16 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -24,7 +24,7 @@ * @{ */ -#include +#include "ch.h" /** @cond never */ ReadyList rlist; -- cgit v1.2.3 From 7bd8164f8ff6ffd0a9458d44e18097582adae201 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 20 Jan 2010 14:39:34 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1532 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 15f7a1a16..f7be9c6a8 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -60,7 +60,7 @@ Thread *chSchReadyI(Thread *tp) { #endif Thread *cp; - tp->p_state = PRREADY; + tp->p_state = THD_STATE_READY; cp = (Thread *)&rlist.r_queue; do { cp = cp->p_next; @@ -82,7 +82,7 @@ void chSchGoSleepS(tstate_t newstate) { Thread *otp; (otp = currp)->p_state = newstate; - (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif @@ -99,21 +99,21 @@ static void wakeup(void *p) { #if CH_USE_SEMAPHORES || CH_USE_MUTEXES || CH_USE_CONDVARS switch (tp->p_state) { #if CH_USE_SEMAPHORES - case PRWTSEM: - chSemFastSignalI(tp->p_wtsemp); + case THD_STATE_WTSEM: + chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); /* Falls into, intentional. */ #endif #if CH_USE_MUTEXES - case PRWTMTX: + case THD_STATE_WTMTX: #endif #if CH_USE_CONDVARS - case PRWTCOND: + case THD_STATE_WTCOND: #endif /* States requiring dequeuing.*/ dequeue(tp); } #endif - chSchReadyI(tp)->p_rdymsg = RDY_TIMEOUT; + chSchReadyI(tp)->p_u.rdymsg = RDY_TIMEOUT; } /** @@ -149,7 +149,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { } else chSchGoSleepS(newstate); - return currp->p_rdymsg; + return currp->p_u.rdymsg; } /** @@ -166,7 +166,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { */ void chSchWakeupS(Thread *ntp, msg_t msg) { - ntp->p_rdymsg = msg; + ntp->p_u.rdymsg = msg; /* If the waken thread has a not-greater priority than the current * one then it is just inserted in the ready list else it made * running immediately and the invoking thread goes in the ready @@ -179,7 +179,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif - (currp = ntp)->p_state = PRCURR; + (currp = ntp)->p_state = THD_STATE_CURRENT; chDbgTrace(otp, ntp); chSysSwitchI(otp, ntp); } @@ -195,7 +195,7 @@ void chSchDoRescheduleI(void) { Thread *otp = currp; /* Pick the first thread from the ready queue and makes it current.*/ - (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; chSchReadyI(otp); #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; @@ -258,7 +258,7 @@ void chSchDoYieldS(void) { * ready list there is at least one thread with priority equal or higher * than the current one. */ - otp->p_state = PRREADY; + otp->p_state = THD_STATE_READY; do { cp = cp->p_prev; } while (cp->p_prio < otp->p_prio); @@ -267,7 +267,7 @@ void chSchDoYieldS(void) { otp->p_next->p_prev = cp->p_next = otp; /* Pick the first thread from the ready queue and makes it current.*/ - (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif -- cgit v1.2.3 From e515bcf581c92643c21eb6ed53ba0d0b1604fe4b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 2 Feb 2010 20:20:12 +0000 Subject: Implemented registry subsystem (still in progress). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1558 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index f7be9c6a8..5b4d18133 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -26,9 +26,10 @@ #include "ch.h" -/** @cond never */ +/** + * @brief Ready list header. + */ ReadyList rlist; -/** @endcond */ /** * @brief Scheduler initialization. @@ -42,6 +43,9 @@ void scheduler_init(void) { #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif +#if CH_USE_REGISTRY + rlist.p_newer = rlist.p_older = (Thread *)&rlist; +#endif } /** -- cgit v1.2.3 From f17db1931e95f5ebb42f557b6eead2bf1320db5a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 6 Feb 2010 10:55:53 +0000 Subject: Reformatted doxygen tags into the kernel sources to make them more readable. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1567 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 111 ++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 57 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 5b4d18133..5bd016226 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -18,8 +18,9 @@ */ /** - * @file chschd.c - * @brief Scheduler code. + * @file chschd.c + * @brief Scheduler code. + * * @addtogroup scheduler * @{ */ @@ -27,14 +28,13 @@ #include "ch.h" /** - * @brief Ready list header. + * @brief Ready list header. */ ReadyList rlist; /** - * @brief Scheduler initialization. - * - * @note Internally invoked by the @p chSysInit(). + * @brief Scheduler initialization. + * @note Internally invoked by the @p chSysInit(), not an API. */ void scheduler_init(void) { @@ -49,12 +49,12 @@ void scheduler_init(void) { } /** - * @brief Inserts a thread in the Ready List. + * @brief Inserts a thread in the Ready List. + * @note The function does not reschedule, the @p chSchRescheduleS() should + * be called soon after. * - * @param[in] tp the Thread to be made ready - * @return The Thread pointer. - * @note The function does not reschedule, the @p chSchRescheduleS() should - * be called soon after. + * @param[in] tp the Thread to be made ready + * @return The Thread pointer. */ #if CH_OPTIMIZE_SPEED /* NOTE: it is inlined in this module only.*/ @@ -76,11 +76,11 @@ Thread *chSchReadyI(Thread *tp) { } /** - * @brief Puts the current thread to sleep into the specified state. + * @brief Puts the current thread to sleep into the specified state. * @details The thread goes into a sleeping state. The @ref thread_states are * described into @p threads.h. * - * @param[in] newstate the new thread state + * @param[in] newstate the new thread state */ void chSchGoSleepS(tstate_t newstate) { Thread *otp; @@ -121,24 +121,24 @@ static void wakeup(void *p) { } /** - * @brief Puts the current thread to sleep into the specified state with - * timeout specification. + * @brief Puts the current thread to sleep into the specified state with + * timeout specification. * @details The thread goes into a sleeping state, if it is not awakened * explicitly within the specified timeout then it is forcibly * awakened with a @p RDY_TIMEOUT low level message. The @ref * thread_states are described into @p threads.h. * - * @param[in] newstate the new thread state - * @param[in] time the number of ticks before the operation timeouts, the - * special values are handled as follow: - * - @a TIME_INFINITE the thread enters an infinite sleep - * state, this is equivalent to invoking @p chSchGoSleepS() - * but, of course, less efficient. - * - @a TIME_IMMEDIATE this value is accepted but interpreted - * as a normal time specification not as an immediate timeout - * specification. - * . - * @return The wakeup message. + * @param[in] newstate the new thread state + * @param[in] time the number of ticks before the operation timeouts, the + * special values are handled as follow: + * - @a TIME_INFINITE the thread enters an infinite sleep + * state, this is equivalent to invoking + * @p chSchGoSleepS() but, of course, less efficient. + * - @a TIME_IMMEDIATE this value is accepted but + * interpreted as a normal time specification not as an + * immediate timeout specification. + * . + * @return The wakeup message. * @retval RDY_TIMEOUT if a timeout occurs. */ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { @@ -157,24 +157,25 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { } /** - * @brief Wakes up a thread. + * @brief Wakes up a thread. * @details 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 @p chSchReadyI() followed by a + * @p chSchRescheduleS() but much more efficient. + * @note The function assumes that the current thread has the highest + * priority. * - * @param[in] ntp the Thread to be made ready - * @param[in] msg message to the awakened thread - * @note It is equivalent to a @p chSchReadyI() followed by a - * @p chSchRescheduleS() but much more efficient. - * @note The function assumes that the current thread has the highest priority + * @param[in] ntp the Thread to be made ready + * @param[in] msg message to the awakened thread */ void chSchWakeupS(Thread *ntp, msg_t msg) { ntp->p_u.rdymsg = msg; /* If the waken thread has a not-greater priority than the current - * one then it is just inserted in the ready list else it made - * running immediately and the invoking thread goes in the ready - * list instead.*/ + one then it is just inserted in the ready list else it made + running immediately and the invoking thread goes in the ready + list instead.*/ if (ntp->p_prio <= currp->p_prio) chSchReadyI(ntp); else { @@ -190,10 +191,9 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { } /** - * @brief Switches to the first thread on the runnable queue. - * - * @note It is intended to be called if @p chSchRescRequiredI() evaluates to - * @p TRUE. + * @brief Switches to the first thread on the runnable queue. + * @note It is intended to be called if @p chSchRescRequiredI() evaluates + * to @p TRUE. */ void chSchDoRescheduleI(void) { @@ -209,7 +209,7 @@ void chSchDoRescheduleI(void) { } /** - * @brief Performs a reschedulation if a higher priority thread is runnable. + * @brief Performs a reschedulation if a higher priority thread is runnable. * @details If a thread with a higher priority than the current thread is in * the ready list then make the higher priority thread running. */ @@ -220,34 +220,33 @@ void chSchRescheduleS(void) { } /** - * @brief Evaluates if a reschedulation is required. + * @brief Evaluates if a reschedulation is required. * @details 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 @p chVTDoTickI() is invoked. * - * @retval TRUE if there is a thread that should go in running state. - * @retval FALSE if a reschedulation is not required. - * - * @note This function is meant to be used in the timer interrupt handler - * where @p chVTDoTickI() is invoked. + * @retval TRUE if there is a thread that should go in running state. + * @retval FALSE if a reschedulation is not required. */ bool_t chSchIsRescRequiredExI(void) { tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; #if CH_TIME_QUANTUM > 0 /* If the running thread has not reached its time quantum, reschedule only - * if the first thread on the ready queue has a higher priority. - * Otherwise, if the running thread has used up its time quantum, reschedule - * if the first thread on the ready queue has equal or higher priority.*/ + if the first thread on the ready queue has a higher priority. + Otherwise, if the running thread has used up its time quantum, reschedule + if the first thread on the ready queue has equal or higher priority.*/ return rlist.r_preempt ? p1 > p2 : p1 >= p2; #else - /* If the round robin feature is not enabled then performs a simpler - * comparison.*/ + /* If the round robin preemption feature is not enabled then performs a + simpler comparison.*/ return p1 > p2; #endif } /** - * @brief Yields the time slot. + * @brief Yields the time slot. * @details Yields the CPU control to the next thread in the ready list with * equal priority, if any. */ @@ -257,11 +256,9 @@ void chSchDoYieldS(void) { Thread *cp = (Thread *)&rlist.r_queue; Thread *otp = currp; - /* - * Note, the following insertion code works because we know that on the - * ready list there is at least one thread with priority equal or higher - * than the current one. - */ + /* Note, the following insertion code works because we know that on the + ready list there is at least one thread with priority equal or higher + than the current one.*/ otp->p_state = THD_STATE_READY; do { cp = cp->p_prev; -- cgit v1.2.3 From 157b6f9695e7f72f2d54b231c19cb4045710ed01 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Feb 2010 07:24:53 +0000 Subject: Updated license dates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1646 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 560 ++++++++++++++++++++++++------------------------- 1 file changed, 280 insertions(+), 280 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 5bd016226..8cfd5cd81 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -1,280 +1,280 @@ -/* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chschd.c - * @brief Scheduler code. - * - * @addtogroup scheduler - * @{ - */ - -#include "ch.h" - -/** - * @brief Ready list header. - */ -ReadyList rlist; - -/** - * @brief Scheduler initialization. - * @note Internally invoked by the @p chSysInit(), not an API. - */ -void scheduler_init(void) { - - queue_init(&rlist.r_queue); - rlist.r_prio = NOPRIO; -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif -#if CH_USE_REGISTRY - rlist.p_newer = rlist.p_older = (Thread *)&rlist; -#endif -} - -/** - * @brief Inserts a thread in the Ready List. - * @note The function does not reschedule, the @p chSchRescheduleS() should - * be called soon after. - * - * @param[in] tp the Thread to be made ready - * @return The Thread pointer. - */ -#if CH_OPTIMIZE_SPEED -/* NOTE: it is inlined in this module only.*/ -INLINE Thread *chSchReadyI(Thread *tp) { -#else -Thread *chSchReadyI(Thread *tp) { -#endif - Thread *cp; - - tp->p_state = THD_STATE_READY; - cp = (Thread *)&rlist.r_queue; - do { - cp = cp->p_next; - } while (cp->p_prio >= tp->p_prio); - /* Insertion on p_prev.*/ - tp->p_prev = (tp->p_next = cp)->p_prev; - tp->p_prev->p_next = cp->p_prev = tp; - return tp; -} - -/** - * @brief Puts the current thread to sleep into the specified state. - * @details The thread goes into a sleeping state. The @ref thread_states are - * described into @p threads.h. - * - * @param[in] newstate the new thread state - */ -void chSchGoSleepS(tstate_t newstate) { - Thread *otp; - - (otp = currp)->p_state = newstate; - (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif - chDbgTrace(otp, currp); - chSysSwitchI(otp, currp); -} - -/* - * Timeout wakeup callback. - */ -static void wakeup(void *p) { - Thread *tp = (Thread *)p; - -#if CH_USE_SEMAPHORES || CH_USE_MUTEXES || CH_USE_CONDVARS - switch (tp->p_state) { -#if CH_USE_SEMAPHORES - case THD_STATE_WTSEM: - chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); - /* Falls into, intentional. */ -#endif -#if CH_USE_MUTEXES - case THD_STATE_WTMTX: -#endif -#if CH_USE_CONDVARS - case THD_STATE_WTCOND: -#endif - /* States requiring dequeuing.*/ - dequeue(tp); - } -#endif - chSchReadyI(tp)->p_u.rdymsg = RDY_TIMEOUT; -} - -/** - * @brief Puts the current thread to sleep into the specified state with - * timeout specification. - * @details The thread goes into a sleeping state, if it is not awakened - * explicitly within the specified timeout then it is forcibly - * awakened with a @p RDY_TIMEOUT low level message. The @ref - * thread_states are described into @p threads.h. - * - * @param[in] newstate the new thread state - * @param[in] time the number of ticks before the operation timeouts, the - * special values are handled as follow: - * - @a TIME_INFINITE the thread enters an infinite sleep - * state, this is equivalent to invoking - * @p chSchGoSleepS() but, of course, less efficient. - * - @a TIME_IMMEDIATE this value is accepted but - * interpreted as a normal time specification not as an - * immediate timeout specification. - * . - * @return The wakeup message. - * @retval RDY_TIMEOUT if a timeout occurs. - */ -msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { - - if (TIME_INFINITE != time) { - VirtualTimer vt; - - chVTSetI(&vt, time, wakeup, currp); - chSchGoSleepS(newstate); - if (chVTIsArmedI(&vt)) - chVTResetI(&vt); - } - else - chSchGoSleepS(newstate); - return currp->p_u.rdymsg; -} - -/** - * @brief Wakes up a thread. - * @details 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 @p chSchReadyI() followed by a - * @p chSchRescheduleS() but much more efficient. - * @note The function assumes that the current thread has the highest - * priority. - * - * @param[in] ntp the Thread to be made ready - * @param[in] msg message to the awakened thread - */ -void chSchWakeupS(Thread *ntp, msg_t msg) { - - ntp->p_u.rdymsg = msg; - /* If the waken thread has a not-greater priority than the current - one then it is just inserted in the ready list else it made - running immediately and the invoking thread goes in the ready - list instead.*/ - if (ntp->p_prio <= currp->p_prio) - chSchReadyI(ntp); - else { - Thread *otp = currp; - chSchReadyI(otp); -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif - (currp = ntp)->p_state = THD_STATE_CURRENT; - chDbgTrace(otp, ntp); - chSysSwitchI(otp, ntp); - } -} - -/** - * @brief Switches to the first thread on the runnable queue. - * @note It is intended to be called if @p chSchRescRequiredI() evaluates - * to @p TRUE. - */ -void chSchDoRescheduleI(void) { - - Thread *otp = currp; - /* Pick the first thread from the ready queue and makes it current.*/ - (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; - chSchReadyI(otp); -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif - chDbgTrace(otp, currp); - chSysSwitchI(otp, currp); -} - -/** - * @brief Performs a reschedulation if a higher priority thread is runnable. - * @details If a thread with a higher priority than the current thread is in - * the ready list then make the higher priority thread running. - */ -void chSchRescheduleS(void) { - - if (chSchIsRescRequiredI()) - chSchDoRescheduleI(); -} - -/** - * @brief Evaluates if a reschedulation is required. - * @details 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 @p chVTDoTickI() is invoked. - * - * @retval TRUE if there is a thread that should go in running state. - * @retval FALSE if a reschedulation is not required. - */ -bool_t chSchIsRescRequiredExI(void) { - tprio_t p1 = firstprio(&rlist.r_queue); - tprio_t p2 = currp->p_prio; -#if CH_TIME_QUANTUM > 0 - /* If the running thread has not reached its time quantum, reschedule only - if the first thread on the ready queue has a higher priority. - Otherwise, if the running thread has used up its time quantum, reschedule - if the first thread on the ready queue has equal or higher priority.*/ - return rlist.r_preempt ? p1 > p2 : p1 >= p2; -#else - /* If the round robin preemption feature is not enabled then performs a - simpler comparison.*/ - return p1 > p2; -#endif -} - -/** - * @brief Yields the time slot. - * @details Yields the CPU control to the next thread in the ready list with - * equal priority, if any. - */ -void chSchDoYieldS(void) { - - if (chSchCanYieldS()) { - Thread *cp = (Thread *)&rlist.r_queue; - Thread *otp = currp; - - /* Note, the following insertion code works because we know that on the - ready list there is at least one thread with priority equal or higher - than the current one.*/ - otp->p_state = THD_STATE_READY; - do { - cp = cp->p_prev; - } while (cp->p_prio < otp->p_prio); - /* Insertion on p_next.*/ - otp->p_next = (otp->p_prev = cp)->p_next; - otp->p_next->p_prev = cp->p_next = otp; - - /* Pick the first thread from the ready queue and makes it current.*/ - (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif - chDbgTrace(otp, currp); - chSysSwitchI(otp, currp); - } -} - -/** @} */ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file chschd.c + * @brief Scheduler code. + * + * @addtogroup scheduler + * @{ + */ + +#include "ch.h" + +/** + * @brief Ready list header. + */ +ReadyList rlist; + +/** + * @brief Scheduler initialization. + * @note Internally invoked by the @p chSysInit(), not an API. + */ +void scheduler_init(void) { + + queue_init(&rlist.r_queue); + rlist.r_prio = NOPRIO; +#if CH_TIME_QUANTUM > 0 + rlist.r_preempt = CH_TIME_QUANTUM; +#endif +#if CH_USE_REGISTRY + rlist.p_newer = rlist.p_older = (Thread *)&rlist; +#endif +} + +/** + * @brief Inserts a thread in the Ready List. + * @note The function does not reschedule, the @p chSchRescheduleS() should + * be called soon after. + * + * @param[in] tp the Thread to be made ready + * @return The Thread pointer. + */ +#if CH_OPTIMIZE_SPEED +/* NOTE: it is inlined in this module only.*/ +INLINE Thread *chSchReadyI(Thread *tp) { +#else +Thread *chSchReadyI(Thread *tp) { +#endif + Thread *cp; + + tp->p_state = THD_STATE_READY; + cp = (Thread *)&rlist.r_queue; + do { + cp = cp->p_next; + } while (cp->p_prio >= tp->p_prio); + /* Insertion on p_prev.*/ + tp->p_prev = (tp->p_next = cp)->p_prev; + tp->p_prev->p_next = cp->p_prev = tp; + return tp; +} + +/** + * @brief Puts the current thread to sleep into the specified state. + * @details The thread goes into a sleeping state. The @ref thread_states are + * described into @p threads.h. + * + * @param[in] newstate the new thread state + */ +void chSchGoSleepS(tstate_t newstate) { + Thread *otp; + + (otp = currp)->p_state = newstate; + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; +#if CH_TIME_QUANTUM > 0 + rlist.r_preempt = CH_TIME_QUANTUM; +#endif + chDbgTrace(otp, currp); + chSysSwitchI(otp, currp); +} + +/* + * Timeout wakeup callback. + */ +static void wakeup(void *p) { + Thread *tp = (Thread *)p; + +#if CH_USE_SEMAPHORES || CH_USE_MUTEXES || CH_USE_CONDVARS + switch (tp->p_state) { +#if CH_USE_SEMAPHORES + case THD_STATE_WTSEM: + chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); + /* Falls into, intentional. */ +#endif +#if CH_USE_MUTEXES + case THD_STATE_WTMTX: +#endif +#if CH_USE_CONDVARS + case THD_STATE_WTCOND: +#endif + /* States requiring dequeuing.*/ + dequeue(tp); + } +#endif + chSchReadyI(tp)->p_u.rdymsg = RDY_TIMEOUT; +} + +/** + * @brief Puts the current thread to sleep into the specified state with + * timeout specification. + * @details The thread goes into a sleeping state, if it is not awakened + * explicitly within the specified timeout then it is forcibly + * awakened with a @p RDY_TIMEOUT low level message. The @ref + * thread_states are described into @p threads.h. + * + * @param[in] newstate the new thread state + * @param[in] time the number of ticks before the operation timeouts, the + * special values are handled as follow: + * - @a TIME_INFINITE the thread enters an infinite sleep + * state, this is equivalent to invoking + * @p chSchGoSleepS() but, of course, less efficient. + * - @a TIME_IMMEDIATE this value is accepted but + * interpreted as a normal time specification not as an + * immediate timeout specification. + * . + * @return The wakeup message. + * @retval RDY_TIMEOUT if a timeout occurs. + */ +msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { + + if (TIME_INFINITE != time) { + VirtualTimer vt; + + chVTSetI(&vt, time, wakeup, currp); + chSchGoSleepS(newstate); + if (chVTIsArmedI(&vt)) + chVTResetI(&vt); + } + else + chSchGoSleepS(newstate); + return currp->p_u.rdymsg; +} + +/** + * @brief Wakes up a thread. + * @details 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 @p chSchReadyI() followed by a + * @p chSchRescheduleS() but much more efficient. + * @note The function assumes that the current thread has the highest + * priority. + * + * @param[in] ntp the Thread to be made ready + * @param[in] msg message to the awakened thread + */ +void chSchWakeupS(Thread *ntp, msg_t msg) { + + ntp->p_u.rdymsg = msg; + /* If the waken thread has a not-greater priority than the current + one then it is just inserted in the ready list else it made + running immediately and the invoking thread goes in the ready + list instead.*/ + if (ntp->p_prio <= currp->p_prio) + chSchReadyI(ntp); + else { + Thread *otp = currp; + chSchReadyI(otp); +#if CH_TIME_QUANTUM > 0 + rlist.r_preempt = CH_TIME_QUANTUM; +#endif + (currp = ntp)->p_state = THD_STATE_CURRENT; + chDbgTrace(otp, ntp); + chSysSwitchI(otp, ntp); + } +} + +/** + * @brief Switches to the first thread on the runnable queue. + * @note It is intended to be called if @p chSchRescRequiredI() evaluates + * to @p TRUE. + */ +void chSchDoRescheduleI(void) { + + Thread *otp = currp; + /* Pick the first thread from the ready queue and makes it current.*/ + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; + chSchReadyI(otp); +#if CH_TIME_QUANTUM > 0 + rlist.r_preempt = CH_TIME_QUANTUM; +#endif + chDbgTrace(otp, currp); + chSysSwitchI(otp, currp); +} + +/** + * @brief Performs a reschedulation if a higher priority thread is runnable. + * @details If a thread with a higher priority than the current thread is in + * the ready list then make the higher priority thread running. + */ +void chSchRescheduleS(void) { + + if (chSchIsRescRequiredI()) + chSchDoRescheduleI(); +} + +/** + * @brief Evaluates if a reschedulation is required. + * @details 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 @p chVTDoTickI() is invoked. + * + * @retval TRUE if there is a thread that should go in running state. + * @retval FALSE if a reschedulation is not required. + */ +bool_t chSchIsRescRequiredExI(void) { + tprio_t p1 = firstprio(&rlist.r_queue); + tprio_t p2 = currp->p_prio; +#if CH_TIME_QUANTUM > 0 + /* If the running thread has not reached its time quantum, reschedule only + if the first thread on the ready queue has a higher priority. + Otherwise, if the running thread has used up its time quantum, reschedule + if the first thread on the ready queue has equal or higher priority.*/ + return rlist.r_preempt ? p1 > p2 : p1 >= p2; +#else + /* If the round robin preemption feature is not enabled then performs a + simpler comparison.*/ + return p1 > p2; +#endif +} + +/** + * @brief Yields the time slot. + * @details Yields the CPU control to the next thread in the ready list with + * equal priority, if any. + */ +void chSchDoYieldS(void) { + + if (chSchCanYieldS()) { + Thread *cp = (Thread *)&rlist.r_queue; + Thread *otp = currp; + + /* Note, the following insertion code works because we know that on the + ready list there is at least one thread with priority equal or higher + than the current one.*/ + otp->p_state = THD_STATE_READY; + do { + cp = cp->p_prev; + } while (cp->p_prio < otp->p_prio); + /* Insertion on p_next.*/ + otp->p_next = (otp->p_prev = cp)->p_next; + otp->p_next->p_prev = cp->p_next = otp; + + /* Pick the first thread from the ready queue and makes it current.*/ + (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; +#if CH_TIME_QUANTUM > 0 + rlist.r_preempt = CH_TIME_QUANTUM; +#endif + chDbgTrace(otp, currp); + chSysSwitchI(otp, currp); + } +} + +/** @} */ -- cgit v1.2.3 From 075b89133ec371480bdcf670d3f412b1cf131b0e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 14 Mar 2010 09:13:21 +0000 Subject: Performance optimization (not complete yet). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1739 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 8cfd5cd81..441559c36 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -90,8 +90,8 @@ void chSchGoSleepS(tstate_t newstate) { #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif - chDbgTrace(otp, currp); - chSysSwitchI(otp, currp); + chDbgTrace(currp, otp); + chSysSwitchI(currp, otp); } /* @@ -185,8 +185,8 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { rlist.r_preempt = CH_TIME_QUANTUM; #endif (currp = ntp)->p_state = THD_STATE_CURRENT; - chDbgTrace(otp, ntp); - chSysSwitchI(otp, ntp); + chDbgTrace(ntp, otp); + chSysSwitchI(ntp, otp); } } @@ -204,8 +204,8 @@ void chSchDoRescheduleI(void) { #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif - chDbgTrace(otp, currp); - chSysSwitchI(otp, currp); + chDbgTrace(currp, otp); + chSysSwitchI(currp, otp); } /** @@ -272,8 +272,8 @@ void chSchDoYieldS(void) { #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif - chDbgTrace(otp, currp); - chSysSwitchI(otp, currp); + chDbgTrace(currp, otp); + chSysSwitchI(currp, otp); } } -- cgit v1.2.3 From 8cf7b70436de8a93b2a0b3ddaeffbc7bfe4a5666 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 15 Mar 2010 16:04:47 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1743 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 441559c36..412467b65 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -196,16 +196,17 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { * to @p TRUE. */ void chSchDoRescheduleI(void) { + Thread *otp, *ntp; - Thread *otp = currp; - /* Pick the first thread from the ready queue and makes it current.*/ - (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; - chSchReadyI(otp); #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif - chDbgTrace(currp, otp); - chSysSwitchI(currp, otp); + otp = currp; + /* Pick the first thread from the ready queue and makes it current.*/ + (currp = ntp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; + chSchReadyI(otp); + chDbgTrace(ntp, otp); + chSysSwitchI(ntp, otp); } /** -- cgit v1.2.3 From 0eed163a696d4b6daab19fd8daf05b980058f5f3 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 16 Mar 2010 15:43:23 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1745 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 56 ++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 34 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 412467b65..023c35d41 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -21,7 +21,13 @@ * @file chschd.c * @brief Scheduler code. * - * @addtogroup scheduler + * @defgroup scheduler Scheduler + * @ingroup base + * @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. * @{ */ @@ -30,7 +36,9 @@ /** * @brief Ready list header. */ +#if !defined(PORT_OPTIMIZED_RLIST_VAR) || defined(__DOXYGEN__) ReadyList rlist; +#endif /* !defined(PORT_OPTIMIZED_RLIST_VAR) */ /** * @brief Scheduler initialization. @@ -56,6 +64,7 @@ void scheduler_init(void) { * @param[in] tp the Thread to be made ready * @return The Thread pointer. */ +#if !defined(PORT_OPTIMIZED_READYI) || defined(__DOXYGEN__) #if CH_OPTIMIZE_SPEED /* NOTE: it is inlined in this module only.*/ INLINE Thread *chSchReadyI(Thread *tp) { @@ -74,6 +83,7 @@ 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. @@ -82,6 +92,7 @@ Thread *chSchReadyI(Thread *tp) { * * @param[in] newstate the new thread state */ +#if !defined(PORT_OPTIMIZED_GOSLEEPS) || defined(__DOXYGEN__) void chSchGoSleepS(tstate_t newstate) { Thread *otp; @@ -93,6 +104,7 @@ void chSchGoSleepS(tstate_t newstate) { chDbgTrace(currp, otp); chSysSwitchI(currp, otp); } +#endif /* !defined(PORT_OPTIMIZED_GOSLEEPS) */ /* * Timeout wakeup callback. @@ -169,6 +181,7 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { * @param[in] ntp the Thread to be made ready * @param[in] msg message to the awakened thread */ +#if !defined(PORT_OPTIMIZED_WAKEUPS) || defined(__DOXYGEN__) void chSchWakeupS(Thread *ntp, msg_t msg) { ntp->p_u.rdymsg = msg; @@ -189,12 +202,14 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { chSysSwitchI(ntp, otp); } } +#endif /* !defined(PORT_OPTIMIZED_WAKEUPS) */ /** * @brief Switches to the first thread on the runnable queue. * @note It is intended to be called if @p chSchRescRequiredI() evaluates * to @p TRUE. */ +#if !defined(PORT_OPTIMIZED_DORESCHEDULEI) || defined(__DOXYGEN__) void chSchDoRescheduleI(void) { Thread *otp, *ntp; @@ -202,23 +217,26 @@ void chSchDoRescheduleI(void) { rlist.r_preempt = CH_TIME_QUANTUM; #endif otp = currp; - /* Pick the first thread from the ready queue and makes it current.*/ + /* Picks the first thread from the ready queue and makes it current.*/ (currp = ntp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; chSchReadyI(otp); chDbgTrace(ntp, otp); chSysSwitchI(ntp, otp); } +#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEI) */ /** * @brief Performs a reschedulation if a higher priority thread is runnable. * @details If a thread with a higher priority than the current thread is in * the ready list then make the higher priority thread running. */ +#if !defined(PORT_OPTIMIZED_RESCHEDULES) || defined(__DOXYGEN__) void chSchRescheduleS(void) { if (chSchIsRescRequiredI()) chSchDoRescheduleI(); } +#endif /* !defined(PORT_OPTIMIZED_RESCHEDULES) */ /** * @brief Evaluates if a reschedulation is required. @@ -230,6 +248,7 @@ void chSchRescheduleS(void) { * @retval TRUE if there is a thread that should go in running state. * @retval FALSE if a reschedulation is not required. */ +#if !defined(PORT_OPTIMIZED_ISRESCHREQUIREDEXI) || defined(__DOXYGEN__) bool_t chSchIsRescRequiredExI(void) { tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; @@ -245,37 +264,6 @@ bool_t chSchIsRescRequiredExI(void) { return p1 > p2; #endif } - -/** - * @brief Yields the time slot. - * @details Yields the CPU control to the next thread in the ready list with - * equal priority, if any. - */ -void chSchDoYieldS(void) { - - if (chSchCanYieldS()) { - Thread *cp = (Thread *)&rlist.r_queue; - Thread *otp = currp; - - /* Note, the following insertion code works because we know that on the - ready list there is at least one thread with priority equal or higher - than the current one.*/ - otp->p_state = THD_STATE_READY; - do { - cp = cp->p_prev; - } while (cp->p_prio < otp->p_prio); - /* Insertion on p_next.*/ - otp->p_next = (otp->p_prev = cp)->p_next; - otp->p_next->p_prev = cp->p_next = otp; - - /* Pick the first thread from the ready queue and makes it current.*/ - (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif - chDbgTrace(currp, otp); - chSysSwitchI(currp, otp); - } -} +#endif /* !defined(PORT_OPTIMIZED_ISRESCHREQUIREDEXI) */ /** @} */ -- cgit v1.2.3 From ad3d21e81592481539a56e93234f5bf1fa2c0504 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 16 Mar 2010 19:36:21 +0000 Subject: Documentation reorganization. Moved the description from kernel.dox into the source code for ease of editing and reference. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1746 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 023c35d41..9bf34d43a 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -21,8 +21,7 @@ * @file chschd.c * @brief Scheduler code. * - * @defgroup scheduler Scheduler - * @ingroup base + * @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. -- cgit v1.2.3 From cf1b70f486a2696d523d585e91d0e4e5c7b8021c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 18 Mar 2010 16:01:11 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1749 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 9bf34d43a..ac69c6661 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -105,23 +105,21 @@ void chSchGoSleepS(tstate_t newstate) { } #endif /* !defined(PORT_OPTIMIZED_GOSLEEPS) */ +#if !defined(PORT_OPTIMIZED_GOSLEEPTIMEOUTS) || defined(__DOXYGEN__) /* * Timeout wakeup callback. */ static void wakeup(void *p) { Thread *tp = (Thread *)p; -#if CH_USE_SEMAPHORES || CH_USE_MUTEXES || CH_USE_CONDVARS +#if CH_USE_SEMAPHORES || (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) switch (tp->p_state) { #if CH_USE_SEMAPHORES case THD_STATE_WTSEM: chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); /* Falls into, intentional. */ #endif -#if CH_USE_MUTEXES - case THD_STATE_WTMTX: -#endif -#if CH_USE_CONDVARS +#if CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT case THD_STATE_WTCOND: #endif /* States requiring dequeuing.*/ @@ -166,6 +164,7 @@ 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. @@ -191,8 +190,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { if (ntp->p_prio <= currp->p_prio) chSchReadyI(ntp); else { - Thread *otp = currp; - chSchReadyI(otp); + Thread *otp = chSchReadyI(currp); #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif @@ -225,7 +223,7 @@ void chSchDoRescheduleI(void) { #endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEI) */ /** - * @brief Performs a reschedulation if a higher priority thread is runnable. + * @brief Performs a reschedule if a higher priority thread is runnable. * @details If a thread with a higher priority than the current thread is in * the ready list then make the higher priority thread running. */ @@ -238,14 +236,14 @@ void chSchRescheduleS(void) { #endif /* !defined(PORT_OPTIMIZED_RESCHEDULES) */ /** - * @brief Evaluates if a reschedulation is required. + * @brief Evaluates if a reschedule is required. * @details 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 @p chVTDoTickI() is invoked. * * @retval TRUE if there is a thread that should go in running state. - * @retval FALSE if a reschedulation is not required. + * @retval FALSE if a reschedule is not required. */ #if !defined(PORT_OPTIMIZED_ISRESCHREQUIREDEXI) || defined(__DOXYGEN__) bool_t chSchIsRescRequiredExI(void) { -- cgit v1.2.3 From 7370e125969d1f5a9808280c507d7ac38d2fc1bc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 18 Mar 2010 18:36:27 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1751 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index ac69c6661..c561cbd41 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -112,6 +112,7 @@ void chSchGoSleepS(tstate_t newstate) { static void wakeup(void *p) { Thread *tp = (Thread *)p; + tp->p_u.rdymsg = RDY_TIMEOUT; #if CH_USE_SEMAPHORES || (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) switch (tp->p_state) { #if CH_USE_SEMAPHORES @@ -126,7 +127,7 @@ static void wakeup(void *p) { dequeue(tp); } #endif - chSchReadyI(tp)->p_u.rdymsg = RDY_TIMEOUT; + chSchReadyI(tp); } /** -- cgit v1.2.3 From 55e8eabccb4f0c5fe448055a16b4dfa916977477 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 18 Mar 2010 21:41:33 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1753 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index c561cbd41..d5c8a0a5a 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -112,7 +112,6 @@ void chSchGoSleepS(tstate_t newstate) { static void wakeup(void *p) { Thread *tp = (Thread *)p; - tp->p_u.rdymsg = RDY_TIMEOUT; #if CH_USE_SEMAPHORES || (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) switch (tp->p_state) { #if CH_USE_SEMAPHORES @@ -127,6 +126,8 @@ static void wakeup(void *p) { dequeue(tp); } #endif + /* Done this way in order to allow a tail call.*/ + tp->p_u.rdymsg = RDY_TIMEOUT; chSchReadyI(tp); } -- cgit v1.2.3 From 79075f9e81d9d56be5da3bf6cdae56f4ace950de Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Mar 2010 12:48:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1755 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index d5c8a0a5a..7170fb0ec 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -96,7 +96,8 @@ void chSchGoSleepS(tstate_t newstate) { Thread *otp; (otp = currp)->p_state = newstate; - (currp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; + setcurrp(fifo_remove(&rlist.r_queue)); + currp->p_state = THD_STATE_CURRENT; #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif @@ -196,7 +197,8 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif - (currp = ntp)->p_state = THD_STATE_CURRENT; + setcurrp(ntp); + ntp->p_state = THD_STATE_CURRENT; chDbgTrace(ntp, otp); chSysSwitchI(ntp, otp); } @@ -217,7 +219,8 @@ void chSchDoRescheduleI(void) { #endif otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ - (currp = ntp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; + (ntp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; + setcurrp(ntp); chSchReadyI(otp); chDbgTrace(ntp, otp); chSysSwitchI(ntp, otp); -- cgit v1.2.3 From b61fb43e6cc681f9fc53a5efb116accc13e0d35d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Mar 2010 15:45:25 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1756 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 7170fb0ec..cee046af2 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -51,7 +51,7 @@ void scheduler_init(void) { rlist.r_preempt = CH_TIME_QUANTUM; #endif #if CH_USE_REGISTRY - rlist.p_newer = rlist.p_older = (Thread *)&rlist; + rlist.r_newer = rlist.r_older = (Thread *)&rlist; #endif } @@ -96,11 +96,11 @@ void chSchGoSleepS(tstate_t newstate) { Thread *otp; (otp = currp)->p_state = newstate; - setcurrp(fifo_remove(&rlist.r_queue)); - currp->p_state = THD_STATE_CURRENT; #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif + setcurrp(fifo_remove(&rlist.r_queue)); + currp->p_state = THD_STATE_CURRENT; chDbgTrace(currp, otp); chSysSwitchI(currp, otp); } -- cgit v1.2.3 From 295f370672c3238bc166743261f067bd8fe80cc4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Mar 2010 20:27:40 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1758 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index cee046af2..c75f099f6 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -212,18 +212,18 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { */ #if !defined(PORT_OPTIMIZED_DORESCHEDULEI) || defined(__DOXYGEN__) void chSchDoRescheduleI(void) { - Thread *otp, *ntp; + Thread *otp; #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ - (ntp = fifo_remove(&rlist.r_queue))->p_state = THD_STATE_CURRENT; - setcurrp(ntp); + setcurrp(fifo_remove(&rlist.r_queue)); + currp->p_state = THD_STATE_CURRENT; chSchReadyI(otp); - chDbgTrace(ntp, otp); - chSysSwitchI(ntp, otp); + chDbgTrace(currp, otp); + chSysSwitchI(currp, otp); } #endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEI) */ -- cgit v1.2.3 From e55b9dfdcb1a285aed416fc49d702b01e18de03f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Mar 2010 20:39:23 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1759 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index c75f099f6..d412798c0 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -101,7 +101,7 @@ void chSchGoSleepS(tstate_t newstate) { #endif setcurrp(fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; - chDbgTrace(currp, otp); + chDbgTrace(otp); chSysSwitchI(currp, otp); } #endif /* !defined(PORT_OPTIMIZED_GOSLEEPS) */ @@ -199,7 +199,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { #endif setcurrp(ntp); ntp->p_state = THD_STATE_CURRENT; - chDbgTrace(ntp, otp); + chDbgTrace(otp); chSysSwitchI(ntp, otp); } } @@ -222,7 +222,7 @@ void chSchDoRescheduleI(void) { setcurrp(fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; chSchReadyI(otp); - chDbgTrace(currp, otp); + chDbgTrace(otp); chSysSwitchI(currp, otp); } #endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEI) */ -- cgit v1.2.3 From 0ea17958535e56f50064ae47a50a3cd742f88163 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 29 Aug 2010 06:29:01 +0000 Subject: Fixed bug 3055329. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2139 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index d412798c0..51987749f 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -78,7 +78,8 @@ Thread *chSchReadyI(Thread *tp) { cp = cp->p_next; } while (cp->p_prio >= tp->p_prio); /* Insertion on p_prev.*/ - tp->p_prev = (tp->p_next = cp)->p_prev; + tp->p_next = cp; + tp->p_prev = cp->p_prev; tp->p_prev->p_next = cp->p_prev = tp; return tp; } -- cgit v1.2.3 From 1a0fead19b521501ec5b7ff7532d6a7b435fdaa6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 3 Sep 2010 18:23:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2162 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 51987749f..c4a6a3fd0 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -72,6 +72,12 @@ Thread *chSchReadyI(Thread *tp) { #endif Thread *cp; + /* Integrity check.*/ + chDbgAssert((tp->p_state != THD_STATE_READY) && + (tp->p_state != THD_STATE_FINAL), + "chSchReadyI(), #1", + "invalid state"); + tp->p_state = THD_STATE_READY; cp = (Thread *)&rlist.r_queue; do { -- cgit v1.2.3 From 9ffea7e261ec4016d788abbbf7c4a6d3a78e0a04 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 18 Sep 2010 06:48:56 +0000 Subject: Documentation improvements, renamed some event APIs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2179 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index c4a6a3fd0..213d999ce 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -57,11 +57,15 @@ void scheduler_init(void) { /** * @brief Inserts a thread in the Ready List. - * @note The function does not reschedule, the @p chSchRescheduleS() should - * be called soon after. + * @pre The thread must not be already inserted in any list through its + * @p p_next and @p p_prev or list corruption would occur. + * @post This function does not reschedule so a call to a rescheduling + * function must be performed before unlocking the kernel. Note that + * interrupt handlers always reschedule on exit so an explicit + * reschedule must not be performed in ISRs. * - * @param[in] tp the Thread to be made ready - * @return The Thread pointer. + * @param[in] tp the thread to be made ready + * @return The thread pointer. */ #if !defined(PORT_OPTIMIZED_READYI) || defined(__DOXYGEN__) #if CH_OPTIMIZE_SPEED @@ -93,8 +97,8 @@ Thread *chSchReadyI(Thread *tp) { /** * @brief Puts the current thread to sleep into the specified state. - * @details The thread goes into a sleeping state. The @ref thread_states are - * described into @p threads.h. + * @details The thread goes into a sleeping state. The possible + * @ref thread_states are defined into @p threads.h. * * @param[in] newstate the new thread state */ @@ -144,8 +148,8 @@ static void wakeup(void *p) { * timeout specification. * @details The thread goes into a sleeping state, if it is not awakened * explicitly within the specified timeout then it is forcibly - * awakened with a @p RDY_TIMEOUT low level message. The @ref - * thread_states are described into @p threads.h. + * awakened with a @p RDY_TIMEOUT low level message. The possible + * @ref thread_states are defined into @p threads.h. * * @param[in] newstate the new thread state * @param[in] time the number of ticks before the operation timeouts, the @@ -181,6 +185,8 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { * @details The thread is inserted into the ready list or immediately made * running depending on its relative priority compared to the current * thread. + * @pre The thread must not be already inserted in any list through its + * @p p_next and @p p_prev or list corruption would occur. * @note It is equivalent to a @p chSchReadyI() followed by a * @p chSchRescheduleS() but much more efficient. * @note The function assumes that the current thread has the highest -- cgit v1.2.3 From 07351222e6d0b6b3dcd4f50ecb18bc09e7402d1c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 21 Sep 2010 10:22:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2184 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 213d999ce..c7db9ad60 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -41,7 +41,8 @@ ReadyList rlist; /** * @brief Scheduler initialization. - * @note Internally invoked by the @p chSysInit(), not an API. + * + * @notapi */ void scheduler_init(void) { @@ -66,6 +67,8 @@ void scheduler_init(void) { * * @param[in] tp the thread to be made ready * @return The thread pointer. + * + * @iclass */ #if !defined(PORT_OPTIMIZED_READYI) || defined(__DOXYGEN__) #if CH_OPTIMIZE_SPEED @@ -101,6 +104,8 @@ Thread *chSchReadyI(Thread *tp) { * @ref thread_states are defined into @p threads.h. * * @param[in] newstate the new thread state + * + * @sclass */ #if !defined(PORT_OPTIMIZED_GOSLEEPS) || defined(__DOXYGEN__) void chSchGoSleepS(tstate_t newstate) { @@ -163,6 +168,8 @@ static void wakeup(void *p) { * . * @return The wakeup message. * @retval RDY_TIMEOUT if a timeout occurs. + * + * @sclass */ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { @@ -194,6 +201,8 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { * * @param[in] ntp the Thread to be made ready * @param[in] msg message to the awakened thread + * + * @sclass */ #if !defined(PORT_OPTIMIZED_WAKEUPS) || defined(__DOXYGEN__) void chSchWakeupS(Thread *ntp, msg_t msg) { @@ -222,6 +231,8 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { * @brief Switches to the first thread on the runnable queue. * @note It is intended to be called if @p chSchRescRequiredI() evaluates * to @p TRUE. + * + * @iclass */ #if !defined(PORT_OPTIMIZED_DORESCHEDULEI) || defined(__DOXYGEN__) void chSchDoRescheduleI(void) { @@ -244,6 +255,8 @@ void chSchDoRescheduleI(void) { * @brief Performs a reschedule if a higher priority thread is runnable. * @details If a thread with a higher priority than the current thread is in * the ready list then make the higher priority thread running. + * + * @iclass */ #if !defined(PORT_OPTIMIZED_RESCHEDULES) || defined(__DOXYGEN__) void chSchRescheduleS(void) { @@ -262,6 +275,8 @@ void chSchRescheduleS(void) { * * @retval TRUE if there is a thread that should go in running state. * @retval FALSE if a reschedule is not required. + * + * @iclass */ #if !defined(PORT_OPTIMIZED_ISRESCHREQUIREDEXI) || defined(__DOXYGEN__) bool_t chSchIsRescRequiredExI(void) { -- cgit v1.2.3 From 719e83e6e85e24242a95e9a4d48845fd5400dc5b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 24 Sep 2010 17:31:31 +0000 Subject: Fixed bug 3074984, undone change to the virtual timers. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2186 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index c7db9ad60..f12103324 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -143,9 +143,12 @@ static void wakeup(void *p) { dequeue(tp); } #endif - /* Done this way in order to allow a tail call.*/ - tp->p_u.rdymsg = RDY_TIMEOUT; - chSchReadyI(tp); + /* Handling the special case where the thread has been made ready by another + thread with higher priority.*/ + if (tp->p_state != THD_STATE_READY) { + tp->p_u.rdymsg = RDY_TIMEOUT; + chSchReadyI(tp); + } } /** -- cgit v1.2.3 From 5b3fec0235acc100600054917d9d393db189b5cb Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 24 Sep 2010 17:58:21 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2187 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index f12103324..ff10dbe2d 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -131,6 +131,10 @@ static void wakeup(void *p) { #if CH_USE_SEMAPHORES || (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) switch (tp->p_state) { + case THD_STATE_READY: + /* Handling the special case where the thread has been made ready by + another thread with higher priority.*/ + return; #if CH_USE_SEMAPHORES case THD_STATE_WTSEM: chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); @@ -143,12 +147,8 @@ static void wakeup(void *p) { dequeue(tp); } #endif - /* Handling the special case where the thread has been made ready by another - thread with higher priority.*/ - if (tp->p_state != THD_STATE_READY) { - tp->p_u.rdymsg = RDY_TIMEOUT; - chSchReadyI(tp); - } + tp->p_u.rdymsg = RDY_TIMEOUT; + chSchReadyI(tp); } /** -- cgit v1.2.3 From 79b466c6f867a30e38ea2164a4f96b5ddba3d9e2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 24 Sep 2010 18:05:46 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2188 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index ff10dbe2d..9adf656ff 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -129,12 +129,12 @@ void chSchGoSleepS(tstate_t newstate) { static void wakeup(void *p) { Thread *tp = (Thread *)p; -#if CH_USE_SEMAPHORES || (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) switch (tp->p_state) { case THD_STATE_READY: /* Handling the special case where the thread has been made ready by another thread with higher priority.*/ return; +#if CH_USE_SEMAPHORES || (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) #if CH_USE_SEMAPHORES case THD_STATE_WTSEM: chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); @@ -145,8 +145,8 @@ static void wakeup(void *p) { #endif /* States requiring dequeuing.*/ dequeue(tp); - } #endif + } tp->p_u.rdymsg = RDY_TIMEOUT; chSchReadyI(tp); } -- cgit v1.2.3 From f2386f6a22c55842203278c5b1f9691c5ac5f8fd Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 21 Dec 2010 10:30:39 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2515 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 9adf656ff..5b04c1f3d 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -71,12 +71,7 @@ void scheduler_init(void) { * @iclass */ #if !defined(PORT_OPTIMIZED_READYI) || defined(__DOXYGEN__) -#if CH_OPTIMIZE_SPEED -/* NOTE: it is inlined in this module only.*/ -INLINE Thread *chSchReadyI(Thread *tp) { -#else Thread *chSchReadyI(Thread *tp) { -#endif Thread *cp; /* Integrity check.*/ -- cgit v1.2.3 From b3b1028036a2f18327fb97f2126192a2ace62bb2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 21 Feb 2011 19:06:46 +0000 Subject: TIME_IMMEDIATE and TIME_INFINITE values swapped. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2757 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 5b04c1f3d..85e968904 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -160,9 +160,7 @@ static void wakeup(void *p) { * - @a TIME_INFINITE the thread enters an infinite sleep * state, this is equivalent to invoking * @p chSchGoSleepS() but, of course, less efficient. - * - @a TIME_IMMEDIATE this value is accepted but - * interpreted as a normal time specification not as an - * immediate timeout specification. + * - @a TIME_IMMEDIATE this value is not allowed. * . * @return The wakeup message. * @retval RDY_TIMEOUT if a timeout occurs. -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 85e968904..210dbfdc1 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From f5ae2552307f20f3fa3d987591fa60576981ce3d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 29 Mar 2011 14:51:08 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2850 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 210dbfdc1..54e7918b1 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -45,7 +45,7 @@ ReadyList rlist; * * @notapi */ -void scheduler_init(void) { +void _scheduler_init(void) { queue_init(&rlist.r_queue); rlist.r_prio = NOPRIO; -- cgit v1.2.3 From 807c5f1882224c2afd471a44889b83c2adf80589 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 18 May 2011 17:54:55 +0000 Subject: Fixed bug 3303908. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2972 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 54e7918b1..d41649b4c 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -130,12 +130,16 @@ static void wakeup(void *p) { /* Handling the special case where the thread has been made ready by another thread with higher priority.*/ return; -#if CH_USE_SEMAPHORES || (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) +#if CH_USE_SEMAPHORES || CH_USE_QUEUES || \ + (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) #if CH_USE_SEMAPHORES case THD_STATE_WTSEM: chSemFastSignalI((Semaphore *)tp->p_u.wtobjp); /* Falls into, intentional. */ #endif +#if CH_USE_QUEUES + case THD_STATE_WTQUEUE: +#endif #if CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT case THD_STATE_WTCOND: #endif -- cgit v1.2.3 From b9933c2089f5f0cd93738ae9081c45fcf3df54b7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 11 Aug 2011 17:51:37 +0000 Subject: Implemented system state checker debug option, remove the option CH_USE_NESTED_LOCKS. Documentation improvements and fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3221 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index d41649b4c..e989f4039 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -113,7 +113,6 @@ void chSchGoSleepS(tstate_t newstate) { #endif setcurrp(fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; - chDbgTrace(otp); chSysSwitchI(currp, otp); } #endif /* !defined(PORT_OPTIMIZED_GOSLEEPS) */ @@ -222,7 +221,6 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { #endif setcurrp(ntp); ntp->p_state = THD_STATE_CURRENT; - chDbgTrace(otp); chSysSwitchI(ntp, otp); } } @@ -247,7 +245,6 @@ void chSchDoRescheduleI(void) { setcurrp(fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; chSchReadyI(otp); - chDbgTrace(otp); chSysSwitchI(currp, otp); } #endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEI) */ -- cgit v1.2.3 From 43752ee8d132fc57028a9ff15156c5bfcd81c013 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 12 Aug 2011 11:10:19 +0000 Subject: Extended state check to all kernel I-class and s-class APIs, corrected some test cases where call protocol rules were not strictly observerd. No the whole test suite pass with the state checker enabled. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3223 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index e989f4039..b481a0b6a 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -75,7 +75,8 @@ void _scheduler_init(void) { Thread *chSchReadyI(Thread *tp) { Thread *cp; - /* Integrity check.*/ + /* Integrity checks.*/ + chDbgCheckClassI(); chDbgAssert((tp->p_state != THD_STATE_READY) && (tp->p_state != THD_STATE_FINAL), "chSchReadyI(), #1", @@ -107,6 +108,8 @@ Thread *chSchReadyI(Thread *tp) { void chSchGoSleepS(tstate_t newstate) { Thread *otp; + chDbgCheckClassS(); + (otp = currp)->p_state = newstate; #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; @@ -173,6 +176,8 @@ static void wakeup(void *p) { */ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { + chDbgCheckClassS(); + if (TIME_INFINITE != time) { VirtualTimer vt; @@ -207,6 +212,8 @@ msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) { #if !defined(PORT_OPTIMIZED_WAKEUPS) || defined(__DOXYGEN__) void chSchWakeupS(Thread *ntp, msg_t msg) { + chDbgCheckClassS(); + ntp->p_u.rdymsg = msg; /* If the waken thread has a not-greater priority than the current one then it is just inserted in the ready list else it made @@ -237,6 +244,8 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { void chSchDoRescheduleI(void) { Thread *otp; + chDbgCheckClassI(); + #if CH_TIME_QUANTUM > 0 rlist.r_preempt = CH_TIME_QUANTUM; #endif @@ -259,6 +268,8 @@ void chSchDoRescheduleI(void) { #if !defined(PORT_OPTIMIZED_RESCHEDULES) || defined(__DOXYGEN__) void chSchRescheduleS(void) { + chDbgCheckClassS(); + if (chSchIsRescRequiredI()) chSchDoRescheduleI(); } -- cgit v1.2.3 From aaad958769e757093a258cfdd5c75f515534fd7a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 13 Aug 2011 07:06:02 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3224 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 74 ++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index b481a0b6a..f2014b8c7 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -76,7 +76,6 @@ Thread *chSchReadyI(Thread *tp) { Thread *cp; /* Integrity checks.*/ - chDbgCheckClassI(); chDbgAssert((tp->p_state != THD_STATE_READY) && (tp->p_state != THD_STATE_FINAL), "chSchReadyI(), #1", @@ -116,7 +115,7 @@ void chSchGoSleepS(tstate_t newstate) { #endif setcurrp(fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; - chSysSwitchI(currp, otp); + chSysSwitch(currp, otp); } #endif /* !defined(PORT_OPTIMIZED_GOSLEEPS) */ @@ -228,36 +227,11 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { #endif setcurrp(ntp); ntp->p_state = THD_STATE_CURRENT; - chSysSwitchI(ntp, otp); + chSysSwitch(ntp, otp); } } #endif /* !defined(PORT_OPTIMIZED_WAKEUPS) */ -/** - * @brief Switches to the first thread on the runnable queue. - * @note It is intended to be called if @p chSchRescRequiredI() evaluates - * to @p TRUE. - * - * @iclass - */ -#if !defined(PORT_OPTIMIZED_DORESCHEDULEI) || defined(__DOXYGEN__) -void chSchDoRescheduleI(void) { - Thread *otp; - - chDbgCheckClassI(); - -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif - otp = currp; - /* Picks the first thread from the ready queue and makes it current.*/ - setcurrp(fifo_remove(&rlist.r_queue)); - currp->p_state = THD_STATE_CURRENT; - chSchReadyI(otp); - chSysSwitchI(currp, otp); -} -#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEI) */ - /** * @brief Performs a reschedule if a higher priority thread is runnable. * @details If a thread with a higher priority than the current thread is in @@ -271,24 +245,25 @@ void chSchRescheduleS(void) { chDbgCheckClassS(); if (chSchIsRescRequiredI()) - chSchDoRescheduleI(); + chSchDoReschedule(); } #endif /* !defined(PORT_OPTIMIZED_RESCHEDULES) */ /** - * @brief Evaluates if a reschedule is required. + * @brief Evaluates if preemption is required. * @details 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 @p chVTDoTickI() is invoked. + * @note Not a user function, it is meant to be invoked by the scheduler + * itself or from within the port layer. * - * @retval TRUE if there is a thread that should go in running state. - * @retval FALSE if a reschedule is not required. + * @retval TRUE if there is a thread that must go in running state + * immediately. + * @retval FALSE if preemption is not required. * - * @iclass + * @special */ -#if !defined(PORT_OPTIMIZED_ISRESCHREQUIREDEXI) || defined(__DOXYGEN__) -bool_t chSchIsRescRequiredExI(void) { +#if !defined(PORT_OPTIMIZED_ISPREEMPTIONREQUIRED) || defined(__DOXYGEN__) +bool_t chSchIsPreemptionRequired(void) { tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; #if CH_TIME_QUANTUM > 0 @@ -303,6 +278,29 @@ bool_t chSchIsRescRequiredExI(void) { return p1 > p2; #endif } -#endif /* !defined(PORT_OPTIMIZED_ISRESCHREQUIREDEXI) */ +#endif /* !defined(PORT_OPTIMIZED_ISPREEMPTIONREQUIRED) */ + +/** + * @brief Switches to the first thread on the runnable queue. + * @note Not a user function, it is meant to be invoked by the scheduler + * itself or from within the port layer. + * + * @special + */ +#if !defined(PORT_OPTIMIZED_DORESCHEDULE) || defined(__DOXYGEN__) +void chSchDoReschedule(void) { + Thread *otp; + +#if CH_TIME_QUANTUM > 0 + rlist.r_preempt = CH_TIME_QUANTUM; +#endif + otp = currp; + /* Picks the first thread from the ready queue and makes it current.*/ + setcurrp(fifo_remove(&rlist.r_queue)); + currp->p_state = THD_STATE_CURRENT; + chSchReadyI(otp); + chSysSwitch(currp, otp); +} +#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULE) */ /** @} */ -- cgit v1.2.3 From de5dcbba856524599a8f06d3a9bdbf1b01db44c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Jan 2012 14:29:42 +0000 Subject: License text updated with new year. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3846 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index f2014b8c7..4acc500af 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 4401d0e7b2874074e37c90e0178667a854d0da1f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 6 Feb 2012 19:45:47 +0000 Subject: Round robin scheduling improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3930 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 95 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 15 deletions(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 4acc500af..3dd226b1b 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -49,9 +49,6 @@ void _scheduler_init(void) { queue_init(&rlist.r_queue); rlist.r_prio = NOPRIO; -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif #if CH_USE_REGISTRY rlist.r_newer = rlist.r_older = (Thread *)&rlist; #endif @@ -59,6 +56,8 @@ void _scheduler_init(void) { /** * @brief Inserts a thread in the Ready List. + * @details The thread is positioned behind all threads with higher or equal + * priority. * @pre The thread must not be already inserted in any list through its * @p p_next and @p p_prev or list corruption would occur. * @post This function does not reschedule so a call to a rescheduling @@ -111,7 +110,9 @@ void chSchGoSleepS(tstate_t newstate) { (otp = currp)->p_state = newstate; #if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; + /* The thread is renouncing its remaining time slices so it will have a new + time quantum when it will wakeup.*/ + otp->p_preempt = CH_TIME_QUANTUM; #endif setcurrp(fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; @@ -222,9 +223,6 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { chSchReadyI(ntp); else { Thread *otp = chSchReadyI(currp); -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif setcurrp(ntp); ntp->p_state = THD_STATE_CURRENT; chSysSwitch(ntp, otp); @@ -237,7 +235,7 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { * @details If a thread with a higher priority than the current thread is in * the ready list then make the higher priority thread running. * - * @iclass + * @sclass */ #if !defined(PORT_OPTIMIZED_RESCHEDULES) || defined(__DOXYGEN__) void chSchRescheduleS(void) { @@ -245,7 +243,7 @@ void chSchRescheduleS(void) { chDbgCheckClassS(); if (chSchIsRescRequiredI()) - chSchDoReschedule(); + chSchDoRescheduleAhead(); } #endif /* !defined(PORT_OPTIMIZED_RESCHEDULES) */ @@ -271,7 +269,7 @@ bool_t chSchIsPreemptionRequired(void) { if the first thread on the ready queue has a higher priority. Otherwise, if the running thread has used up its time quantum, reschedule if the first thread on the ready queue has equal or higher priority.*/ - return rlist.r_preempt ? p1 > p2 : p1 >= p2; + return currp->r_preempt ? p1 > p2 : p1 >= p2; #else /* If the round robin preemption feature is not enabled then performs a simpler comparison.*/ @@ -282,25 +280,92 @@ bool_t chSchIsPreemptionRequired(void) { /** * @brief Switches to the first thread on the runnable queue. + * @details The current thread is positioned in the ready list behind all + * threads having the same priority. The thread regains its time + * quantum. * @note Not a user function, it is meant to be invoked by the scheduler * itself or from within the port layer. * * @special */ -#if !defined(PORT_OPTIMIZED_DORESCHEDULE) || defined(__DOXYGEN__) -void chSchDoReschedule(void) { +#if !defined(PORT_OPTIMIZED_DORESCHEDULEBEHIND) || defined(__DOXYGEN__) +void chSchDoRescheduleBehind(void) { Thread *otp; -#if CH_TIME_QUANTUM > 0 - rlist.r_preempt = CH_TIME_QUANTUM; -#endif otp = currp; /* Picks the first thread from the ready queue and makes it current.*/ setcurrp(fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; + otp->p_preempt = CH_TIME_QUANTUM; chSchReadyI(otp); chSysSwitch(currp, otp); } +#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEBEHIND) */ + +/** + * @brief Switches to the first thread on the runnable queue. + * @details The current thread is positioned in the ready list ahead of all + * threads having the same priority. + * @note Not a user function, it is meant to be invoked by the scheduler + * itself or from within the port layer. + * + * @special + */ +#if !defined(PORT_OPTIMIZED_DORESCHEDULEAHEAD) || defined(__DOXYGEN__) +void chSchDoRescheduleAhead(void) { + Thread *otp, *cp; + + otp = currp; + /* Picks the first thread from the ready queue and makes it current.*/ + setcurrp(fifo_remove(&rlist.r_queue)); + currp->p_state = THD_STATE_CURRENT; + + otp->p_state = THD_STATE_READY; + cp = (Thread *)&rlist.r_queue; + do { + cp = cp->p_next; + } while (cp->p_prio > otp->p_prio); + /* Insertion on p_prev.*/ + otp->p_next = cp; + otp->p_prev = cp->p_prev; + otp->p_prev->p_next = cp->p_prev = otp; + + chSysSwitch(currp, otp); +} +#endif /* !defined(PORT_OPTIMIZED_DORESCHEDULEAHEAD) */ + +/** + * @brief Switches to the first thread on the runnable queue. + * @details 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. + * @note Not a user function, it is meant to be invoked by the scheduler + * itself or from within the port layer. + * + * @special + */ +#if !defined(PORT_OPTIMIZED_DORESCHEDULE) || defined(__DOXYGEN__) +void chSchDoReschedule(void) { + +#if CH_TIME_QUANTUM > 0 + /* If CH_TIME_QUANTUM is enabled then there are two different scenarios to + handle on preemption: time quantum elapsed or not.*/ + if (currp->p_preempt == 0) { + /* The thread consumed its time quantum so it is enqueued behind threads + with same priority level, however, it acquires a new time quantum.*/ + chSchDoRescheduleBehind(); + } + else { + /* The thread didn't consume all its time quantum so it is put ahead of + threads with equal priority and does not acquire a new time quantum.*/ + chSchDoRescheduleAhead(); + } +#else /* !(CH_TIME_QUANTUM > 0) */ + /* If the round-robin mechanism is disabled then the thread goes always + ahead of its peers.*/ + chSchDoRescheduleAhead(); +#endif /* !(CH_TIME_QUANTUM > 0) */ +} #endif /* !defined(PORT_OPTIMIZED_DORESCHEDULE) */ /** @} */ -- cgit v1.2.3 From d32014ff1ead0fd53a405aaf82869dbe442c7c16 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 8 Feb 2012 08:51:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3943 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 3dd226b1b..808e06300 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -269,7 +269,7 @@ bool_t chSchIsPreemptionRequired(void) { if the first thread on the ready queue has a higher priority. Otherwise, if the running thread has used up its time quantum, reschedule if the first thread on the ready queue has equal or higher priority.*/ - return currp->r_preempt ? p1 > p2 : p1 >= p2; + return currp->p_preempt ? p1 > p2 : p1 >= p2; #else /* If the round robin preemption feature is not enabled then performs a simpler comparison.*/ -- cgit v1.2.3 From 18b8b495244411bb33254ea0d8b868259077be7d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 8 Feb 2012 17:53:52 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3946 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 808e06300..9739a595b 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -127,10 +127,12 @@ void chSchGoSleepS(tstate_t newstate) { static void wakeup(void *p) { Thread *tp = (Thread *)p; + chSysLockFromIsr(); switch (tp->p_state) { case THD_STATE_READY: /* Handling the special case where the thread has been made ready by another thread with higher priority.*/ + chSysUnlockFromIsr(); return; #if CH_USE_SEMAPHORES || CH_USE_QUEUES || \ (CH_USE_CONDVARS && CH_USE_CONDVARS_TIMEOUT) @@ -151,6 +153,7 @@ static void wakeup(void *p) { } tp->p_u.rdymsg = RDY_TIMEOUT; chSchReadyI(tp); + chSysUnlockFromIsr(); } /** -- cgit v1.2.3 From cb5fb91d7174222a07842a2d795f28bcda2ef704 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 12 Feb 2012 09:01:03 +0000 Subject: Fixed bug 3486874. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3951 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 9739a595b..6f28d04bb 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -299,7 +299,9 @@ void chSchDoRescheduleBehind(void) { /* Picks the first thread from the ready queue and makes it current.*/ setcurrp(fifo_remove(&rlist.r_queue)); currp->p_state = THD_STATE_CURRENT; +#if CH_TIME_QUANTUM > 0 otp->p_preempt = CH_TIME_QUANTUM; +#endif chSchReadyI(otp); chSysSwitch(currp, otp); } -- cgit v1.2.3 From 456a8cbd82f200dda163e7997d60fe4a92c5841e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 16 Jun 2012 15:07:15 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4280 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index 6f28d04bb..a7864bc71 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -74,6 +74,8 @@ void _scheduler_init(void) { Thread *chSchReadyI(Thread *tp) { Thread *cp; + chDbgCheckClassI(); + /* Integrity checks.*/ chDbgAssert((tp->p_state != THD_STATE_READY) && (tp->p_state != THD_STATE_FINAL), -- cgit v1.2.3 From 184a71345c6a36a9a8664eda8fbcc3ea728267a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Feb 2013 10:58:09 +0000 Subject: Updated license years. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5102 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chschd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chschd.c') diff --git a/os/kernel/src/chschd.c b/os/kernel/src/chschd.c index a7864bc71..1106cf03f 100644 --- a/os/kernel/src/chschd.c +++ b/os/kernel/src/chschd.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3