forked from CapstoneStorage/TOMS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conf_gastask.c
229 lines (201 loc) · 5.18 KB
/
conf_gastask.c
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include "gastask.h"
static void
parse_genetic(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
if (sscanf(buf, "%u %u %lf %lf", &max_gen, &n_pops, &cutoff, &penalty) != 4) {
FATAL(2, "cannot load configuration: invalid genetic parameters: %s", trim(buf));
}
}
}
static void
parse_cpufreq(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
double wcet_scale, power_active, power_idle;
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
if (sscanf(buf, "%lf %lf %lf", &wcet_scale, &power_active, &power_idle) != 3) {
FATAL(2, "cannot load configuration: invalid CPU frequency format: %s", trim(buf));
}
if (wcet_scale < 0 || wcet_scale > 1) {
FATAL(2, "invalid cpu frequency wcet scale: %s", trim(buf));
}
if (power_active < 0 || power_idle < 0) {
FATAL(2, "invalid cpu frequency power: %s", trim(buf));
}
add_cpufreq(wcet_scale, power_active, power_idle);
}
}
static void
parse_task(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
unsigned wcet, period, memreq;
double mem_active_ratio;
unsigned task_size;
unsigned input_size, output_size;
unsigned offloading_bool;
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
if (sscanf(buf, "%u %u %u %lf %u %u %u %u", &wcet, &period, &memreq, &mem_active_ratio, &task_size, &input_size, &output_size, &offloading_bool) != 8) {
FATAL(2, "cannot load configuration: invalid task format: %s", trim(buf));
}
if (wcet >= period) {
FATAL(2, "wcet is larger or equal than period: %s", trim(buf));
}
add_task(wcet, period, memreq, mem_active_ratio, task_size, input_size, output_size, offloading_bool);
}
}
static void
parse_network(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
unsigned uplink, downlink;
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
if (sscanf(buf, "%u %u", &uplink, &downlink) != 2) {
FATAL(2, "cannot load configuration: invalid network format: %s", trim(buf));
}
add_network(uplink, downlink);
}
}
static void
parse_net_commander(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
unsigned intercept_out, intercept_in;
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
if (sscanf(buf, "%u %u", &intercept_out, &intercept_in) != 2) {
FATAL(2, "cannot load configuration: invalid network commander format: %s", trim(buf));
}
add_net_commander(intercept_out, intercept_in);
}
}
void
parse_cloud(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
double computation_power, power_active, power_idle, offloading_limit;
unsigned max_capacity;
char type[1024];
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
if (sscanf(buf, "%s %lf %lf %lf %u %lf", type, &computation_power, &power_active, &power_idle, &max_capacity, &offloading_limit) != 6) {
FATAL(2, "cannot load configuration: invalid cloud format: %s", trim(buf));
}
if(max_capacity == 0){
FATAL(2, "invalid max memory capacity: %s", trim(buf));
}
if (power_active < 0 || power_idle < 0) {
FATAL(2, "invalid memory power: %s", trim(buf));
}
if (offloading_limit > 1){
FATAL(2, "offloading limit is smaller or equal to one: %s", trim(buf));
}
add_cloud(type, computation_power, power_active, power_idle, max_capacity, offloading_limit);
}
}
static void
parse_offloadingratio(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
double r;
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
if (sscanf(buf, "%lf", &r) != 1) {
FATAL(2, "cannot load configuration: invalid ratio format: %s", trim(buf));
}
if (r < 0) {
FATAL(2, "ratio should not be a negative value: %s", trim(buf));
}
if (r > 1) {
FATAL(2, "ratio is smaller or equal to one: %s", trim(buf));
}
add_offloadingratio(r);
}
}
void
parse_conf(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
if (buf[0] == '\n' || buf[0] == '#')
continue;
switch (check_section(buf)) {
case SECT_GENETIC:
parse_genetic(fp);
break;
case SECT_GENTASK:
case SECT_GENNETWORK:
case SECT_GENNETCOMMANDER:
skip_section(fp);
break;
case SECT_CPUFREQ:
parse_cpufreq(fp);
break;
case SECT_MEM:
parse_mem(fp);
break;
case SECT_TASK:
if (n_cpufreqs == 0) {
FATAL(2, "cpu frequency section should be defined ahead of task section");
}
parse_task(fp);
break;
case SECT_OFFLOADINGRATIO:
parse_offloadingratio(fp);
break;
case SECT_CLOUD:
parse_cloud(fp);
break;
case SECT_NETWORK:
parse_network(fp);
break;
case SECT_NET_COMMANDER:
parse_net_commander(fp);
break;
default:
errmsg("unknown section: %s", trim(buf));
FATAL(2, "cannot load configuration");
}
}
}