Skip to content

Instantly share code, notes, and snippets.

@abidibo
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abidibo/dfd0961667adb5f098c4 to your computer and use it in GitHub Desktop.
Save abidibo/dfd0961667adb5f098c4 to your computer and use it in GitHub Desktop.

NVIDIA OPTIMUS

Two graphic cards:
a typical platform includes both a lower-performance integrated unit by Intel and a high-performance one by Nvidia. Optimus should save battery life by automatically switching the power of the discrete graphics processing unit (GPU) off when it is not needed and switching it on when needed again.

Is this my case?

Run

$ lspci -vnn | grep '\''[030[02]\]'
00:02.0 VGA compatible controller [0300]: Intel Corporation 3rd Gen Core processor Graphics Controller [8086:0166] (rev 09) (prog-if 00 [VGA controller])
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GF108M [GeForce GT 635M] [10de:0de3] (rev ff) (prog-if ff)

Then yes, this is my case.

Problem

Ubuntu default installation doesn't manage optimus cards. So power consumption is maximum because the GPU is always ON even if not used.

Bumblebee

Install Bumblebee which will provide two interesting things:

  1. power off and on the GPU when needed
  2. provides a command (optirun, or primusrun for ubuntu>13.04) to use to run applications with the GPU enabled (games for examples)

How to install

Follow: https://wiki.ubuntu.com/Bumblebee

But some problems are round the corner: nvidia-current at the time of this writing is the nvidia-304, and doesn't work with my graphic card. So:

$ sudo apt-get uninstall nvidia-304
$ sudo apt-get install nvidia-319
$ sudo reboot

###Is bumblebee running?

$ ps ax | grep bumbl
 1355 ?        Ss     0:00 /usr/sbin/bumblebeed --use-syslog --driver nvidia --driver-module nvidia-331 --ldpath /usr/lib/nvidia-331:/usr/lib32/nvidia-331 --module-path /usr/lib/nvidia-331/xorg,/usr/lib/xorg/modules
 7296 pts/8    S+     0:00 grep --color=auto bumbl

Yes, it is running.

Is my GPU on or off?

Run

$ cat /proc/acpi/bbswitch 
0000:01:00.0 OFF

Is off.

How to test

Install one package:

$ sudo apt-get install mesa-utils

Notice: glxgears IS NOT A TOOL TO TEST PERFORMANCE!

Run

$ glxinfo | grep render
GLX_MESA_multithread_makecurrent, GLX_MESA_query_renderer, 
GLX_MESA_multithread_makecurrent, GLX_MESA_query_renderer, 
OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile 
GL_NV_conditional_render, GL_NV_depth_clamp, GL_NV_packed_depth_stencil, 
GL_NV_blend_square, GL_NV_conditional_render, GL_NV_depth_clamp, 

Here the intel card is used. Now run:

$ optirun glxinfo | grep render
direct rendering: Yes
OpenGL renderer string: GeForce GT 635M/PCIe/SSE2
GL_NVX_conditional_render, GL_NVX_gpu_memory_info, 
GL_NV_conditional_render, GL_NV_copy_depth_to_color, GL_NV_copy_image, 
GL_NV_parameter_buffer_object2, GL_NV_path_rendering, 
GL_NVX_conditional_render, GL_NVX_gpu_memory_info, 
GL_NV_conditional_render, GL_NV_copy_depth_to_color, GL_NV_copy_image, 
GL_NV_parameter_buffer_object2, GL_NV_path_rendering, 

GeForce is used, good. Direct rendering: Yes => 3D acceleration should work.

glxgears

In my case:

abidibo@abidibook:~$ glxgears
Running synchronized to the vertical refresh.  The framerate should be
approximately the same as the monitor refresh rate.
304 frames in 5.0 seconds = 60.709 FPS
300 frames in 5.0 seconds = 60.000 FPS

Framerate is as monitor refresh 'cause vsync is enabled. Same fps with optirun and primusrun. Now:

