Search This Blog

Tuesday, March 24, 2015

How does Bumblebee work with Optimus NVIDIA GPU

How does Bumblebee work with Optimus NVIDIA GPU


What is bumblebee? Sounds like the name of an Insect or perhaps you would recognize it with the Transformer Series of Movies. The yellow Car which uses the voices from the Car's Audio system, to talk to people. Well all this is true, However What I am referring to is entirely different and it concerns Linux. Especially Linux on Computers with the Optimus Graphic Cards from Nvidia. These systems are very different from the traditional single graphics Card systems. In Traditional systems what would happen on the desktop and laptop computers is that, you would have only one graphics card. Either an Integrated graphics card or a dedicated graphics card.

What if your system had the option of having both types of cards. I mean if a computer had an Integrated graphics card capable enough of running most of the graphics stack on your computer, and onother dedicated Card to handle the heavy duty gaming stuff, How would things be then ? How would one manage the graphics cards and their settings then?

This is mostly achieved in modern hardware by using a combination of an Intel Integrated GPU and a secondary discrete NVIDIA gpu. The technology is called as Optimus. Well most of the latops these days come with the NVIDIA/INTEL Optimus setup. However having the technology at the hardware level only is not sufficient. We need to have a software stack which would then use the technology within the Operating Systems. How do we achieve this? and Quite Frankly Microsoft Windows leads in this area as the most widely used Desktop operating system hence with windows, The Optimus Technology is quite well supported out of the box wth almost zero effort on the user's part. Whenever a graphics intensive application is launched the system automatically switches to the more powerful NVIDIA GPU. Which is great as the user gets great performance without having to worry about anything. When there is no need for the NVIDIA GPU, the System automatically switches back to the Intel Integrated GPU. The result being more efficient utilization of the system resources and Improved battery life with optimum performance for you graphic intensive applications.

Well that is how it was supposed to work. However that is true only on the windows side of the world. We know MS Windows is not the end of the world. So we now talk a bit about Linux. With Linux the road is a bit bumpy, however we also have a perfect solution for Linux. We rather have two solutions to the same problem. I will cover both in this POST.

We need to understand one basic fact that with Linux, the automatic switching from Intel to NVIDIA GPU and Vice Versa is not yet supported. We can switch however user intervention is needed. Apart from this there is no other caveat to this.

The First Option is called NVIDIA PRIME. Under NVIDIA Prime, One Installs nvidia drivers alongwith the nvidia prme and nvidia-settings. In this method Nvidia-Settings program is used to switch between the driver. One can use only on GPU at one time. The Entire System will use on GPU at one time. We can Change and choose Which GPU we want however after selecting we need to logout of the session and start a new session. So this is a soluion requiring the least amount of configuration and consequently we have to live with the fact that we need to switch he graphic Card for the whole system and start a new session to use the newly selected GPU.(This works only with Nvidia Closed Source Drivers supplied by NVIDIA)

The Second Option is called the Bumblebee !! you hear it .. It is indeed called Bumblebee. Well I am not going to go into why it is called so, the fact of the matter is that it is a great solution to use in case you have the Optimus based hardware like I have. It allows you to select the GPU at run time by selecting which application you would want to run on the dedicated GPU. Yes it is true. You can launch applications to use a the high power NVIDIA GPU. By default the system always uses the Integrated Intel GPU. However when needed you can launch a application specifically targeting the NIDIA GPU.Not only that this works well with NVIDIA Closed Source Drivers but with the nuoveau Open Source Drivers as well.

I am going to be elaborating a more on the Bumblebee Stuff as there is still a lot of confusion for the new users to Linux as to how it exactly works. Bumblebee is a very Interesting piece of software. It is however often misunderstood and hence not everyone prefers it. But I strongly recommend it. Almost all Linux Distros have a small wiki dedicated to how to get Bumblebee working. There is a special case of Ubuntu and anything based on Ubuntu that I would like to point this article to.

If there is a new user ever starting the switch from Other Operating Systems to Linux, there is a high chance that he will land on to a Ubuntu or Ubuntu Spin. If the user has an Optmus Laptop then things become really Interesting. The user is used to out of box experiences and Linux in this case does not offer one. So there needs so be a specific wiki/documentation for this. There is however i personally believe it is not sufficient. There are some specfics which I think are still not covered in any Wiki for Ubuntu. I am going to focus on Ubuntu beause I fee Ubuntu documentation on bumblebee is poor.

