Hprofile

From Gentoo Wiki
Revision as of 13:14, 4 July 2012 by Tclover (Talk | contribs)

Jump to: navigation, search

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/hprofile

Switching VGA profile

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 (x11-drivers/nvidia-drivers), nouveau (x11-drivers/xf86-video-nouveau) and nv (x11-drivers/xf86-video-nv) when the previous profiles do no work; and to switch ati (x11-drivers/xf86-video-ati) and intel (x11-drivers/xf86-video-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.

Filehprofile.initd.patch

--- /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

Create the necessaries folder /etc/hprofile/profiles/vga/{scripts,files/etc/X11/xorg.conf.d} and add the following files.

Note
Of course, the necessary files should be added for the following profiles, you do not need to copy every single profile related file if you do not have any use of it. Just do not switch to that particular profile with missing files later when using vga profile. Or even better, do not add, or rather remove, those particular profiles from the profile list file.
File/etc/hprofile/profiles/vga/profiles

intel
radeon
nvidia
nv
nouveau
fglrx
Note
This is necessary because the console font will be messed whenever a new profile is switched.
File/etc/hprofile/profiles/vga/post-start

#!/bin/sh
echo "Finished starting profile ${1}"
/etc/init.d/consolefont restart
File/etc/hprofile/profiles/vga/stop

#!/bin/sh
[ "${1}" == "intel" ] || [ "${1}" == "radeon" ] &&
    echo ON >/sys/kernel/debug/vgaswitcheroo/switch
echo "Finished Stopping profile ${1} and moving back xorg.conf"
Note
If a specific kernel module is loaded with an initramfs or modules init services, the appropriate profile will be selected with the following script.
File/etc/hprofile/profiles/vga/ptest

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
File/etc/hprofile/profiles/vga/scripts/fglrx.start

#!/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
File/etc/hprofile/profiles/vga/scripts/fglrx.stop

#!/bin/sh
echo "Stopping nvidia profile."
rmmod fglrx || echo "failed to remove fglrx module." && exit 1
File/etc/hprofile/profiles/vga/scripts/intel.start

#!/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
File/etc/hprofile/profiles/vga/scripts/nouveau.start

#!/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
File/etc/hprofile/profiles/vga/scripts/nouveau.stop

#!/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
File/etc/hprofile/profiles/vga/scripts/radeon.start

#!/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
File/etc/hprofile/profiles/vga/scripts/nvidia.start

#!/bin/sh
echo "Starting nvidia profile."
modprobe nvidia || echo "failed to load nvidia module." && exit 1
[ "$(eselect opengl show)" != "nvidia" ] && eselect opengl set nvidia
File/etc/hprofile/profiles/vga/scripts/nvidia.stop

#!/bin/sh
echo "Stopping nvidia profile."
rmmod nvidia || echo "failed to remove nvidia module." && exit 1
File/etc/hprofile/profiles/vga/files/etc/X11/xorg.conf.d/40-monitor.conf.fglrx

Section "Monitor"
	Identifier  "LVDS"
	VendorName  "CMO Model"
	ModelName   "Lenovo Ideapad 330-LVDS"
EndSection

Section "Device"
	Identifier  "HD3450M"
	Driver      "fglrx"
	BusID       "PCI:1:0:0"
EndSection

Section "Screen"
	Identifier "FGLRX"
	Device     "HD3450M"
	Monitor    "LVDS"
	SubSection "Display"
		Viewport  0 0
		Depth     24
	EndSubSection
EndSection
File/etc/hprofile/profiles/vga/files/etc/X11/xorg.conf.d/40-monitor.conf.intel

Section "Monitor"
	Identifier  "LVDS"
	VendorName  "CMO Model"
	ModelName   "Lenovo Ideapad 330-LVDS"
EndSection

Section "Device"
	Option      "DRI" "True"
	Option      "XvMCSurfaces" "6"
	Identifier  "GMA-X4500MHD"
	Driver      "intel"
	BusID       "PCI:0:2:0"
EndSection

Section "Screen"
	Identifier "INTEL"
	Device     "GMA-X4500MHD"
	Monitor    "LVDS"
	SubSection "Display"
		Viewport  0 0
		Depth     24
	EndSubSection
EndSection
File/etc/hprofile/profiles/vga/files/etc/X11/xorg.conf.d/40-monitor.conf.nouveau

Section "Monitor"
    Identifier  "DFP-0"
    VendorName  "DELL"
    ModelName   "2000WFP"
    Option      "PreferredMode" "1680x1050"
EndSection

Section "Device"
    Option      "EXAVsync"  "True"
    Option      "GLXVBlank" "True"
    Identifier  "8800GT"
    Driver      "nouveau"
    BusID       "PCI:1:0:0"
EndSection

Section "Screen"
    Identifier "NOUVEAU"
    Device     "8800GT"
    Monitor    "DFP-0"
    SubSection "Display"
        Viewport  0 0
        Depth     24
    EndSubSection
EndSection
File/etc/hprofile/profiles/vga/files/etc/X11/xorg.conf.d/40-monitor.conf.nvidia

Section "Monitor"
    Identifier "DFP-0"
    VendorName "DELL"
    ModelName  "2000WFP"
    Option     "PreferredMode" "1680x1050"
EndSection

Section "Device"
    Option     "AddARGBGLXVisuals"  "on"
    Option     "NoLogo"
    Identifier "8800GT"
    Driver     "nvidia"
    BusID      "PCI:1:0:0"
EndSection

Section "Screen"
    Identifier "NVIDIA"
    Device     "8800GT"
    Monitor    "DFP-0"
    SubSection "Display"
        Viewport  0 0
        Depth     24
    EndSubSection
EndSection
File/etc/hprofile/profiles/vga/files/etc/X11/xorg.conf.d/40-monitor.conf.radeon

Section "Monitor"
	Identifier   "LVDS"
	VendorName   "CMO Model"
	ModelName    "Lenovo Ideapad 330-LVDS"
EndSection

Section "Device"
	Option      "AccelMethod" "EXA"
	Option      "ClockGating" "On"
	Option      "ForceLowPowerMode" "On"
	Option      "VGAAccess" "On"
	Identifier  "HD3450M"
	Driver      "radeon"
	BusID       "PCI:1:0:0"
	Option	    "MonitorLayout" "LVDS, AUTO"
EndSection

Section "Screen"
	Identifier "RADEON"
	Device     "HD3450M"
	Monitor    "LVDS"
	SubSection "Display"
		Viewport  0 0
		Depth     24
	EndSubSection
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.

File/etc/hprofile/profiles/vga/default

intel

Switching disk profile

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.

File/etc/hprofile/profiles/disk/default

adp
File/etc/hprofile/profiles/disk/post-start

#!/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
File/etc/hprofile/profiles/disk/ptest

#!/bin/sh
[ -e /etc/runlevels/battery ] &&
    [ "rc-status -r" != "default" ] && echo "bat" || echo "adp"
exit
File/etc/hprofil/profiles/disk/profiles

bat
adp
fast
quiet
File/etc/hprofile/profiles/disk/stop

#!/bin/sh
hdparm -q -S120 -B254 -M254 /dev/sd[a-z]
File/etc/hprofile/profiles/disk/scripts/adp.start

#!/bin/sh
hdparm -q -S120 -B230 -M254 /dev/sd[a-z]
File/etc/hprofile/profiles/disk/scripts/bat.start

#!/bin/sh
hdparm -q -S120 -B210 -M230 /dev/sd[a-z]
File/etc/hprofile/profiles/disk/scripts/fast.start

#!/bin/sh
hdparm -q -S180 -B254 -M254 /dev/sd[a-z]
File/etc/hprofile/profiles/disk/scripts/quiet.start

#!/bin/sh
hdparm -q -S120 -B200 -M200 /dev/sd[a-z]
Personal tools
Namespaces

Variants
Actions
Gentoo Websites logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Navigation
Toolbox
Categories