-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
415 lines (380 loc) · 15.6 KB
/
main.py
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/usr/bin/env python3
"""This is the main file of our evaluation."""
from schedTest import tgPath # Task generation from SSSEvaluation
from schedTest import RTEDF, UDLEDF, SCEDF, WLAEDF, UniFramework, FP_Analyses # Analyses from SSSEvaluation
from schedTest import EL # Our analysis
from effsstsPlot import effsstsPlot # Plot function from SSSEvaluation
# Other packages
import numpy as np
import os
import random
from multiprocessing import Pool
from itertools import repeat
from argparse import ArgumentParser
def plot_results(
gPrefixdata, gSchemes, gMinsstype, gMaxsstype,
gSSofftypes, gUStart, gUEnd, gUStep, gTasksinBkt, Ncol, plotallname):
""" Plot the results."""
effsstsPlot.effsstsPlotAll(
gPrefixdata, True, gSchemes, gMinsstype, gMaxsstype,
gSSofftypes, gUStart, gUEnd, gUStep, gTasksinBkt, Ncol=Ncol,
plotsingle=False, plotallname=plotallname)
def check(ischeme, tasks, EL_depth=None, EL_max_a=None):
"""Check function to apply multiprocessing."""
numfail = 0
# --- 1 DM Evaluation. ---
if ischeme == 'EL DM': # EL scheduling
EL.set_prio(tasks, prio_policy=2)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'UniFramework':
if UniFramework.UniFramework(tasks) is False:
numfail += 1
elif ischeme == 'SuspObl':
if FP_Analyses.SuspObl(tasks) is False:
numfail += 1
elif ischeme == 'SuspJit':
if FP_Analyses.SuspJit(tasks) is False:
numfail += 1
elif ischeme == 'SuspBlock':
if FP_Analyses.SuspBlock(tasks) is False:
numfail += 1
# --- 2 EDF Evaluation. ---
elif ischeme == 'EL EDF': # EL scheduling
EL.set_prio(tasks, prio_policy=3)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'Our EMSoft': # Our EMSoft
if RTEDF.RTEDF(tasks) is False:
numfail += 1
elif ischeme == 'Dong and Liu':
if UDLEDF.UDLEDF(tasks) is False:
numfail += 1
elif ischeme == 'Liu and Anderson':
if WLAEDF.WLAEDF(tasks) is False:
numfail += 1
elif ischeme == 'Susp as Comp':
if SCEDF.SC_EDF(tasks) is False:
numfail += 1
# --- 3 EQDF Evaluation. ---
elif ischeme == 'EL EQDF lam=0':
EL.set_prio(tasks, prio_policy=101, lam=0)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL EQDF lam=-1':
EL.set_prio(tasks, prio_policy=101, lam=-1)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL EQDF lam=+1':
EL.set_prio(tasks, prio_policy=101, lam=+1)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL EQDF any lam in [-10,10]':
fail_flag = True
for lam in [0] + list(range(-10, 11, 1)): # lam range
# (Testing 0 first gives results faster.)
EL.set_prio(tasks, prio_policy=101, lam=lam)
if EL.EL_fixed(tasks, depth=EL_depth) is True:
fail_flag = False
break
if fail_flag:
numfail += 1
# --- 4 SAEDF Evaluation. ---
elif ischeme == 'EL SAEDF lam=0':
EL.set_prio(tasks, prio_policy=201, lam=0)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL SAEDF lam=-1':
EL.set_prio(tasks, prio_policy=201, lam=-1)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL SAEDF lam=+1':
EL.set_prio(tasks, prio_policy=201, lam=+1)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL SAEDF any lam in [-10,10]':
fail_flag = True
for lam in [0] + list(range(-10, 11, 1)): # lam range
# (Testing 0 first gives results faster.)
EL.set_prio(tasks, prio_policy=201, lam=lam)
if EL.EL_fixed(tasks, depth=EL_depth) is True:
fail_flag = False
break
if fail_flag:
numfail += 1
# --- 5a Arb deadline DM Evaluation. ---
elif ischeme == 'EL-fix DM D1.0':
# Set Deadlines.
for itask in tasks:
itask['deadline'] = 1.0 * itask['period']
# Set priorities.
EL.set_prio(tasks, prio_policy=2)
# Sched test.
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL-fix DM D1.1':
for itask in tasks:
itask['deadline'] = 1.1 * itask['period']
EL.set_prio(tasks, prio_policy=2)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL-fix DM D1.2':
for itask in tasks:
itask['deadline'] = 1.2 * itask['period']
EL.set_prio(tasks, prio_policy=2)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL-fix DM D1.5':
for itask in tasks:
itask['deadline'] = 1.5 * itask['period']
EL.set_prio(tasks, prio_policy=2)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
# --- 5b Arb deadline DM Evaluation. ---
elif ischeme == 'EL-var DM D1.0':
# Set Deadlines.
for itask in tasks:
itask['deadline'] = 1.0 * itask['period']
# Set priorities.
EL.set_prio(tasks, prio_policy=2)
# Sched test.
if EL.EL_var(tasks, depth=EL_depth, max_a=EL_max_a) is False:
numfail += 1
elif ischeme == 'EL-var DM D1.1':
for itask in tasks:
itask['deadline'] = 1.1 * itask['period']
EL.set_prio(tasks, prio_policy=2)
if EL.EL_var(tasks, depth=EL_depth, max_a=EL_max_a) is False:
numfail += 1
elif ischeme == 'EL-var DM D1.2':
for itask in tasks:
itask['deadline'] = 1.2 * itask['period']
EL.set_prio(tasks, prio_policy=2)
if EL.EL_var(tasks, depth=EL_depth, max_a=EL_max_a) is False:
numfail += 1
elif ischeme == 'EL-var DM D1.5':
for itask in tasks:
itask['deadline'] = 1.5 * itask['period']
EL.set_prio(tasks, prio_policy=2)
if EL.EL_var(tasks, depth=EL_depth, max_a=EL_max_a) is False:
numfail += 1
# --- 6a Arb deadline EDF Evaluation. ---
elif ischeme == 'EL-fix EDF D1.0':
# Set Deadlines.
for itask in tasks:
itask['deadline'] = 1.0 * itask['period']
# Set priorities.
EL.set_prio(tasks, prio_policy=3)
# Sched test.
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL-fix EDF D1.1':
for itask in tasks:
itask['deadline'] = 1.1 * itask['period']
EL.set_prio(tasks, prio_policy=3)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL-fix EDF D1.2':
for itask in tasks:
itask['deadline'] = 1.2 * itask['period']
EL.set_prio(tasks, prio_policy=3)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
elif ischeme == 'EL-fix EDF D1.5':
for itask in tasks:
itask['deadline'] = 1.5 * itask['period']
EL.set_prio(tasks, prio_policy=3)
if EL.EL_fixed(tasks, depth=EL_depth) is False:
numfail += 1
# --- 6b Arb deadline EDF Evaluation. ---
elif ischeme == 'EL-var EDF D1.0':
# Set Deadlines.
for itask in tasks:
itask['deadline'] = 1.0 * itask['period']
# Set priorities.
EL.set_prio(tasks, prio_policy=3)
# Sched test.
if EL.EL_var(tasks, depth=EL_depth, max_a=EL_max_a) is False:
numfail += 1
elif ischeme == 'EL-var EDF D1.1':
for itask in tasks:
itask['deadline'] = 1.1 * itask['period']
EL.set_prio(tasks, prio_policy=3)
if EL.EL_var(tasks, depth=EL_depth, max_a=EL_max_a) is False:
numfail += 1
elif ischeme == 'EL-var EDF D1.2':
for itask in tasks:
itask['deadline'] = 1.2 * itask['period']
EL.set_prio(tasks, prio_policy=3)
if EL.EL_var(tasks, depth=EL_depth, max_a=EL_max_a) is False:
numfail += 1
elif ischeme == 'EL-var EDF D1.5':
for itask in tasks:
itask['deadline'] = 1.5 * itask['period']
EL.set_prio(tasks, prio_policy=3)
if EL.EL_var(tasks, depth=EL_depth, max_a=EL_max_a) is False:
numfail += 1
else:
raise ValueError(f"{ischeme=} is not a valid option.")
return numfail
if __name__ == '__main__':
###
# Options
###
parser = ArgumentParser()
parser.add_argument("-q", "--quick", dest="quick", action="store_true", default=False,
help="Run only a small configuration to test that the program runs. Otherwise, the full evaluation is performed.")
parser.add_argument("-p", "--processes", dest="proc", type=int,
help="Specify the number of concurrent processes.")
parser.add_argument("scheme", help="Choose a scheme flag option from: [1, 2, 3, 4, 5a, 5b, 6a, 6b]")
args = vars(parser.parse_args())
###
# Global variables
###
if args["quick"]: # Quick setting to check if the program runs completely without Error.
gTotBucket = 10 # total number of task sets per utilization
gTasksinBkt = 3 # tasks per set
gUStep = 50 # utilization step
gUStart = 0 # utilization start
gUEnd = 100 # utilization end
EL_depth = 2 # depth for EL schedulability test
EL_max_a = 2 # maximal a for EL schedulability test
num_processors = 6 # number of processors for the evaluation
else: # Full evaluation.
gTotBucket = 500 # total number of task sets per utilization
gTasksinBkt = 50 # tasks per set
gUStep = 5 # utilization step
gUStart = 0 # utilization start
gUEnd = 100 # utilization end
EL_depth = 5 # depth for EL schedulability test
EL_max_a = 10 # maximal a for EL schedulability test
num_processors = 100 # number of processors for the evaluation
# Share from (period - wcet) for self-suspension:
gMaxsstype = 0.5 # maximal total self-suspension length
gMinsstype = 0.0 # minimal total self-suspension length
gSSofftypes = 0 # number of segments does not matter
Ncol = 3 # number of columns in Legend
# Further plotting preferences.
gPrefixdata = "effsstsPlot/Data" # path to store data
# Modify the number of processes
if args["proc"] is not None and args["proc"] > 0:
num_processors = args["proc"]
# Set the scheme flag.
scheme_flag = args["scheme"]
###
# Choose schedulability tests to be run + assign corresponding gSchemes and plotallname:
###
plotallname = ''
if scheme_flag == '1':
# 1 DM Evaluation.
gSchemes = ['EL DM', 'UniFramework', 'SuspJit', 'SuspBlock', 'SuspObl']
plotallname = '1_dm'
elif scheme_flag == '2':
# 2 EDF Evaluation.
gSchemes = ['EL EDF', 'Our EMSoft', 'Liu and Anderson',
'Susp as Comp']
plotallname = '2_edf'
elif scheme_flag == '3':
# 3 EQDF Evaluation.
gSchemes = ['EL EQDF lam=-1', 'EL EQDF lam=0', 'EL EQDF lam=+1',
'EL EQDF any lam in [-10,10]']
Ncol = 2
plotallname = '3_eqdf'
elif scheme_flag == '4':
# 4 SAEDF Evaluation.
gSchemes = ['EL SAEDF lam=-1', 'EL SAEDF lam=0', 'EL SAEDF lam=+1',
'EL SAEDF any lam in [-10,10]']
Ncol = 2
plotallname = '4_saedf'
elif scheme_flag == '5a':
# 5a Arb deadline DM Evaluation.
gSchemes = ['EL-fix DM D1.0', 'EL-fix DM D1.1', 'EL-fix DM D1.2',
'EL-fix DM D1.5']
Ncol = 2
plotallname = '5a_arb_dl_dm'
elif scheme_flag == '5b':
# 5b Arb deadline DM Evaluation.
gSchemes = ['EL-var DM D1.0', 'EL-var DM D1.1', 'EL-var DM D1.2',
'EL-var DM D1.5']
Ncol = 2
plotallname = '5b_arb_dl_dm'
elif scheme_flag == '6a':
# 6a Arb deadline EDF Evaluation.
gSchemes = ['EL-fix EDF D1.0', 'EL-fix EDF D1.1', 'EL-fix EDF D1.2',
'EL-fix EDF D1.5']
Ncol = 2
plotallname = '6a_arb_dl_edf'
elif scheme_flag == '6b':
# 6b Arb deadline EDF Evaluation.
gSchemes = ['EL-var EDF D1.0', 'EL-var EDF D1.1', 'EL-var EDF D1.2',
'EL-var EDF D1.5']
Ncol = 2
plotallname = '6b_arb_dl_edf'
else:
raise ValueError(f'{scheme_flag=} is no valid argument.')
###
# Create Task sets
###
random.seed(331) # Get same task sets for each plot.
tasksets_difutil = [] # task set differentiated by utilization
for u in range(gUStart, gUEnd, gUStep):
tasksets = []
for i in range(0, gTotBucket, 1):
percentageU = u / 100
# Create task set with predefined parameters.
tasks = tgPath.taskGeneration_p(gTasksinBkt, percentageU, gMinsstype,
gMaxsstype, vRatio=1,
numLog=int(2))
# Sort tasks by period.
sortedTasks = sorted(tasks, key=lambda item: item['period'])
tasksets.append(sortedTasks) # add
for itask in tasks:
if itask['period'] != itask['deadline']:
print('period and deadline are different')
breakpoint()
tasksets_difutil.append(tasksets) # add
###
# Schedulability tests
###
for ischeme in gSchemes:
x = np.arange(gUStart, gUEnd + 1, gUStep)
print(x)
y = np.zeros(int((gUEnd - gUStart) / gUStep) + 1)
print(y)
ifskip = False # skip flag when 0 is reached
# Iterate through taskset.
for u, tasksets in enumerate(tasksets_difutil, start=0):
print("Scheme:", ischeme, "Task-sets:", gTotBucket, "Tasks per set:",
gTasksinBkt, "U:", gUStart + u * gUStep, "SSLength:",
str(gMinsstype), " - ", str(gMaxsstype))
if u == 0: # utilization of 0 percent
y[u] = 1
continue
if u * gUStep == 100: # utilization 100 percent
y[u] = 0
continue
if ifskip: # skip iteration when flag is done
print("acceptanceRatio:", 0)
y[u] = 0
continue
with Pool(num_processors) as p: # Use several processes and apply the check function.
fails = p.starmap(check, zip(repeat(ischeme), tasksets, repeat(EL_depth), repeat(EL_max_a)))
numfail = sum(fails) # total number of fails
acceptanceRatio = 1 - (numfail / len(tasksets))
print("acceptanceRatio:", acceptanceRatio)
y[u] = acceptanceRatio
# if acceptanceRatio == 0:
# ifskip = True
# Store results
plotPath = (gPrefixdata + '/' + str(gMinsstype) + '-' + str(gMaxsstype)
+ '/' + str(gSSofftypes) + '/')
plotfile = (gPrefixdata + '/' + str(gMinsstype) + '-' + str(gMaxsstype)
+ '/' + str(gSSofftypes) + '/' + ischeme + str(gTasksinBkt))
if not os.path.exists(plotPath):
os.makedirs(plotPath)
np.save(plotfile, np.array([x, y]))
###
# Plot
###
plot_results(gPrefixdata, gSchemes, gMinsstype, gMaxsstype, gSSofftypes, gUStart, gUEnd, gUStep, gTasksinBkt, Ncol,
plotallname)