Ok let us Understand the Operation and how it to be correctly configured.

While using Bumbelee to control the Optimus/Hybrid graphics on a laptop we must understand that Bumblebee takes total control of the Driver or the Nvidia Graphics Card. This means that Bumblebee Daemon controls the loading and unloading of the Driver. The Module for Loading the Graphics Drivers for Nvidia Cards, Namely Nouveau and nvidia-XXX driver is to be controlled by Bumblebee.

So here is a few things one needs to ensure while configuring bumblebee on Ubuntu. We need to ensure that the Driver/Kernel Module for the NVIDIA CARD is completely Blacklisted so that it never loads automatically. We want bumblebee to completely control this card.
This can be done as below.

  1. Blacklist Noueau Driver so it does not load automatically. (This is generally done Automatically by the Bumblebee Install.) Config Files to look at. /etc/modprobe.d/nvidia-XXX_hybrid.conf in case you Installed your Nvidia Proprietary Drivers alongwith Bumblebee. If you do not plan on using only Noveau, Then you must manually create a /etc/modprobe.d/blacklist-nouveau.conf and add one line to it, blacklist nouveau.
  2. Blacklist the NVIDIA-XXX Driver , We need to ensure that the NVIDIA-XXX driver needs to stay blacklisted as well. This most likely shoul happen automatically however if you are using any driver newer thatn Nvidia-331, Then it is a good option to look in /etc/modprobe.d/bumblebee.conf. This file is automatically generated while Installing Nvidia Graphics Drivers after installing Bumblebee. If you do not see the driver you are using in the file, you must add it manually. 
  3. Automatically load i915 Driver for Intel card. We need to add bbswitch and i195 to the /etc/modules file. This is because we want the bbswitch module to load automatically, this is what actually turns on and off the Nvidia Graphics Card. We also want that the Intel Integrated Card to be in use always so we add that to the file.

The above three steps ensure that we have only Intel Card enabled by default and Nvidia Drivers completely removed from getting automatically loaded. We also are loading he bbswitch module automatically which will actually switch the Nvidia Gaphics Cad ON and OFF when launching any program using optirun or primusrun prefix from the terminal. These two are the commands that need to be prefixed while launching wine or Steam depending on which of these you use or gaming. Or any other program which needs some Juice from the Nvidia Graphics Card.

Configure Bumblebee to use your Nivida-Drivers

The Only other piece of configuration that needs to be done is as below.

sudo gedit /etc/bumblebee/bumblebee.conf

1. line 22:

Driver=nvidia

2. line 55:

KernelDriver=nvidia-331

3. line 58:

LibraryPath=/usr/lib/nvidia-331:/usr/lib32/nvidia-331

4. line 61:

XorgModulePath=/usr/lib/nvidia-331/xorg,/usr/lib/xorg/modules

5. Reinstall bbswitch-dkms:

sudo apt-get install --reinstall bbswitch-dkms

6. Reboot

Note:- Just ensure that you replace nvidia-331 with the driver you have Installed.

If you are planing to use Nouveau driver then you don't need the above configuration, I will automatially work with Nouveay driver.

I now hope that after readin this post, many Ubuntu Users will understand the Bumblebee Concepts Clearly.

Friday, March 13, 2015

How to install Bumblebee on Ubuntu 15.04/14/04 and Derivatives on Laptops with Optimus Nvidia Cards


How to install Bumblebee on Ubuntu 15.04/14/04 and Derivatives on Laptops with Optimus Nvidia Cards

Nvidia Optimus technology is something that is not completely supported out of the box. I have recently purchased a Lenovo Z50 laptop which has a 2GB NVIDIA GE FORCE GT820M. This is an entry level gaming card but can play most games without issues.

So I was happy with my purchase. Since I am a Linux Power User I immediately got rid of Windows and installed Ubuntu on it. However to my surprise I always got a black screen after installing Nvidia proprietary drivers.

Bumblebee would also throw errors . After 2 weeks or breaking my head against the wall an formatting my laptop 5 times now I am back. I have been able to successfully install the nvidia drivers and configure bumblebee as well.

I LOVE LINUX..

Below are the steps I took to get things working for myself. I am sharing this to make things easier for others.


1) Install Bumblebee from the Official Ubuntu Repositories.