abidibo@abidibook:~$ vblank_mode=0 glxgears
ATTENTION: default value of option vblank_mode overridden by environment.
ATTENTION: default value of option vblank_mode overridden by environment.
34864 frames in 5.0 seconds = 6972.702 FPS
35187 frames in 5.0 seconds = 7037.238 FPS
XIO:  fatal IO error 11 (Resource temporari

quite better. Now:

abidibo@abidibook:~$ vblank_mode=0 optirun glxgears
6621 frames in 5.0 seconds = 1324.179 FPS
6710 frames in 5.0 seconds = 1341.815 FPS

Lower! Now:

abidibo@abidibook:~$ vblank_mode=0 primusrun glxgears
ATTENTION: default value of option vblank_mode overridden by environment.
11733 frames in 5.0 seconds = 2346.447 FPS
12762 frames in 5.0 seconds = 2552.211 FPS

Lower than without primusrun!

So it doensn't work! NO, probably it works:
https://github.com/Bumblebee-Project/Bumblebee/wiki/FAQ#why-do-i-get-a-much-lower-fps-with-optirun-glxgears-in-comparison-with-just-glxgears

What can I do? Install and use glxspheres. How? Continue reading.

glxspheres

Ubuntu 14.04 LTS no more in repositories. Goto:

http://sourceforge.net/projects/virtualgl/files/2.3.3/

and download the virtualgl_2.3.3_amd64.deb package (http://sourceforge.net/projects/virtualgl/files/2.3.3/virtualgl_2.3.3_amd64.deb/download).

Then:

$ cd Download
$ sudo dpkg -i --force-depends virtualgl_2.3.3_amd64.deb
$ sudo apt-get -f install

Run:

$ vblank_mode=0 /opt/VirtualGL/bin/glxspheres64 
Polygons in scene: 62464
ATTENTION: default value of option vblank_mode overridden by environment.
ATTENTION: default value of option vblank_mode overridden by environment.
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: Mesa DRI Intel(R) Ivybridge Mobile 
235.582537 frames/sec - 262.910111 Mpixels/sec
199.061091 frames/sec - 222.152178 Mpixels/sec
199.543329 frames/sec - 222.690355 Mpixels/sec
198.332512 frames/sec - 221.339084 Mpixels/sec


$ primusrun /opt/VirtualGL/bin/glxspheres64 
Polygons in scene: 62464
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: GeForce GT 635M/PCIe/SSE2
62.378227 frames/sec - 69.614101 Mpixels/sec
59.999542 frames/sec - 66.959489 Mpixels/sec

Mmmm, like without primusrun, smells like vsync is activated, run

$ vblank_mode=0 primusrun /opt/VirtualGL/bin/glxspheres64 
ATTENTION: default value of option vblank_mode overridden by environment.
ATTENTION: default value of option vblank_mode overridden by environment.
Polygons in scene: 62464
ATTENTION: default value of option vblank_mode overridden by environment.
ATTENTION: default value of option vblank_mode overridden by environment.
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: GeForce GT 635M/PCIe/SSE2
ATTENTION: default value of option vblank_mode overridden by environment.
ATTENTION: default value of option vblank_mode overridden by environment.
224.974213 frames/sec - 251.071222 Mpixels/sec
232.535877 frames/sec - 259.510038 Mpixels/sec
228.921051 frames/sec - 255.475893 Mpixels/sec
229.269872 frames/sec - 255.865177 Mpixels/sec

With PRIMUS_SYNC=1:

$ vblank_mode=0 PRIMUS_SYNC=1 primusrun /opt/VirtualGL/bin/glxspheres64 
Polygons in scene: 62464
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: GeForce GT 635M/PCIe/SSE2
242.250115 frames/sec - 270.351128 Mpixels/sec
246.393936 frames/sec - 274.975633 Mpixels/sec
246.691599 frames/sec - 275.307825 Mpixels/sec
245.455787 frames/sec - 273.928659 Mpixels/sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment