Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2322a16

Browse files
authored
Support pinning down Pixel 6 Mali GPU frequency (iree-org#7801)
1 parent 71282bf commit 2322a16

File tree

3 files changed

+81
-5
lines changed

3 files changed

+81
-5
lines changed

‎build_tools/benchmarks/run_benchmarks_on_android.py‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
BenchmarkResults, BenchmarkRun,
6565
execute_cmd,
6666
execute_cmd_and_get_output,
67+
get_android_device_model,
6768
IREE_PRETTY_NAMES_TO_DRIVERS)
6869

6970
# All benchmarks' relative path against root build directory.
@@ -547,12 +548,25 @@ def filter_and_run_benchmarks(
547548
return (benchmark_files, captures, errors)
548549

549550

550-
def set_frequency_scaling_governor(governor: str):
551+
def set_cpu_frequency_scaling_governor(governor: str):
551552
git_root = execute_cmd_and_get_output(["git", "rev-parse", "--show-toplevel"])
552553
cpu_script = os.path.join(
553554
git_root, "build_tools/benchmarks/set_android_scaling_governor.sh")
554-
adb_push_to_tmp_dir(cpu_script)
555-
adb_execute(["su", "root", "./set_android_scaling_governor.sh", governor])
555+
android_path = adb_push_to_tmp_dir(cpu_script)
556+
adb_execute(["su", "root", android_path, governor])
557+
558+
559+
def set_gpu_frequency_scaling_policy(policy: str):
560+
git_root = execute_cmd_and_get_output(["git", "rev-parse", "--show-toplevel"])
561+
device_model = get_android_device_model()
562+
if device_model == "Pixel-6":
563+
gpu_script = os.path.join(
564+
git_root, "build_tools/benchmarks/set_pixel6_gpu_scaling_policy.sh")
565+
else:
566+
raise RuntimeError(
567+
f"Unsupported device '{device_model}' for setting GPU scaling policy")
568+
android_path = adb_push_to_tmp_dir(gpu_script)
569+
adb_execute(["su", "root", android_path, policy])
556570

557571

558572
def parse_arguments():
@@ -617,6 +631,10 @@ def check_exe_path(path):
617631
"--pin_cpu_freq",
618632
action="store_true",
619633
help="Pin CPU frequency for all cores to the maximum. Requires root")
634+
parser.add_argument("--pin-gpu-freq",
635+
"--pin_gpu_freq",
636+
action="store_true",
637+
help="Pin GPU frequency to the maximum. Requires root")
620638
parser.add_argument(
621639
"--keep_going",
622640
"--keep-going",
@@ -658,8 +676,11 @@ def main(args):
658676
"need to update the map")
659677

660678
if args.pin_cpu_freq:
661-
set_frequency_scaling_governor("performance")
662-
atexit.register(set_frequency_scaling_governor, "schedutil")
679+
set_cpu_frequency_scaling_governor("performance")
680+
atexit.register(set_cpu_frequency_scaling_governor, "schedutil")
681+
if args.pin_gpu_freq:
682+
set_gpu_frequency_scaling_policy("always_on")
683+
atexit.register(set_gpu_frequency_scaling_policy, "coarse_demand")
663684

664685
previous_benchmarks = None
665686
previous_captures = None

‎build_tools/benchmarks/set_android_scaling_governor.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ done
4040

4141
echo "CPU info (after changing governor):"
4242
echo 'cpu\tgovernor\tcur\tmin\tmax'
43+
echo "------------------------------------------------"
4344
for i in `cat /sys/devices/system/cpu/present | tr '-' ' ' | xargs seq`; do \
4445
echo "cpu${i}" | paste \
4546
- \
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
3+
# Copyright 2021 The IREE Authors
4+
#
5+
# Licensed under the Apache License v2.0 with LLVM Exceptions.
6+
# See https://llvm.org/LICENSE.txt for license information.
7+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
9+
# Runs on a Pixel 6 device itself to set the GPU frequency scaling policy.
10+
11+
################################### WARNING ####################################
12+
# This will overheat the phone if it's not on a cooling plate, resulting in #
13+
# thermal throttling. To prevent anything catching on fire, the actual GPU #
14+
# frequencies will be throttled to below the maximum, skewing your results. #
15+
################################################################################
16+
17+
set -euo pipefail
18+
19+
POLICY="${1:-always_on}"
20+
21+
readonly MALI_GPU_PATH="/sys/devices/platform/1c500000.mali"
22+
23+
echo "GPU info (before changing power policy):"
24+
echo 'policy\t\t\t\t\tcur\tmin\tmax'
25+
echo "--------------------------------------------------------------"
26+
paste \
27+
"${MALI_GPU_PATH}/power_policy" \
28+
"${MALI_GPU_PATH}/cur_freq" \
29+
"${MALI_GPU_PATH}/min_freq" \
30+
"${MALI_GPU_PATH}/max_freq"
31+
32+
echo "Setting GPU power policy to ${POLICY}"
33+
34+
if [[ "$POLICY" == "always_on" ]]; then
35+
echo "always_on" > "${MALI_GPU_PATH}/power_policy"
36+
cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_max_freq"
37+
cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_min_freq"
38+
elif [[ "$POLICY" == "coarse_demand" ]]; then
39+
echo "coarse_demand" > "${MALI_GPU_PATH}/power_policy"
40+
cat "${MALI_GPU_PATH}/max_freq" > "${MALI_GPU_PATH}/scaling_max_freq"
41+
cat "${MALI_GPU_PATH}/min_freq" > "${MALI_GPU_PATH}/scaling_min_freq"
42+
else
43+
echo "Unknown power policy: ${POLICY}"
44+
exit 1
45+
fi
46+
47+
echo "GPU info (after changing power policy):"
48+
echo 'policy\t\t\t\t\tcur\tmin\tmax'
49+
echo "--------------------------------------------------------------"
50+
paste \
51+
"${MALI_GPU_PATH}/power_policy" \
52+
"${MALI_GPU_PATH}/cur_freq" \
53+
"${MALI_GPU_PATH}/min_freq" \
54+
"${MALI_GPU_PATH}/max_freq"

0 commit comments

Comments
 (0)