From de9eb7df1a47730d60819733506f794a7a467ffb Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 22 Mar 2013 11:14:28 -0400 Subject: [PATCH] Modified to fix EDF; if tasks miss too many deadlines during normal operation, the program kills itself to prevent it from spiraling out of control. --- EDFScheduler.cpp | 2 +- SchedulingAlgorithms.cc | 11 +++++++++-- Task.cpp | 13 ++++++++++++- Task.h | 4 +++- TestSets/Test6 | 2 +- Thread.h | 10 +++++----- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/EDFScheduler.cpp b/EDFScheduler.cpp index 77134e3..183f43c 100755 --- a/EDFScheduler.cpp +++ b/EDFScheduler.cpp @@ -23,7 +23,7 @@ void EDFScheduler::scheduleTasks() { Task *task = taskSet[i]; //if this task is running, set it back to ready - if(task->getPriority() <= TP_RUNNING) { + if(task->getPriority() != TP_READY) { task->setPriority(TP_READY); } diff --git a/SchedulingAlgorithms.cc b/SchedulingAlgorithms.cc index c3393d0..5738ab5 100755 --- a/SchedulingAlgorithms.cc +++ b/SchedulingAlgorithms.cc @@ -2,6 +2,7 @@ #include #include #include +#include using namespace std; #include "SchedulingAlgorithms.h" @@ -55,12 +56,18 @@ int main(int argc, char *argv[]) { //start the simulation sc->start(); - sc->join(); //this will stick because the thread never gets stop()'d - cout << "Exiting..." << endl; +// usleep(100000); + +// sc->stop(); + sc->join(); //this will stick because the thread never gets stop()'d //cleanup delete sc; + + cout << "Exiting..." << endl; + + } else { cerr << "Usage: " << argv[0] << " Filename SchedulerInt" << endl; } diff --git a/Task.cpp b/Task.cpp index bbfd985..5679818 100755 --- a/Task.cpp +++ b/Task.cpp @@ -8,6 +8,7 @@ #include "Task.h" #include #include +#include //1ms deadline and period #define TIMER_PERIOD_NANO (5000000) @@ -45,6 +46,7 @@ scheduler(scheduler) { } Task::~Task() { + pthread_abort(thread); sem_destroy(&doWork); timer_delete(deadlineTimer); } @@ -117,7 +119,7 @@ void Task::setComputeTime(int c) { long Task::getRemainingDeadline() { timer_gettime(deadlineTimer, &deadlineRemainingSpec); - return deadlineRemainingSpec.it_value.tv_nsec; + return (deadlineRemainingSpec.it_value.tv_nsec + 2500000)/50000000; } int Task::getPeriod() { @@ -136,6 +138,7 @@ void Task::setDeadline(int d) { deadline = d; } +static int missedDeadlines = 0; void Task::tick(union sigval sig) { //get the schedulers semaphore from the timer... Task* self = (Task*) sig.sival_ptr; @@ -149,6 +152,14 @@ void Task::tick(union sigval sig) { #if TRACE_EVENT_LOG_CRITICAL TraceEvent(_NTO_TRACE_INSERTUSRSTREVENT, TRACE_EVENT_DEADLINE_MISS, self->deadlineMissedMsg); #endif + missedDeadlines++; + + if(missedDeadlines > MAX_DEADLINE_MISSES) { + exit(-1); + } + } else { + if((missedDeadlines > 0)) + missedDeadlines--; } self->state = TP_READY; diff --git a/Task.h b/Task.h index f5f7594..be2c4a7 100755 --- a/Task.h +++ b/Task.h @@ -17,8 +17,10 @@ #include "Thread.h" #include "SchedulingAlgorithms.h" +#define MAX_DEADLINE_MISSES (15) + enum TaskPriority { - TP_FINISHED = 1, TP_READY = 37, TP_RUNNING = 38, TP_SCHEDULER = 39 + TP_FINISHED = 1, TP_READY = 7, TP_RUNNING = 8, TP_SCHEDULER = 9 }; class Task : public Thread { diff --git a/TestSets/Test6 b/TestSets/Test6 index 55306a6..d540e3b 100644 --- a/TestSets/Test6 +++ b/TestSets/Test6 @@ -1,2 +1,2 @@ T1 3 4 4 -T2 2 8 8 +T2 3 8 8 diff --git a/Thread.h b/Thread.h index 8e15ab8..2108c6c 100755 --- a/Thread.h +++ b/Thread.h @@ -68,16 +68,16 @@ class Thread { */ std::string name; -private: /** - * Static function which calls the Thread's run() method. + * pthread id for this thread. */ - static void* pthread_entry(void* args); + pthread_t thread; +private: /** - * pthread id for this thread. + * Static function which calls the Thread's run() method. */ - pthread_t thread; + static void* pthread_entry(void* args); }; #endif /* THREAD_H_ */