Hprofile
| External resources |
sys-apps/hprofile is a little application that can be used to manage multiple profiles be it hardware or software. The following subsection are just examples on what could be done with hprofile.
To be able to to go further, one should, of course, merge the package.
root # emerge --ask sys-apps/hprofileContents |
Hardware profiles
Preparation
--- /etc/init.d/hprofile 2012-07-04 02:01:29.861618809 +0200
+++ /etc/init.d/hprofile 2012-07-04 02:03:49.713870416 +0200
@@ -2,24 +2,26 @@
# Copyright 1999-2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
-
depend() {
- before modules
+ after modules
}
start() {
- profile=$(/usr/local/sbin/hpdet boot)
- ebegin "Selecting hardware profile ${profile}"
- /usr/local/sbin/hprofile boot
+ local vgap=$(/usr/sbin/hpdet vga)
+ local pwrp=$(/usr/sbin/hpdet disk)
+ ebegin "Selecting hardware profile vga.$vgap and power.$pwrp"
+ /usr/sbin/hprofile vga
+ /usr/sbin/hprofile power
eend $?
}
stop() {
- profile=$(/usr/local/sbin/hprofile -c boot)
- ebegin "Stopping hardware profile ${profile}"
- /usr/local/sbin/hprofile -s boot
+ local vgap=$(/usr/sbin/hprofile -c vga)
+ local pwrp=$(/usr/sbin/hprofile -c disk)
+ ebegin "Stopwrping hardware profile vga.$vgap and power.$pwrp"
+ /usr/sbin/hprofile -s vga
+ /usr/sbin/hprofile -s power
eend $?
}
-
# vim:ts=4
Power
When thinking a better to have different dynamic power profiles that could dynamically switched depending on hardware of software state is not straightforward especially for power management which could depend on many software e.g. sys-power/powertop, sys-power/cpufrequtils, sys-apps/hdparm to name a few. So how could you get hardware profiles and switch between them dynamically? And how to get everything together? How many deamons to start depending on what hardware or software state?
That sum up quite a few considerations to what a user can face when trying to build a nice setup with power management in mind. [S]he can remember of Windows(tm) days power management profiles if [s]he ever used it. Or else, [s]he did not any thought about it because [s]he used to run a GNU Linux or BSD based distribution with everything putted together and does not know how to begin with if [s]he is not satisfied with what [s]he gets.
Now sys-power/powertop-2 grew up to be quite a good piece of software. If you're runnng an Intel based platform, you can get access to pretty much everything one would expect if trying to build power manager profiles. But the package does not ship with a daemon nor with a configuration or profile file which PowerTOP could pick up when launched in the next restart. One has to launch it again and again in a terminal and enable power management for every power manageable hardware.
Now, it will a bit long to go pick enough power management tuning that a software like PowerTOP use to be able to manage almost everything. This is just a beginning to that. One can use acpid to switch between different hardware profiles depending on hardware state.
This basic profile will try to implement Hprofile#Disk, CPU (see Hprofile#Extra_resources, network interfaces and ALSA drivers power saving capabilities.
One would need the following files to set up basic power management profiles.
adp bat dyn med quiet
adp
#!/bin/sh
if [ -e "/sys/class/power_supply/ADP1/online" ]; then
status=$(cat /sys/class/power_supply/ADP1/online)
case "$status" in
1) profile="adp";;
0) profile="bat";;
esac
fi
echo "${profile:-adp}"#!/bin/sh hprofile disk.adp for c in $(ls -d /sys/devices/system/cpu/cpu[0-9]*); do echo ondemand >$c/cpufreq/scaling_governor done echo 200 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor echo 0 >/sys/devices/system/cpu/sched_mc_power_savings echo default >/sys/module/pcie_aspm/parameters/policy for h in $(ls -d /sys/class/scsi_host/host[0-9]*); do [ "$(cat $h/proc_name)" = "ahci" ] && echo min_power >$h/link_power_management_policy done [ -e /run/openrc/started/alsasound ] && echo 0 >/sys/module/snd_hda_intel/parameters/power_save #iwpriv wlan0 set_power 2 xbacklight -set 40 xset dpms 600 900 1200
#!/bin/sh hprofile disk.adp for c in $(ls -d /sys/devices/system/cpu/cpu[0-9]*); do echo ondemand >$c/cpufreq/scaling_governor done echo 200 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor echo 1 >/sys/devices/system/cpu/sched_mc_power_savings echo powersave >/sys/module/pcie_aspm/parameters/policy for h in $(ls -d /sys/class/scsi_host/host[0-9]*); do [ "$(cat $h/proc_name)" = "ahci" ] && echo min_power >$h/link_power_management_policy done [ -e /run/openrc/started/alsasound ] && echo 0 >/sys/module/snd_hda_intel/parameters/power_save #iwpriv wlan0 set_power 4 xbacklight -set 30 xset dpms 300 400 600
#!/bin/sh hprofile disk.adp for c in $(ls -d /sys/devices/system/cpu/cpu[0-9]*); do echo performance >$c/cpufreq/scaling_governor done echo 200 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor echo 0 >/sys/devices/system/cpu/sched_mc_power_savings echo performance >/sys/module/pcie_aspm/parameters/policy for h in $(ls -d /sys/class/scsi_host/host[0-9]*); do [ "$(cat $h/proc_name)" = "ahci" ] && echo max_performance >$h/link_power_management_policy done [ -e /run/openrc/started/alsasound ] && echo 0 >/sys/module/snd_hda_intel/parameters/power_save #iwpriv wlan0 set_power 1 xbacklight -set 40 xset dpms 0 0 2400
#!/bin/sh hprofile disk.adp for c in $(ls -d /sys/devices/system/cpu/cpu[0-9]*); do echo ondemand >$c/cpufreq/scaling_governor done echo 200 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor echo 1 >/sys/devices/system/cpu/sched_mc_power_savings echo performance >/sys/module/pcie_aspm/parameters/policy for h in $(ls -d /sys/class/scsi_host/host[0-9]*); do [ "$(cat $h/proc_name)" = "ahci" ] && echo min_power >$h/link_power_management_policy done [ -e /run/openrc/started/alsasound ] && echo 0 >/sys/module/snd_hda_intel/parameters/power_save #iwpriv wlan0 set_power 6 xbacklight -set 30 xset dpms 500 700 900
#!/bin/sh hprofile disk.adp for c in $(ls -d /sys/devices/system/cpu/cpu[0-9]*); do echo ondemand >$c/cpufreq/scaling_governor done echo 200 >/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor echo 1 >/sys/devices/system/cpu/sched_mc_power_savings echo powersave >/sys/module/pcie_aspm/parameters/policy for h in $(ls -d /sys/class/scsi_host/host[0-9]*); do [ "$(cat $h/proc_name)" = "ahci" ] && echo min_power >$h/link_power_management_policy done [ -e /run/openrc/started/alsasound ] && echo 0 >/sys/module/snd_hda_intel/parameters/power_save #iwpriv wlan0 set_power 6 xbacklight -set 20 xset dpms 0 0 300
I have a battery runlevel, a copycat of default runlevel, that is dynamically switched if AC power is unplugged. See ACPI article for more info. That's not enough? Do you want more tunings? Expand the article then! I wish PowerTOP implement a daemon-ish profile-able application which is the right sport for Intel based hardware.
RFKill
This hardware profile subsection could be beneficial to the previous section, but killing radio of devices can be quite troublesome which require hard reboot and removing battery/AC power for a few second to be able to get back usable wireless interfaces again. This happen on my Intel GM45 based laptop. Luckily there is a physical switch to kill bluetooth and wifi radio.
There's no much consideration for this section, if your hardware support RFKill, add it to your hardware profile!
bsw ksw wsw
#!/bin/sh echo 1 >/sys/class/rfkill/rfkill1/state echo 1 >/sys/class/rfkill/rfkill7/state
#!/bin/sh echo 0 >/sys/class/rfkill/rfkill1/state echo 0 >/sys/class/rfkill/rfkill7/state
#!/bin/sh echo 1 >/sys/class/rfkill/rfkill0/state echo 1 >/sys/class/rfkill/rfkill2/state
#!/bin/sh echo 0 >/sys/class/rfkill/rfkill0/state echo 0 >/sys/class/rfkill/rfkill2/state
#!/bin/sh hprofile rfkill.wsw hprofile rfkill.bsw
VGA
I use sys-apps/hprofile to manage VGA profile to my laptop and my desktop. On my desktop, I use hprofile to switch between nvidia-drivers, nouveau and nv (x11-drivers/xf86-video-nv) when the previous profiles do no work; and to switch radeon and intel on my laptop which has switchable graphics via VGASwitcheroo.
Just be sure to built kernel modules about everything — at least i9{1,6}5, nouveau, radeon, ttm, drm, and optionally (?) ac, button, video, i2c-algo-bit — to avoid useless hassles.
Create the necessaries folder /etc/hprofile/profiles/vga/{scripts,files/etc/X11/xorg.conf.d} and add the following files.
intel radeon nvidia nv nouveau fglrx
#!/bin/sh
echo "Finished starting profile ${1}"
/etc/init.d/consolefont restart
#!/bin/sh
[ "${1}" == "intel" ] || [ "${1}" == "radeon" ] &&
echo ON >/sys/kernel/debug/vgaswitcheroo/switch
echo "Finished Stopping profile ${1} and moving back xorg.conf"
if [ ! -e /sys/kernel/debug/vgaswitcheroo/switch ]; then
[ -z "$(lsmod | grep -i radeon)" ] && modprobe radeon && sleep 3
[ -z "$(lsmod | grep -i i915)" ] && modprobe i915 && sleep 3
fi
[ $(grep DIS:+ /sys/kernel/debug/vgaswitcheroo/switch) ] && echo "radeon" && exit
[ $(grep IGD:+ /sys/kernel/debug/vgaswitcheroo/switch) ] && echo "intel" && exit
for drv in nouveau nvidia radeon fglrx; do
[ -n "$(lspci -k | grep "Kernel driver in use: $drv")" ] && echo "$drv" && exit
done
for drv in i9{6,1}5; do
[ -n "$(lspci -k | grep "Kernel driver in use: $drv")" ] && echo intel && exit
done
echo "invalid" && exit 1
#!/bin/sh echo "Starting fglrx profile." modprobe fglrx || echo "failed to load fglrx module." && exit 1 [ "$(eselect opengl show)" != "ati" ] && eselect opengl set ati [ "$(eselect xvmc show)" != "ati" ] && eselect xvmc set ati
#!/bin/sh echo "Stopping nvidia profile." rmmod fglrx || echo "failed to remove fglrx module." && exit 1
#!/bin/sh echo "Starting intel VGA profile." echo IGD >/sys/kernel/debug/vgaswitcheroo/switch echo OFF >/sys/kernel/debug/vgaswitcheroo/switch [ "$(eselect opengl show)" != "xorg-x11" ] && eselect opengl set xorg-x11 [ "$(eselect xvmc show)" != "intel-i815" ] && eselect xvmc set intel-i815
#!/bin/sh echo "Starting nouveau profile." modprobe nouveau || echo "failed to load nouveau module." [ "$(eselect opengl show)" != "xorg-x11" ] && eselect opengl set xorg-x11 exit
#!/bin/sh echo "Stopping nouveau profile." echo 0 >/sys/class/vtconsole/vtcon1/bind rmmod nouveau || echo "failed to remove nouveau module." && exit 1 /etc/init.d/consolefont restart rmmod ttm rmmod drm_kms_helper rmmod dri
#!/bin/sh echo "Starting radeon profile." echo DIS >/sys/kernel/debug/vgaswitcheroo/switch echo OFF >/sys/kernel/debug/vgaswitcheroo/switch echo low >/sys/class/drm/card0/device/power_profile [ "$(eselect opengl show)" != "xorg-x11" ] && eselect opengl set xorg-x11 [ "$(eselect xvmc show)" != "xorg-x11" ] && eselect xvmc set xorg-x11 echo dynpm >/sys/class/drm/card0/device/power_method # or use the following because "dynpm" can cause screen flickering # echo profile >/sys/class/drm/card0/device/power_method # echo auto[|low|mid] >/sys/class/drm/card0/device/power_profile
#!/bin/sh echo "Starting nvidia profile." modprobe nvidia || echo "failed to load nvidia module." && exit 1 [ "$(eselect opengl show)" != "nvidia" ] && eselect opengl set nvidia
#!/bin/sh echo "Stopping nvidia profile." rmmod nvidia || echo "failed to remove nvidia module." && exit 1
Section "Monitor" Identifier "Default" EndSection Section "Device" Identifier "ATI" Driver "fglrx" EndSection Section "Screen" Identifier "FGLRX" Device "ATI" Monitor "Default" EndSection
Section "Monitor" Identifier "Default" EndSection Section "Device" Option "DRI" "True" Option "XvMCSurfaces" "6" Identifier "GMAX" Driver "intel" EndSection Section "Screen" Identifier "INTEL" Device "GMAX" Monitor "Default" EndSection
Section "Monitor"
Identifier "Default"
EndSection
Section "Device"
Option "EXAVsync" "True"
Option "GLXVBlank" "True"
Identifier "nVidia"
Driver "nouveau"
EndSection
Section "Screen"
Identifier "NOUVEAU"
Device "nVidia"
Monitor "Default"
EndSection
Section "Monitor"
Identifier "Default"
EndSection
Section "Device"
Option "AddARGBGLXVisuals" "on"
Option "NoLogo"
Identifier "nVidia"
Driver "nvidia"
EndSection
Section "Screen"
Identifier "NVIDIA"
Device "nVidia"
Monitor "Default"
EndSection
Section "Monitor" Identifier "Default" EndSection Section "Device" Option "AccelMethod" "EXA" Option "ClockGating" "On" Option "ForceLowPowerMode" "On" Option "VGAAccess" "On" Identifier "RadeonHD" Driver "radeon" Option "MonitorLayout" "LVDS, AUTO" EndSection Section "Screen" Identifier "RADEON" Device "RadeonHD" Monitor "Default" EndSection
And with that, you should be able to switch vga profile as you like without needing an extra kernel and setup.
The ptest script will just look if VGASwitcheroo is available and which driver is loaded and then start the appropriate profile. One can black list a module and leave the other un-black listed to be able to chose ...a default VGA profile. Or else, use of `/etc/hprofile/profiles/vga/default' file.
intel
Hard disk
A disk profile is even straightforward because there fewer issue to keep in mind. So this section will be short and straightforward. Additionally, one need sys-apps/hdparm.
adp
#!/bin/sh
for dev in $(ls -d /sys/devices/pci*/*/ata*/host*/target*/*/block/sd[a-z] 2>/dev/null); do
echo cfq >/sys/block/${dev##*/}/queue/scheduler
echo 0 >/sys/block/${dev##*/}/queue/iosched/slice_idle
echo 64 >/sys/block/${dev##*/}/queue/iosched/quantum
# more opitmizations with ncq
echo 1024 >/sys/block/${dev##*/}/queue/nr_requests
echo 2 >/sys/block/${dev##*/}/device/queue_depth
done
for dev in $(ls -d /sys/devices/pci*/*/usb*/*/*/host*/target*/*/block/sd[a-z] 2>/dev/null)
do echo noop >/sys/block/${dev##*/}/queue/scheduler; done
#!/bin/sh
[ -e /etc/runlevels/battery ] &&
[ "rc-status -r" != "default" ] && echo "bat" || echo "adp"
exit
bat adp fast quiet
#!/bin/sh hdparm -q -S120 -B254 -M254 /dev/sd[a-z]
#!/bin/sh hdparm -q -S120 -B230 -M254 /dev/sd[a-z]
#!/bin/sh hdparm -q -S120 -B210 -M230 /dev/sd[a-z]
#!/bin/sh hdparm -q -S180 -B254 -M254 /dev/sd[a-z]
#!/bin/sh hdparm -q -S120 -B200 -M200 /dev/sd[a-z]
External resources
- Power management/Processor - See that article for CPU power management insight.