24 February 2013

Dell XPS 15 L502X Optimus Graphics under Ubuntu 12.04


Firstly I apologise for the quality of this article, its somewhere between the quality of the notes that I usually write for myself to keep track of instructions like this, and the quality that I publish so others can follow the logic. I'm a bit out of time at the moment, but thought these instructions could be of use to more people than just myself so I thought that I'd put in some effort to get them out...but only just so much effort.

Its been a while since I've played around trying to get the NVIDIA card in this laptop to play nicely under Linux and I thought I'd give it another spin. This laptop has Optimus which when it was released meant there were quite limited options in terms of getting NVIDIA GPU working. I played around with it a little bit back then, but the bumblebee project was really in its infancy, and getting it all installed and working was quite painful. Whilst I found things are still more complicated than they need to be obviously the bumblebee team have done a huge amount of work to get things working this well as they do now. Unfortunately the install process from Ubuntu on this laptop is still a little more difficult than it needs to be, so I've taken the time to list some notes on how I managed to get everything working.


Overview


To the best of my understanding the following diagram explains how the graphics hardware in this laptop is connected (apologies for the quality of the diagram, but hopefully its enough to convey the message).


By running the following command you can examine the hardware connection of both GPU's:

$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09)
01:00.0 VGA compatible controller: NVIDIA Corporation GF108 [GeForce GT 540M] (rev ff)


This means that if you have just the Intel GPU working you can get access to both the laptop display and the display port. If you have just the NVIDIA GPU enabled you can get the HDMI output to work. When Optimus is enabled content is rendered on the GPU and copied back to the Intel GPU for display on the laptop panel or display port. It seems that the bumblebee team are keen to get HDMI working whilst using bumblebee, but they arn't there yet.

This currently leaves you with two options: 
  • Intel - Bumblebee - Laptop display + Display Port: You can get the laptops internal display working and the display port working. You can even enable hardware rendering on the NVIDIA GPU using bumblebee to support Optimus for display on the either of these displays.
  • NVIDIA - HDMI: You can get the HDMI port working with all content rendered on the NVIDIA GPU.

Unfortunately presently you can't have both options working at the same time.


All of these instructions presume a fresh install of Ubuntu 12.04 (in my case 12.04.02), presumeably if you've done any other config there could be reminants of an old install that leave these instructions not working.


Intel - Bumblebee - Laptop display + Display Port


Installing Bumblebee to primarily use the Intel GPU and load the NVIDIA GPU selectively for GPU intensive applications.

The advantages of this method are that you can use both the internal laptop display and the display port simultaneously as well as the more powerful NVIDIA GPU when you need to and have bumblebee manage the power of the NVIDIA GPU so its not wasting as much power when it's idle.

Initially I essentially followed the bumblebee guide for intalling it under Linux which is fairly straight forward:
http://bumblebee-project.org/install.html#Ubuntu

Install Bumblebee:
$ sudo add-apt-repository ppa:bumblebee/stable
$ sudo apt-get update
$ sudo apt-get install bumblebee bumblebee-nvidia

This is where I found that the instructions let me down a bit. Unfortunately when installing the bumblebee package it asks to remove the following packages:

The following packages will be REMOVED:
  libgl1-mesa-dri-lts-quantal libgl1-mesa-glx-lts-quantal
  libglapi-mesa-lts-quantal libxatracker1-lts-quantal
  x11-xserver-utils-lts-quantal xserver-common-lts-quantal
  xserver-xorg-core-lts-quantal xserver-xorg-input-all-lts-quantal
  xserver-xorg-input-evdev-lts-quantal xserver-xorg-input-mouse-lts-quantal
  xserver-xorg-input-synaptics-lts-quantal xserver-xorg-input-vmmouse-lts-quantal
  xserver-xorg-input-wacom-lts-quantal xserver-xorg-lts-quantal
  xserver-xorg-video-all-lts-quantal xserver-xorg-video-ati-lts-quantal
  xserver-xorg-video-cirrus-lts-quantal xserver-xorg-video-fbdev-lts-quantal
  xserver-xorg-video-intel-lts-quantal xserver-xorg-video-mach64-lts-quantal
  xserver-xorg-video-mga-lts-quantal xserver-xorg-video-modesetting-lts-quantal
  xserver-xorg-video-neomagic-lts-quantal xserver-xorg-video-nouveau-lts-quantal
  xserver-xorg-video-openchrome-lts-quantal xserver-xorg-video-r128-lts-quantal
  xserver-xorg-video-radeon-lts-quantal xserver-xorg-video-s3-lts-quantal
  xserver-xorg-video-savage-lts-quantal
  xserver-xorg-video-siliconmotion-lts-quantal xserver-xorg-video-sis-lts-quantal
  xserver-xorg-video-sisusb-lts-quantal xserver-xorg-video-tdfx-lts-quantal
  xserver-xorg-video-trident-lts-quantal xserver-xorg-video-vesa-lts-quantal
  xserver-xorg-video-vmware-lts-quantal



