Hprofile
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/hprofileSwitching 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.
--- /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=4Create 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
#!/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 "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
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
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
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
EndSectionSection "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.
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.
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"
exitbat 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]