Scheduler
system.cpp
Go to the documentation of this file.
1 
10 #include "system.h"
11 
12 #include <cassert>
13 #include <memory>
14 
15 #include <utils/log.h>
16 #include <utils/randomGenerator.h>
17 
18 #include "process.h"
19 #include "processor.h"
20 #include "queue.h"
21 #include "schedulerConfiguration.h"
22 #include "taskScheduler.h"
23 
24 using namespace Scheduler;
25 
26 System *System::instance = nullptr;
27 
29 {
30  assert (instance != nullptr);
31  return instance;
32 }
33 
34 void System::buildSystem(std::shared_ptr<SchedulerConfiguration> c)
35 {
37 
38  if (instance == nullptr)
39  {
40  instance = new System();
41  instance->conf = c;
42  instance->proc = new Processor(c);
43  instance->proc->setTemperatureModel(c->getTemperatureModelFromFile());
44  instance->governor = instance->conf->getFreqGovernorFromFile();
45  assert(instance->governor != nullptr);
46  Utils::Log log;
47 #ifdef PRINT
48  log << Utils::Log::Color::green << "Using frequency governor ";
49  log << instance->governor->getName() << Utils::Log::Color::normal << "\n";
50 #endif
51  instance->reportsFolder = c->getStringValue("global", "reportsFolder");
52  }
53  else
54  {
55  instance->conf = c;
56  }
57  delete processGen;
58 }
59 
60 System::System()
61 {
62 }
63 
65 {
66  delete proc;
67  delete scheduler;
68  delete governor;
69 }
70 
71 void System::updateTemperature(double timeInterval)
72 {
73  proc->updateTemperature(timeInterval);
74 }
75 
77 {
78  return proc;
79 }
80 
81 
82 void System::printReports()
83 {
84  proc->printReports(reportsFolder);
85  governor->printReport(reportsFolder);
87 }
88 
90 {
91  for (size_t i = 0; i < staticTaskSet.size(); i++)
92  {
93  std::shared_ptr<Process> p = staticTaskSet[i];
94  std::ofstream file;
95  file.open((conf->getFilePrefix() + "processes.txt"), std::ios_base::app);
96  p->print(file);
97  file.close();
98  }
99 }
100 
101 
103 {
104  if (!proc->powered())
105  return;
106  Queue *queue = Queue::getReadyQueue();
107  governor->updateFreq(proc, queue);
108 }
109 
111 {
112  assert(conf != nullptr);
113  if (scheduler == nullptr)
114  scheduler = new TaskScheduler(conf);
115  return scheduler;
116 }
117 
118 
119 
121 {
122  scheduler->end(reportsFolder);
123  printReports();
124 }
125 
126 
127 void System::addRealTimeTask(std::shared_ptr<Process> p)
128 {
129  staticTaskSet.push_back(p);
130 }
131 
132 
133 std::vector<std::shared_ptr<Process>> System::getStaticTaskSet()
134 {
135  return staticTaskSet;
136 }
137 
138 
140 {
141  return jobsArrivalCount;
142 }
143 
145 {
146  jobsArrivalCount++;
147 }
148 
149 
150 
151 
static void buildSystem(std::shared_ptr< SchedulerConfiguration > conf)
Definition: system.cpp:34
void updateTemperature(double timeInterval)
updates and logs the temperature of the processor. This function has to be called at least every time...
Definition: system.cpp:71
void addRealTimeTask(std::shared_ptr< Process > p)
add a real-time task to the system&#39;s list
Definition: system.cpp:127
This class implements the ready queue and the wait queue. Those queues contain processes ready to run...
Definition: queue.h:28
void end(std::string reportsFolder)
cleanup and print reports
virtual void printReport(std::string)
Definition: freqGovernor.h:31
static System * getInstance()
Definition: system.cpp:28
long long int getJobsArrivalCount()
returns the number of jobs issued since the beginning of the simulation
Definition: system.cpp:139
static Queue * getReadyQueue()
get a pointer to the system&#39;s ready queue
Definition: queue.cpp:30
void printProcessesReport()
Definition: system.cpp:89
void end()
prints reports
Definition: system.cpp:120
TaskScheduler * getScheduler()
returns the task scheduler object
Definition: system.cpp:110
void incrementJobsArrivalCount()
increments the number of jobs issued since the beginning of simulation
Definition: system.cpp:144
void updateTemperature(double timeInterval)
Definition: processor.cpp:100
Definition: log.h:18
bool powered() const
return true if the processor is powered on
Definition: processor.cpp:179
Processor * getProc()
return the processor
Definition: system.cpp:76
std::vector< std::shared_ptr< Process > > getStaticTaskSet()
get the list of real-time tasks in the system
Definition: system.cpp:133
virtual std::string getName()=0
virtual void updateFreq(Processor *proc, Queue *readyQueue)=0
void printReports(std::string folder) const
Definition: processor.cpp:160
void setTemperatureModel(TemperatureModel *)
Definition: processor.cpp:111
void updateFreq()
invokes the frequency governor to changes the frequency of the processor
Definition: system.cpp:102