title: Slow OpenGL context access on Ubuntu 12.4
body: <p>I have an application which accesses OpenGL context.I run it on 2 OSs :</p>
  
  <p>1.Kubuntu 13.4</p>
  
  <p>2.Ubuntu 12.4</p>
  
  <p>I am experiencing the following issue: on OS 1 it takes around 60 ms to setup the context, while on OS 2 it takes 10 times more.Both OSs use Nvidia GPUs with driver version 319.It also seems like OpenGL API calls are slower in general for OS 2.The contexts are offscreen.Currently I have no clue what could cause it.My question is what are possible sources of such an overhead?X11 setup?Or may be something on the OS level?</p>
  
  <p>Another difference is that OS 1 uses Nvidia GTX680 while OS2 uses Nvidia GRID K1 card.Also OS2 resides on a server and the latency tests are run locally on that machine.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>This is the part which causes most of overhead:</p>
  
  <pre><code>typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
  typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
  static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
  static glXMakeContextCurrentARBProc glXMakeContextCurrentARB = 0;
  
  int main(int argc, const char* argv[]){
      static int visual_attribs[] = {
              None
      };
      int context_attribs[] = {
              GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
              GLX_CONTEXT_MINOR_VERSION_ARB, 0,
              None
      };
  
      Display* dpy = XOpenDisplay(0);
      int fbcount = 0;
      GLXFBConfig* fbc = NULL;
      GLXContext ctx;
      GLXPbuffer pbuf;
  
      /* open display */
      if ( ! (dpy = XOpenDisplay(0)) ){
              fprintf(stderr, "Failed to open display\n");
              exit(1);
      }
  
      /* get framebuffer configs, any is usable (might want to add proper attribs) */
      if ( !(fbc = glXChooseFBConfig(dpy, DefaultScreen(dpy), visual_attribs, &amp;fbcount) ) ){
              fprintf(stderr, "Failed to get FBConfig\n");
              exit(1);
      }
  
      /* get the required extensions */
      glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB");
      glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc)glXGetProcAddressARB( (const GLubyte *) "glXMakeContextCurrent");
      if ( !(glXCreateContextAttribsARB &amp;&amp; glXMakeContextCurrentARB) ){
              fprintf(stderr, "missing support for GLX_ARB_create_context\n");
              XFree(fbc);
              exit(1);
      }
  
      /* create a context using glXCreateContextAttribsARB */
      if ( !( ctx = glXCreateContextAttribsARB(dpy, fbc[0], 0, True, context_attribs)) ){
              fprintf(stderr, "Failed to create opengl context\n");
              XFree(fbc);
              exit(1);
      }
  
      /* create temporary pbuffer */
      int pbuffer_attribs[] = {
              GLX_PBUFFER_WIDTH, 800,
              GLX_PBUFFER_HEIGHT, 600,
              None
      };
      pbuf = glXCreatePbuffer(dpy, fbc[0], pbuffer_attribs);
  
      XFree(fbc);
      XSync(dpy, False);
  
      /* try to make it the current context */
      if ( !glXMakeContextCurrent(dpy, pbuf, pbuf, ctx) ){
              /* some drivers does not support context without default framebuffer, so fallback on
               * using the default window.
               */
              if ( !glXMakeContextCurrent(dpy, DefaultRootWindow(dpy), DefaultRootWindow(dpy), ctx) ){
                      fprintf(stderr, "failed to make current\n");
                      exit(1);
              }
      }
  
      /* try it out */
      printf("vendor: %s\n", (const char*)glGetString(GL_VENDOR));
  
      return 0;
  }
  </code></pre>
  
  <p>Specifically , the line :</p>
  
  <pre><code>pbuf = glXCreatePbuffer(dpy, fbc[0], pbuffer_attribs);
  </code></pre>
  
  <p>where the dummy pbuffer is created is the slowest.If the rest of function calls take in average 2-4 ms,this call takes 40 ms on OS 1. Now , on OS2 (which is slow) the pbuffer creation takes 700ms! I hope now my problems looks more clear.</p>