[Comm] cpufreq-simple (was: Simply Linux DVD beta)

Michael Shigorin mike на osdn.org.ua
Пт Ноя 4 16:32:31 UTC 2011


On Fri, Nov 04, 2011 at 01:48:56AM +0400, Mikhail Efremov wrote:
> Я сделал простенький пакет cpufreq-simple, он умеет только
> переключать governor при подключении/отключении питания
> (по умолчанию performance/ondemand, можно настроить в
> /etc/sysconfig/cpufreq-simple).

Лучше ondemand/ondemand, он хорошо работает и меньше будет жалоб
на вой пропеллера при работе от розетки.  И если это стационарник
(десктоп или сервер), то тоже хорошо бы попробовать ткнуть
ondemand: вреда за многие годы не видел ни разу -- разве если
ignore_nice_load=1, может быть менее оптимально в некоторых
случаях.

> Просьба заинтересованным протестировать, если не будет проблем
> - включу в Симпли.

Прошёл чуть напильником: (упс, git.alt прилёг будто, прилагаю);
разумеется, стоит включить, в mkimage-profiles обязательно добавлю.
Причём в инитскрипте поправил на старт по умолчанию, чтоб не было
конфузов вида "колориметр работает, исправно лежит в сейфе"...

Спасибо, тёзка!

-- 
 ---- WBR, Michael Shigorin <mike на altlinux.ru>
  ------ Linux.Kiev http://www.linux.kiev.ua/
----------- следующая часть -----------
From 97a0a4d29d6f95930fa43127b5cc23b765ca4016 Mon Sep 17 00:00:00 2001
From: Michael Shigorin <mike на altlinux.org>
Date: Fri, 4 Nov 2011 18:17:25 +0200
Subject: [PATCH 1/2] reworked scripts and defautls a bit

Added:
- "unknown" AC state (defaulting to ondemand governor)
- attempt to load the missing governor module
- libshell use for error reporting

Changed:
- service is on by default: it's pretty safe,
  remove the package if unneeded
- default AC_ON state CPU governor changed to ondemand:
  it is vastly preferred to performance governor in either
  notebook, desktop, or server case regarding power, heat,
  and noise
---
 cpufreq-simple/cpufreq-simple           |   38 +++++++++++++++++++-----------
 cpufreq-simple/cpufreq-simple.init      |   11 ++++-----
 cpufreq-simple/cpufreq-simple.sysconfig |    5 +++-
 3 files changed, 33 insertions(+), 21 deletions(-)
 mode change 100644 => 100755 cpufreq-simple/cpufreq-simple
 mode change 100644 => 100755 cpufreq-simple/cpufreq-simple.sysconfig

diff --git a/cpufreq-simple/cpufreq-simple b/cpufreq-simple/cpufreq-simple
old mode 100644
new mode 100755
index 3bef32d..50931e7
--- a/cpufreq-simple/cpufreq-simple
+++ b/cpufreq-simple/cpufreq-simple
@@ -4,18 +4,25 @@ CPU=
 GOVERNOR_AC_ON=
 GOVERNOR_AC_OFF=
 
+. shell-error
+
 [ -f /etc/sysconfig/cpufreq-simple ] && . /etc/sysconfig/cpufreq-simple
 
 CPUFREQ=/sys/devices/system/cpu/cpu0/cpufreq
+GOVERNORS="$CPUFREQ/scaling_available_governors"
 cmd="${1-}"
 
 get_ac_state()
 {
-	[ -d /proc/acpi/ac_adapter/ ] || return 1
-
-	local state_file="$(find /proc/acpi/ac_adapter/ -name state | head -1)"
-
-	[ -n "$state_file" -a -r "$state_file" ] && sed 's;^state:[[:blank:]]*;;' "$state_file" | head -1
+	local state_file
+	if [ -d /proc/acpi/ac_adapter/ ]; then
+		state_file="$(find /proc/acpi/ac_adapter/ -name state | head -1)"
+		if [ -n "$state_file" -a -r "$state_file" ]; then
+			sed 's;^state:[[:blank:]]*;;' "$state_file" | head -1
+		fi
+	else
+		echo "unknown"
+	fi
 }
 
 init_command()
@@ -26,27 +33,28 @@ init_command()
 
 set_cpufreq()
 {
+	# getopt seems overkill right now
+	if [ "$1" = "-g" -a -n "$2" ]; then
+		grep -Fq -- "$2" "$GOVERNORS" || modprobe "cpufreq_$2"
+	fi
 	for i in $CPU; do
 		cpufreq-set -c "$i" "$@"
 	done
 }
 
-if ! [ -f "$CPUFREQ/scaling_governor" -a -f "$CPUFREQ/scaling_available_governors" ]; then
-	echo "Your system is not configured correctly to support cpu frequency scaling" >&2
-	exit 1
+if ! [ -f "$CPUFREQ/scaling_governor" -a -f "$GOVERNORS" ]; then
+	fatal "system not configured correctly for CPU frequency scaling"
 fi
 
 [ -n "$cmd" ] || cmd="$(init_command)"
 
 if [ -z "$cmd" ]; then
-	echo "Couldn't to set initial settings" >&2
-	exit 1
+	fatal "couldn't apply initial settings"
 fi
 
 [ -n "$CPU" ] || CPU="$(grep '^processor' /proc/cpuinfo | sed 's/^.*: //;' | tr '\n' ' ')"
 if [ -z "$CPU" ]; then
-	echo "Couldn't to detect CPUs number" >&2
-	exit 1
+	fatal "couldn't detect the number of CPUs"
 fi
 
 case "$cmd" in
@@ -56,8 +64,10 @@ case "$cmd" in
 	ac-off-line)
 		[ -z "$GOVERNOR_AC_OFF" ] || set_cpufreq -g "$GOVERNOR_AC_OFF"
 		;;
