Scheduler
processor.cpp
Go to the documentation of this file.
1 
10 #include "processor.h"
11 
12 #include <iomanip>
13 #include <iostream>
14 #include <fstream>
15 
16 #include <utils/log.h>
17 
18 #include "time.h"
19 #include "process.h"
21 
22 using namespace Scheduler;
23 
24 //TODO: make the Utils::Record use a shared_ptr so we don't need get()
25 Processor::Processor(std::shared_ptr<Utils::Configuration> c) : conf(c), usageHistory(Utils::Record(c, "usage")), freqHistory(Utils::Record(c, "frequency"))
26 {
27 }
28 
30 {
31  delete temperatureModel;
32 }
33 
34 double Processor::getMaxFreq() const
35 {
36  return maxFreq;
37 }
38 
39 double Processor::getMinFreq() const
40 {
41  return minFreq;
42 }
43 
44 double Processor::getUsage() const
45 {
46  return usage;
47 }
48 
50 {
51  long long int deltaIdle = totalIdleTicks - previousIdleTicks;
52  long long int deltaBusy = totalBusyTicks - previousBusyTicks;
53  previousIdleTicks = totalIdleTicks;
54  previousBusyTicks = totalBusyTicks;
55  long long int sumDelta = deltaIdle + deltaBusy;
56  if (sumDelta == 0)
57  {
58  usage = 0.0;
59  }
60  else
61  {
62  usage = (double)deltaBusy/(double)sumDelta;
63  }
64  usageHistory.add(Time::getTime(), usage);
65 }
66 
68 {
69  totalBusyTicks = totalIdleTicks = 0;
70 }
71 
72 bool Processor::isBusy() const
73 {
74  return (runningTask != nullptr);
75 }
76 
77 
78 bool Processor::isRunning(std::shared_ptr<Process> p) const
79 {
80  return (runningTask == p);
81 }
82 
83 
84 void Processor::setRunning(std::shared_ptr<Process> p)
85 {
86  runningTask = p;
87 }
88 
89 
90 
91 
92 std::shared_ptr<Process> Processor::getRunningTask()
93 {
94  return runningTask;
95 }
96 
97 
98 
99 
100 void Processor::updateTemperature(double timeInterval)
101 {
102  /*FIXME where should the powerCoeff of an idle processor be defined?*/
103  double powerCoeff = (runningTask==nullptr) ? 0.0: runningTask->powerCoeff;
104 
105  temperatureModel->updateTemperature(timeInterval, &powerParams, powerCoeff, freq);
106 
107 }
108 
109 
110 
112 {
113  temperatureModel = model;
114 }
115 
117 {
118  return temperatureModel;
119 }
120 
121 void Processor::setFreq(double f)
122 {
123  double epsilon = 0.0000001;
124  if (f < (freq - epsilon) || (f > freq + epsilon))
125  freqHistory.add(Time::getTime(), f);
126  freq = f;
127 }
128 
129 
130 double Processor::getFreq() const
131 {
132  return freq;
133 }
134 
135 
136 
137 void Processor::printTemperatureReport(std::string folder) const
138 {
139  temperatureModel->printTemperatureHistory(folder);
140 }
141 
142 void Processor::printEnergyReport(std::string folder) const
143 {
144  temperatureModel->printEnergyHistory(folder);
145 }
146 
147 
148 
149 
150 void Processor::printUsageReport(std::string folder) const
151 {
152  usageHistory.printToFile(folder);
153 }
154 
155 void Processor::printFreqReport(std::string folder) const
156 {
157  freqHistory.printToFile(folder);
158 }
159 
160 void Processor::printReports(std::string folder) const
161 {
162  printTemperatureReport(folder);
163  printEnergyReport(folder);
164  printUsageReport(folder);
165  printFreqReport(folder);
166 }
167 
168 
170 {
171  busy ? (totalBusyTicks++) : (totalIdleTicks++);
172 }
173 
174 void Processor::power(bool b)
175 {
176  powerParams.powered = b;
177 }
178 
179 bool Processor::powered() const
180 {
181  return powerParams.powered;
182 }
183 
184 
186 {
187  return temperatureModel->getTemperature();
188 }
189 
190 
191 
192 
double getMinFreq() const
get the minimum frequency at which this processor can operate
Definition: processor.cpp:39
double getFreq() const
get the current frequency of the processor
Definition: processor.cpp:130
static double getTime()
Definition: time.cpp:16
void printToFile(std::string folder) const
Definition: record.cpp:23
virtual void printTemperatureHistory(std::string filename)=0
void printEnergyReport(std::string folder) const
Definition: processor.cpp:142
TemperatureModel * getTemperatureModel()
Definition: processor.cpp:116
void updateUsage()
updates the value of the usage percentage.
Definition: processor.cpp:49
void setRunning(std::shared_ptr< Process > p)
Definition: processor.cpp:84
void printTemperatureReport(std::string folder) const
Definition: processor.cpp:137
void add(double time, double element)
Definition: record.cpp:41
bool isBusy() const
return true if the processor is running any task
Definition: processor.cpp:72
Processor(std::shared_ptr< Utils::Configuration >)
Definition: processor.cpp:25
virtual double getTemperature()=0
double getTemperature() const
Definition: processor.cpp:185
double getUsage() const
get the current usage of the processor
Definition: processor.cpp:44
void printFreqReport(std::string folder) const
Definition: processor.cpp:155
void printUsageReport(std::string folder) const
Definition: processor.cpp:150
void power(bool p)
power the processor on or off
Definition: processor.cpp:174
void setFreq(double)
set the current frequency of the processor
Definition: processor.cpp:121
virtual void printEnergyHistory(std::string filename)=0
void updateTemperature(double timeInterval)
Definition: processor.cpp:100
bool powered() const
return true if the processor is powered on
Definition: processor.cpp:179
double getMaxFreq() const
get the maximum frequency at which this processor can operate
Definition: processor.cpp:34
Definition: context.h:16
virtual double updateTemperature(double timeInterval, struct PowerParams *params, double taskPowerCoeff, double freq)=0
std::shared_ptr< Process > getRunningTask()
Definition: processor.cpp:92
void printReports(std::string folder) const
Definition: processor.cpp:160
void setTemperatureModel(TemperatureModel *)
Definition: processor.cpp:111
bool isRunning(std::shared_ptr< Process > p) const
returns true if the processor is running the task provided as argument
Definition: processor.cpp:78