Skip to content

Commit bbb1146

Browse files
author
Rebecca Cran
committed
Several fixes and improvements
- Create efi-vars disk images for each instance: this prevents them stomping on the single copy, corrupting it and causing the firmware to crash. - Improve README.md. - Create a new file env.sh to hold common variables such as version numbers. - Replace duplication of version numbers by environment variables. - Fix issues noted by ShellCheck. - Improve stop_qemu.sh by storing the QEMU PIDs in qemu_pids.txt and using that to kill the instances. - Count the rounds from 1, not 0. - Clean up more files in stop_qemu.sh. - In run_pts.sh, wait for the ssh commands to finish.
1 parent 6c82a22 commit bbb1146

File tree

6 files changed

+67
-53
lines changed

6 files changed

+67
-53
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ It should run on other distros and architectures (POWER, RISCV64, LOONGSON etc.)
4040
## Run
4141

4242
Run PTS / coremark on each instance.
43-
Argument 1 is the number of times you want to run Coremark on each QEMU.
43+
Argument 1 is the number of times you want to run CoreMark on each QEMU.
4444
Default Value is 1
4545

4646
```
4747
./run_pts.sh <count>
4848
```
49-
Example - It will report the output as follow -
49+
Example - it will report the output as follow -
5050
```
51-
$ ./run_pts_once.sh 2
52-
23 QEMU running in parallel. Total CoreMark Score is: 1937195
53-
23 QEMU running in parallel. Total CoreMark Score is: 1940554
51+
$ ./run_pts.sh 2
52+
23 instances of pts/coremark running in parallel in arm64 VMs!
53+
Round 1 - Total CoreMark Score is: 1937195
54+
Round 2 - Total CoreMark Score is: 1940554
5455
```
5556
## Teardown
5657
To stop / kill QEMU instances

build_qemu.sh

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
#
55
# SPDX-License-Identifier: BSD-3-Clause
66

7-
87
# Runs coremark in an arm64 QEMU VM
9-
# Version 20241002-01
8+
# Version 20241005-01
109

1110
set -o errexit
1211
set -o nounset
1312

13+
. env.sh
14+
1415
echo "Checking for prerequisites"
1516

16-
DISTRO_LIKE="$(cat /etc/os-release | grep ID_LIKE | awk -F '=' '{print $2}')"
17+
DISTRO_LIKE="$(grep ID_LIKE /etc/os-release | awk -F '=' '{print $2}')"
1718

1819
if [ "${DISTRO_LIKE}" = "debian" ]; then
1920
QEMU_AARCH64_FW="/usr/share/qemu-efi-aarch64/QEMU_EFI.fd"
@@ -61,8 +62,6 @@ if [ "${DISTRO_LIKE}" = "debian" ]; then
6162
echo "Instaling bzip2"
6263
sudo apt-get install -y bzip2
6364
fi
64-
65-
6665
elif [ ! "$(command -v ninja)" ] || [ ! "$(command -v gcc)" ] || [ ! "$(command -v g++)" ] || [ ! "$(command -v git)" ] ||
6766
[ ! "$(command -v make)" ] || [ ! "$(command -v wget)" ] || [ ! "$(command -v cloud-localds)" ] ||
6867
[ ! "$(command -v bzip2)" ]; then
@@ -82,7 +81,7 @@ fi
8281
echo "Downloading Phoronix Test Suite"
8382
mkdir phoronix-test-suite || true
8483
pushd phoronix-test-suite || exit 1
85-
wget -c -O phoronix-test-suite_10.8.4_all.deb https://phoronix-test-suite.com/releases/repo/pts.debian/files/phoronix-test-suite_10.8.4_all.deb
84+
wget -c -O "phoronix-test-suite_${PTS_VERSION}_all.deb" "https://phoronix-test-suite.com/releases/repo/pts.debian/files/phoronix-test-suite_${PTS_VERSION}_all.deb"
8685
cat >phoronix-test-suite.xml <<EOF
8786
<?xml version="1.0"?>
8887
<!--Phoronix Test Suite v10.8.4-->
@@ -170,13 +169,13 @@ EOF
170169
popd || exit 1
171170

