Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Optimus laptop ghetto nvidia/intel selection at boot
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
Saundersx
Apprentice
Apprentice


Joined: 11 Apr 2005
Posts: 247

PostPosted: Mon Jul 14, 2014 2:08 am    Post subject: Optimus laptop ghetto nvidia/intel selection at boot Reply with quote

BEWARE! Doing any of the following may make your system not boot and/or xorg not load. however the following "works for me".

I wanted a way to select at boot time between booting with nvidia-only or intel-only on my optimus laptop (MSI GE60 2PE). Some quick testing showed that at idle with the screen on that Intel-only hovered around 25 watts usage and nvidia-only around 36 watts, so a ~30% savings was certainly worth it (tested with a kill-a-watt similar to http://www.p3international.com/products/p4400.html ).

So first thing was changing grub around.
Code:

cp /etc/grub.d/10_linux /etc/grub.d/11_linux_nvidia
cp /etc/grub.d/10_linux /etc/grub.d/12_linux_intel
chmod -x /etc/grub.d/10_linux
# edit the new files
grub2-mkconfig -o /boot/grub/grub.cfg


then edit the two new files as such (both diff against 10_linux)

11_linux_nvidia
Code:

93c93
<       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
---
>       echo "menuentry '$(echo "$title NVIDIA" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
95c95
<       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
---
>       echo "menuentry '$(echo "$os NVIDIA" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
225c225
<     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
---
>     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} garbage=nvidia"
238c238
<               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
---
>               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} garbage=nvidia"


12_linux_intel
Code:

93c93
<       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
---
>       echo "menuentry '$(echo "$title INTEL" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
95c95
<       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
---
>       echo "menuentry '$(echo "$os INTEL" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
225c225
<     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
---
>     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} garbage=intel modprobe.blacklist=nvidia"
238c238
<               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
---
>               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} garbage=intel modprobe.blacklist=nvidia"


now add this up around the top of /etc/X11/startDM.sh (emerge bbswitch to fully disable nvidia card, you should notice the orange power light change to blue on this laptop denoting the nvidia card is not active)
Code:

if [ "$(cat /proc/cmdline | grep 'garbage=nvidia' | wc -l)" == "1" ]; then
  cp -f /etc/X11/xorg.conf.nvidia.only /etc/X11/xorg.conf
  eselect opengl set nvidia
  #modprobe bbswitch load_state=1 unload_state=1
else
  cp -f /etc/X11/xorg.conf.intel.only /etc/X11/xorg.conf
  eselect opengl set xorg-x11
  modprobe bbswitch load_state=0 unload_state=0
fi


/etc/X11/xorg.conf.nvidia.only - note the "/lib/firmware/edid/1920x1080_ge60_screen.bin" I dumped from the laptop using some linux utility I don't remember, I also dumped it under windows to double check and they were identical. You can probably remove this line and it will still work.
Code:

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0"
    Inactive       "intel"
#    InputDevice    "Keyboard0" "CoreKeyboard"
#    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
EndSection

#Section "InputDevice"
#    # generated from data in "/etc/conf.d/gpm"
#    Identifier     "Mouse0"
#    Driver         "mouse"
#    Option         "Protocol"
#    Option         "Device" "/dev/input/mice"
#    Option         "Emulate3Buttons" "no"
#    Option         "ZAxisMapping" "4 5"
#EndSection

#Section "InputDevice"
#    # generated from default
#    Identifier     "Keyboard0"
#    Driver         "kbd"
#EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    # Stuff on the net says to use BusID "PCI:1:0:0" but the manual says to use "1@0:0:0"
    BusID          "1@0:0:0"
    Option         "ConnectedMonitor" "eDP-0"
    Option         "CustomEDID" "eDP-0:/lib/firmware/edid/1920x1080_ge60_screen.bin"
    Option         "UseEDID" "True"
    Option         "ModeValidation" "NoVirtualSizeCheck"
    Option         "ModeDebug" "True"
    Option         "HWCursor" "1"
    Option         "SWCursor" "0"
    Option         "CursorShadow" "1"
    Option         "RenderAccel" "1"
    Option         "TripleBuffer" "1"
    Option         "AllowGLXWithComposite" "1"
    Option         "AddARGBGLXVisuals" "1"
    Option         "DamageEvents" "1"
    Option         "Coolbits" "5"
    Option         "SLI" "0"                    # one card
    Option         "Stereo" "0"
    Option         "NoLogo" "1"
    #Option        "GLShaderDiskCache" "1"
    Option         "ConnectToAcpid" "1"
    # https://wiki.archlinux.org/index.php/xorg#Display_size_and_DPI
    # its recommended to use 144 (50% over 96) instead of actual ~ 142x143 rounded up
    # however 144 is too large for text, stick to 96x96
    Option         "DPI" "96x96"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    # does this even go here?
    Option         "RenderAccel" "True"
    Option         "NoRenderExtension" "False"
    Option         "AllowGLXWithComposite" "True"
    Option         "AddARGBGLXVisuals" "True"
    Option         "DamageEvents" "True"
    Option         "ConnectToAcpid" "True"
    SubSection     "Display"
        Depth       24
        Modes      "1920x1080"
    EndSubSection
EndSection

Section "Device"
    Identifier     "intel"
    Driver         "modesetting"
    Option         "CustomEDID" "eDP-0:/lib/firmware/edid/1920x1080_ge60_screen.bin"
EndSection

