summaryrefslogtreecommitdiff
blob: 3cfdd51931019d22121b2a9c33c67c2d470348a1 (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
#!/sbin/runscript
#
# Based on the Debian init script written by Celso Gonzalez <celso@bulma.net>,
# and on the cpufreqd Gentoo init script written by Robert Gogolok <robertgogolok@web.de>.
# 

DAEMON=/usr/sbin/cpudynd
PIDFILE=/var/run/cpudynd.pid

depend() {
	need localmount
}

checkconfig() {
    local CPUFREQ_24="/proc/cpufreq"
    local CPUFREQ_25="/sys/devices/system/cpu/cpu0/cpufreq /sysfs/devices/system/cpu/cpu0/cpufreq"
    local CPUFREQ_ACPI="/proc/acpi/processor/CPU0/throttling"
    local CPUFREQ_FILES="${CPUFREQ_24} ${CPUFREQ_25} ${CPUFREQ_ACPI}"
    local CPUFREQ_FILE=""
    for i in ${CPUFREQ_FILES}; do [ -e ${i} ] && CPUFREQ_FILE="${i}" && break ; done
    if [ -z "${CPUFREQ_FILE}" ]; then
        eerror "Neither CPUFreq nor ACPI throttling support were found"
		return 1
    fi
    if [ "${CPUFREQ_FILE}" = "${CPUFREQ_ACPI}" ]; then
        # see if the file says we are supported or not
        grep 'not supported' ${CPUFREQ_ACPI} 2>&1 >/dev/null
        retval="$?"
        if [ $retval -eq 0 ]; then
		    eerror "ACPI throttling support found, but hardware doesn't support it"
		    return 1
        fi
        # now check that we can write to the file
        local acpistate=`grep 'active state' ${CPUFREQ_ACPI} | cut -dT -f2-`
        echo $acpistate > ${CPUFREQ_ACPI}
        retval="$?"
        if [ ! $retval -eq 0 ]; then
		    eerror "Writing to ACPI throttling file failed"
		    return 1
        fi
    fi
}


start() {
    local CPUDYN_OPTS="-d"
	if [ -n "$INTERVAL" ]; then CPUDYN_OPTS="$CPUDYN_OPTS -i $INTERVAL"; fi
	if [ -n "$CPU_UP" -a -n "$CPU_DOWN" ]; then CPUDYN_OPTS="$CPUDYN_OPTS -p $CPU_UP $CPU_DOWN"; fi
	if [ -n "$THROTTLING_LOW" ]; then CPUDYN_OPTS="$CPUDYN_OPTS -l $THROTTLING_LOW"; fi
	if [ -n "$TIMEOUT" ]; then CPUDYN_OPTS="$CPUDYN_OPTS -t $TIMEOUT"; fi
	if [ -n "$DISKS" ]; then CPUDYN_OPTS="$CPUDYN_OPTS -h $DISKS"; fi
	
	ebegin "Starting cpudynd"
	if checkconfig; then
		start-stop-daemon --start --quiet --pidfile $PIDFILE \
			--background --make-pidfile --exec $DAEMON -- $CPUDYN_OPTS
		eend $?
	else
		eend 1
	fi
}

stop() {
	ebegin "Stopping cpudynd"
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
		--exec $DAEMON && rm -f $PIDFILE
	eend $?
}