-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemModel.py
179 lines (142 loc) · 5.3 KB
/
systemModel.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
#!/usr/bin/python
from taskModel import task
import taskGenerator as TG
import binPacking as bp
class processor:
def __init__(self, id, type, a, b, static, freqSet):
self.id = id
self.type = type
self.alpha = a
self.b = b
self.static = static
self.freqSet = freqSet
self.currentFreq = max(freqSet)
self.mappedTasks = []
self.util = 0
# flag to indicate whether the processor already has split task
self.split_1 = False
self.split_2 = False
def get_id(self):
return self.id
def get_type(self):
return self.type
def get_alpha(self):
return self.alpha
def get_b(self):
return self.b
def reset_map(self):
self.mappedTasks = []
self.util = 0
def get_static(self):
return self.static
def set_split_1(self):
self.split_1 = True
def get_split_1(self):
return self.split_1
def set_split_2(self):
self.split_2 = True
def get_split_2(self):
return self.split_2
def get_freqSet(self):
return self.freqSet
def get_currentFreq(self):
return self.currentFreq
def get_alltasks(self):
return self.mappedTasks
def has_task(self):
return len(self.get_alltasks()) != 0
def get_totalUtil(self):
return self.util
def remove_task(self,task):
self.get_alltasks().remove(task)
self.util -= task.get_utilization()
def map_one_task(self,t):
assert isinstance(t,task) == True, "mapped object is %s, not a task type " %type(t)
self.mappedTasks.append(t)
self.util += t.get_utilization()
def printout_tasks(self):
return " \n".join([i.print_task() for i in self.get_alltasks()])
def printout_proc(self):
return "id: %s type: %s a: %s b: %s static: %s utilization: %s" %(self.get_id(), self.get_type(),
self.get_alpha(), self.get_b(), self.get_static(), self.get_totalUtil())
class cluster:
def __init__(self, id, type, num):
self.id = id
self.clusterType = type
self.numProcessor = num
self.allProcessors = []
def get_id(self):
return self.id
def get_clusterType(self):
return self.clusterType
def get_numProcessor(self):
return self.numProcessor
def init_processor(self, processor):
self.processors.append(processor)
def reset_map(self):
for i in self.get_allProcessors():
i.reset_map()
def get_allProcessors(self):
return self.allProcessors
def add_processor(self, proc):
assert isinstance(proc,processor) == True, 'the added object is %s, not a processor type' \
%type(proc)
self.allProcessors.append(proc)
def printout_cluster(self):
return "id: %s type: %s number of processors: %s" %(self.get_id(), self.get_clusterType(),
self.get_numProcessor())
def main():
"""
For test
"""
cl = cluster(1, "ARM Cortex A15", 3)
freqBig = [800,1000,1200,1400,1600,1800,2000]
cl.add_processor(processor(1,"ARM Cortex A15",3.0e-9,2.261,0.5,freqBig))
cl.add_processor(processor(2,"ARM Cortex A15",3.0e-9,2.261,0.5,freqBig))
cl.add_processor(processor(3,"ARM Cortex A15",3.0e-9,2.261,0.5,freqBig))
winner = 0
for t in range(100):
ffd = 0
ffd_split = 0
taskset = TG.generateTasks(6, 2)
print cl.printout_cluster()
## for i in taskset:
## print i.print_task()
## print "total utilization: %s" %(sum([i.get_utilization() for i in taskset]))
fd = bp.FFD(taskset, cl)
print "==================================================================="
print "==================================================================="
print "FFD"
cnt = 0
for i in fd.get_allProcessors():
print "processor %s" %i.get_id()
print i.printout_proc()
print i.printout_tasks()
if i.has_task():
cnt += 1
if cnt == 2:
ffd += 1
bd = bp.FFD_split_test(taskset, cl)
print "==================================================================="
print "==================================================================="
print "FFD with split"
cnt = 0
for i in bd.get_allProcessors():
print "processor %s" %i.get_id()
print i.printout_proc()
print i.printout_tasks()
if i.has_task():
cnt += 1
if cnt == 2:
ffd_split += 1
print "ffd:", ffd, "ffd_split:", ffd_split
if ffd - ffd_split > 0:
winner += 1
print "FFD Split is better in %s sets" %winner
#proc_test.map_one_task(task(1,6000,31000,18000))
#proc_test.map_one_task(task(2,2000,9800,9000))
#print proc_test.printout_tasks()
#print proc_test.printout_proc()
#print proc_test.get_totalUtil()
if __name__ == "__main__":
main()