# X segfaults with NVidia Optimus

## Rongidge

I've recently bought a new laptop with a NVidia Optimus system and I can get the Intel GMA working just fine.

But, if I try to switch to the NVidia card, the screen stays black at first (as is to be expected, since I'm not using .xinitrc yet).

So I switch to a terminal (CTRL+ALT+F2) and 

```
user123@KANTE ~ $ DISPLAY=:0 xrandr --listproviders

Providers: number : 2

Provider 0: id: 0x2b5 cap: 0x1, Source Output crtcs: 0 outputs: 0 associated providers: 0 name:NVIDIA-0

Provider 1: id: 0x46 cap: 0x2, Sink Output crtcs: 3 outputs: 4 associated providers: 0 name:modesetting
```

So far, so good.

Now I try to switch the provider

```
user123@KANTE ~ $ DISPLAY=:0 xrandr --setprovideroutputsource modesetting NVIDIA-0

XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"

      after 17 requests (17 known processed) with 0 events remaining
```

and X segfaults.

Sadly, I'm a complete idiot when it comes to segfaults and searching with google didn't provide me with an answer, so I'm rather clueless and hope someone here can help me.

Xorg.0.log: http://pastebin.com/WD0xDTF5

xorg.conf: 

```
Section "ServerLayout"

   Identifier "layout"

   Screen 0 "nvidia"

   Inactive "intel"

EndSection

Section "Device"

   Identifier "nvidia"

   Driver "nvidia"

   BusID "PCI:1:0:0"

EndSection

Section "Screen"

   Identifier "nvidia"

   Device "nvidia"

   # Uncomment this line if your computer has no display devices connected to

   # the NVIDIA GPU. Leave it commented if you have display devices

   # connected to the NVIDIA GPU that you would like to use.

   Option "UseDisplayDevice" "none"

   Option "AllowEmptyInitialConfiguration"

EndSection

Section "Device"

   Identifier "intel"

   Driver "modesetting"

   #BusID "PCI:0:0:2"

EndSection

Section "Screen"

   Identifier "intel"

   Device "intel"

EndSection

Section "InputClass"

   Identifier "keyboard-all"

   Driver "evdev"

   Option "XkbLayout" "at"

   Option "XkbModel" "pc104"

   #Option "XkbOptions" "terminate:ctrl_alt_bksp"

   Option "XkbVariant" "nodeadkeys,"

   #MatchIsKeyboard "on"

EndSection

```

emerge --info:

```
 Portage 2.2.7 (default/linux/amd64/13.0/desktop/gnome, gcc-4.7.3, glibc-2.15-r3, 3.9.11-gentoo-r1 x86_64)

=================================================================

System uname: Linux-3.9.11-gentoo-r1-x86_64-Intel-R-_Core-TM-_i5-4200M_CPU_@_2.50GHz-with-gentoo-2.2

KiB Mem:     3962524 total,   3674064 free

KiB Swap:    4194300 total,   4194300 free

Timestamp of tree: Mon, 04 Nov 2013 19:30:01 +0000

ld GNU ld (GNU Binutils) 2.23.1

app-shells/bash:          4.2_p45

dev-java/java-config:     2.1.12-r1

dev-lang/python:          2.7.5-r3, 3.2.5-r3

dev-util/cmake:           2.8.11.2

dev-util/pkgconfig:       0.28

sys-apps/baselayout:      2.2

sys-apps/openrc:          0.12.4

sys-apps/sandbox:         2.6-r1

sys-devel/autoconf:       2.13, 2.69

sys-devel/automake:       1.12.6, 1.13.4

sys-devel/binutils:       2.23.1

sys-devel/gcc:            4.7.3-r1, 4.8.1-r1

sys-devel/gcc-config:     1.7.3

sys-devel/libtool:        2.4.2

sys-devel/make:           3.82-r4

sys-kernel/linux-headers: 3.9 (virtual/os-headers)

sys-libs/glibc:           2.15-r3

Repositories: gentoo desktop-effects gamerlay ohnobinki_overlay proaudio science sunrise x11 xfce-dev local-repo g-octave

ACCEPT_KEYWORDS="amd64"

ACCEPT_LICENSE="* -@EULA"

CBUILD="x86_64-pc-linux-gnu"

CFLAGS="-O2 -pipe -march=native"

CHOST="x86_64-pc-linux-gnu"

CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"

CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"

CXXFLAGS="-O2 -pipe -march=native"

DISTDIR="/usr/portage/distfiles"

FCFLAGS="-O2 -pipe"

FEATURES="assume-digests binpkg-logs compressdebug config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync"

FFLAGS="-O2 -pipe"

GENTOO_MIRRORS="http://distfiles.gentoo.org"

LANG="de_AT.utf8@euro"

LDFLAGS="-Wl,-O1 -Wl,--as-needed"

MAKEOPTS="-j3"

PKGDIR="/usr/portage/packages"

PORTAGE_CONFIGROOT="/"

PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"

PORTAGE_TMPDIR="/var/tmp"

PORTDIR="/usr/portage"

PORTDIR_OVERLAY="/var/lib/layman/desktop-effects /var/lib/layman/gamerlay /var/lib/layman/ohnobinki /var/lib/layman/pro-audio /var/lib/layman/science /var/lib/layman/sunrise /var/lib/layman/x11 /var/lib/layman/xfce-dev /usr/local/portage /var/lib/g-octave"

USE="X a52 aac aalib acl acpi alsa amd64 bash-completion berkdb branding bzip2 cairo cdda cddb cdr cli colord consolekit cracklib crypt cups cxx dbus dri dts dvd dvdr eds emboss emerald encode evo exif extras fam ffmpeg fftw firefox flac fontconfig fortran gconf gdbm geoip gif gnome gnome-keyring gnome-online-accounts gpm grub gstreamer gtk iconv id3 introspection ipv6 jack java jpeg kate lame laptop lash lcms ldap libnotify libsamplerate libsecret mad matroska mmx mng modules mono mp3 mp4 mpeg mplayer mtp mudflap multilib musepack music nautilus ncurses networkmanager nls nptl offensive ogg opengl openmp pam pango pcre pdf png policykit ppds pulseaudio qt3support qt4 radius rdesktop readline samba schroedinger sdl session socialweb spell sse sse2 sse3 sse4 ssl ssse3 startup-notification svg tcpd theora threads tiff truetype udev udisks unicode upower usb uxa v4l vala vdpau video vnc vorbis wavpack wxwidgets x264 xcb xcomposite xinerama xml xv xvid zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" GRUB_PLATFORMS="pc" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="de en" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_2" RUBY_TARGETS="ruby19 ruby18" USERLAND="GNU" VIDEO_CARDS="modesetting nvidia intel" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"

Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, SYNC, USE_PYTHON
```

If you need additional information, let me know.

----------

## eyoung100

See:

 *eyoung100 wrote:*   

>  *NeddySeagoon wrote:*   The Intel one is a complete graphics system. It can write new images in the pixel buffer and read the pixel buffer out to the dispaly. 
> 
> The nVidia graphics can only write new images in the pixel buffer. It has no way to get the pixel buffer onto the screen. 
> 
> This means that for low power/performce you use the Intel system. 
> ...

 

See No Device Detected While startx and Mini Display Port on ThinkPad T530

----------

## Rongidge

Hi eyoung,

Thanks for the fast answer, but I'm not sure which one of the solutions from the other threads would apply here. I followed the instructions from the nvidia-drivers documentation and get stuck when trying to use xrandr. 

By renaming xorg.conf (so it uses an empty one) and switching the opengl profile I get direct rendering working via Mesa.

```
user123@KANTE ~ $ glxinfo | grep render

direct rendering: Yes

OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile

<two lines with GL capabilities>
```

Should I expect something like this when everything works? Does it just work out-of-the-box?

----------

## eyoung100

Have you installed Bumblebee  :Question: 

----------

## Rongidge

 *eyoung100 wrote:*   

> Have you installed Bumblebee 

 

From what I've read in this post it isn't needed anymore.

Edit: To clarify: No, I haven't installed bumblebee because I didn't think it was needed anymore. Could installing it help with detecting the cause of the problem at hand?

----------

## eyoung100

I read that post, and his benchmark has bumblebeed running

----------

## Rongidge

 *GenBlack wrote:*   

> Nouveau driver and bumblebeed : 1500 fps in 5 seconds (glxgears)
> 
> Nvidia driver and bumblebeed : 1500 to 1700 fps in 5 seconds (glxgears)
> 
> New driver support the optimus by nvidia : 8000 to 8800 fps in 5 seconds (glxgears)

 

That last line is where I'd like to end up at, and it doesn't mention bumblebee.

----------

## Dr.Willy

Just to clarify, you don't need bumblebee with the binary drivers anymore. I don't know about nouvau.

----------

## cyberjun

@Rongidge, did you find a solution yet? X segfaults when I try to use optimus without bumblebee.   :Sad: 

--cyberjun

----------

## Rongidge

The solution for my problem was that --setprovideroutputsource has to be run from the active VT. So you can check if your xorg.conf works first, by running the --listproviders command, but you will have to use .xinitrc if you want to get it running.

The other problem in my case was that the xserver missed the following patch: http://cgit.freedesktop.org/xorg/xserver/commit/?id=bdd1e22cbde9ea2324e4e1991c9e152f22f88151

After patching, recompiling and writing a few lines in .xinitrc I am now able to use my NVidia card behind the Intel GMA. Actual Optimus doesn't work though, but you can't have it all, I guess.

----------

## cyberjun

What do you mean by active VT? I run startx from VT1 and run xrandr from VT2 after setting the DISPLAY variable appropriately. xorg.conf works, since the session starts properly but the display remains black. I can confirm this by running ps. All xfce processes start properly. 

However, as soon as I run the xrandr --serprovideroutputsource command, X server segfaults.  :Sad: 

Also, if I put these commands in .xinitrc, X segfaults immediately after it starts.

Is the patch you are talking about present in xorg-server-1.14.3-r2? I am using nvidia-drivers-331.38.

--cyberjun

----------

