File: rcpowersaved.redhat

package info (click to toggle)
powersave 0.14.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,764 kB
  • ctags: 999
  • sloc: sh: 11,357; cpp: 8,103; ansic: 2,631; makefile: 388
file content (248 lines) | stat: -rwxr-xr-x 8,354 bytes parent folder | download | duplicates (2)
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
#!/bin/bash
###########################################################################
#                                                                         #
#                         Powersave Daemon                                #
#                                                                         #
#          Copyright (C) 2004,2005 SUSE Linux Products GmbH               #
#                                                                         #
#               Author(s): Holger Macht <hmacht@suse.de>                  #
#                                                                         #
# 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 you   #
# 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 St, Fifth Floor, Boston, MA 02110-1301 USA                  #
#                                                                         #
###########################################################################
#
# powersaved:   Powersave daemon
#
# chkconfig: 345 99 04
# description:  This is a daemon for powermanagement. Powersaved support \
#               trigger suspend2disk/ram and standby. It support cpufreq \
#               scaling and many more functions to save power.
#
# processname: powersaved
# pidfile: /var/run/powersaved.pid
#

# Check for missing binaries (stale symlinks should not happen)
powersaved_BIN=/usr/sbin/powersaved
powersave_BIN=/usr/bin/powersave
ACPID_BIN=/usr/sbin/acpid
# this is the default set of acpi modules loaded if nothing is configured
DEFAULT_ACPI_MODULES="ac battery button fan processor thermal"

test -x $powersaved_BIN || exit 5
# Check for existence of needed config file and read it

CONFIG=/etc/powersave

test -r $CONFIG || exit 6
. $CONFIG/common
. $CONFIG/cpufreq
. $CONFIG/thermal
if test -e /etc/sysconfig/security; then
 . /etc/sysconfig/security
fi

LOGGER="/usr/bin/logger -t rcpowersaved"

# source functions
. /etc/init.d/functions


OPTS=""
SYSFS_PATH="/sys/devices/system/cpu/cpu0/cpufreq"

function load_governors()
{
    if [ ! -r $SYSFS_PATH ];then
	$LOGGER Cannot load cpufreq governors - No cpufreq driver available
	return 1
    fi
    read govs < $SYSFS_PATH/scaling_available_governors
    case "$govs" in
	*powersave*) 
	    ;;
	*) 
	    modprobe -q cpufreq_powersave >/dev/null 2>&1
	    [ $? != 0 ] && $LOGGER powersave cpufreq governor could not be loaded
	    ;;
    esac
    case "$govs" in
	*performance*) 
	    ;;
	*) 
	    modprobe -q cpufreq_performance >/dev/null 2>&1
	    [ $? != 0 ] && $LOGGER perfromance cpufreq governor could not be loaded
	    ;;
    esac
    case "$govs" in
	*userspace*) 
	    ;;
	*) 
	    modprobe -q cpufreq_userspace >/dev/null 2>&1
	    [ $? != 0 ] && $LOGGER userspace cpufreq governor could not be loaded
	    ;;
    esac
    case "$govs" in
	*ondemand*)
	    ;;
	*) 
	    modprobe -q cpufreq_ondemand >/dev/null 2>&1
	    [ $? != 0 ] && $LOGGER ondemand cpufreq governor could not be loaded
	    ;;
    esac
    return 0
}

