Skip to content

Commit

Permalink
Modified to fix EDF; if tasks miss too many deadlines during normal o…
Browse files Browse the repository at this point in the history
…peration, the program kills itself to prevent it from spiraling out of control.
  • Loading branch information
jpm8766 committed Mar 22, 2013
1 parent e4d66e2 commit de9eb7d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion EDFScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 9 additions & 2 deletions SchedulingAlgorithms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h>
using namespace std;

#include "SchedulingAlgorithms.h"
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 12 additions & 1 deletion Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Task.h"
#include <cassert>
#include <semaphore.h>
#include <stdlib.h>

//1ms deadline and period
#define TIMER_PERIOD_NANO (5000000)
Expand Down Expand Up @@ -45,6 +46,7 @@ scheduler(scheduler) {
}

Task::~Task() {
pthread_abort(thread);
sem_destroy(&doWork);
timer_delete(deadlineTimer);
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion TestSets/Test6
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
T1 3 4 4
T2 2 8 8
T2 3 8 8
10 changes: 5 additions & 5 deletions Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */

0 comments on commit de9eb7d

Please sign in to comment.