-
Notifications
You must be signed in to change notification settings - Fork 0
/
tss.py
74 lines (62 loc) · 2.25 KB
/
tss.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
from queue import PriorityQueue
from parser import Parser
from utils import DAG, listify
from schedulers.sched_algs import etf, hlfet
from schedulers.utils import compute_static_level, compute_est
import sys
import copy
class Scheduler:
"""
@brief : running is a dict that holds the assignment of tasks to cores
"""
def __init__(self, cores):
self.cores = cores
self.ready = PriorityQueue()
self.running = {}
self.parser = Parser()
def compute_makespan(self, scheduling):
# TODO compute with finish time
makespan = -1
for node in scheduling:
tasks = scheduling[node]
for task in tasks:
makespan = max(makespan, task.finish())
return makespan
def compute_flowtime(self, scheduling):
# TODO compute with finish time
flowtime = 0
for node in scheduling:
tasks = scheduling[node]
for task in tasks:
flowtime += task.finish()
return flowtime
def benchmarking(self):
print("[*] Running Earliest Time First algorithm with " + str(self.cores) + " cores")
scheduling = hlfet(self.parser.dag, self.cores)
print(scheduling)
makespan = self.compute_makespan(scheduling)
flowtime = self.compute_flowtime(scheduling)
print(makespan, flowtime)
print("[*] Running The Highest Level First with Estimated Time algorithm with " + str(self.cores) + " cores")
self.parser.dag.clear_time()
scheduling = etf(self.parser.dag, self.cores)
print(scheduling)
makespan = self.compute_makespan(scheduling)
flowtime = self.compute_flowtime(scheduling)
print(makespan, flowtime)
def main():
print("[*] Task scheduler simulator started ...")
print("[*] Configuring the environment ...")
parser = Parser()
# skip first 2 lines
sys.stdin.readline()
sys.stdin.readline()
scheduler = Scheduler(4)
scheduler.parser.parse()
visited = scheduler.parser.no_nodes * [False]
compute_static_level(scheduler.parser.dag, visited)
visited = scheduler.parser.no_nodes * [False]
compute_est(scheduler.parser.dag, visited)
scheduler.benchmarking()
if __name__ == "__main__":
main()