start() {
		checkpid $powersaved_BIN
		RETVAL=$?
		if [ $RETVAL = 0 ]; then
		    echo -n "daemon already running"
		    echo 
		    return $RETVAL;
		elif [ -e /var/run/powersaved.pid ];then 
		    rm -f  /var/run/powersaved.pid&> /dev/null
		fi;
		checkpid "cpufreqd" &>/dev/null
		RETVAL=$?
		if [ $RETVAL = 0 ]; then
		    echo -n "cpufreqd already running, stop it first and restart service"
		    echo
		    return $RETVAL
		fi

		ACPI_APM=`$powersave_BIN --apm-acpi`
		if [ "$ACPI_APM" = "ACPI" ]; then
	        # set thermal polling frequency
	        # this should be managed by the daemon later
		    if [ "$THERMAL_POLLING_FREQUENCY" != "0" ];then
			[ -z "$THERMAL_POLLING_FREQUENCY" ] && THERMAL_POLLING_FREQUENCY=2
			for x in /proc/acpi/thermal_zone/*; do
			    [ -w $x/polling_frequency ] && echo "$THERMAL_POLLING_FREQUENCY" >$x/polling_frequency
			done
		    fi

		    ACCESS_PROC_EVENTS=" (accessing ACPI events over acpid) "
		    ACPI_EVENT_FILE="/var/run/acpid.socket"

		    pidof $ACPID_BIN >/dev/null
		    ACPID_NOT_RUNNING=$?
		    # if acpid is not there we need access to /proc/acpi/event
		    if [ $ACPID_NOT_RUNNING = 1 ];then
			$LOGGER "WARN: Service powersaved skipped. You have to start acpid before powersaved"
			echo -n "###############################################
# ACPI system but acpid not running.          #
# Start acpid first, then restart powersaved! #
###############################################"
			return $ACPID_NOT_RUNNING
		    fi
		elif [ "$ACPI_APM" = "APM" ]; then
		    # check whether apmd is already running
		    checkpid "apmd" &>/dev/null
		    RETVAL=$?
		    if [ $RETVAL = 0 ];then
			echo -n "APM daemon is already running, stop it first and restart service"
			echo
			return $RETVAL
		    fi
		    echo -n "This machine supports APM "
		
		#### when neither APM nor ACPI is found, do still start the powersave daemon
        #### we still provide suspend to disk and possibly cpufreq feature
        #### this is always the case on ppc workstations
#		else
#		    $LOGGER "INFO: Your system does neither support ACPI nor APM. \
#the powersave service does not provide any features for this machine, therefore the service is skipped."
#		    rc_status -s
		fi 

		CPUFREQ_MODULES="speedstep_centrino powernow_k8 powernow_k7 powernow_k6 longrun longhaul acpi speedstep_ich"
		CPUFREQ_MODULES_GREP="^speedstep_centrino\|^speedstep_ich\|^powernow_k8\|^powernow_k7\|^powernow_k6\|^longrun\|^longhaul\|^acpi"

		###### load CPUFREQ modules############
		# module specfied in sysconfig.cpufreq?
		# also check whether /sys/.../cpufreq already exists This might
		# happen if modules are already loaded or compiled into kernel 
                # (default on ppc)
		if [ "$CPUFREQD_MODULE" != "off" ] && [ ! -d /sys/devices/system/cpu/cpu0/cpufreq ]; then
			# test for already loaded modules
			ALREADY_LOADED_MODS=`grep $CPUFREQ_MODULES_GREP /proc/modules`
			if [ "$CPUFREQD_MODULE" ]; then
				modprobe -q $CPUFREQD_MODULE $CPUFREQD_MODULE_OPTS &>/dev/null
				RETVAL=$?
			# try to load one of the modules we know
			elif [ -z "$ALREADY_LOADED_MODS" ] ; then 
				for MODULE in $CPUFREQ_MODULES; do
					modprobe $MODULE &>/dev/null
					RETVAL=$?
					[ "$RETVAL" = 0 ] && break
				done
				# skip if no module could be loaded!
				if [ "$RETVAL" != 0 ]; then
					$LOGGER "CPU frequency scaling is not supported by your processor."
					$LOGGER "enter 'CPUFREQD_MODULE=off' in $CONFIG/cpufreq to avoid this warning."
				else
					$LOGGER "enter '$MODULE' into CPUFREQD_MODULE in $CONFIG/cpufreq."
					$LOGGER "this will speed up starting powersaved and avoid unnecessary warnings in syslog."
				fi
			fi
			# sleeping should not be necessary, all is processed sequential
                        # usleep 10000
		fi

		# see function above 
                # -> load powersave,performance,userspace and ondemand governor
		[ "$CPUFREQD_MODULE" != "off" ] && load_governors

		###### load CPUFREQ modules############
		echo -ne "Starting powersaved $ACCESS_PROC_EVENTS"
		OPTS="$OPTS -v ${DEBUG:-3}"
		daemon $powersaved_BIN -d ${ACPI_EVENT_FILE:+-f "$ACPI_EVENT_FILE"} $OPTS
		RETVAL=$?
		echo 
		return $RETVAL
}

stop() {
    echo -n "Shutting down powersaved "
    killproc $powersaved_BIN
    RETVAL=$?
    echo
    return $RETVAL
}

case "$1" in
        start)
	        start
		;;
	stop)   
	        stop
		;;
	restart)
		stop
		start
		;;
	status)
		status $powersaved_BIN
		RETVAL=$?
		;;
	*)
		echo "Usage: $0" \
		     "{start|stop|status|}"
		exit 1
		;;
esac

exit $RETVAL