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 --- docs/Doxyfile | 2 +- docs/reports/SPC563M64-80.txt | 6 +- docs/rsc/layout.xml | 184 ++++++++++++++++++++++++++++++++++++++++++ os/kernel/include/chschd.h | 30 +++++-- os/kernel/kernel.dox | 12 --- os/kernel/src/chschd.c | 56 +++++-------- os/kernel/src/chthreads.c | 7 +- readme.txt | 7 ++ 8 files changed, 247 insertions(+), 57 deletions(-) create mode 100644 docs/rsc/layout.xml diff --git a/docs/Doxyfile b/docs/Doxyfile index 9ebf7f47d..6f2187e40 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -511,7 +511,7 @@ FILE_VERSION_FILTER = # file name after the option, if omitted DoxygenLayout.xml will be used as the name # of the layout file. -LAYOUT_FILE = +LAYOUT_FILE = ./rsc/layout.xml #--------------------------------------------------------------------------- # configuration options related to warning and progress messages diff --git a/docs/reports/SPC563M64-80.txt b/docs/reports/SPC563M64-80.txt index 2b4930c77..a11669746 100644 --- a/docs/reports/SPC563M64-80.txt +++ b/docs/reports/SPC563M64-80.txt @@ -92,7 +92,7 @@ Settings: SYSCLK=80, optimal wait states, prefetching enabled --- Result: SUCCESS ---------------------------------------------------------------------------- --- Test Case 11.1 (Benchmark, messages #1) ---- Score : 280181 msgs/S, 560362 ctxswc/S +--- Score : 280180 msgs/S, 560360 ctxswc/S --- Result: SUCCESS ---------------------------------------------------------------------------- --- Test Case 11.2 (Benchmark, messages #2) @@ -120,7 +120,7 @@ Settings: SYSCLK=80, optimal wait states, prefetching enabled --- Result: SUCCESS ---------------------------------------------------------------------------- --- Test Case 11.8 (Benchmark, round robin context switching) ---- Score : 654408 reschedulations/S, 654408 ctxswc/S +--- Score : 614140 reschedulations/S, 614140 ctxswc/S --- Result: SUCCESS ---------------------------------------------------------------------------- --- Test Case 11.9 (Benchmark, I/O Queues throughput) @@ -128,7 +128,7 @@ Settings: SYSCLK=80, optimal wait states, prefetching enabled --- Result: SUCCESS ---------------------------------------------------------------------------- --- Test Case 11.10 (Benchmark, virtual timers set/reset) ---- Score : 1093662 timers/S +--- Score : 1093664 timers/S --- Result: SUCCESS ---------------------------------------------------------------------------- --- Test Case 11.11 (Benchmark, semaphores wait/signal) diff --git a/docs/rsc/layout.xml b/docs/rsc/layout.xml new file mode 100644 index 000000000..eba6d68b3 --- /dev/null +++ b/docs/rsc/layout.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/os/kernel/include/chschd.h b/os/kernel/include/chschd.h index c06ed8100..b8406722b 100644 --- a/os/kernel/include/chschd.h +++ b/os/kernel/include/chschd.h @@ -66,6 +66,7 @@ * * @brief Ready list header. */ +#if !defined(PORT_OPTIMIZED_READYLIST_STRUCT) || defined(__DOXYGEN__) typedef struct { ThreadsQueue r_queue; /**< @brief Threads queue. */ tprio_t r_prio; /**< @brief This field must be @@ -85,10 +86,11 @@ typedef struct { thread. */ #endif } ReadyList; +#endif /* !defined(PORT_OPTIMIZED_READYLIST_STRUCT) */ -#if !defined(__DOXYGEN__) +#if !defined(PORT_OPTIMIZED_RLIST_EXT) && !defined(__DOXYGEN__) extern ReadyList rlist; -#endif +#endif /* !defined(PORT_OPTIMIZED_RLIST_EXT) */ #ifdef CH_CURRP_REGISTER_CACHE register Thread *currp asm(CH_CURRP_REGISTER_CACHE); @@ -115,19 +117,35 @@ extern "C" { } #endif +/** + * @brief Determines if the current thread must reschedule. + * @details This function returns @p TRUE if there is a ready thread with + * higher priority. + */ +#if !defined(PORT_OPTIMIZED_ISRESCHREQUIREDI) && !defined(__DOXYGEN__) +#define chSchIsRescRequiredI() (firstprio(&rlist.r_queue) > currp->p_prio) +#endif /* !defined(PORT_OPTIMIZED_ISRESCHREQUIREDI) */ + /** * @brief Determines if yielding is possible. * @details This function returns @p TRUE if there is a ready thread with * equal or higher priority. */ +#if !defined(PORT_OPTIMIZED_CANYIELDS) && !defined(__DOXYGEN__) #define chSchCanYieldS() (firstprio(&rlist.r_queue) >= currp->p_prio) +#endif /* !defined(PORT_OPTIMIZED_CANYIELDS) */ /** - * @brief Determines if the current thread must reschedule. - * @details This function returns @p TRUE if there is a ready thread with - * higher priority. + * @brief Yields the time slot. + * @details Yields the CPU control to the next thread in the ready list with + * equal or higher priority, if any. */ -#define chSchIsRescRequiredI() (firstprio(&rlist.r_queue) > currp->p_prio) +#if !defined(PORT_OPTIMIZED_DOYIELDS) || defined(__DOXYGEN__) +#define chSchDoYieldS(void) { \ + if (chSchCanYieldS()) \ + chSchDoRescheduleI(); \ +} +#endif /* !defined(PORT_OPTIMIZED_DOYIELDS) */ #endif /* _CHSCHD_H_ */ diff --git a/os/kernel/kernel.dox b/os/kernel/kernel.dox index 5ca6005f6..b55d53d49 100644 --- a/os/kernel/kernel.dox +++ b/os/kernel/kernel.dox @@ -61,18 +61,6 @@ * @ingroup base */ -/** - * @defgroup scheduler Scheduler - * ChibiOS/RT scheduler APIs and macros. - * @ingroup base - */ - -/** - * @defgroup threads Threads - * Threads related APIs. - * @ingroup base - */ - /** * @defgroup synchronization Synchronization * Synchronization services. 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) */ /** @} */ diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 79ea23f94..a2745b94c 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -21,7 +21,12 @@ * @file chthreads.c * @brief Threads code. * - * @addtogroup threads + * @defgroup threads Threads + * @ingroup base + * @details This module contains all the threads related APIs, creation, + * termination, synchronization, delay etc. Dynamic variants of + * the base static API are also included. + * * @{ */ diff --git a/readme.txt b/readme.txt index 7af58f577..670871f95 100644 --- a/readme.txt +++ b/readme.txt @@ -65,9 +65,16 @@ subdirectory, this should make things easier for RIDE7 users. The normal makefile is still available of course. - NEW: New article in the documentation. Fixed an orphaned page (STM8 port). +- NEW: The port layer now can "capture" the implementation of individual + scheduler API functions in order to provide architecture-optimized + versions. This is done because further scheduler optimizations are + becoming increasingly pointless without considering architecture and + compiler related constraints. - OPT: Optimization on the interface between scheduler and port layer, now the kernel is even smaller and the context switch performance improved quite a bit on all the supported architectures. +- OPT: Simplified the implementation of chSchYieldS() and made it a macro. + The previous implementation was probably overkill and took too much space. *** 1.5.3 *** - FIX: Removed C99-style variables declarations (bug 2964418)(backported -- cgit v1.2.3