Home | History | Annotate | Download | only in power_management
      1 #! /bin/sh
      2 #
      3 # Copyright (c) International Business Machines  Corp., 2001
      4 # Author: Nageswara R Sastry <nasastry (at] in.ibm.com>
      5 #
      6 # This program is free software;  you can redistribute it and#or modify
      7 # it under the terms of the GNU General Public License as published by
      8 # the Free Software Foundation; either version 2 of the License, or
      9 # (at your option) any later version.
     10 #
     11 # This program is distributed in the hope that it will be useful, but
     12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     13 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14 # for more details.
     15 #
     16 # You should have received a copy of the GNU General Public License
     17 # along with this program;  if not, write to the Free Software Foundation,
     18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19 #
     20 
     21 export TCID="Power_Management03"
     22 export TST_TOTAL=4
     23 
     24 . test.sh
     25 . pm_include.sh
     26 
     27 check_cpufreq_sysfs_files() {
     28 	total_cpus=$(tst_ncpus)
     29 	(( total_cpus-=1 ))
     30 	RC=0
     31 
     32 	for cpu in $(seq 0 "${total_cpus}" )
     33 	do
     34 		cpufiles=$(find /sys/devices/system/cpu/cpu"${cpu}"/cpufreq/ \
     35 			-name "*" -type f -perm /400)
     36 		for files in ${cpufiles}
     37 		do
     38 			cat ${files} >/dev/null 2>&1
     39 			if [ $? -ne 0 ] ; then
     40 				echo "${0}: FAIL: cat ${files}"
     41 				RC=1
     42 			fi
     43 		done
     44 	done
     45 	if [ ${RC} -eq 0 ] ; then
     46 		echo "${0}: PASS: Checking cpu freq sysfs files"
     47 	fi
     48 	return $RC
     49 }
     50 
     51 change_govr() {
     52 	available_govr=$(get_supporting_govr)
     53 
     54 	total_cpus=$(tst_ncpus)
     55 	(( total_cpus-=1 ))
     56 	RC=0
     57 
     58 	for cpu in $(seq 0 "${total_cpus}" )
     59 	do
     60 		for govr in ${available_govr}
     61 		do
     62 			echo ${govr} > \
     63 	/sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_governor
     64 			if [ "$?" -ne "0" ] ; then
     65 				echo "${0}: FAIL: Unable to set" \
     66 					"governor -- ${govr} for cpu${cpu}"
     67 				RC=1
     68 			fi
     69 		done
     70 	done
     71 	if [ ${RC} -eq 0 ] ; then
     72 		echo "${0}: PASS: Changing cpu governors"
     73 	fi
     74 	return $RC
     75 }
     76 
     77 change_freq() {
     78 	available_freq=$(get_supporting_freq)
     79 	available_govr=$(get_supporting_govr)
     80 	RC=0
     81 
     82 	total_cpus=$(tst_ncpus)
     83 	(( total_cpus-=1 ))
     84 
     85 	if ( echo ${available_govr} | grep -i "userspace" \
     86 		>/dev/null 2>&1 ); then
     87 		for cpu in $(seq 0 "${total_cpus}" )
     88 		do
     89 			echo userspace > \
     90 	/sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_governor
     91 			if [ $? -ne 0 ] ; then
     92 				RC=1
     93 			fi
     94 		done
     95 		if [ ${RC} -ne 1 ] ; then
     96 			for cpu in $(seq 0 "${total_cpus}" )
     97 			do
     98 				for freq in ${available_freq}
     99 				do
    100 					echo ${freq} > \
    101 	/sys/devices/system/cpu/cpu${cpu}/cpufreq/scaling_setspeed
    102 					if [ "$?" -ne "0" ] ; then
    103 						echo "${0}: FAIL: Unable" \
    104 							"to set frequency -- ${freq} for cpu${cpu}"
    105 						RC=1
    106 					fi
    107 				done
    108 			done
    109 		fi
    110 	fi
    111 	if [ ${RC} -eq 0 ] ; then
    112 		echo "${0}: PASS: Changing cpu frequencies"
    113 	fi
    114 	return $RC
    115 }
    116 
    117 pwkm_load_unload() {
    118 	RC=0
    119 	loaded_governor=`cat \
    120 		/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
    121 	for module in `modprobe -l | grep cpufreq_ | \
    122 		cut -f8 -d"/" | cut -f1 -d"."`
    123 	do
    124 		#echo -n "Loading $module ... "
    125 		if [ $module != "cpufreq_$loaded_governor" ]; then
    126 			modprobe $module >/dev/null
    127 			if [ $? -ne 0 ] ; then
    128 				echo "${0}: FAIL: Loading of module $module" \
    129 					"or check whether you compiled as module or not"
    130 				RC=1
    131 			fi
    132 		fi
    133 	done
    134 	for module in `modprobe -l | grep cpufreq_ | \
    135 		cut -f8 -d"/" | cut -f1 -d"."`
    136 		do
    137 		#echo -n "Unloading $module ... "
    138 		if [ $module != "cpufreq_$loaded_governor" ]; then
    139 			modprobe -r $module >/dev/null
    140 			if [ $? -ne 0 ] ; then
    141 				echo "${0}: FAIL: Loading of module $module" \
    142 					"or check whether you compiled as module or not"
    143 				RC=1
    144 			fi
    145 		fi
    146 	done
    147 	return $RC
    148 }
    149 
    150 # Checking test environment
    151 check_kervel_arch
    152 
    153 # Checking cpufreq sysfs interface files
    154 if [ ! -d /sys/devices/system/cpu/cpu0/cpufreq ] ; then
    155 	tst_brkm TCONF "Required kernel configuration for CPU_FREQ NOT set"
    156 fi
    157 
    158 if check_cpufreq_sysfs_files ; then
    159 	tst_resm TPASS "CPUFREQ sysfs tests"
    160 else
    161 	tst_resm TFAIL "CPUFREQ sysfs tests"
    162 fi
    163 
    164 # Changing governors
    165 if change_govr ; then
    166 	tst_resm TPASS "Changing governors"
    167 else
    168 	tst_resm TFAIL "Changing governors"
    169 fi
    170 
    171 # Changing frequencies
    172 if change_freq ; then
    173 	tst_resm TPASS "Changing frequncies"
    174 else
    175     tst_resm TFAIL "Changing frequncies"
    176 fi
    177 
    178 # Loading and Unloading governor related kernel modules
    179 if pwkm_load_unload ; then
    180 	tst_resm TPASS "Loading and Unloading of governor kernel" \
    181 		"modules"
    182 else
    183 	tst_resm TFAIL "Loading and Unloading of governor kernel" \
    184 		"modules got failed"
    185 fi
    186 
    187 tst_exit
    188