Sudo apt-get install bumblebee bumblebee-nvidia  --– This installs bumblebee.
dkms status-- This tels whch ersion of bbswitch and kernel is installed
sudo apt-get install bbswitch-dkms - Install bbswitch dkms
sudo apt-get install primus
sudo systemctl enable bumblebeed ( Ubuntu 15.04 Since it uses systemd now)
sudo gpasswd -a $USER bumblebee

2) Add the following lines to the /etc/modules file
i915
bbswitch

I am using Ubuntu 15.04 beta and it has switched to Systemd so I have added these two into this file.
/etc/modules-load.d/modules.conf

3) Now We need to blacklist nouveau module, we need to do it event though we might need to use it later. This is important we want only bbswitch to load either the nouveau or nvidia drivers
/etc/modprobe.d/nouveau.conf OR /etc/modprobe.d/blacklist-nouveau.conf
just add one line to any of these files

blacklist nouveau

4) Reboot and then run
sudo cat /proc/acpi/bbswitch this shoud give a result as OFF

sudo echo ON > /proc/acpi/bbswitch

sudo cat /proc/acpi/bbswitch This should now give a result of ON

This confirms that BBSWITCH works.

6) One more reboot

Once rebooted if you run the command
primusrun glxinfo | grep OpenGL

You would see the OpenGL String points to
OpenGL vendor string: nouveau

This confirms that bumblebee is working fine and able to load the nouveau driver fine.

NOTE no need to edit the /etc/bumblebee/bumblebee.conf file as of yet as it is already configured for using nouveau drivers.


7) Now the really tricky part. Which means We need to install the Proprietary NVIDIA Drivers which Will override the nuoveau drivers.
IMPORTANT TO NOTE THAT THERE IS A BUMBLEBEE BLACKLIST FILE BY DEFAULT IN THE FOLDER.

/etc/modprobe.d/

bumblebee.conf

Contents of this file are

sudo cat /etc/modprobe.d/bumblebee.conf
# installed by bumblebee-nvidia
# to be used by kmod / module-init-tools, and installed in /etc/modprobe.d/
# or equivalent

# do not automatically load nouveau as it may prevent nvidia from loading
blacklist nouveau
# do not automatically load nvidia as it's unloaded anyway when bumblebeed
# starts and may fail bumblebeed to disable the card in a race condition.
blacklist nvidia
blacklist nvidia-current
blacklist nvidia-current-updates
# 304
blacklist nvidia-304
blacklist nvidia-304-updates
blacklist nvidia-experimental-304
# 310
blacklist nvidia-310
blacklist nvidia-310-updates
blacklist nvidia-experimental-310
# 313
blacklist nvidia-313
blacklist nvidia-313-updates
blacklist nvidia-experimental-313
# 319
blacklist nvidia-319
blacklist nvidia-319-updates
blacklist nvidia-experimental-319
# 325
blacklist nvidia-325
blacklist nvidia-325-updates
blacklist nvidia-experimental-325
# 331
blacklist nvidia-331
blacklist nvidia-331-updates
blacklist nvidia-experimental-331
# 334
blacklist nvidia-334
blacklist nvidia-334-updates
blacklist nvidia-experimental-334
# 337
blacklist nvidia-337
blacklist nvidia-337-updates
blacklist nvidia-experimental-337
# 340
blacklist nvidia-340
blacklist nvidia-340-updates
blacklist nvidia-experimental-340
#343
blacklist nvidia-343
blacklist nvidia-343-updates
blacklist nvidia-experimental-343

This is a problem specific to Ubuntu and its derivatives only.(Sorry for this earlier I posted that one needs to uncomment the Driver in above file which is not true.)

So if you see the contents of this file reveal that no matter what you do you can't get succes in getting bumbleebee work with any of the nvidia drivers unless you Ensure that your Driver is listed above and blacklisted.

This will ensure that the driver Is not loaded automatically. If it loads automatically, you will have a BLACK SCREEN at boot.

Bumblebee needs to be controlling the Loading and Unloading of the NVIDIA DRIVER MODULE.

Or example i am using the 340 series of drivers so My drivers were already blacklisted.

blacklist nvidia-340
blacklist nvidia-340-updates
blacklist nvidia-experimental-340

Now you can edid the bumblebee.conf as below.

Sudo gedit /etc/bumblebee/bumblebee.conf

1. line 22:

Driver=nvidia

2. line 55:

KernelDriver=nvidia-331

3. line 58:

