xref: /OK3568_Linux_fs/kernel/tools/power/cpupower/bench/cpufreq-bench_script.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/bash
2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-or-later
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun# Author/Copyright(c): 2009, Thomas Renninger <trenn@suse.de>, Novell Inc.
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun# Ondemand up_threshold and sampling rate test script for cpufreq-bench
8*4882a593Smuzhiyun# mircobenchmark.
9*4882a593Smuzhiyun# Modify the general variables at the top or extend or copy out parts
10*4882a593Smuzhiyun# if you want to test other things
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun# Default with latest kernels is 95, before micro account patches
14*4882a593Smuzhiyun# it was 80, cmp. with git commit 808009131046b62ac434dbc796
15*4882a593SmuzhiyunUP_THRESHOLD="60 80 95"
16*4882a593Smuzhiyun# Depending on the kernel and the HW sampling rate could be restricted
17*4882a593Smuzhiyun# and cannot be set that low...
18*4882a593Smuzhiyun# E.g. before git commit cef9615a853ebc4972084f7 one could only set
19*4882a593Smuzhiyun# min sampling rate of 80000 if CONFIG_HZ=250
20*4882a593SmuzhiyunSAMPLING_RATE="20000 80000"
21*4882a593Smuzhiyun
22*4882a593Smuzhiyunfunction measure()
23*4882a593Smuzhiyun{
24*4882a593Smuzhiyun    local -i up_threshold_set
25*4882a593Smuzhiyun    local -i sampling_rate_set
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun    for up_threshold in $UP_THRESHOLD;do
28*4882a593Smuzhiyun	for sampling_rate in $SAMPLING_RATE;do
29*4882a593Smuzhiyun	    # Set values in sysfs
30*4882a593Smuzhiyun	    echo $up_threshold >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold
31*4882a593Smuzhiyun	    echo $sampling_rate >/sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
32*4882a593Smuzhiyun	    up_threshold_set=$(cat /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold)
33*4882a593Smuzhiyun	    sampling_rate_set=$(cat /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate)
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun	    # Verify set values in sysfs
36*4882a593Smuzhiyun	    if [ ${up_threshold_set} -eq ${up_threshold} ];then
37*4882a593Smuzhiyun		echo "up_threshold: $up_threshold, set in sysfs: ${up_threshold_set}"
38*4882a593Smuzhiyun	    else
39*4882a593Smuzhiyun		echo "WARNING: Tried to set up_threshold: $up_threshold, set in sysfs: ${up_threshold_set}"
40*4882a593Smuzhiyun	    fi
41*4882a593Smuzhiyun	    if [ ${sampling_rate_set} -eq ${sampling_rate} ];then
42*4882a593Smuzhiyun		echo "sampling_rate: $sampling_rate, set in sysfs: ${sampling_rate_set}"
43*4882a593Smuzhiyun	    else
44*4882a593Smuzhiyun		echo "WARNING: Tried to set sampling_rate: $sampling_rate, set in sysfs: ${sampling_rate_set}"
45*4882a593Smuzhiyun	    fi
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun	    # Benchmark
48*4882a593Smuzhiyun	    cpufreq-bench -o /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}
49*4882a593Smuzhiyun	done
50*4882a593Smuzhiyun    done
51*4882a593Smuzhiyun}
52*4882a593Smuzhiyun
53*4882a593Smuzhiyunfunction create_plots()
54*4882a593Smuzhiyun{
55*4882a593Smuzhiyun    local command
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun    for up_threshold in $UP_THRESHOLD;do
58*4882a593Smuzhiyun	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 %\""
59*4882a593Smuzhiyun	for sampling_rate in $SAMPLING_RATE;do
60*4882a593Smuzhiyun	    command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"sampling_rate = $sampling_rate\""
61*4882a593Smuzhiyun	done
62*4882a593Smuzhiyun	echo $command
63*4882a593Smuzhiyun	eval "$command"
64*4882a593Smuzhiyun	echo
65*4882a593Smuzhiyun    done
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun    for sampling_rate in $SAMPLING_RATE;do
68*4882a593Smuzhiyun	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\""
69*4882a593Smuzhiyun	for up_threshold in $UP_THRESHOLD;do
70*4882a593Smuzhiyun	    command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"up_threshold = $up_threshold\""
71*4882a593Smuzhiyun	done
72*4882a593Smuzhiyun	echo $command
73*4882a593Smuzhiyun	eval "$command"
74*4882a593Smuzhiyun	echo
75*4882a593Smuzhiyun    done
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun    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\""
78*4882a593Smuzhiyun    for sampling_rate in $SAMPLING_RATE;do
79*4882a593Smuzhiyun	for up_threshold in $UP_THRESHOLD;do
80*4882a593Smuzhiyun	    command="${command} /var/log/cpufreq-bench/up_threshold_${up_threshold}_sampling_rate_${sampling_rate}/* \"up_threshold = $up_threshold - sampling_rate = $sampling_rate\""
81*4882a593Smuzhiyun	done
82*4882a593Smuzhiyun    done
83*4882a593Smuzhiyun    echo "$command"
84*4882a593Smuzhiyun    eval "$command"
85*4882a593Smuzhiyun}
86*4882a593Smuzhiyun
87*4882a593Smuzhiyunmeasure
88*4882a593Smuzhiyuncreate_plots
89