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