diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/chinit.c | 2 | ||||
-rw-r--r-- | src/chschd.c | 12 | ||||
-rw-r--r-- | src/include/scheduler.h | 2 | ||||
-rw-r--r-- | src/templates/chconf.h | 7 |
4 files changed, 22 insertions, 1 deletions
diff --git a/src/chinit.c b/src/chinit.c index b8d36a6e5..2aee810a0 100644 --- a/src/chinit.c +++ b/src/chinit.c @@ -70,10 +70,12 @@ void chSysInit(void) { * together with the \p CH_TIME_QUANTUM macro, the round robin interval. */ void chSysTimerHandlerI(void) { +#ifdef CH_USE_ROUNDROBIN /* running thread has not used up quantum yet? */ if (rlist.r_preempt > 0) /* decrement remaining quantum */ rlist.r_preempt--; +#endif #ifdef CH_USE_SYSTEMTIME rlist.r_stime++; #endif diff --git a/src/chschd.c b/src/chschd.c index 6a82eb1d8..c3e0fbaed 100644 --- a/src/chschd.c +++ b/src/chschd.c @@ -36,7 +36,9 @@ void chSchInit(void) { fifo_init(&rlist.r_queue); rlist.r_prio = NOPRIO; +#ifdef CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; +#endif #ifdef CH_USE_SYSTEMTIME rlist.r_stime = 0; #endif @@ -83,7 +85,9 @@ void chSchGoSleepS(tstate_t newstate) { (otp = currp)->p_state = newstate; (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; +#ifdef CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; +#endif #ifdef CH_USE_TRACE chDbgTrace(otp, currp); #endif @@ -152,7 +156,9 @@ void chSchWakeupS(Thread *ntp, msg_t msg) { Thread *otp = currp; chSchReadyI(otp); (currp = ntp)->p_state = PRCURR; +#ifdef CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; +#endif #ifdef CH_USE_TRACE chDbgTrace(otp, ntp); #endif @@ -172,7 +178,9 @@ void chSchDoRescheduleI(void) { chSchReadyI(otp); /* pick the first thread from the ready queue */ (currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR; +#ifdef CH_USE_ROUNDROBIN rlist.r_preempt = CH_TIME_QUANTUM; +#endif #ifdef CH_USE_TRACE chDbgTrace(otp, currp); #endif @@ -204,12 +212,16 @@ void chSchRescheduleS(void) { bool_t chSchRescRequiredI(void) { tprio_t p1 = firstprio(&rlist.r_queue); tprio_t p2 = currp->p_prio; +#ifdef 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 + return p1 > p2; +#endif } /** @} */ diff --git a/src/include/scheduler.h b/src/include/scheduler.h index 3a6486efe..362dd9d31 100644 --- a/src/include/scheduler.h +++ b/src/include/scheduler.h @@ -41,7 +41,9 @@ typedef struct { ThreadsQueue r_queue; tprio_t r_prio; +#ifdef CH_USE_ROUNDROBIN cnt_t r_preempt; +#endif #ifndef CH_CURRP_REGISTER_CACHE /** the currently running thread */ Thread *r_current; diff --git a/src/templates/chconf.h b/src/templates/chconf.h index cc4f992f2..d059f3097 100644 --- a/src/templates/chconf.h +++ b/src/templates/chconf.h @@ -39,6 +39,10 @@ * included in the kernel.*/
#define CH_USE_VIRTUAL_TIMERS
+/** Configuration option: if specified then the kernel performs the round
+ * robin scheduling algorithm on threads of equal priority. */
+#define CH_USE_ROUNDROBIN
+
/** Configuration option: if specified then the System Timer subsystem is
* included in the kernel.*/
#define CH_USE_SYSTEMTIME
@@ -139,7 +143,8 @@ #define CH_FREQUENCY 1000
/** Configuration option: This constant is the number of ticks allowed for the
- * threads before preemption occurs.*/
+ * threads before preemption occurs. This option is only meaningful if the
+ * option \p CH_USE_ROUNDROBIN is also active.*/
#define CH_TIME_QUANTUM 20
/** Configuration option: Defines a CPU register to be used as storage for the
|