From 25e84695c48ae09387c8cb398966206d9091e686 Mon Sep 17 00:00:00 2001 From: Terraneo Federico <fede.tft@miosix.org> Date: Fri, 13 May 2016 00:41:24 +0200 Subject: [PATCH] Reverted part of the previous refactoring, because calling IRQfindNextThread() before IRQwakeThreads() in IRQtierInterrupt() prevents threads that will be woken up from being eligible for execution. --- miosix/kernel/kernel.cpp | 7 ++++--- miosix/kernel/kernel.h | 2 +- miosix/kernel/scheduler/priority/priority_scheduler.cpp | 9 +++------ miosix/kernel/scheduler/priority/priority_scheduler.h | 4 +--- miosix/kernel/scheduler/scheduler.h | 6 ++---- miosix/kernel/scheduler/timer_interrupt.h | 7 ++++--- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/miosix/kernel/kernel.cpp b/miosix/kernel/kernel.cpp index 79e8c507..80856516 100644 --- a/miosix/kernel/kernel.cpp +++ b/miosix/kernel/kernel.cpp @@ -83,6 +83,8 @@ static unsigned char interruptDisableNesting=0; #ifdef USE_CSTIMER +#define CST_QUANTUM 84000 //FIXME: find a way to propagate this here!!! + /// Used for context switches with the high resolution timer static SleepData csRecord; @@ -210,7 +212,6 @@ void startKernel() // Dispatch the task to the architecture-specific function #ifdef USE_CSTIMER // Set the first checkpoint interrupt -#define CST_QUANTUM 84000 //FIXME: find a way to propagate this here!!! csRecord.p = 0; csRecord.wakeup_time = CST_QUANTUM; csRecord.next = sleeping_list; @@ -293,7 +294,7 @@ void IRQaddToSleepingList(SleepData *x) * It is used by the kernel, and should not be used by end users. * \return true if some thread was woken. */ -bool IRQwakeThreads(long long currentTick, unsigned int burst) +bool IRQwakeThreads(long long currentTick) { #ifndef USE_CSTIMER tick++;//Increment tick @@ -318,7 +319,7 @@ bool IRQwakeThreads(long long currentTick, unsigned int burst) //Add next cs item to the list via IRQaddToSleepingList //Note that the next timer interrupt is set by IRQaddToSleepingList //according to the head of the list! - csRecord.wakeup_time += burst; + csRecord.wakeup_time += CST_QUANTUM; IRQaddToSleepingList(&csRecord); //It would also set the next timer interrupt } #endif //USE_CSTIMER diff --git a/miosix/kernel/kernel.h b/miosix/kernel/kernel.h index 50c8d951..936e6ed4 100644 --- a/miosix/kernel/kernel.h +++ b/miosix/kernel/kernel.h @@ -1010,7 +1010,7 @@ private: //Need access to status friend void IRQaddToSleepingList(SleepData *x); //Needs access to status - friend bool IRQwakeThreads(long long currentTick, unsigned int burst); + friend bool IRQwakeThreads(long long currentTick); //Needs access to watermark, status, next friend void *idleThread(void *argv); //Needs to create the idle thread diff --git a/miosix/kernel/scheduler/priority/priority_scheduler.cpp b/miosix/kernel/scheduler/priority/priority_scheduler.cpp index 36453354..6f58904e 100644 --- a/miosix/kernel/scheduler/priority/priority_scheduler.cpp +++ b/miosix/kernel/scheduler/priority/priority_scheduler.cpp @@ -29,8 +29,6 @@ #include "kernel/error.h" #include "kernel/process.h" -static const unsigned int cstQuantum=84000; ///FIXME: remove - #ifdef SCHED_TYPE_PRIORITY namespace miosix { @@ -199,9 +197,9 @@ void PriorityScheduler::IRQsetIdleThread(Thread *idleThread) idle=idleThread; } -unsigned int PriorityScheduler::IRQfindNextThread() +void PriorityScheduler::IRQfindNextThread() { - if(kernel_running!=0) return cstQuantum;//If kernel is paused, do nothing + if(kernel_running!=0) return;//If kernel is paused, do nothing for(int i=PRIORITY_MAX-1;i>=0;i--) { if(thread_list[i]==NULL) continue; @@ -228,7 +226,7 @@ unsigned int PriorityScheduler::IRQfindNextThread() //Rotate to next thread so that next time the list is walked //a different thread, if available, will be chosen first thread_list[i]=temp; - return cstQuantum; + return; } else temp=temp->schedData.next; if(temp==thread_list[i]->schedData.next) break; } @@ -239,7 +237,6 @@ unsigned int PriorityScheduler::IRQfindNextThread() #ifdef WITH_PROCESSES MPUConfiguration::IRQdisable(); #endif //WITH_PROCESSES - return cstQuantum; } Thread *PriorityScheduler::thread_list[PRIORITY_MAX]={0}; diff --git a/miosix/kernel/scheduler/priority/priority_scheduler.h b/miosix/kernel/scheduler/priority/priority_scheduler.h index bc7d335f..51004298 100644 --- a/miosix/kernel/scheduler/priority/priority_scheduler.h +++ b/miosix/kernel/scheduler/priority/priority_scheduler.h @@ -136,10 +136,8 @@ public: * If the kernel is paused does nothing. * It's behaviour is to modify the global variable miosix::cur which always * points to the currently running thread. - * \return the burst or time quantum. That is, the time till the next - * preemption */ - static unsigned int IRQfindNextThread(); + static void IRQfindNextThread(); private: diff --git a/miosix/kernel/scheduler/scheduler.h b/miosix/kernel/scheduler/scheduler.h index 566c98cc..08e1f162 100644 --- a/miosix/kernel/scheduler/scheduler.h +++ b/miosix/kernel/scheduler/scheduler.h @@ -163,12 +163,10 @@ public: * If the kernel is paused does nothing. * It's behaviour is to modify the global variable miosix::cur which always * points to the currently running thread. - * \return the burst or time quantum. That is, the time till the next - * preemption */ - static unsigned int IRQfindNextThread() + static void IRQfindNextThread() { - return T::IRQfindNextThread(); + T::IRQfindNextThread(); } }; diff --git a/miosix/kernel/scheduler/timer_interrupt.h b/miosix/kernel/scheduler/timer_interrupt.h index f7d05a74..6ae14068 100644 --- a/miosix/kernel/scheduler/timer_interrupt.h +++ b/miosix/kernel/scheduler/timer_interrupt.h @@ -40,15 +40,16 @@ namespace miosix { extern volatile int kernel_running;///\internal Do not use outside the kernel extern volatile bool tick_skew;///\internal Do not use outside the kernel extern volatile Thread *cur;///\internal Do not use outside the kernel -extern bool IRQwakeThreads(long long currentTick, unsigned int burst);///\internal Do not use outside the kernel +extern bool IRQwakeThreads(long long currentTick);///\internal Do not use outside the kernel inline void IRQtimerInterrupt(long long currentTick) { miosix_private::IRQstackOverflowCheck(); + IRQwakeThreads(currentTick); - unsigned int burst=Scheduler::IRQfindNextThread();//If the kernel is running, preempt + Scheduler::IRQfindNextThread();//If the kernel is running, preempt if(kernel_running!=0) tick_skew=true; - IRQwakeThreads(currentTick,burst); + #ifndef SCHED_TYPE_PRIORITY -- GitLab