summaryrefslogtreecommitdiff
path: root/pm/sleep.d/94cpufreq
blob: 56648b02ffc7f6b21312371d685b1ae9b73fcf6d (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
#!/bin/sh

. /usr/lib/pm-utils/functions

hibernate_cpufreq()
{
	[ -d /sys/devices/system/cpu/ ] || return 0
	pushd /sys/devices/system/cpu/ >/dev/null 2>&1
	for x in $(ls -1) ; do
		[ -d $x/cpufreq ] || continue
		[ -f $x/cpufreq/scaling_governor ] || continue

		savestate ${x}_governor $(cat $x/cpufreq/scaling_governor)
	done
	for x in $(ls -1) ; do
		[ -d $x/cpufreq ] || continue
		[ -f $x/cpufreq/scaling_governor ] || continue

		gov="$TEMPORARY_CPUFREQ_GOVERNOR"
		grep -q "$GOVERNOR" $x/cpufreq/scaling_available_governors \
			|| gov="userspace"
		sh -c "echo \"$gov\" > $x/cpufreq/scaling_governor"
	done
	popd >/dev/null 2>&1
}

thaw_cpufreq()
{
	x=0
	while :; do
		gov=$(restorestate $(echo cpu${x}_governor))
		[ -z "$gov" ] && break

		sh -c "echo \"$gov\" > /sys/devices/system/cpu/cpu$x/cpufreq/scaling_governor"
		unset gov
		x=$(($x + 1))
	done
	unset x
}

case "$1" in
	suspend|hibernate)
		hibernate_cpufreq
		;;
	resume|thaw)
		thaw_cpufreq
		;;
	*)
		;;
esac

exit $?