-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautotest.py
executable file
·351 lines (309 loc) · 13.4 KB
/
autotest.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
###################################################################################
# Copyright (c) 2013, Wictor Lund. All rights reserved. #
# Copyright (c) 2013, Åbo Akademi University. All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# * Redistributions of source code must retain the above copyright #
# notice, this list of conditions and the following disclaimer. #
# * Redistributions in binary form must reproduce the above copyright #
# notice, this list of conditions and the following disclaimer in the #
# documentation and/or other materials provided with the distribution. #
# * Neither the name of the Åbo Akademi University nor the #
# names of its contributors may be used to endorse or promote products #
# derived from this software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
# DISCLAIMED. IN NO EVENT SHALL ÅBO AKADEMI UNIVERSITY BE LIABLE FOR ANY #
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES #
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; #
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND #
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT #
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS #
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
###################################################################################
class TemperatureLogger:
def run_thread(self):
from time import sleep
temp_file = '/sys/devices/platform/hkdk_tmu/curr_temp'
while True:
with open(temp_file) as f:
d = f.read()
self.temperature = float(d)
sleep(1.0)
def __init__(self):
from threading import Thread
from functools import partial
self.thread = Thread(target=partial(TemperatureLogger.run_thread, self))
self.thread.daemon = True
self.thread.start()
class OnlineCPULogger:
def run_thread(self):
from time import sleep
temp_file = '/sys/devices/system/cpu/online'
while True:
with open(temp_file) as f:
d = f.read()
self.online_cpus = d
sleep(1.0)
def __init__(self):
from threading import Thread
from functools import partial
self.thread = Thread(target=partial(OnlineCPULogger.run_thread, self))
self.thread.daemon = True
self.thread.start()
class PowerSerialLogger:
def run_thread(self):
from StringIO import StringIO
from csv import reader as csvreader
with open(self.file) as open_file:
iterator = iter(open_file.readline,b'')
# Ignore rubbish in the beginning
i = 0
for line in iterator:
i += 1
if i > 50:
break
for line in iterator:
values = line.split(',')
values = map(float, values)
self.power = values[0] * values[1] * 10.0
self.voltage = values[0]
self.current = values[1] * 10.0
def __init__(self):
from threading import Thread
from functools import partial
self.file = "/dev/ttyUSB0"
self.power = 0.0
self.voltage = 0.0
self.current = 0.0
self.thread = Thread(target=partial(PowerSerialLogger.run_thread, self))
self.thread.daemon = True
self.thread.start()
def get_nowait(self):
return self.power
proc_sys_kernel_olord_files = [
'sched_olord_bi_directional',
'sched_olord_cpu_load_limit',
'sched_olord_cpu_period_lower_limit',
'sched_olord_cpu_period_upper_limit',
'sched_olord_ignore_IO',
'sched_olord_ignore_nice',
'sched_olord_lb_lower_limit',
'sched_olord_lb_multiplier',
'sched_olord_lb_upper_limit',
'sched_olord_period',
'sched_olord_rq_safety_margin'
]
sys_ondemand_files = [
'hotplug_in_load_limit',
'hotplug_in_sampling_period',
'hotplug_out_load_limit',
'hotplug_out_sampling_period',
'up_threshold'
]
def read_maybe(file_name, maybe_str=""):
try:
with open(file_name) as f:
return f.read()
except:
return maybe_str
def get_kernel_olord_settings():
sys_kernel_olord_path = "/proc/sys/kernel/"
ret = {}
for name in proc_sys_kernel_olord_files:
ret[name] = read_maybe(sys_kernel_olord_path + name, maybe_str="0.0")
return ret
def get_ondemand_settings():
sys_ondemand_path = "/sys/devices/system/cpu/cpufreq/ondemand/"
ret = {}
for name in sys_ondemand_files:
ret[name] = read_maybe(sys_ondemand_path + name, maybe_str="0.0")
return ret
def get_smt_mc_power_savings():
smt_file = '/sys/devices/system/cpu/sched_smt_power_savings'
mc_file = '/sys/devices/system/cpu/sched_mc_power_savings'
return 'smt: ' + read_maybe(smt_file, maybe_str="???").strip() + ", mc: " + \
read_maybe(mc_file, maybe_str="???")
def get_smt_mc_power_savings_old():
smt_file = '/sys/devices/system/cpu/sched_smt_power_savings'
mc_file = '/sys/devices/system/cpu/sched_mc_power_savings'
try:
with open(smt_file) as f:
d = f.read().strip()
ret += str(d)
except:
ret += '???'
ret += ', mc: '
try:
with open(mc_file) as f:
d = f.read().strip()
ret += str(d)
except:
ret += '???'
return ret
def get_governor_string():
from glob import glob
ret = ''
for file_name in glob('/sys/devices/system/cpu/cpu?/cpufreq/scaling_governor'):
with open(file_name) as f:
d = f.read().strip()
ret += d + " "
return ret
def set_config_file(filename, val):
try:
with open(filename, "w") as f:
f.write(str(val))
except IOError as e:
print "Could not write to file", filename
def parse_arguments():
return {}
def main():
config = parse_arguments()
from sqlalchemy import create_engine
from sqlalchemy import Column, Table, MetaData
from sqlalchemy import String, Integer, Float
from sqlalchemy.orm import sessionmaker, mapper
from sqlalchemy.ext.declarative import declarative_base
from time import sleep, time
from stat_reader import StatReader
from itertools import product as set_product
from os import getuid
engine = create_engine('sqlite:///auto_test_log.sqlite')
metadata = MetaData(bind=engine)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
if getuid() != 0:
print "Must be root!!"
return
experiment_info = Table('experiment_info', metadata,
Column('experiment_id', String(32), primary_key=True),
Column('start_time', String()),
Column('end_time', String()),
Column('total_time', Float()),
Column('scheduler', String()),
Column('uname_a', String()),
Column('cpufreq_governor', String()),
Column('mt_mc_state', String()),
Column('target_load_level', String()),
Column('num_of_process', String()))
for c_name in proc_sys_kernel_olord_files:
experiment_info.append_column(Column(c_name, Float))
for c_name in sys_ondemand_files:
experiment_info.append_column(Column(c_name, Float))
experiment_data = Table('experiment_data', metadata,
Column('data_id', String(48), primary_key=True),
Column('experiment_id', String(32)),
Column('time', Float()),
Column('voltage', Float),
Column('current', Float),
Column('power', Float),
Column('temperature', Float),
Column('cpus_online', String(10)))
metadata.create_all()
class ExperimentInfo(Base):
__table__ = experiment_info
class ExperimentData(Base):
__table__ = experiment_data
eii = experiment_info.insert()
eid = experiment_data.insert()
psl = PowerSerialLogger()
tl = TemperatureLogger()
ocl = OnlineCPULogger()
def perform_experiment_a(experiment_config):
from md5 import new as new_md5
from pickle import dumps as pickle_dump
from platform import uname
from datetime import datetime
from threading import Thread
from pprint import PrettyPrinter
from simple_run import run_test
pp = PrettyPrinter(indent = 4)
print "Running experiment with config:"
pp.pprint(experiment_config)
current_experiment_id = new_md5(pickle_dump(experiment_config) + str(datetime.now())).hexdigest()
info_dict = {'experiment_id': current_experiment_id,
'start_time': str(datetime.now()),
'scheduler': experiment_config['scheduler'],
'uname_a': ' '.join(uname()),
'cpufreq_governor': get_governor_string(),
'mt_mc_state': get_smt_mc_power_savings(),
'target_load_level': experiment_config['target_load_level'],
'num_of_process': experiment_config['num_of_process'],
'num_of_ops': experiment_config['num_of_ops']}
info_dict.update(get_kernel_olord_settings())
info_dict.update(get_ondemand_settings())
eii.execute(info_dict)
test_args = {'n': experiment_config['num_of_process'],
'a': 'dont_set',
'l': experiment_config['target_load_level'],
'o': experiment_config['num_of_ops']}
class TestThread(Thread):
def __init__(self, args):
self.args = args
Thread.__init__(self)
def run(self):
self.total_time = run_test(self.args)
tt = TestThread(test_args)
tt.start()
start_time = time()
data_counter = 0
while tt.is_alive():
t = time() - start_time
data_dict = {'data_id': current_experiment_id + str(data_counter).zfill(16),
'experiment_id': current_experiment_id,
'time': t,
'voltage': psl.voltage,
'current': psl.current,
'power': psl.power,
'temperature': tl.temperature,
'cpus_online': ocl.online_cpus}
eid.execute(data_dict)
sleep_time = 1.0 - time() + (t + start_time)
sleep_time = 0.0 if (sleep_time < 0) else sleep_time
#print sleep_time
sleep(sleep_time)
data_counter += 1
r = session.query(ExperimentInfo).filter_by(experiment_id = current_experiment_id).first()
r.end_time = str(datetime.now())
r.total_time = float(tt.total_time)
session.commit()
iter_set = set_product([80],
[10],
[10],
[30],
[80],
range(90,9,-5),
range(10))
iter_set = list(iter_set)
test_size = len(iter_set)
start_time = time()
counter = 0
for i in iter_set:
sleep(10.0)
if psl.power < 0.1:
print "Power ridiculously small, check connection to power source."
return
set_config_file('/sys/devices/system/cpu/cpufreq/ondemand/hotplug_in_load_limit', i[0])
set_config_file('/sys/devices/system/cpu/cpufreq/ondemand/hotplug_out_load_limit', i[1])
set_config_file('/sys/devices/system/cpu/cpufreq/ondemand/hotplug_in_sampling_period', i[2])
set_config_file('/sys/devices/system/cpu/cpufreq/ondemand/hotplug_out_sampling_period', i[2])
set_config_file('/sys/devices/system/cpu/cpufreq/ondemand/up_threshold', i[3])
set_config_file('/proc/sys/kernel/sched_olord_lb_upper_limit', i[4])
counter += 1
print "Starting test #%i of ~%i" % (counter, test_size)
t = time() - start_time
r = float(counter) / float(test_size)
eta = t/r - t
print "Estimated time left:", eta, "s"
perform_experiment_a({'scheduler': 'CFS',
'target_load_level': i[5]/100.0,
'num_of_process': 4,
'num_of_ops': 100000})
if __name__ == '__main__':
main()