From 82a8c6c956da9a30ba14ab942be2bbcd256bced7 Mon Sep 17 00:00:00 2001 From: Denes Tarjan Date: Mon, 21 Oct 2024 15:51:56 +0000 Subject: [PATCH] Prepare scripts for multithreaded benchmarking --- scripts/benchmark/perf_test_op.sh | 35 +++++++++++++++++++++++------ scripts/benchmark/run_benchmarks.sh | 21 +++++++++++++---- scripts/build-opencv.sh | 2 -- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/scripts/benchmark/perf_test_op.sh b/scripts/benchmark/perf_test_op.sh index 598348f09..2d6800499 100755 --- a/scripts/benchmark/perf_test_op.sh +++ b/scripts/benchmark/perf_test_op.sh @@ -7,7 +7,7 @@ set -eu CUSTOM_BUILD_SUFFIX=$1 -CPU=$2 +CPU_MASK=$2 THERMAL_ZONE_ID=$3 DISP_NAME=$4 PERF_TEST_BINARY_BASENAME=$5 @@ -16,12 +16,27 @@ GTEST_PARAM_FILTER=$7 : "${DEV_DIR:=/data/local/tmp}" -CPU_MASK=$(echo "obase=16;2^${CPU}" | bc) - -FREQ_GOVERNOR_FILE="/sys/devices/system/cpu/cpu${CPU}/cpufreq/scaling_governor" +get_freq_governor() { + cat "/sys/devices/system/cpu/cpu${1}/cpufreq/scaling_governor" +} +set_freq_governor() { + echo "${2}" >"/sys/devices/system/cpu/cpu${1}/cpufreq/scaling_governor" +} -PREV_FREQ_GOVERNOR=$(cat "${FREQ_GOVERNOR_FILE}") -echo performance > "${FREQ_GOVERNOR_FILE}" +i=0 +x=1 +c=$((0x${CPU_MASK})) +CPUS='' +PREV_GOVERNORS='' +while [ "$c" -ge "$i" ]; do + if [ 0 -ne $(( c & x )) ]; then + CPUS="$i $CPUS" + PREV_GOVERNORS="$(get_freq_governor "$i") $PREV_GOVERNORS" + set_freq_governor "$i" performance + fi + i=$((i + 1)) + x=$((x * 2)) +done THERMAL_ZONE_DIR="/sys/devices/virtual/thermal/thermal_zone${THERMAL_ZONE_ID}" @@ -62,7 +77,13 @@ if [ -f "${DEV_DIR}/${PERF_TEST_BINARY_BASENAME}_kleidicv_${CUSTOM_BUILD_SUFFIX} run_test "kleidicv_${CUSTOM_BUILD_SUFFIX}" fi -echo "${PREV_FREQ_GOVERNOR}" > "${FREQ_GOVERNOR_FILE}" +while [ -n "${CPUS}" ]; do + c=$(echo "${CPUS}" | cut -d ' ' -f1) + CPUS=$(echo "${CPUS}" | cut -d ' ' -f2- -s) + g=$(echo "${PREV_GOVERNORS}" | cut -d ' ' -f1) + PREV_GOVERNORS=$(echo "${PREV_GOVERNORS}" | cut -d ' ' -f2- -s) + set_freq_governor "$c" "$g" +done if [ "${START_CDEV_TRANSITION_COUNT}" != "$(cat "${CDEV_TRANSITION_COUNT_FILE}")" ]; then >&2 echo "BENCHMARK ERROR: CPU throttling happened, exiting..." diff --git a/scripts/benchmark/run_benchmarks.sh b/scripts/benchmark/run_benchmarks.sh index c5d402ed2..135189ffd 100755 --- a/scripts/benchmark/run_benchmarks.sh +++ b/scripts/benchmark/run_benchmarks.sh @@ -24,20 +24,24 @@ set -eu # Environment: # DEV_DIR: Directory on the devicewhere all relevant files are stored. # Defaults to '/data/local/tmp'. -# CPU: Identifier of the core to run benchmarks on. -# Defaults to '4', which is most often a mid core. +# CPU_MASK: CPU mask to pass to 'taskset' to filter the cores to run benchmarks on. +# Defaults to '30', which most often specifies two mid cores. # CUSTOM_BUILD_SUFFIX: Build name suffix for the extra build. # Defaults to 'custom'. # RESOLUTION: Sets the resolution to bechmark. See select_resolution() below for # supported formats. Defaults to 4K. # THERMAL_ZONE_ID: Identifier of the thermal zone to watch for changes. # Defaults to '1', which is most often the zone associated with mid cores. +# BENCHMARK_FILTER: An optional filter (substring of the name) to restrict benchmark running. +# Defaults to '' (empty string), which means no filtering, run all benchmarks. # ------------------------------------------------------------------------------ : "${DEV_DIR:=/data/local/tmp}" -: "${CPU:=4}" +: "${CPU_MASK:=30}" : "${CUSTOM_BUILD_SUFFIX:=custom}" : "${THERMAL_ZONE_ID:=1}" +: "${BENCHMARK_FILTER:=}" +: "${OPENCV_FOR_THREADS_NUM:=1}" # ------------------------------------------------------------------------------ @@ -66,6 +70,12 @@ select_resolution() { fi case "${RESOLUTION:-}" in + VGA) + PIXEL_FORMAT="640x480" + ;; + 720p) + PIXEL_FORMAT="1280x720" + ;; FHD | 1080p) PIXEL_FORMAT="1920x1080" ;; @@ -92,6 +102,8 @@ foreach_benchmark() { [ -z "${line}" ] && continue # Skip lines starting with '#' [ -z "${line%\#*}" ] && continue + # Skip benchmarks not matching the filter + [ 0 -eq "$(expr "$line" : "\w*${BENCHMARK_FILTER}\w*")" ] && continue "${2}" "${line}" done < "${1}" @@ -127,9 +139,10 @@ run_benchmark() { # Many shells support 'local', therefore this warning is ignored. local -r disp_name="${spec%%:*}" + export OPENCV_FOR_THREADS_NUM # shellcheck disable=SC2086 # Word splitting at the end is required here to produce PERF_TEST_BINARY_BASENAME, GTEST_FILTER and GTEST_PARAM_FILTER. - eval "${DEV_DIR}"/perf_test_op.sh "${CUSTOM_BUILD_SUFFIX}" "${CPU}" "${THERMAL_ZONE_ID}" "${disp_name}" ${spec#*:} + eval "${DEV_DIR}"/perf_test_op.sh "${CUSTOM_BUILD_SUFFIX}" "${CPU_MASK}" "${THERMAL_ZONE_ID}" "${disp_name}" ${spec#*:} >&2 echo } diff --git a/scripts/build-opencv.sh b/scripts/build-opencv.sh index aeb39e9ae..e83937b28 100755 --- a/scripts/build-opencv.sh +++ b/scripts/build-opencv.sh @@ -96,8 +96,6 @@ cmake_config_args=( "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}" "-DCMAKE_SHARED_LINKER_FLAGS=${CMAKE_SHARED_LINKER_FLAGS}" "-DCMAKE_CXX_STANDARD=14" - "-DOPENCV_DISABLE_THREAD_SUPPORT=ON" - "-DCV_TRACE=OFF" "-DBUILD_EXAMPLES=OFF" "-DBUILD_opencv_apps=OFF" -- GitLab