Skip to content

Commit 527cfa9

Browse files
authored
Merge pull request #34 from zoybai/lh_hwloc_sweeptest
Add automatic lstopo core order generation to lockhammer sweeptest
2 parents 7c1e80b + 91b2eba commit 527cfa9

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

benchmarks/lockhammer/scripts/lh_test_cfg.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,19 @@ sweeptest:
7676
- a: 5000
7777
c: 0ns
7878
p: 0ns
79+
o: lstopo
7980
- a: 5000
8081
c: 1000ns
8182
p: 0ns
83+
o: lstopo
8284
- a: 5000
8385
c: 200ns
8486
p: 1000ns
87+
o: lstopo
8588
- a: 5000
8689
c: 1000ns
8790
p: 5000ns
91+
o: lstopo
8892

8993
## Unittest Settings
9094
#
@@ -123,6 +127,7 @@ unittest:
123127
a: 100
124128
c: 50ns
125129
p: 0ns
130+
o: lstopo
126131
extra:
127132
u: 10
128133
s: 2
@@ -132,6 +137,8 @@ unittest:
132137
a: 100
133138
c: 50ns
134139
p: 0ns
140+
i: 1
141+
o: '0,1,2,3'
135142
extra:
136143
r: 4
137144
m: 1

benchmarks/lockhammer/scripts/test_lockhammer.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import sys
3737
import os
3838
import sh
39+
import re
3940
import errno
4041
import platform
4142
import unittest
@@ -50,7 +51,7 @@
5051
# config file should be in the same directory of this script
5152
LH_CFG = "lh_test_cfg.yaml"
5253
# lockhammer.c has these parameters
53-
LH_ARGU_LIST = ['t', 'a', 'c', 'p']
54+
LH_ARGU_LIST = ['t', 'a', 'c', 'p', 'i', 'o']
5455

5556

5657
# python unittest framework container class
@@ -130,6 +131,30 @@ def full_func_name(cmdName, paramList, fillZero):
130131
fullName += str(random.random())
131132
return fullName
132133

134+
# convert lstopo output to special cpu core order string, used by sweeptest -o
135+
def parse_lstopo():
136+
result = ''
137+
try:
138+
lst = sh.Command("lstopo")
139+
out = str(sh.grep(lst("--no-io", "--no-cache"), "PU"))
140+
except sh.CommandNotFound:
141+
print("Error, cannot find lstopo, need to install hwloc package first.")
142+
sys.exit(2)
143+
else:
144+
for line in out.splitlines():
145+
match = re.search("P#(\d+)", line.strip())
146+
if match:
147+
result += (match.group(1) + ',')
148+
finally:
149+
if result[-1] == ',':
150+
result = result[:-1]
151+
152+
# sample output for single-socket EPYC 7601 server:
153+
#0,32,8,40,16,48,24,56,4,36,12,44,20,52,28,60,1,33,9,41,17,49,25,57,5,37,\
154+
#13,45,21,53,29,61,2,34,10,42,18,50,26,58,6,38,14,46,22,54,30,62,3,35,11,\
155+
#43,19,51,27,59,7,39,15,47,23,55,31,63
156+
return result
157+
133158
# convert parameter from {key:value} to string list
134159
def expand_param(ctrl, valueList):
135160
outParam = []
@@ -146,6 +171,11 @@ def expand_param(ctrl, valueList):
146171
outParam.append(['-t', multiprocessing.cpu_count()])
147172
else:
148173
outParam.append(['-' + ctrl, valueList])
174+
elif isinstance(valueList, str):
175+
if ctrl == 'o' and valueList == 'lstopo':
176+
outParam.append(['-o', parse_lstopo()])
177+
else:
178+
outParam.append(['-' + ctrl, valueList])
149179
else:
150180
outParam.append(['-' + ctrl, valueList])
151181
return outParam
@@ -189,7 +219,10 @@ def prepare_param(arguList):
189219
for elem in arguList:
190220
paramList = []
191221
for key in elem:
192-
paramList.extend(['-'+key, elem[key]])
222+
if key == 'o' and str(elem[key]) == 'lstopo':
223+
paramList.extend(['-o', parse_lstopo()])
224+
else:
225+
paramList.extend(['-'+key, elem[key]])
193226
arguLL.append(paramList)
194227
return arguLL
195228

0 commit comments

Comments
 (0)