172171
# Build QEMU
173-
echo "8d2f4cfe25af01c73526ea0d5059fcae qemu-9.1.0.tar.gz" > MD5SUM
172+
echo "${QEMU_MD5} qemu-${QEMU_VERSION}.tar.gz" > MD5SUM
174173
if ! md5sum -c MD5SUM; then
175174
echo "Downloading QEMU"
176-
wget -c -O qemu-9.1.0.tar.gz https://github.com/qemu/qemu/archive/refs/tags/v9.1.0.tar.gz
175+
wget -c -O qemu-${QEMU_VERSION}.tar.gz https://github.com/qemu/qemu/archive/refs/tags/v${QEMU_VERSION}.tar.gz
177176
fi
178-
tar xf qemu-9.1.0.tar.gz
179-
pushd qemu-9.1.0 || exit 1
177+
tar xf qemu-${QEMU_VERSION}.tar.gz
178+
pushd qemu-${QEMU_VERSION} || exit 1
180179
if [ ! -e "build/qemu-system-aarch64" ]; then
181180
echo "Building QEMU"
182181
./configure --target-list=aarch64-softmmu --enable-slirp --enable-kvm
@@ -189,7 +188,6 @@ echo "Setting up VM configuration"
189188
cp -vf "${QEMU_AARCH64_FW}" efi-code.img
190189

191190
truncate -s 64m efi-code.img
192-
truncate -s 64m efi-vars.img
193191

194192
SSH_KEY_FILE="id_rsa_coremark_qemu"
195193
if [ ! -e "${SSH_KEY_FILE}" ]; then

env.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2024, Ampere Computing LLC
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
QEMU_VERSION="9.1.0"
6+
QEMU_MD5="8d2f4cfe25af01c73526ea0d5059fcae"
7+
PTS_VERSION="10.8.4"
8+
DEBIAN_FILENAME="debian-12-genericcloud-arm64-20240901-1857.qcow2"

launch_qemu.sh

+18-10
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
set -o errexit
88
set -o nounset
99

10-
bash stop_qemu.sh
11-
sleep 5
10+
. env.sh
11+
12+
if [ -f "qemu_pids.txt" ]; then
13+
./stop_qemu.sh
14+
fi
1215

1316
# Download img file (debian genericcloud arm64) to load into QEMU
1417
if [ ! -f "disk.qcow2" ]; then
1518
echo "Downloading Debian 'genericcloud' arm64 image"
16-
wget -c -O debian-12-genericcloud-arm64-20240901-1857.qcow2 https://cloud.debian.org/images/cloud/bookworm/20240901-1857/debian-12-genericcloud-arm64-20240901-1857.qcow2
17-
./qemu-9.1.0/build/qemu-img resize -q debian-12-genericcloud-arm64-20240901-1857.qcow2 5G
19+
wget -c -O "${DEBIAN_FILENAME}" "https://cloud.debian.org/images/cloud/bookworm/20240901-1857/${DEBIAN_FILENAME}"
20+
"./qemu-${QEMU_VERSION}/build/qemu-img" resize -q "${DEBIAN_FILENAME}" 5G
1821
fi
1922

2023
if [ "$(uname -m)" = "aarch64" ]; then
@@ -27,18 +30,23 @@ fi
2730

2831
echo -n "Running QEMU VMs"
2932

30-
bash ./thread.sh
33+
./thread.sh
3134

3235
count=0
3336
portnum=2000
3437
qemu_pids=()
3538
while read line; do
36-
if [ ! -f "disk${count}.qemu" ]; then
37-
./qemu-9.1.0/build/qemu-img create -q -f qcow2 -F qcow2 -b debian-12-genericcloud-arm64-20240901-1857.qcow2 disk${count}.qcow2
39+
if [ ! -f "disk${count}.qcow2" ]; then
40+
"./qemu-${QEMU_VERSION}/build/qemu-img" create -q -f qcow2 -F qcow2 -b "${DEBIAN_FILENAME}" "disk${count}.qcow2"
41+
fi
42+
43+
if [ ! -f "efi-vars-${count}.img" ]; then
44+
truncate -s 64m "efi-vars-${count}.img"
3845
fi
3946

