-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule.hpp
151 lines (124 loc) · 3.66 KB
/
schedule.hpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef _SCHEDULE_
#define _SCHEDULE_
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include "adj_list.hpp"
#include "task.hpp"
const unsigned int MAX_DUR = 100; //100ms
const double delta = 0.000001;
typedef struct {
double start;
task t;
double freq;
} slot;
class schedule {
private:
std::vector<slot> HP, LP;
double lp_time, hp_time;
void display(std::ofstream &stream, std::vector<slot> &P, char type) {
for (unsigned int i = 0; i < P.size(); ++i) {
if (i != 0) stream << ' ';
double size;
if (type == 'L') {
size = P[i].t.lp_size() * f_LP_max/P[i].freq;
} else {
size = P[i].t.size() * f_HP_max/P[i].freq;
}
if (P[i].t.get_id() >= MAX_TASKs) {
stream << 2*MAX_TASKs - 1 - P[i].t.get_id() << "' ";
} else {
stream << P[i].t.get_id() << ' ';
}
stream << P[i].start << ' ' << size << ' ' << P[i].freq;
}
stream << std::endl;
}
double energy_for(const std::vector<slot> &P, double P_idle, char type, double &ended) const {
double E = 0.0;
for (unsigned int i = 0; i < P.size(); ++i) {
if (ended < P[i].start) {
E += (P[i].start - ended) * P_idle;
}
double size;
if (type == 'L') {
size = P[i].t.lp_size() * f_LP_max/P[i].freq;
E += size * P[i].t.power_lp(P[i].freq);
} else {
size = P[i].t.size() * f_HP_max/P[i].freq;
E += size * P[i].t.power_hp(P[i].freq);
}
ended = P[i].start + size;
}
return E;
}
public:
schedule() {
lp_time = hp_time = 0.0;
}
void wait() {
// Make idle processor wait for running processor
lp_time = hp_time = std::max(lp_time, hp_time);
}
double lpt() const { return lp_time; }
double hpt() const { return hp_time; }
void add_HP_slot(task t, double freq=f_HP_max) {
HP.push_back({hp_time, t, freq});
hp_time += t.size() * f_HP_max/freq;
}
void add_LP_slot(task t, double freq=f_LP_max) {
LP.push_back({lp_time, t, freq});
lp_time += t.lp_size() * f_LP_max/freq;
}
double energy() const {
double E = 0.0;
if (LP.size() != 0 && HP.size() != 0) {
double lp_started = LP[0].start,
hp_started = HP[0].start;
if (hp_started > lp_started) {
E += (lp_started - hp_started) * P_HP_idle;
} else if (lp_started > hp_started) {
E += (hp_started - lp_started) * P_LP_idle;
}
}
double lp_ended = 0.0, hp_ended = 0.0;
E += energy_for(LP, P_LP_idle, 'L', lp_ended)
+ energy_for(HP, P_HP_idle, 'H', hp_ended);
if (lp_ended > hp_ended) {
E += (lp_ended - hp_ended) * P_HP_idle;
} else if (hp_ended > lp_ended) {
E += (hp_ended - lp_ended) * P_LP_idle;
}
double end_time = std::max(lp_ended, hp_ended);
if (end_time < MAX_DUR) {
E += (MAX_DUR - end_time) * (P_LP_idle + P_HP_idle);
}
return E;
}
double utilization() {
double sigma_W_LP = 0.0;
for (const slot &s : HP) {
sigma_W_LP += s.t.lp_size();
}
for (const slot &s : LP) {
sigma_W_LP += s.t.lp_size();
}
return sigma_W_LP/MAX_DUR * 100.0;
}
void show(std::ofstream &stream) {
display(stream, HP, 'H');
display(stream, LP, 'L');
stream << std::setprecision(15) << std::fixed << energy() << std::endl;
}
friend schedule uniform_scale(const schedule &, const schedule &);
friend schedule contingency_schedule(const schedule &);
};
typedef std::priority_queue<task, std::vector<task>, compare_task_by_size> ready_list;
void clear_tasks(ready_list &, const std::vector<task> &, const std::vector<int> &, std::vector<int> &);
std::vector<int> parent_task_count(const adj_list &);
// Largest Task First
schedule ltf_schedule(const std::vector<task> &, const adj_list &);
// Threshold-based List Scheduling
schedule tbls_schedule(const std::vector<task> &, const adj_list &, double=tbls_threshold);
#endif