Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # PM-QA validation test suite for the power management on ARM |
| 4 | # |
| 5 | # Copyright (C) 2011, Linaro Limited. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or |
| 8 | # modify it under the terms of the GNU General Public License |
| 9 | # as published by the Free Software Foundation; either version 2 |
| 10 | # of the License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program; if not, write to the Free Software |
| 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | # |
| 21 | # Contributors: |
| 22 | # Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation) |
| 23 | # - initial API and implementation |
| 24 | # |
| 25 | |
Daniel Lezcano | 65b8b4b | 2011-08-03 09:58:11 +0200 | [diff] [blame^] | 26 | # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#cpufreq_06 |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 27 | |
| 28 | source ../include/functions.sh |
| 29 | |
| 30 | CPUCYCLE=../utils/cpucycle |
| 31 | |
| 32 | compute_freq_ratio() { |
| 33 | |
| 34 | local cpu=$1 |
| 35 | local freq=$2 |
| 36 | |
| 37 | set_frequency $cpu $freq |
| 38 | |
| 39 | result=$($CPUCYCLE $cpu) |
| 40 | if [ $? != 0 ]; then |
| 41 | return 1 |
| 42 | fi |
| 43 | |
| 44 | results[$index]=$(echo "scale=3;($result / $freq)" | bc -l) |
| 45 | index=$((index + 1)) |
| 46 | } |
| 47 | |
| 48 | compute_freq_ratio_sum() { |
| 49 | |
| 50 | res=${results[$index]} |
| 51 | sum=$(echo "($sum + $res)" | bc -l) |
| 52 | index=$((index + 1)) |
| 53 | |
| 54 | } |
| 55 | |
| 56 | __check_freq_deviation() { |
| 57 | |
| 58 | res=${results[$index]} |
| 59 | |
| 60 | # compute deviation |
| 61 | dev=$(echo "scale=3;((( $res - $avg ) / $avg) * 100 )" | bc -l) |
| 62 | |
| 63 | # change to absolute |
| 64 | dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}') |
| 65 | |
| 66 | index=$((index + 1)) |
| 67 | |
| 68 | res=$(echo "($dev > 5.0)" | bc -l) |
| 69 | if [ "$res" = "1" ]; then |
| 70 | return 1 |
| 71 | fi |
| 72 | |
| 73 | return 0 |
| 74 | } |
| 75 | |
| 76 | check_freq_deviation() { |
| 77 | |
| 78 | local cpu=$1 |
| 79 | local freq=$2 |
| 80 | |
| 81 | check "deviation for frequency $(frequnit $freq)" __check_freq_deviation |
| 82 | |
| 83 | } |
| 84 | |
| 85 | check_deviation() { |
| 86 | |
| 87 | local cpu=$1 |
| 88 | |
| 89 | set_governor $cpu userspace |
| 90 | |
| 91 | for_each_frequency $cpu compute_freq_ratio |
| 92 | |
| 93 | index=0 |
| 94 | sum=0 |
| 95 | |
| 96 | for_each_frequency $cpu compute_freq_ratio_sum |
| 97 | |
| 98 | avg=$(echo "scale=3;($sum / $index)" | bc -l) |
| 99 | |
| 100 | index=0 |
| 101 | for_each_frequency $cpu check_freq_deviation |
| 102 | } |
| 103 | |
| 104 | if [ $(id -u) != 0 ]; then |
| 105 | log_skip "run as non-root" |
| 106 | exit 0 |
| 107 | fi |
| 108 | |
| 109 | save_governors |
| 110 | save_frequencies |
| 111 | |
| 112 | trap "restore_frequencies; restore_governors; sigtrap" SIGHUP SIGINT SIGTERM |
| 113 | |
| 114 | for_each_cpu check_deviation |
| 115 | |
| 116 | restore_frequencies |
| 117 | restore_governors |