Scheduler
missedDeadline.cpp
Go to the documentation of this file.
1 
10 #include "missedDeadline.h"
11 
12 #include <cassert>
13 #include <iostream>
14 #include <iomanip>
15 
16 #include <utils/log.h>
17 #include <scheduler/process.h>
19 #include <scheduler/system.h>
20 #include <scheduler/queue.h>
21 
22 using namespace Scheduler;
23 
25 {
26  assert(task != nullptr);
27  //std::cout << "deadline for process "<<task->getPid()<<"\n";
28  /*If we can't find the job in the system, it has already successfully completed*/
29  bool inSystem = false;
30  std::shared_ptr<Process> running = System::getInstance()->getProc()->getRunningTask();
31  if (running != nullptr
32  && running->getPid() == task->getPid()
33  && running->getJobNumber() == task->getJobNumber())
34  {
35  inSystem = true;
36  }
37  else
38  {
39  Queue *queue = Queue::getReadyQueue();
40  for (auto it = queue->begin(); it != queue->end(); it++)
41  //this is very bad performance. Can we do better?
42  {
43  if ((*it) == task
44  && ((*it)->getJobNumber() == task->getJobNumber()))
45  {
46  inSystem = true;
47  break;
48  }
49  }
50  }
51  if (inSystem)
52  {
53  print();
55  scheduler->dealWithMissedDeadlines(task);
56  scheduler->scheduleTask(eventType);
57  }
58  else
59  {
60  //std::cout << "Task "<<task->getPid()<<":"<<task->getJobNumber()<<" has completed successfully\n";
61  }
62 }
63 
64 
65 
67 {
68  assert(task != nullptr);
69  return "process missed deadline";
70 }
71 
72 
74 {
75 #ifdef PRINT
76  Utils::Log log;
77  log << std::fixed << std::setfill(' ') << std::setw(7) << std::setprecision(3);
78  log << getTime() << ": ";
79  log << Utils::Log::Color::red << "process ";
80  log << task->getPid()<<" missed deadline\n"<< Utils::Log::Color::normal;
81 #endif
82 }
std::shared_ptr< Process > task
Definition: event.h:60
This class implements the ready queue and the wait queue. Those queues contain processes ready to run...
Definition: queue.h:28
static System * getInstance()
Definition: system.cpp:28
static Queue * getReadyQueue()
get a pointer to the system&#39;s ready queue
Definition: queue.cpp:30
iterator begin()
Definition: queue.cpp:65
void scheduleTask(TriggeringEvent trigger)
This function is the scheduler. When called, it schedule the task to be executed on the processor ama...
void print() override
print information about the event
TaskScheduler * getScheduler()
returns the task scheduler object
Definition: system.cpp:110
void process()
handle the the event TODO: &#39;process&#39; is maybe not the best word for that, given that our simulator ac...
void dealWithMissedDeadlines(std::shared_ptr< Process > p)
to be called when a deadline mis event happends. This function will terminate the task and update the...
Definition: log.h:18
Processor * getProc()
return the processor
Definition: system.cpp:76
TriggeringEvent eventType
The event type is need by the scheduling discipline, to determine if this kind of event triggers invo...
Definition: event.h:64
std::string getName()
get the name of the event
iterator end()
Definition: queue.cpp:69
double getTime()
get the time at which the event is scheduled
Definition: event.cpp:36
std::shared_ptr< Process > getRunningTask()
Definition: processor.cpp:92