Section "Screen"
    Identifier    "intel"
    Device        "intel"
    SubSection     "Display"
        Depth       24
        Modes      "1920x1080"
    EndSubSection
    Monitor        "Monitor0"
EndSection

Section "Extensions"
    Option         "Composite" "Enable"
    Option         "RENDER" "Enable"
    #Option        "DAMAGE" "Enable"
EndSection


/etc/X11/xorg.conf.intel.only - this is mainly a copied and slightly modified version of the nvidia one, I'm guessing 90% of this file is useless.
Code:

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0"
#    Inactive       "intel"
#    InputDevice    "Keyboard0" "CoreKeyboard"
#    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
EndSection

#Section "InputDevice"
#    # generated from data in "/etc/conf.d/gpm"
#    Identifier     "Mouse0"
#    Driver         "mouse"
#    Option         "Protocol"
#    Option         "Device" "/dev/input/mice"
#    Option         "Emulate3Buttons" "no"
#    Option         "ZAxisMapping" "4 5"
#EndSection

#Section "InputDevice"
#    # generated from default
#    Identifier     "Keyboard0"
#    Driver         "kbd"
#EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "intel"
    # Stuff on the net says to use BusID "PCI:1:0:0" but the manual says to use "1@0:0:0"
    BusID          "0@0:02:0"
    Option         "ConnectedMonitor" "eDP-0"
    Option         "CustomEDID" "eDP-0:/lib/firmware/edid/1920x1080_ge60_screen.bin"
    Option         "UseEDID" "True"
    Option         "ModeValidation" "NoVirtualSizeCheck"
    Option         "ModeDebug" "True"
    Option         "HWCursor" "1"
    Option         "SWCursor" "0"
    Option         "CursorShadow" "1"
    Option         "RenderAccel" "1"
    Option         "TripleBuffer" "1"
    Option         "AllowGLXWithComposite" "1"
    Option         "AddARGBGLXVisuals" "1"
    Option         "DamageEvents" "1"
    Option         "Coolbits" "5"
    Option         "SLI" "0"                    # one card
    Option         "Stereo" "0"
    Option         "NoLogo" "1"
    #Option        "GLShaderDiskCache" "1"
    Option         "ConnectToAcpid" "1"
    # https://wiki.archlinux.org/index.php/xorg#Display_size_and_DPI
    # its recommended to use 144 (50% over 96) instead of actual ~ 142x143 rounded up
    # however 144 is too large for text, stick to 96x96
    Option         "DPI" "96x96"
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    # does this even go here?
    Option         "RenderAccel" "True"
    Option         "NoRenderExtension" "False"
    Option         "AllowGLXWithComposite" "True"
    Option         "AddARGBGLXVisuals" "True"
    Option         "DamageEvents" "True"
    Option         "ConnectToAcpid" "True"
    SubSection     "Display"
        Depth       24
        Modes      "1920x1080"
    EndSubSection
EndSection

Section "Extensions"
    Option         "Composite" "Enable"
    Option         "RENDER" "Enable"
    #Option        "DAMAGE" "Enable"
EndSection


and add this to your /usr/share/config/kdm/Xsetup for the nvidia-only setup (to clarify this is not the bumblebee method, 100% nvidia).
Code:

if [ "$(cat /proc/cmdline | grep 'garbage=nvidia' | wc -l)" == "1" ]; then
  # setup nvidia as the only gpu
  modprobe nvidia
  /usr/bin/xrandr --setprovideroutputsource modesetting NVIDIA-0
  /usr/bin/xrandr --auto
  /opt/bin/nvidia-settings --load-config-only -a InitialPixmapPlacement=2
fi


add to your make.conf (i965 is specific to my setup, get yours from https://wiki.gentoo.org/wiki/I915 )
Code:

VIDEO_CARDS="nvidia modesetting intel i965"


more stuff
https://wiki.gentoo.org/wiki/NVIDIA_Driver_with_Optimus_Laptops - nvidia-only config I based mine off
https://wiki.archlinux.org/index.php/NVIDIA_Optimus#Using_nvidia - more
http://pastebin.com/A1q3sDRF - kernel config for my MSI GE60 2PE , this is a WIP. I haven't bothered to get the hibernation working yet.
https://github.com/wearefractal/msi-keyboard - and led keyboard control for this laptop, works pretty good, nodejs though...

as a bonus here is my mvp.sh script to launch mpv with acceleration in either nvidia/intel only modes. cpu usage hovers around 1-3% using this. I was forced to switch to pulseaudio because of the great satan skype.
Code:

#!/bin/sh

AO="pulse" #"alsa:device=[hw:1,0]"
if [ "$(cat /proc/cmdline | grep 'garbage=nvidia' | wc -l)" == "1" ]; then
  VO="vdpau,xv,sdl"
  HWDEC="vdpau"
else
  VO="opengl,xv,sdl" # vaapi slow
  HWDEC="vaapi"
fi

QUIET="--really-quiet"  # comment out for testing

# make 5.1 audio louder on 2.0 speakers
if [ "`file "$*" | grep -E "(Matroska data|creator matroska)" | wc -l`" == "1" ]; then
  AC3AUDIO="--af=volume=10"
fi

/usr/bin/mpv \
  ${QUIET} \
  ${AC3AUDIO} \
  --ao ${AO} \
  --vo ${VO} \
  --hwdec=${HWDEC} \
  --cache=$((1024*8)) --cache-min=80 \
  --monitoraspect=16:9 \
  --no-sub-visibility \
  --fs \
  "$*"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum