aboutsummaryrefslogtreecommitdiff
path: root/include/thermal_functions.sh
blob: a51240ba34abd1c18cc13d1958ce22846ff2f9da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#!/bin/bash
#
# PM-QA validation test suite for the power management on Linux
#
# Copyright (C) 2011, Linaro Limited.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
# Contributors:
#     Amit Daniel <amit.kachhap@linaro.org> (Samsung Electronics)
#       - initial API and implementation
#

THERMAL_PATH="/sys/devices/virtual/thermal"
MAX_ZONE=0-12
MAX_CDEV=0-50
ALL_ZONE=
ALL_CDEV=

check_valid_temp() {
    local file=$1
    local zone_name=$2
    local dir=$THERMAL_PATH/$2

    local temp_file=$dir/$1
    local func=cat
    shift 2;

    local temp_val=$($func $temp_file)
    local descr="'$zone_name'/'$file' ='$temp_val'"
    log_begin "checking $descr"

    if [ $temp_val -gt 0 ]; then
        log_end "Ok"
        return 0
    fi

    log_end "Err"

    return 1
}

for_each_thermal_zone() {

    local func=$1
    shift 1

    zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")

    ALL_ZONE=$zone
    for zone in $zones; do
	INC=0
	$func $zone $@
    done

    return 0
}

get_total_trip_point_of_zone() {

    local zone_path=$THERMAL_PATH/$1
    local count=0
    shift 1
    trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp")
    for trip in $trips; do
	count=$((count + 1))
    done
    return $count
}

for_each_trip_point_of_zone() {

    local zone_path=$THERMAL_PATH/$1
    local count=0
    local func=$2
    local zone_name=$1
    shift 2
    trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp")
    for trip in $trips; do
	$func $zone_name $count
	count=$((count + 1))
    done
    return 0
}

for_each_binding_of_zone() {

    local zone_path=$THERMAL_PATH/$1
    local count=0
    local func=$2
    local zone_name=$1
    shift 2
    trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point")
    for trip in $trips; do
	$func $zone_name $count
	count=$((count + 1))
    done

    return 0

}

check_valid_binding() {
    local trip_point=$1
    local zone_name=$2
    local dirpath=$THERMAL_PATH/$2
    local temp_file=$2/$1
    local trip_point_val=$(cat $dirpath/$trip_point)
    get_total_trip_point_of_zone $zone_name
    local trip_point_max=$?
    local descr="'$temp_file' valid binding"
    shift 2

    log_begin "checking $descr"
    if [ $trip_point_val -ge $trip_point_max ]; then
        log_end "Err"
        return 1
    fi

    log_end "Ok"
    return 0
}

validate_trip_bindings() {
    local zone_name=$1
    local bind_no=$2
    local dirpath=$THERMAL_PATH/$1
    local trip_point=cdev$2_trip_point
    shift 2

    check_file $trip_point $dirpath || return 1
    check_valid_binding $trip_point $zone_name || return 1
}

validate_trip_level() {
    local zone_name=$1
    local trip_no=$2
    local dirpath=$THERMAL_PATH/$1
    local trip_temp=trip_point_$2_temp
    local trip_type=trip_point_$2_type
    shift 2

    check_file $trip_temp $dirpath || return 1
    check_file $trip_type $dirpath || return 1
    check_valid_temp $trip_temp $zone_name || return 1
}

for_each_cooling_device() {

    local func=$1
    shift 1

    devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']")
    if [ "$devices" == "" ]; then
	log_skip "no cooling devices"
	return 0
    fi

    ALL_DEVICE=$devices
    for device in $devices; do
	INC=0
	$func $device $@
    done

    return 0
}
check_scaling_freq() {

    local before_freq_list=$1
    local after_freq_list=$2
    shift 2
    local index=0

    local flag=0
    for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
	if [ $before_freq_list[$index] -ne $afterf_req_list[$index] ] ; then
	    flag=1	
	fi
        index=$((index + 1)) 
    done
    return $flag
}

store_scaling_maxfreq() {
    scale_freq=
    local index=0

    for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
	scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq)
        index=$((index + 1))
    done
    return 0
}

get_trip_id() {

    local trip_name=$1
    shift 1

    local id1=$(echo $trip_name|cut -c12)
    local id2=$(echo $trip_name|cut -c13)
    if [ $id2 != "_" ]; then
	id1=$(($id2 + 10*$id1))
    fi
    return $id1
}

disable_all_thermal_zones() {

    mode_list=
    local index=0

    local th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
    for zone in $th_zones; do
	mode_list[$index]=$(cat $THERMAL_PATH/$zone/mode)
        index=$((index + 1))
	echo -n "disabled" > $THERMAL_PATH/$zone/mode
    done
    return 0
}

enable_all_thermal_zones() {

    local index=0

    local th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
    for zone in $th_zones; do
	echo $mode_list[$index] > $THERMAL_PATH/$zone/mode
        index=$((index + 1))
    done
    return 0
}

GPU_HEAT_BIN=/usr/bin/glmark2
gpu_pid=0

start_glmark2() {
    if [ -n "$ANDROID" ]; then
        am start org.linaro.glmark2/.Glmark2Activity
        return
    fi

    if [ -x $GPU_HEAT_BIN ]; then
        $GPU_HEAT_BIN &
        gpu_pid=$(pidof $GPU_HEAT_BIN)
        # Starting X application from serial console needs this
        if [ -z "$gpu_pid" ]; then
            cp /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.bk
            echo "autologin-user=root" >> /etc/lightdm/lightdm.conf
            export DISPLAY=localhost:0.0
            restart lightdm
            sleep 5
            mv /etc/lightdm/lightdm.conf.bk /etc/lightdm/lightdm.conf
            $GPU_HEAT_BIN &
            gpu_pid=$(pidof $GPU_HEAT_BIN)
        fi
        test -z "$gpu_pid" && cpu_pid=0
        echo "start gpu heat binary $gpu_pid"
    else
        echo "glmark2 not found." 1>&2
    fi
}

kill_glmark2() {
    if [ -n "$ANDROID" ]; then
        am kill org.linaro.glmark2
        return
    fi

    if [ "$gpu_pid" -ne 0 ]; then
	kill -9 $gpu_pid
    fi
}