47+
# shellcheck disable=SC2086
4048
nohup taskset -c ${line} \
41-
$PWD/qemu-9.1.0/build/qemu-system-aarch64 \
49+
"$PWD/qemu-${QEMU_VERSION}/build/qemu-system-aarch64" \
4250
-machine virt,gic-version=max \
4351
-m 4G \
4452
-cpu ${QEMU_CPU} \
@@ -67,8 +75,7 @@ sleep 5
6775
echo "Checking if VMs successfully started."
6876
count=0
6977
for p in "${qemu_pids[@]}"; do
70-
if ! kill -0 $p 2>/dev/null; then
71-
#wait $!
78+
if ! kill -0 "$p" 2>/dev/null; then
7279
echo "QEMU VM ${count} failed to start. See /tmp/qemu${count}.log for details."
7380
exit 1
7481
fi
@@ -89,5 +96,6 @@ while read line; do
8996
count=$((count+1))
9097
done < core_spread.txt
9198

99+
echo "${qemu_pids[@]}" > "qemu_pids.txt"
92100

93101
echo "The QEMU VMs are ready."

run_pts.sh

+16-25
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,46 @@ set -o errexit
88
set -o nounset
99

1010
# Assign default value if no argument is passed
11-
arg=${1:-1}
11+
num_iterations=${1:-1}
1212

1313
num_inst=$(wc -l core_spread.txt | cut -d" " -f1)
14-
num_minus_1=$((num_inst-1))
15-
num_minus_2=$((num_inst-2))
16-
count=0
1714

18-
SSH_KEY_FILE="id_rsa_coremark_qemu"
15+
ssh_key_file="id_rsa_coremark_qemu"
1916

2017
echo "${num_inst} instances of pts/coremark running in parallel in arm64 VMs!"
21-
while true; do
18+
ssh_pids=()
19+
# shellcheck disable=SC2034
20+
for iter in $(seq 1 ${num_iterations}); do
2221

2322
rm -f /tmp/20*
2423
portnum=2000;
2524

26-
for i in $(seq 0 ${num_minus_2}); do
25+
# shellcheck disable=SC2034
26+
for i in $(seq 0 $((num_inst-1))); do
2727
ssh \
2828
-p ${portnum} \
29-
-i "${SSH_KEY_FILE}" \
29+
-i "${ssh_key_file}" \
3030
debian@localhost \
3131
-o StrictHostKeyChecking=no \
3232
"phoronix-test-suite debug-benchmark pts/coremark" >> /tmp/${portnum} 2>&1 &
33-
portnum=$((${portnum}+1))
33+
ssh_pids+=($!)
34+
portnum=$((portnum+1))
3435
done
3536

36-
ssh \
37-
-p ${portnum} \
38-
-i ${SSH_KEY_FILE} \
39-
debian@localhost \
40-
-o UserKnownHostsFile=/dev/null \
41-
-o StrictHostKeyChecking=no \
42-
"phoronix-test-suite debug-benchmark pts/coremark" >> /tmp/${portnum} 2>&1
37+
for pid in "${ssh_pids[@]}"; do
38+
wait "${pid}"
39+
done
4340

44-
sleep 10
4541
sum=0
4642
portnum=2000;
4743

4844
# Add the coremark scores
49-
for i in $(seq 0 ${num_minus_1}); do
45+
# shellcheck disable=SC2034
46+
for i in $(seq 0 $((num_inst-1))); do
5047
score=$(cat /tmp/${portnum} | grep "Average: " | cut -d " " -f2 | cut -d"." -f1)
5148
sum=$((sum+score))
5249
portnum=$((portnum+1))
5350
done
5451

55-
echo "Round ${count} - Total CoreMark Score is: ${sum}"
56-
57-
count=$((count+1))
58-
59-
if [ "${count}" -ge "$arg" ]; then
60-
exit 0;
61-
fi
52+
echo "Round ${iter} - Total CoreMark Score is: ${sum}"
6253
done

stop_qemu.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
#
55
# SPDX-License-Identifier: BSD-3-Clause
66

7-
killall qemu-system-aarch64
8-
rm -rf disk*.qcow2
7+
if [ -f "qemu_pids.txt" ]; then
8+
QEMU_PIDS="$(cat qemu_pids.txt)"
9+
# shellcheck disable=SC2059
10+
kill ${QEMU_PIDS}
11+
fi
12+
rm -f disk*.qcow2
13+
rm -f efi-vars-*.img
914
rm -f /tmp/qemu*.log
15+
rm -f /tmp/20*
16+
rm -f qemu_pids.txt
17+
rm -f core_spread.txt

0 commit comments

Comments
 (0)