From bb9a3aab9b1bf6696ac8390d0afaa65ce447edb9 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 1 Dec 2021 11:00:38 -0500 Subject: [PATCH 1/2] Support pinning down Pixel 6 Mali GPU frequency --- .../benchmarks/run_benchmarks_on_android.py | 32 +++++++++-- .../set_android_scaling_governor.sh | 1 + .../set_pixel6_gpu_scaling_policy.sh | 54 +++++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100755 build_tools/benchmarks/set_pixel6_gpu_scaling_policy.sh diff --git a/build_tools/benchmarks/run_benchmarks_on_android.py b/build_tools/benchmarks/run_benchmarks_on_android.py index 5bdeb988f8d3..b9fb840b261a 100755 --- a/build_tools/benchmarks/run_benchmarks_on_android.py +++ b/build_tools/benchmarks/run_benchmarks_on_android.py @@ -64,6 +64,7 @@ BenchmarkResults, BenchmarkRun, execute_cmd, execute_cmd_and_get_output, + get_android_device_model, IREE_PRETTY_NAMES_TO_DRIVERS) # All benchmarks' relative path against root build directory. @@ -547,12 +548,25 @@ def filter_and_run_benchmarks( return (benchmark_files, captures, errors) -def set_frequency_scaling_governor(governor: str): +def set_cpu_frequency_scaling_governor(governor: str): git_root = execute_cmd_and_get_output(["git", "rev-parse", "--show-toplevel"]) cpu_script = os.path.join( git_root, "build_tools/benchmarks/set_android_scaling_governor.sh") - adb_push_to_tmp_dir(cpu_script) - adb_execute(["su", "root", "./set_android_scaling_governor.sh", governor]) + android_path = adb_push_to_tmp_dir(cpu_script) + adb_execute(["su", "root", android_path, governor]) + + +def set_gpu_frequency_scaling_policy(policy: str): + git_root = execute_cmd_and_get_output(["git", "rev-parse", "--show-toplevel"]) + device_model = get_android_device_model() + if device_model == "Pixel-6": + gpu_script = os.path.join( + git_root, "build_tools/benchmarks/set_pixel6_gpu_scaling_policy.sh") + else: + raise RuntimeError( + f"Unsupported device '{device_model}' for setting GPU scaling policy") + android_path = adb_push_to_tmp_dir(gpu_script) + adb_execute(["su", "root", android_path, policy]) def parse_arguments(): @@ -617,6 +631,11 @@ def check_exe_path(path): "--pin_cpu_freq", action="store_true", help="Pin CPU frequency for all cores to the maximum. Requires root") + parser.add_argument( + "--pin-gpu-freq", + "--pin_gpu_freq", + action="store_true", + help="Pin GPU frequency to the maximum. Requires root") parser.add_argument( "--keep_going", "--keep-going", @@ -658,8 +677,11 @@ def main(args): "need to update the map") if args.pin_cpu_freq: - set_frequency_scaling_governor("performance") - atexit.register(set_frequency_scaling_governor, "schedutil") + set_cpu_frequency_scaling_governor("performance") + atexit.register(set_cpu_frequency_scaling_governor, "schedutil") + if args.pin_gpu_freq: + set_gpu_frequency_scaling_policy("always_on") + atexit.register(set_gpu_frequency_scaling_policy, "coarse_demand") previous_benchmarks = None previous_captures = None diff --git a/build_tools/benchmarks/set_android_scaling_governor.sh b/build_tools/benchmarks/set_android_scaling_governor.sh index 4f73f872aa50..e262926f4a13 100755 --- a/build_tools/benchmarks/set_android_scaling_governor.sh +++ b/build_tools/benchmarks/set_android_scaling_governor.sh @@ -40,6 +40,7 @@ done echo "CPU info (after changing governor):" echo 'cpu\tgovernor\tcur\tmin\tmax' +echo "------------------------------------------------" for i in `cat /sys/devices/system/cpu/present | tr '-' ' ' | xargs seq`; do \ echo "cpu${i}" | paste \ - \ diff --git a/build_tools/benchmarks/set_pixel6_gpu_scaling_policy.sh b/build_tools/benchmarks/set_pixel6_gpu_scaling_policy.sh new file mode 100755 index 000000000000..4fbbbb3f9bb2 --- /dev/null +++ b/build_tools/benchmarks/set_pixel6_gpu_scaling_policy.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# Copyright 2021 The IREE Authors +# +# Licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Runs on a Pixel 6 device itself to set the GPU frequency scaling policy. + +################################### WARNING #################################### +# This will overheat the phone if it's not on a cooling plate, resulting in # +# thermal throttling. To prevent anything catching on fire, the actual GPU # +# frequencies will be throttled to below the maximum, skewing your results. # +################################################################################ + +set -euo pipefail + +POLICY="${1:-always_on}" + +readonly MALI_GPU_PATH="/sys/devices/platform/1c500000.mali" + +echo "GPU info (before changing power policy):" +echo 'policy\t\t\t\t\tcur\tmin\tmax' +echo "--------------------------------------------------------------" +paste \ + "${MALI_GPU_PATH}/power_policy" \ + "${MALI_GPU_PATH}/cur_freq" \ + "${MALI_GPU_PATH}/min_freq" \ + "${MALI_GPU_PATH}/max_freq" + +echo "Setting GPU power policy to ${POLICY}" + +if [[ "$POLICY" == "always_on" ]]; then + echo "always_on" > "${MALI_GPU_PATH}/power_policy" + cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_max_freq" + cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_min_freq" +elif [[ "$POLICY" == "coarse_demand" ]]; then + echo "coarse_demand" > "${MALI_GPU_PATH}/power_policy" + cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_max_freq" + cat "${MALI_GPU_PATH}/min_freq" > "${MALI_GPU_PATH}/scaling_min_freq" +else + echo "Unknown power policy: ${POLICY}" + exit 1 +fi + +echo "GPU info (after changing power policy):" +echo 'policy\t\t\t\t\tcur\tmin\tmax' +echo "--------------------------------------------------------------" +paste \ + "${MALI_GPU_PATH}/power_policy" \ + "${MALI_GPU_PATH}/cur_freq" \ + "${MALI_GPU_PATH}/min_freq" \ + "${MALI_GPU_PATH}/max_freq" From 1d04e7a1a649aec250b7b45098c7717149a8bf95 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 2 Dec 2021 09:59:15 -0500 Subject: [PATCH 2/2] Fix formatting --- build_tools/benchmarks/run_benchmarks_on_android.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/build_tools/benchmarks/run_benchmarks_on_android.py b/build_tools/benchmarks/run_benchmarks_on_android.py index b9fb840b261a..2fb34e4606ae 100755 --- a/build_tools/benchmarks/run_benchmarks_on_android.py +++ b/build_tools/benchmarks/run_benchmarks_on_android.py @@ -631,11 +631,10 @@ def check_exe_path(path): "--pin_cpu_freq", action="store_true", help="Pin CPU frequency for all cores to the maximum. Requires root") - parser.add_argument( - "--pin-gpu-freq", - "--pin_gpu_freq", - action="store_true", - help="Pin GPU frequency to the maximum. Requires root") + parser.add_argument("--pin-gpu-freq", + "--pin_gpu_freq", + action="store_true", + help="Pin GPU frequency to the maximum. Requires root") parser.add_argument( "--keep_going", "--keep-going",