/
simGlobalEDFClass.cpp
99 lines (77 loc) · 2.11 KB
/
simGlobalEDFClass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "simGlobalEDFClass.hpp"
simGlobalEDF::simGlobalEDF() :
_numberCPU(1000),
_tasks_generated(deque<Task>())
{ }
/**
* \details Upload a set of tasks from a file
*/
void simGlobalEDF::uploadTask(char* file){
ifstream taskFile(file);
string tasks_text = "";
while (!taskFile.eof())
{
// this does not check for input correctness
string temp;
for (int i = 0; i < 4; ++i)
{
taskFile >> temp;
tasks_text += temp + "\t";
}
tasks_text += "\n";
}
_tasks_generated = Task::generateFromString(tasks_text);
}
/**
* \details Compute the number of CPU needed by global EDF
*/
void simGlobalEDF::computeCPU(){
int globalUtilizationPerc = 0;
for (unsigned int i = 0; i < _tasks_generated.size(); ++i)
{
globalUtilizationPerc += _tasks_generated.at(i).getUtilizationPercent();
}
_numberCPU = ceil(globalUtilizationPerc/100.0);
}
/**
* \details Run global EDF from a file and display the result on the terminal
*/
void simGlobalEDF::run(char* file){
uploadTask(file);
computeCPU();
Simulation s(_numberCPU, _tasks_generated);
vector<int> result = s.runGlobal();
if(result.size()>0)
{
cout << "statistics of the simulation :"<<endl;
cout << "Number of preemption = " << result.at(0) << endl;
cout << "Number of migration = " << result.at(1) << endl;
cout << "idle time = " << result.at(2) << endl;
cout << "studyInterval = " << result.at(4) << endl;
cout << "Core used = " << _numberCPU << endl;
cout << "Core necessary = " << result.at(3) << endl;
}
else
{
cout<<"This system is not schedulable"<<endl;
}
}
/**
* \details Run global EDF from a deque of tasks and return the result.
* \return A vector containing the statistics of the system
* vector[0]= number of preemption
* vector[1]= number of migration
* vector[2]= idle time
* vector[3]= number of core necessary
* vector[4]= studyInterval
* vector[5]= number of core used
*/
vector<int> simGlobalEDF::run(deque<Task> t)
{
_tasks_generated = t;
computeCPU();
Simulation s(_numberCPU, _tasks_generated);
vector<int> result = s.runGlobal();
result.push_back(_numberCPU);
return result;
}