18c2ecf20Sopenharmony_ci#!/bin/bash
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci# Author/Copyright(c): 2009, Thomas Renninger <trenn@suse.de>, Novell Inc.
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci# Ondemand up_threshold and sampling rate test script for cpufreq-bench
88c2ecf20Sopenharmony_ci# mircobenchmark.
98c2ecf20Sopenharmony_ci# Modify the general variables at the top or extend or copy out parts
108c2ecf20Sopenharmony_ci# if you want to test other things
118c2ecf20Sopenharmony_ci#
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci# Default with latest kernels is 95, before micro account patches
148c2ecf20Sopenharmony_ci# it was 80, cmp. with git commit 808009131046b62ac434dbc796
158c2ecf20Sopenharmony_ciUP_THRESHOLD="60 80 95"
168c2ecf20Sopenharmony_ci# Depending on the kernel and the HW sampling rate could be restricted
178c2ecf20Sopenharmony_ci# and cannot be set that low...
188c2ecf20Sopenharmony_ci# E.g. before git commit cef9615a853ebc4972084f7 one could only set
198c2ecf20Sopenharmony_ci# min sampling rate of 80000 if CONFIG_HZ=250
208c2ecf20Sopenharmony_ciSAMPLING_RATE="20000 80000"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cifunction measure()
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci    local -i up_threshold_set
258c2ecf20Sopenharmony_ci    local -i sampling_rate_set
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci    for up_threshold in $UP_THRESHOLD;do
288c2ecf20Sopenharmony_ci	for sampling_rate in $SAMPLING_RATE;do
298c2ecf20Sopenharmony_ci	    # Set values in sysfs
308c2ecf20Sopenharmony_ci	    echo $up_threshold >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
318c2ecf20Sopenharmony_ci	    echo $sampling_rate >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
328c2ecf20Sopenharmony_ci	    up_threshold_set=$(cat /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold)
338c2ecf20Sopenharmony_ci	    sampling_rate_set=$(cat /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	    # Verify set values in sysfs
368c2ecf20Sopenharmony_ci	    if [ ${up_threshold_set} -eq ${up_threshold} ];then
378c2ecf20Sopenharmony_ci		echo "up_threshold: $up_threshold, set in sysfs: ${up_threshold_set}"
388c2ecf20Sopenharmony_ci	    else
398c2ecf20Sopenharmony_ci		echo "WARNING: Tried to set up_threshold: $up_threshold, set in sysfs: ${up_threshold_set}"
408c2ecf20Sopenharmony_ci	    fi
418c2ecf20Sopenharmony_ci	    if [ ${sampling_rate_set} -eq ${sampling_rate} ];then
428c2ecf20Sopenharmony_ci		echo "sampling_rate: $sampling_rate, set in sysfs: ${sampling_rate_set}"
438c2ecf20Sopenharmony_ci	    else
448c2ecf20Sopenharmony_ci		echo "WARNING: Tried to set sampling_rate: $sampling_rate, set in sysfs: ${sampling_rate_set}"
458c2ecf20Sopenharmony_ci	    fi
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	    # Benchmark
488c2ecf20Sopenharmony_ci	    cpufreq-bench -o /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}
498c2ecf20Sopenharmony_ci	done
508c2ecf20Sopenharmony_ci    done
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cifunction create_plots()
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci    local command
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci    for up_threshold in $UP_THRESHOLD;do
588c2ecf20Sopenharmony_ci	command="cpufreq-bench_plot.sh -o \"sampling_rate_${SAMPLING_RATE}_up_threshold_${up_threshold}\" -t \"Ondemand sampling_rate: ${SAMPLING_RATE} comparison - Up_threshold: $up_threshold %\""
598c2ecf20Sopenharmony_ci	for sampling_rate in $SAMPLING_RATE;do
608c2ecf20Sopenharmony_ci	    command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"sampling_rate = $sampling_rate\""
618c2ecf20Sopenharmony_ci	done
628c2ecf20Sopenharmony_ci	echo $command
638c2ecf20Sopenharmony_ci	eval "$command"
648c2ecf20Sopenharmony_ci	echo
658c2ecf20Sopenharmony_ci    done
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci    for sampling_rate in $SAMPLING_RATE;do
688c2ecf20Sopenharmony_ci	command="cpufreq-bench_plot.sh -o \"up_threshold_${UP_THRESHOLD}_sampling_rate_${sampling_rate}\" -t \"Ondemand up_threshold: ${UP_THRESHOLD} % comparison - sampling_rate: $sampling_rate\""
698c2ecf20Sopenharmony_ci	for up_threshold in $UP_THRESHOLD;do
708c2ecf20Sopenharmony_ci	    command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"up_threshold = $up_threshold\""
718c2ecf20Sopenharmony_ci	done
728c2ecf20Sopenharmony_ci	echo $command
738c2ecf20Sopenharmony_ci	eval "$command"
748c2ecf20Sopenharmony_ci	echo
758c2ecf20Sopenharmony_ci    done
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci    command="cpufreq-bench_plot.sh -o \"up_threshold_${UP_THRESHOLD}_sampling_rate_${SAMPLING_RATE}\" -t \"Ondemand up_threshold: ${UP_THRESHOLD} and sampling_rate ${SAMPLING_RATE} comparison\""
788c2ecf20Sopenharmony_ci    for sampling_rate in $SAMPLING_RATE;do
798c2ecf20Sopenharmony_ci	for up_threshold in $UP_THRESHOLD;do
808c2ecf20Sopenharmony_ci	    command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"up_threshold = $up_threshold - sampling_rate = $sampling_rate\""
818c2ecf20Sopenharmony_ci	done
828c2ecf20Sopenharmony_ci    done
838c2ecf20Sopenharmony_ci    echo "$command"
848c2ecf20Sopenharmony_ci    eval "$command"
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cimeasure
888c2ecf20Sopenharmony_cicreate_plots
89