xref: /cloud-hypervisor/scripts/run_metrics.sh (revision d3fade85a725d36653dc4f636a1e55177eac2ddc)
1#!/usr/bin/env bash
2set -x
3
4# shellcheck source=/dev/null
5source "$HOME"/.cargo/env
6source "$(dirname "$0")"/test-util.sh
7
8TEST_ARCH=$(uname -m)
9export TEST_ARCH
10
11WORKLOADS_DIR="$HOME/workloads"
12mkdir -p "$WORKLOADS_DIR"
13
14build_fio() {
15    FIO_DIR="$WORKLOADS_DIR/fio_build"
16    FIO_REPO="https://github.com/axboe/fio.git"
17
18    checkout_repo "$FIO_DIR" "$FIO_REPO" master "1953e1adb5a28ed21370e85991d7f5c3cdc699f3"
19    if [ ! -f "$FIO_DIR/.built" ]; then
20        pushd "$FIO_DIR" || exit
21        ./configure
22        make -j "$(nproc)"
23        cp fio "$WORKLOADS_DIR/fio"
24        touch .built
25        popd || exit
26    fi
27}
28
29process_common_args "$@"
30
31cp scripts/sha1sums-"${TEST_ARCH}" "$WORKLOADS_DIR"
32
33if [ "${TEST_ARCH}" == "aarch64" ]; then
34    FOCAL_OS_IMAGE_NAME="focal-server-cloudimg-arm64-custom-20210929-0.qcow2"
35else
36    FOCAL_OS_IMAGE_NAME="focal-server-cloudimg-amd64-custom-20210609-0.qcow2"
37fi
38
39FOCAL_OS_IMAGE_URL="https://ch-images.azureedge.net/$FOCAL_OS_IMAGE_NAME"
40FOCAL_OS_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_IMAGE_NAME"
41if [ ! -f "$FOCAL_OS_IMAGE" ]; then
42    pushd "$WORKLOADS_DIR" || exit
43    time wget --quiet $FOCAL_OS_IMAGE_URL || exit 1
44    popd || exit
45fi
46
47if [ "${TEST_ARCH}" == "aarch64" ]; then
48    FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-arm64-custom-20210929-0.raw"
49else
50    FOCAL_OS_RAW_IMAGE_NAME="focal-server-cloudimg-amd64-custom-20210609-0.raw"
51fi
52
53FOCAL_OS_RAW_IMAGE="$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_NAME"
54if [ ! -f "$FOCAL_OS_RAW_IMAGE" ]; then
55    pushd "$WORKLOADS_DIR" || exit
56    time qemu-img convert -p -f qcow2 -O raw $FOCAL_OS_IMAGE_NAME $FOCAL_OS_RAW_IMAGE_NAME || exit 1
57    popd || exit
58fi
59
60pushd "$WORKLOADS_DIR" || exit
61if ! grep focal sha1sums-"${TEST_ARCH}" | sha1sum --check; then
62    echo "sha1sum validation of images failed, remove invalid images to fix the issue."
63    exit 1
64fi
65popd || exit
66
67if [ "${TEST_ARCH}" == "aarch64" ]; then
68    build_fio
69
70    # Update the fio in the cloud image to use io_uring on AArch64
71    FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_NAME="focal-server-cloudimg-arm64-custom-20210929-0-update-tool.raw"
72    cp "$FOCAL_OS_RAW_IMAGE" "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_NAME"
73    FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_ROOT_DIR="$WORKLOADS_DIR/focal-server-cloudimg-root"
74    if [ ! -d "$FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_ROOT_DIR" ]; then
75        mkdir -p "$FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_ROOT_DIR"
76    fi
77    # Mount the 'raw' image, replace the fio and umount the working folder
78    guestmount -a "$WORKLOADS_DIR/$FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_NAME" -m /dev/sda1 "$FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_ROOT_DIR" || exit 1
79    cp "$WORKLOADS_DIR"/fio "$FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_ROOT_DIR"/usr/bin/fio
80    guestunmount "$FOCAL_OS_RAW_IMAGE_UPDATE_TOOL_ROOT_DIR"
81fi
82
83# Build custom kernel based on virtio-pmem and virtio-fs upstream patches
84build_custom_linux
85
86CFLAGS=""
87if [[ "${BUILD_TARGET}" == "${TEST_ARCH}-unknown-linux-musl" ]]; then
88    # shellcheck disable=SC2034
89    CFLAGS="-I /usr/include/${TEST_ARCH}-linux-musl/ -idirafter /usr/include/"
90fi
91
92cargo build --features mshv --all --release --target "$BUILD_TARGET"
93
94# setup hugepages
95HUGEPAGESIZE=$(grep Hugepagesize /proc/meminfo | awk '{print $2}')
96PAGE_NUM=$((12288 * 1024 / HUGEPAGESIZE))
97echo "$PAGE_NUM" | sudo tee /proc/sys/vm/nr_hugepages
98sudo chmod a+rwX /dev/hugepages
99
100if [ -n "$test_filter" ]; then
101    test_binary_args+=("--test-filter $test_filter")
102fi
103
104# Ensure that git commands can be run in this directory (for metrics report)
105git config --global --add safe.directory "$PWD"
106
107RUST_BACKTRACE_VALUE=$RUST_BACKTRACE
108if [ -z "$RUST_BACKTRACE_VALUE" ]; then
109    export RUST_BACKTRACE=1
110else
111    echo "RUST_BACKTRACE is set to: $RUST_BACKTRACE_VALUE"
112fi
113# shellcheck disable=SC2048,SC2086
114time target/"$BUILD_TARGET"/release/performance-metrics ${test_binary_args[*]}
115RES=$?
116
117exit $RES
118