LibraryPath=/usr/lib/nvidia-331:/usr/lib32/nvidia-331

4. line 61:

XorgModulePath=/usr/lib/nvidia-331/xorg,/usr/lib/xorg/modules

5. Reinstall bbswitch-dkms:

sudo apt-get install --reinstall bbswitch-dkms

6. Reboot

NOTE :- You neeed to make sure that you place the nvidia-331 with whatever driver version you have installed in previous steps and the one you uncommented from the bbswitch.conf file under /etc/modprobe.d/bumblebee.conf

In my case below is what my bumblebee.conf looks like.



# Configuration file for Bumblebee. Values should **not** be put between quotes

## Server options. Any change made in this section will need a server restart
# to take effect.
[bumblebeed]
# The secondary Xorg server DISPLAY number
VirtualDisplay=:8
# Should the unused Xorg server be kept running? Set this to true if waiting
# for X to be ready is too long and don't need power management at all.
KeepUnusedXServer=false
# The name of the Bumbleblee server group name (GID name)
ServerGroup=bumblebee
# Card power state at exit. Set to false if the card shoud be ON when Bumblebee
# server exits.
TurnCardOffAtExit=false
# The default behavior of '-f' option on optirun. If set to "true", '-f' will
# be ignored.
NoEcoModeOverride=false
# The Driver used by Bumblebee server. If this value is not set (or empty),
# auto-detection is performed. The available drivers are nvidia and nouveau
# (See also the driver-specific sections below)
Driver=nvidia
# Directory with a dummy config file to pass as a -configdir to secondary X
XorgConfDir=/etc/bumblebee/xorg.conf.d

## Client options. Will take effect on the next optirun executed.
[optirun]
# Acceleration/ rendering bridge, possible values are auto, virtualgl and
# primus.
Bridge=auto
# The method used for VirtualGL to transport frames between X servers.
# Possible values are proxy, jpeg, rgb, xv and yuv.
VGLTransport=proxy
# List of paths which are searched for the primus libGL.so.1 when using
# the primus bridge
PrimusLibraryPath=/usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus
# Should the program run under optirun even if Bumblebee server or nvidia card
# is not available?
AllowFallbackToIGC=false


# Driver-specific settings are grouped under [driver-NAME]. The sections are
# parsed if the Driver setting in [bumblebeed] is set to NAME (or if auto-
# detection resolves to NAME).
# PMMethod: method to use for saving power by disabling the nvidia card, valid
# values are: auto - automatically detect which PM method to use
# bbswitch - new in BB 3, recommended if available
# switcheroo - vga_switcheroo method, use at your own risk
# none - disable PM completely
# https://github.com/Bumblebee-Project/Bumblebee/wiki/Comparison-of-PM-methods

## Section with nvidia driver specific options, only parsed if Driver=nvidia
[driver-nvidia]
# Module name to load, defaults to Driver if empty or unset
KernelDriver=nvidia-340
PMMethod=auto
# colon-separated path to the nvidia libraries
LibraryPath=/usr/lib/nvidia-340:/usr/lib32/nvidia-340
# comma-separated path of the directory containing nvidia_drv.so and the
# default Xorg modules path
XorgModulePath=/usr/lib/nvidia-340/xorg,/usr/lib/xorg/modules
XorgConfFile=/etc/bumblebee/xorg.conf.nvidia

## Section with nouveau driver specific options, only parsed if Driver=nouveau
[driver-nouveau]
KernelDriver=nouveau
PMMethod=auto
XorgConfFile=/etc/bumblebee/xorg.conf.nouveau

=======================================================================
So please make changes to your files accordingly..

Now the final Reboot.

After the reboot you can now test

Run the command

primusrun glxinfo | grep OpenGL


primusrun glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 820M/PCIe/SSE2
OpenGL core profile version string: 4.4.0 NVIDIA 340.76
OpenGL core profile shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.4.0 NVIDIA 340.76
OpenGL shading language version string: 4.40 NVIDIA via Cg compiler
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:

So now my Laptop is using the Nvidia Optimus technology with the 340 Series Nvidia Proprietary Driver.

I Hope this helps people..

I have used the below two articles to reach this solution.


My OS :- Ubuntu 14.04.2

Laptop :- Lenovo Z50
Nvidia:- GE GFORCE GT 820M
COREI5 4th gen with Haswell graphics.
4GB RAM

Regards
Rajat Pandita