+	ac-unknown)
+		[ -z "$GOVERNOR_AC_UNKNOWN" ] || set_cpufreq -g "$GOVERNOR_AC_UNKNOWN"
+		;;
 	*)
-		echo "Unknown command: '$cmd'" >&2
-		exit 1
+		fatal "unknown command: '$cmd'"
 		;;
 esac
diff --git a/cpufreq-simple/cpufreq-simple.init b/cpufreq-simple/cpufreq-simple.init
index 5c765e2..e836533 100644
--- a/cpufreq-simple/cpufreq-simple.init
+++ b/cpufreq-simple/cpufreq-simple.init
@@ -2,9 +2,8 @@
 #
 # Load kernel modules needed to enable cpufreq scaling
 #
-# chkconfig: - 12 90
-# description: Make it possible to save power by reducing
-# 		the CPU speed when there is little to do.
+# chkconfig: 345 12 90
+# description: Save power when idling
 
 # Do not load RH compatibility interface.
 WITHOUT_RC_COMPAT=1
@@ -48,7 +47,7 @@ start()
 	echo
 
 	if [ $RETVAL -eq 0 ]; then
-		action "Set cpufreq settings: " cpufreq-simple
+		action "Tune up cpufreq: " cpufreq-simple
 		RETVAL="$?"
 	fi
 
@@ -79,8 +78,8 @@ case "$1" in
 		# Nothing to do
 		;;
 	status)
-		is_loaded && echo "Cpufreq is enabled" ||
-			echo "Cpufreq is disabled"
+		is_loaded && echo "cpufreq is enabled" ||
+			echo "cpufreq is disabled"
 		;;
 	*)
 		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
diff --git a/cpufreq-simple/cpufreq-simple.sysconfig b/cpufreq-simple/cpufreq-simple.sysconfig
old mode 100644
new mode 100755
index db6057f..abe63a1
--- a/cpufreq-simple/cpufreq-simple.sysconfig
+++ b/cpufreq-simple/cpufreq-simple.sysconfig
@@ -3,11 +3,14 @@
 #CPU=
 
 # Scalling governor used when AC is on.
-GOVERNOR_AC_ON=performance
+GOVERNOR_AC_ON=ondemand
 
 # Scalling governor used when AC is off.
 GOVERNOR_AC_OFF=ondemand
 
+# Scalling governor used when AC state is unknown.
+GOVERNOR_AC_UNKNOWN=ondemand
+
 # Cpufreq module. If not set then will be detected
 # automatically by detect-cpufreq-module script.
 #MODULE=
-- 
1.7.7.1

----------- следующая часть -----------
From 427bf13c28652c1a54d568baae43d955d747d617 Mon Sep 17 00:00:00 2001
From: Michael Shigorin <mike на altlinux.org>
Date: Fri, 4 Nov 2011 18:23:05 +0200
Subject: [PATCH 2/2] 0.1.1-alt1

- Minor fixups all over the place.
- Enabled the service by default.
---
 cpufreq-simple.spec |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/cpufreq-simple.spec b/cpufreq-simple.spec
index dea8c48..edc4ab7 100644
--- a/cpufreq-simple.spec
+++ b/cpufreq-simple.spec
@@ -1,5 +1,5 @@
 Name: cpufreq-simple
-Version: 0.1.0
+Version: 0.1.1
 Release: alt1
 
 Summary: Simple scripts for managing CPUfreq settings
@@ -11,20 +11,22 @@ BuildArch: noarch
 
 BuildRequires(pre): rpm-build-licenses
 
-Requires: cpufrequtils
+Requires: cpufrequtils libshell
 
 %description
-Simple scripts for managing CPUfreq settings
+Install this package if you would like it to attempt
+cpufreq autoconfiguration in order to save power
+as well as reduce heat and noise.
 
 %prep
 %setup
 
 %install
-install -Dm0755 %name %buildroot%_bindir/cpufreq-simple
-install -Dm0755 detect-cpufreq-module %buildroot%_bindir/detect-cpufreq-module
-install -Dm0755 %name.init %buildroot%_initdir/%name
-install -Dm0744 96-%name.rules %buildroot%_sysconfdir/udev/rules.d/96-%name.rules
-install -Dm0744 %name.sysconfig %buildroot%_sysconfdir/sysconfig/%name
+install -pDm755 %name %buildroot%_bindir/cpufreq-simple
+install -pDm755 detect-cpufreq-module %buildroot%_bindir/detect-cpufreq-module
+install -pDm755 %name.init %buildroot%_initdir/%name
+install -pDm644 96-%name.rules %buildroot%_sysconfdir/udev/rules.d/96-%name.rules
+install -pDm644 %name.sysconfig %buildroot%_sysconfdir/sysconfig/%name
 
 %post
 %post_service %name
@@ -39,6 +41,10 @@ install -Dm0744 %name.sysconfig %buildroot%_sysconfdir/sysconfig/%name
 %_sysconfdir/udev/rules.d/*.rules
 
 %changelog
+* Fri Nov 04 2011 Michael Shigorin <mike на altlinux.org> 0.1.1-alt1
+- Minor fixups all over the place.
+- Enabled the service by default.
+
 * Thu Nov 03 2011 Mikhail Efremov <sem на altlinux.org> 0.1.0-alt1
 - Initial build.
 
-- 
1.7.7.1

----------- следующая часть -----------
Было удалено вложение не в текстовом формате...
Имя     : отсутствует
Тип     : application/pgp-signature
Размер  : 189 байтов
Описание: отсутствует
Url     : <http://lists.altlinux.org/pipermail/community/attachments/20111104/f6b96969/attachment.bin>


Подробная информация о списке рассылки community