Wednesday, January 11, 2012

Tri-head display on linux Thinkpad W520 (Graphics Adventures)

Note: while all the stuff in this post is still accurate and it is a useful reference, I think that most people will find the solution presented here more useful.

                                                                                                               

Since I got my Thinkpad W520 back in October, I have been in for an adventure in learning about the graphics. One of the reason's that I chose the W520 (and this is only one of many - it is an awesome machine) is that it was advertised to support two external monitors for a total of three including the Thinkpad display (now I know that some T-series can support four with the dock though). Earlier this week, I finally had two monitors in the same place to play with and had amassed the knowledge needed to get it all working right on Linux. I am a Linux noob, so this was a long journey that taught me a great deal about graphics hardware, the open-source world, and the insides of my beloved W520.



Here's what I know in hopes that it will help some other W520 users (and maybe some people using other similar systems):

The W520 uses a system called nvidia Optimus. You can find out more about it here, but basically it means that the Thinkpad Display is always controlled by the intel integrated card. When Windows 7 runs a program with demanding graphics, the nvidia card does the rendering and dumps the output to the intel card to display on the screen.

I am pretty happy with the Lenovo engineers because they give the user the option to disable nvidia Optimus in favor of either the nvidia discrete or intel integrated graphics. In the BIOS (Access by holding F12 when the "Thinkpad" splash screen is displaying at startup), there are three options for the display configuration (note: the OS detection option appears to make the setting go to "nvidia optimus" when linux is running. This is usually not the desired behavior, so I recommend disabling OS detection).

Here are descriptions of the three options:

Integrated - Runs only the intel integrated graphics chip. Here the integrated intel chip controls only the Thinkpad display on the W520. (It seems that on the T420 and T520, the integrated card is also connected to the VGA output, but I have no way of verifying this)

                             __________________
                            | ---------------- |
                            ||                ||
                            ||    Thinkpad    ||
                            ||    Display     ||
                            ||                ||
                            ||________________||
                            --------------------
                                      \____________
                                                   \
                                  -----------       \
                                 \  NVIDIA    \      \
                                  \ Card (off) \      \
      Display Port                   -----------       \
                                                        \
                                          _______________\
                                          \            
                                       ----------        
      VGA Output                      \  Intel    \     
                                       \ Card      \   
                                         ----------- 


Discrete - Runs only the nvidia discrete graphics chip. The nvidia chip is connected to all three outputs, but sadly :,( it can only run two at a time (hence the '2/3' connection markings).

                             __________________
                            | ---------------- |
                            ||                ||
                            ||    Thinkpad    ||
                            ||    Display     ||
                            ||                ||
                            ||________________||
                            --------------------
                                      \            
                                      2/3          
                                        \          
                                  -----------       
                                 \  NVIDIA    \      
                                  \ Card       \       
      Display Port --2/3---          -----------        
                           \                \           
                            \________________\            
                             \                           
                              \        ----------       
      VGA Output ----2/3-------       \  Intel    \    
                                       \ Card (off)\  
                                         ----------- 


Nvidia Optimus - In this mode, both graphics cards are running. The Nvidia chip is connected directly to the external display connections and the intel chip is connected to the Thinkpad Display. In Windows 7, there is native support for the cards to communicate over the motherboard, so everything works out of the box. In linux, the support must come from extenal tools (there may be native support in the future). Bumblebee can be used to render things on the Nvidia card and display them through the intel card, and a program called screenclone (see instructions here and here) can be used to display a desktop rendered on the Intel card through the Nvidia card to the external monitors.

 
                             __________________
                            | ---------------- |
                            ||                ||
                            ||    Thinkpad    ||
                            ||    Display     ||
                            ||                ||
                            ||________________||
                            --------------------
                                      \           
                                       \__________           
                                                  \
                                  -----------      \
                               __\  NVIDIA    \     \
                               \  \ Card       \     \ 
      Display Port --------     \    -----------      \ 
                           \     \        \            \
                            \_____\    Motherboard      \
                             \              \            \
                              \        ----------         \
      VGA Output --------------       \  Intel    \________\
                                       \ Card      \  
                                         ----------- 


So, how do you use this information? Well, here are my recommendations for 3 different types of users:

1. "I want the best battery life!" (and I don't use a projector often)
Use the "Integrated" BIOS display setting. This will only ever run the Intel graphics card. As far as I can tell, you will have to go into the BIOS and change the setting if you want to connect to a projector, but it is definitely possible to get decent graphics performance (compiz, 3d acceleration, etc) off of just the intel card.

2. "I just want everything to look nice and work!"
Use the "Discrete" BIOS display setting. Get the Nvidia proprietary drivers:

$ sudo apt-get install nvidia-current
$ jockey-text -e xorg:nvidia_current

or download from http://www.nvidia.com/object/unix.html and run the file

and have fun with awesome performance! I have never had any problems with these settings, and using disper in conjunction with nvidia-settings to control external displays is a dream! I just feel happy when I think about this configuration! Battery life is honestly not that bad either - the nvidia drivers automatically underclock the card when usage is low.

[tip: to adjust the display brightness when using the nvidia drivers, press Ctrl-Alt-F1 to jump to a tty screen, adjust the brightness, then return to graphical mode using Ctrl-Alt-F7 or add the line
Option  "RegistryDwords" "EnableBrightnessControl=1"
to the device section of xorg.conf] 

3. "I want to be able to use up to 3 displays and turn off the nvidia card when running on battery!" (and I don't mind some extra configuration work)
Ok, so you want to unleash the full power and flexibility of your machine - you're ready to get serious. You definitely must use the "Nvidia Optimus" BIOS mode, which starts both graphics cards. The only way that I have figured out to run all three displays is to use Xinerama to create a single X session with the two external monitors running on the Nvidia card and the Thinkpad display running on the intel card. Using info from these two sites (site 1, site 2), I was able to piece together an xorg.conf file to make it happen. You can download the file here:


To use it, you have to completely exit your gnome/unity/kde/xfce session, including the login screen, and type

startx -- -config xorg.conf.triple.txt

or, if you want to start it automatically every time you start your computer (not recommended), rename it xorg.conf and put it in the correct place (/etc/X11 in my setup). In this configuration (since xrandr is disabled by Xinerama), the only way to change the number of screens is to completely log out of X and use different xorg.conf files for whatever number of screens you have. With this configuration, you can only get 3D hardware acceleration on the external screens running on the nvidia card, and I don't think that it is possible to get desktop effects such as those that are part of compiz running.

In the "Nvidia Optimus" BIOS mode, you can also save power by turning off the nvidia card when you are not using it. This can be accomplished using the bbswitch utility which is part of the Bumblebee project. If you are using ubuntu, you can get bbswitch from the bumblebee repository at https://launchpad.net/~bumblebee/+archive/stable . Instructions for using bbswitch can be found here.

I hope that this post has helped you to understand your computer better, and I hope that you are enjoying your W520 as much as I am!


Notes about my current configuration:
OS: kubuntu 12.04 64 bit
Driver for Intel card: "intel" (DRI (hardware acceleration) is disabled on this (I think because I have the nvidia proprietary driver installed))
Driver for Nvidia card: "nvidia" (proprietary driver 280.13)
Thinkpad model number: W520 4270CTO (with Nvidia Quadro 1000M)
BIOS Display Setting: Nvidia Optimus