This means that after reboot you're left in a state worse than before and you just be left with a black screen with no graphics driver loaded what so ever. Infact it leaves the system so screwed up that on boot you can't even ctrl+alt+f1 to switch to a tty.

...So where do you go from here...

Well if you're sensible you will reinstall the Intel drivers before you reboot and you'll happily be on your way.
$ sudo apt-get install xserver-xorg-video-intel





If you make the mistake that I did and reboot before you install the Intel driver you will be left with a black screen and you wont be able to log in what so ever. I found that while the system is still booting you can switch to one of the virtual consoles by pressing crtl+alt+f1, you must do this while the system is booting because once the system has reached the login state you can't swap back to the virtual console. Once you've got to the the virtual console login and just follow the instruction above. After this point you should be able to get x to start correctly:
$ sudo service lightdm start

(sometimes you need to reboot at this point to get x to start, I've even seen a couple of times where two restarts are required before everything gets going correctly)

After you login you should be able to run bumblebee using:
$ optirum glxspheres



Configuration files:

/etc/X11/xorg.conf
/etc/bumblebee/*

 

 

NVIDIA - HDMI


If you don't care about the laptop display / display port / Optimus / Bumblebee / Power managment and just want to get the NVIDIA card running displaying on HDMI using the most up to date driver from NVIDIA.


Download the latest driver from NVIDIA currently 310.32:
Install the kernel sources (the driver warns you about this if you forget and get part way through and need them):
$ sudo apt-get install linux-headers-generic

Stop X running:
$ sudo service lightdm stop


Switch to a virtual console, (Ctrl + Alt + F1) then login.



Make the driver installer executable:
$ chmod +x NVIDIA-Linux-x86_64-310.32.run

Run the installer:
$ ./NVIDIA-Linux-x86_64-310.32.run


The NVIDIA driver sets up everything you need, with one exception. Because there are two GPU's in the machine you need to tell the x configuration which card you want the driver to be applied to. If you reboot now without updating the xorg configuration the driver wont be loaded correctly. In this case you need to update the xorg.conf file to tell it which device to load the nvidia driver for.

To do this use your faviourite text editor [vi / nano / etc]
$ vi /etc/X11/xorg.conf

Add the following line to the device section:
BusId          "PCI:1:0:0"

E.g.
Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BusId          "PCI:1:0:0"
EndSection


After which you should be able to reboot and have the display work nicely on HDMI. You will notice in the NVIDIA settings there there will be two displays shown CRT-0 and the display connected to your HDMI port. I presume that the CRT display is an artifact of how the NVIDIA GPU connecters to the Intel GPU. In any case I would recommend disabling this display when you are using it in this configuration because its unneeded.



When debugging I found the best log files to find out what was going on:
/var/log/Xorg.0.log
/var/log/Xorg.8.log
/var/log/syslog
/var/log/kern.log
/var/log/nvidia-installer.log
[Only when installing the NVIDIA driver]


Useful information:
http://askubuntu.com/questions/36930/how-well-do-laptops-with-nvidia-optimus-work
http://bumblebee-project.org/install.html#Ubuntu
https://github.com/Bumblebee-Project/Bumblebee/wiki/FAQ
https://github.com/Bumblebee-Project/Bumblebee/wiki/Troubleshooting
http://www.webupd8.org/2012/11/primus-better-performance-and-less.html