forked from rlu-sync/rlu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
executable file
·290 lines (205 loc) · 6.19 KB
/
run_tests.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
import time
import sys
import os
IS_NUMA = 1
IS_2_SOCKET = 0
IS_PERF = 0
CMD_PARAMS = '-a -w%d -b%d -d%d -u%d -i%d -r%d -n%d'
PERF_FILE = "__perf_output.file"
CMD_PREFIX_PERF = "perf stat -d -o %s" % (PERF_FILE,)
CMD_BASE_HARRIS = './bench-harris'
CMD_BASE_HP_HARRIS = './bench-hp-harris'
CMD_BASE_RCU = './bench-rcu'
CMD_BASE_RLU = './bench-rlu'
OUTPUT_FILENAME = '___temp.file'
W_OUTPUT_FILENAME = '__w_check.txt'
CMD_PREFIX_LIBS = 'export LD_PRELOAD=\\"$GPERFTOOLS_LIB/libtcmalloc_minimal.so\\"'
CMD_NUMA_BIND_TO_CPU_0 = 'numactl --cpunodebind=0 '
CMD_NUMA_BIND_TO_CPU_1 = 'numactl --cpunodebind=1 '
CMD_NUMA_BIND_TO_CPU_0_1 = 'numactl --cpunodebind=0,1 '
CMD_NUMA_PREFIX_8 = 'taskset -c 0-7 '
CMD_NUMA_PREFIX_10 = 'taskset -c 0-9 '
CMD_NUMA_PREFIX_12 = 'taskset -c 0-11 '
CMD_NUMA_PREFIX_14 = 'taskset -c 0-13 '
CMD_NUMA_PREFIX_16 = 'taskset -c 0-15 '
CMD_BASE = {
'harris' : CMD_BASE_HARRIS,
'hp_harris' : CMD_BASE_HP_HARRIS,
'rcu' : CMD_BASE_RCU,
'rlu' : CMD_BASE_RLU,
}
result_keys = [
'#ops :',
'#update ops :',
't_writer_writebacks =',
't_writeback_q_iters =',
'a_writeback_q_iters =',
't_pure_readers =',
't_steals =',
't_aborts =',
't_sync_requests =',
't_sync_and_writeback =',
]
perf_result_keys = [
'instructions #',
'branches #',
'branch-misses #',
'L1-dcache-loads #',
'L1-dcache-load-misses #',
]
def cmd_numa_prefix(threads_num):
if (IS_2_SOCKET):
if (threads_num <= 36):
return CMD_NUMA_BIND_TO_CPU_1
return CMD_NUMA_BIND_TO_CPU_0_1
if (threads_num <= 8):
return CMD_NUMA_PREFIX_8
if (threads_num <= 10):
return CMD_NUMA_PREFIX_10
if (threads_num <= 12):
return CMD_NUMA_PREFIX_12
if (threads_num <= 14):
return CMD_NUMA_PREFIX_14
if (threads_num <= 16):
return CMD_NUMA_PREFIX_16
print 'cmd_numa_prefix: ERROR th_num = %d' % (threads_num,)
def extract_data(output_data, key_str):
data = output_data.split(key_str)[1].split()[0].strip()
if (data.find('nan') != -1):
return 0
if (key_str == 'L1-dcache-load-misses #') or (key_str == 'branch-misses #'):
data = data.strip('%')
return float(data)
def extract_keys(output_data):
d = {}
for key in result_keys:
d[key] = extract_data(output_data, key)
if IS_PERF:
for key in perf_result_keys:
d[key] = extract_data(output_data, key)
return d
def print_keys(dict_keys):
print '================================='
for key in result_keys:
print '%s %.2f' % (key, dict_keys[key])
if IS_PERF:
for key in perf_result_keys:
print '%s %.2f' % (key, dict_keys[key])
def run_test(runs_per_test, alg_type, cmd):
ops_total = 0
total_operations = 0
aborts_total = 0
total_combiners = 0
total_num_of_waiting = 0
total_additional_readers = 0
total_additional_writers = 0
cmd_prefix = 'bash -c "' + CMD_PREFIX_LIBS + ' ; '
if (IS_PERF):
cmd_prefix += CMD_PREFIX_PERF + ' '
full_cmd = cmd_prefix + cmd + '"'
print full_cmd
total_dict_keys = {}
for key in result_keys:
total_dict_keys[key] = 0
for i in xrange(runs_per_test):
print 'run %d ' % (i,)
if (IS_PERF):
try:
os.unlink(PERF_FILE)
except OSError:
pass
os.system('w >> %s' % (W_OUTPUT_FILENAME,))
time.sleep(1)
os.system(full_cmd + ' > ' + OUTPUT_FILENAME)
os.system('w >> %s' % (W_OUTPUT_FILENAME,))
time.sleep(1)
f = open(OUTPUT_FILENAME, 'rb')
output_data = f.read()
f.close()
os.unlink(OUTPUT_FILENAME)
if (IS_PERF):
f = open(PERF_FILE, 'rb');
output_data += f.read()
f.close()
os.unlink(PERF_FILE)
print "------------------------------------"
print output_data
print "------------------------------------"
dict_keys = extract_keys(output_data)
print '================================='
for key in dict_keys.keys():
total_dict_keys[key] += dict_keys[key]
print_keys(dict_keys)
for key in total_dict_keys.keys():
total_dict_keys[key] /= runs_per_test
return total_dict_keys
def print_run_results(f_out, rlu_max_ws, update_ratio, th_num, dict_keys):
f_out.write('\n%.2f %.2f %.2f' % (rlu_max_ws, update_ratio, th_num));
for key in result_keys:
f_out.write(' %.2f' % dict_keys[key])
if IS_PERF:
for key in perf_result_keys:
f_out.write(' %.2f' % dict_keys[key])
f_out.flush()
def execute(runs_per_test,
rlu_max_ws,
buckets,
duration,
alg_type,
update_ratio,
initial_size,
range_size,
output_filename,
th_num_list):
f_w = open(W_OUTPUT_FILENAME, 'wb');
f_w.close()
f_out = open(output_filename, 'wb')
cmd_header = '[%s] ' % (alg_type,) + CMD_BASE[alg_type] + ' ' + CMD_PARAMS % (
rlu_max_ws,
buckets,
duration,
update_ratio,
initial_size,
range_size,
0)
f_out.write(cmd_header + '\n')
f_out.flush()
results = []
for th_num in th_num_list:
cmd = CMD_BASE[alg_type] + ' ' + CMD_PARAMS % (
rlu_max_ws,
buckets,
duration,
update_ratio,
initial_size,
range_size,
th_num)
if (IS_NUMA):
cmd = cmd_numa_prefix(th_num) + cmd
print '-------------------------------'
print '[%d] %s ' % (th_num, cmd)
dict_keys = run_test(runs_per_test, alg_type, cmd)
results.append(dict_keys)
print_run_results(f_out, rlu_max_ws, update_ratio, th_num, dict_keys)
f_out.write('\n\n')
f_out.flush()
f_out.close()
print 'DONE: written output to %s' % (output_filename,)
if '__main__' == __name__:
try:
param_num = 10
prog_name, runs_per_test, rlu_max_ws, buckets, duration, alg_type, update_ratio, initial_size, range_size, output_filename = sys.argv[:param_num]
th_num_list = sys.argv[param_num:]
runs_per_test = int(runs_per_test)
rlu_max_ws = int(rlu_max_ws)
buckets = int(buckets)
duration = int(duration)
update_ratio = int(update_ratio)
initial_size = int(initial_size)
range_size = int(range_size)
for i, th_num in enumerate(th_num_list):
th_num_list[i] = int(th_num)
except ValueError, e:
raise e
sys.exit('USAGE: %s [runs_per_test] [rlu_max_ws] [buckets] [duration] [alg_type] [update_ratio] [initial_size] [range_size] [output_filename] [[thread num list]]' % (sys.argv[0],))
execute(runs_per_test, rlu_max_ws, buckets, duration, alg_type, update_ratio, initial_size, range_size, output_filename, th_num_list)