Scheduler
temperatureAndAgingModel.cpp
Go to the documentation of this file.
1 
11 
12 #include <cmath>
13 #include <iostream>
14 #include <utility>
15 
16 #include <utils/log.h>
17 
18 #include <scheduler/time.h>
19 
20 using namespace Scheduler;
21 
22 
23 TemperatureAndAgingModel::TemperatureAndAgingModel(std::shared_ptr<Utils::Configuration> c)
24  : R(c->getDoubleValue("scheduler", "thermalResistance"))
25  , C(c->getDoubleValue("scheduler", "thermalCapacitance"))
26  , temperatureHistory(Utils::Record(c, "temperature"))
27  , energyHistory(Utils::Record(c, "energy"))
28  , instantaneousAgingHistory(Utils::Record(c, "instantaneousAging"))
29  , cumulativeAgingHistory(Utils::Record(c, "cumulativeAging"))
30  , endTime(c->getDoubleValue("scheduler","runningTime"))
31  , recordingTimeRatio(c->getDoubleValue("scheduler", "onlyLogTempAfterRatio"))
32  , activationEnergy(c->getDoubleValue("scheduler", "activationEnergy"))
33  , formFactor(c->getDoubleValue("scheduler", "formFactor"))
34 {
35  logTemperature = c->getBoolValue("scheduler", "logTemperature", false);
36  logEnergy = c->getBoolValue("scheduler", "logEnergy", false);
37  logAging = c->getBoolValue("scheduler", "logAging", false);
38 }
39 
41  , struct PowerParams *params
42  , double taskPowerCoeff
43  , double freq)
44 {
45  /*T(t) = [T0 - (Ta + RP)]exp(-t/(RC)) + (Ta + RP)*/
46  Utils::Log log;
47  if (params->powered)
48  {
49  params->power = params->voltage*params->voltage*freq*params->capa*taskPowerCoeff + params->leakage;
50  }
51  else
52  {
53  params->power = 0.0;
54  }
55  power = params->power;
56  params->energy += params->power*timeInterval;
57  computeAndLog(); //TODO not good
58  computeAging();
59  return T;
60 }
61 
62 
64 {
65  if (logTemperature)
66  temperatureHistory.printToFile(filename);
67  if (logAging)
68  instantaneousAgingHistory.printToFile(filename);
69 }
70 
72 {
73  if (logEnergy)
74  energyHistory.printToFile(filename);
75 }
76 
77 
78 void TemperatureAndAgingModel::computeAndLog()
79 {
80  double currentTime = Time::getTime();
81  double timeInterval = currentTime - previousTime;
82  previousTime = currentTime;
83  A = Ta + R*power;
84  T = (T0 - A)*exp(-timeInterval/(R*C)) + A;
85  T0 = T;
86  if (logTemperature)
87  {
88  if (Time::getTime() > recordingTimeRatio * endTime)
89  {
90  temperatureHistory.add(currentTime, T);
91  }
92  }
93  if (logEnergy)
94  energyHistory.add(currentTime, power);
95 }
96 
98 {
99  return T;
100 }
101 
102 
103 void TemperatureAndAgingModel::computeAging()
104 {
105  static double previousTime = 0.0;
106  //static double previousTemp = 0.0;
107  static double currentTime = 0.0;
108  static double previousRate = 0.0;
109  static double currentRate = 0.0;
110 
111  currentTime = Time::getTime();
112 
113  double Tk = T + 273.15; //Celsius to Kelvin
114 
115  currentRate = exp(-activationEnergy/(k*Tk))/(k*Tk);
116 
117  /*Trapezoidal rule integration*/
118  double a = (currentRate + previousRate)*(currentTime - previousTime)/2.0;
119  consumedLifetime += a;
120 
121  previousTime = currentTime;
122  previousRate = currentRate;
123  if (logAging)
124  instantaneousAgingHistory.add(currentTime, a);
125 }
126 
128 {
129  return consumedLifetime;
130 }
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
static double getTime()
Definition: time.cpp:16
void printTemperatureHistory(std::string filename) override
void printToFile(std::string folder) const
Definition: record.cpp:23
double updateTemperature(double timeInterval, struct PowerParams *params, double taskPowerCoeff, double freq) override
void add(double time, double element)
Definition: record.cpp:41
string filename
Definition: aging.py:5
TemperatureAndAgingModel(std::shared_ptr< Utils::Configuration > conf)
Definition: log.h:18
Definition: context.h:16
void printEnergyHistory(std::string filename) override