Skip to content

Commit 8e8b03a

Browse files
committed
run-tests.sh
This script runs a set of lockhammer executables from an embedded list of test/build/variants against another a list of critical/parallel durations across a number of detected CPUs to do a core-scaling study. The result of each test invocation is stored to a json file. The lists in the script are to be edited by the user. The script is meant to be easily modified for different scaling studies. Change-Id: I6da249bd015b46e139dac51d338a4c790d507785
1 parent 8217fa8 commit 8e8b03a

File tree

1 file changed

+266
-0
lines changed

1 file changed

+266
-0
lines changed
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: Copyright 2019-2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
# This script invokes lockhammer tests.
7+
# This script is meant to be edited for customizing which tests to run.
8+
# Edit the *_LIST variables below to choose the configuration combinations.
9+
# A json file will be made for each variant and test combination.
10+
11+
set -e
12+
13+
usage() {
14+
cat<<USAGE
15+
16+
run-tests.sh [options]
17+
18+
options:
19+
20+
-n do a dry run
21+
-P skip processor skip step above 8 CPUs (default $CPU_SKIP)
22+
For example, -P 16 will measure 2, 4, 8, 24, 40...
23+
-T sec duration of each measurement in seconds (default $DURATION_SECONDS)
24+
-h print this usage help message
25+
26+
USAGE
27+
exit 1
28+
}
29+
30+
CPU_SKIP=8
31+
DRY_RUN=0
32+
DURATION_SECONDS=0.5
33+
IGNORE_UNKNOWN_SCALING_GOVERNOR=-Y
34+
35+
shopt -s extglob
36+
37+
while getopts ":nP:T:h" name; do
38+
case "${name}" in
39+
n) DRY_RUN=1
40+
;;
41+
P) CPU_SKIP=${OPTARG}
42+
;;
43+
T) DURATION_SECONDS=${OPTARG}
44+
;;
45+
h) usage
46+
;;
47+
:) >&2 echo "ERROR: flag -$OPTARG required an argument, but none was given"
48+
usage
49+
;;
50+
*) echo name=$name, OPTARG=$OPTARG
51+
usage
52+
;;
53+
esac
54+
done
55+
56+
shift $((OPTIND-1))
57+
58+
# make the list of build variants to run; use # to comment out variant
59+
60+
# TODO: update lists by arch
61+
62+
VARIANT_LIST=$(grep -v -E '\#|^$' <<'EOF1'
63+
builtin.cond_load.relax_empty
64+
builtin.cond_load.relax_nothing
65+
builtin.cond_load.relax_pause
66+
builtin.relax_empty
67+
builtin.relax_nothing
68+
builtin.relax_pause
69+
cond_load.relax_empty
70+
cond_load.relax_nothing
71+
cond_load.relax_pause
72+
relax_empty
73+
relax_nothing
74+
relax_pause
75+
76+
77+
#builtin.relax_nothing
78+
#builtin.relax_isb
79+
#builtin.cond_load.relax_nothing
80+
#builtin.cond_load.relax_isb
81+
82+
#lse.builtin.relax_nothing
83+
#lse.builtin.relax_isb
84+
#lse.builtin.cond_load.relax_nothing
85+
#lse.builtin.cond_load.relax_isb
86+
EOF1
87+
)
88+
89+
# make the list of tests to run; use # to comment out test
90+
91+
TEST_LIST=$(grep -v -E '\#|^$' <<'EOF2'
92+
lh_cas_event_mutex
93+
lh_cas_lockref
94+
lh_cas_rw_lock
95+
#lh_clh_spinlock
96+
#lh_empty
97+
#lh_event_mutex
98+
#lh_hybrid_spinlock
99+
#lh_hybrid_spinlock_fastdequeue
100+
lh_incdec_refcount
101+
lh_jvm_objectmonitor
102+
lh_osq_lock
103+
#lh_queued_spinlock
104+
#lh_swap_mutex
105+
#lh_tbb_spin_rw_mutex
106+
lh_ticket_spinlock
107+
EOF2
108+
)
109+
110+
CRIT_NS_LIST=$(grep -v -E '\#|^$' <<'EOF_CRIT_NS'
111+
0
112+
500
113+
1000
114+
EOF_CRIT_NS
115+
)
116+
117+
PAR_NS_LIST=$(grep -v -E '\#|^$' <<'EOF_PAR_NS'
118+
0
119+
500
120+
1000
121+
2000
122+
4000
123+
EOF_PAR_NS
124+
)
125+
126+
PAR=""
127+
for a in $PAR_NS_LIST; do PAR+="-p${a}ns "; done
128+
129+
CRIT=""
130+
for a in $CRIT_NS_LIST; do CRIT+="-c${a}ns "; done
131+
132+
133+
# check that a hugepage is available
134+
#HUGEPAGE_SIZE=32MB
135+
#HUGEPAGE_SIZE_KB=$((32*1024))
136+
HUGEPAGE_SIZE=1GB
137+
HUGEPAGE_SIZE_KB=$((1024*1024))
138+
HUGEPAGES_DIR=/sys/kernel/mm/hugepages/hugepages-${HUGEPAGE_SIZE_KB}kB
139+
FREE_HUGEPAGES_FILE=$HUGEPAGES_DIR/free_hugepages
140+
NR_HUGEPAGES_FILE=$HUGEPAGES_DIR/nr_hugepages
141+
NR_HUGEPAGES=$(cat "$NR_HUGEPAGES_FILE")
142+
NR_HUGEPAGES_PLUS_ONE=$((NR_HUGEPAGES+1))
143+
if [ ! -e "$FREE_HUGEPAGES_FILE" ] || [ $(cat "$FREE_HUGEPAGES_FILE") -eq 0 ]; then
144+
echo "ERROR: no free $HUGEPAGE_SIZE hugepages. Perhaps try running:"
145+
echo "echo $NR_HUGEPAGES_PLUS_ONE | sudo tee -a $NR_HUGEPAGES_FILE"
146+
exit -1
147+
fi
148+
HUGEPAGE_FLAGS="--hugepage-size $HUGEPAGE_SIZE"
149+
150+
151+
# determine cpuorder file to use based on hostname.
152+
HOSTNAME_S=$(hostname -s)
153+
CPUORDER_FLAGS=
154+
if [ -e hostname_to_cpuorder_type.sh ]; then
155+
. hostname_to_cpuorder_type.sh
156+
157+
CPUORDER_TYPE=$(hostname_to_cpuorder_type $HOSTNAME_S)
158+
CPUORDER=cpuorders/$CPUORDER_TYPE.cpuorder
159+
160+
if [ ! -e "$CPUORDER" ]; then
161+
echo "ERROR: $CPUORDER does not exist!"
162+
exit -1
163+
fi
164+
165+
CPUORDER_FLAGS="-C $CPUORDER"
166+
fi
167+
168+
# compute the number of threads using the number of available processors
169+
NPROC=$(nproc)
170+
TLIST=
171+
for num_threads in 2 4 $(eval echo "{8..$NPROC..$CPU_SKIP}")
172+
do
173+
if [ $num_threads -gt $NPROC ]; then
174+
break
175+
fi
176+
177+
TLIST+="-t $num_threads "
178+
done
179+
180+
181+
# compute number of test and variants
182+
NUM_TESTS=$(echo $TEST_LIST | wc -w)
183+
NUM_VARIANTS=$(echo $VARIANT_LIST | wc -w)
184+
#echo NUM_VARIANTS=$NUM_VARIANTS NUM_TESTS=$NUM_TESTS
185+
NUM_TEST_AND_VARIANTS=$((NUM_TESTS*NUM_VARIANTS))
186+
TEST_AND_VARIANT_COUNT=0
187+
#echo NUM_TEST_AND_VARIANTS=$NUM_TEST_AND_VARIANTS
188+
189+
#exit 0
190+
191+
# change newline to space for the summary
192+
TEST_LIST=${TEST_LIST//$'\n'/ }
193+
VARIANT_LIST=${VARIANT_LIST//$'\n'/ }
194+
PAR_NS_LIST=${PAR_NS_LIST//$'\n'/ }
195+
CRIT_NS_LIST=${CRIT_NS_LIST//$'\n'/ }
196+
197+
cat<<SUMMARY
198+
hostname = $HOSTNAME_S
199+
cpuorder = $CPUORDER
200+
num_threads = ${TLIST//-t /}
201+
variants = $VARIANT_LIST
202+
tests = $TEST_LIST
203+
critical times (ns) = $CRIT_NS_LIST
204+
parallel times (ns) = $PAR_NS_LIST
205+
duration (sec) = $DURATION_SECONDS
206+
hugepage flags = $HUGEPAGE_FLAGS
207+
SUMMARY
208+
209+
echo
210+
echo ------------------------------------------------------
211+
echo beginning measurements at: $(date)
212+
echo ------------------------------------------------------
213+
214+
START_EPOCHSECONDS=$EPOCHSECONDS
215+
216+
for BUILD_VARIANT in $VARIANT_LIST
217+
do
218+
219+
for test in $TEST_LIST
220+
do
221+
222+
TEST_AND_VARIANT_COUNT=$((TEST_AND_VARIANT_COUNT+1))
223+
echo
224+
echo running $TEST_AND_VARIANT_COUNT of $NUM_TEST_AND_VARIANTS test+variant combinations
225+
echo
226+
227+
EXE=build.$BUILD_VARIANT/$test
228+
JSON=$HOSTNAME_S.$test.$BUILD_VARIANT.json
229+
CMD="$EXE $IGNORE_UNKNOWN_SCALING_GOVERNOR $PAR $CRIT -T $DURATION_SECONDS $CPUORDER_FLAGS $HUGEPAGE_FLAGS $TLIST --json $JSON"
230+
231+
if [ ! -x "$EXE" ]; then
232+
echo ERROR: $EXE is not found or not executable, skipping test
233+
continue
234+
fi
235+
236+
if [ -e "$JSON" ]; then
237+
echo ERROR: $JSON already exists, will not overwrite, skipping test
238+
continue
239+
fi
240+
241+
echo
242+
if [ $DRY_RUN -eq 0 ]; then
243+
echo $CMD
244+
echo
245+
$CMD
246+
else
247+
echo This is a DRY RUN -- the following command will not be executed:
248+
echo
249+
echo $CMD
250+
fi
251+
done
252+
done
253+
254+
FINISH_EPOCHSECONDS=$EPOCHSECONDS
255+
ELAPSED_SECONDS=$((FINISH_EPOCHSECONDS-START_EPOCHSECONDS))
256+
if [ $ELAPSED_SECONDS -ge 86400 ]; then
257+
ELAPSED_TIME=$(date -u -d @$ELAPSED_SECONDS +%j:%T)
258+
else
259+
ELAPSED_TIME=$(date -u -d @$ELAPSED_SECONDS +%T)
260+
fi
261+
262+
echo
263+
echo ------------------------------------------------------
264+
echo finished measurements at: $(date)
265+
echo elapsed time: $ELAPSED_TIME
266+
echo ------------------------------------------------------

0 commit comments

Comments
 (0)