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/include/chschd.h | 19 +++++++++++-------- os/kernel/include/chthreads.h | 6 ++++++ 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'os/kernel/include') diff --git a/os/kernel/include/chschd.h b/os/kernel/include/chschd.h index 54076ec56..215398659 100644 --- a/os/kernel/include/chschd.h +++ b/os/kernel/include/chschd.h @@ -95,9 +95,6 @@ typedef struct { Thread *r_older; /**< @brief Older registry element. */ #endif /* End of the fields shared with the Thread structure.*/ -#if (CH_TIME_QUANTUM > 0) || defined(__DOXYGEN__) - cnt_t r_preempt; /**< @brief Round robin counter. */ -#endif Thread *r_current; /**< @brief The currently running thread. */ } ReadyList; @@ -154,6 +151,12 @@ extern "C" { #if !defined(PORT_OPTIMIZED_ISPREEMPTIONREQUIRED) bool_t chSchIsPreemptionRequired(void); #endif +#if !defined(PORT_OPTIMIZED_DORESCHEDULEBEHIND) || defined(__DOXYGEN__) + void chSchDoRescheduleBehind(void); +#endif +#if !defined(PORT_OPTIMIZED_DORESCHEDULEAHEAD) || defined(__DOXYGEN__) + void chSchDoRescheduleAhead(void); +#endif #if !defined(PORT_OPTIMIZED_DORESCHEDULE) void chSchDoReschedule(void); #endif @@ -197,7 +200,7 @@ extern "C" { #if !defined(PORT_OPTIMIZED_DOYIELDS) || defined(__DOXYGEN__) #define chSchDoYieldS() { \ if (chSchCanYieldS()) \ - chSchDoReschedule(); \ + chSchDoRescheduleBehind(); \ } #endif /* !defined(PORT_OPTIMIZED_DOYIELDS) */ @@ -212,19 +215,19 @@ extern "C" { #define chSchPreemption() { \ tprio_t p1 = firstprio(&rlist.r_queue); \ tprio_t p2 = currp->p_prio; \ - if (rlist.r_preempt) { \ + if (currp->p_preempt) { \ if (p1 > p2) \ - chSchDoReschedule(); \ + chSchDoRescheduleAhead(); \ } \ else { \ if (p1 >= p2) \ - chSchDoReschedule(); \ + chSchDoRescheduleBehind(); \ } \ } #else /* CH_TIME_QUANTUM == 0 */ #define chSchPreemption() { \ if (p1 >= p2) \ - chSchDoReschedule(); \ + chSchDoRescheduleAhead(); \ } #endif /* CH_TIME_QUANTUM == 0 */ /** @} */ diff --git a/os/kernel/include/chthreads.h b/os/kernel/include/chthreads.h index 66b593818..421a3e23f 100644 --- a/os/kernel/include/chthreads.h +++ b/os/kernel/include/chthreads.h @@ -121,6 +121,12 @@ struct Thread { * @brief References to this thread. */ trefs_t p_refs; +#endif + /** + * @brief Number of ticks remaining to this thread. + */ +#if (CH_TIME_QUANTUM > 0) || defined(__DOXYGEN__) + tslices_t p_preempt; #endif #if CH_DBG_THREADS_PROFILING || defined(__DOXYGEN__) /** -- cgit v1.2.3