|
|
#1 | |
|
Registered User
Join Date: Sep 2003
Posts: 57
|
I've known about this driver bug for a while, and I'm bringing it up now with hopes that it'll be fixed. The problem is that when the GLX function glXSwapBuffers waits for the vblank interval, the glFinish and glXWaitGL functions seem to use a busy-loop to wait for the buffer swap, causing 100% CPU usage. I've attached a small sample program to reproduce the problem. It can be compiled as follows:
Code:
$ gcc glbusy.c -o glbusy -lX11 -lGL Run the application with vsync enabled in nvidia-settings or with Code:
__GL_SYNC_TO_VBLANK=1 ./glbusy This bug affects situations where a GL window is encapsulated inside another GL window, like running OpenGL applications on a window compositor. For 1:1 frame-to-frame correspondence, a compositor needs to know that the framebuffers of the child-windows are complete/swapped before deriving the textures from them. Either glFinish or glXWaitGL is needed because glFlush and friends don't make this guarantee. glXSwapBuffers only provides an implicit glFlush. I've attached a nvidia-bug-report.log, also, for completeness. ![]() |
|
|
|
|
|
|
#2 | |
|
Registered User
Join Date: Nov 2007
Posts: 18
|
Try setting 'Option "UseEvents" "on"' in your Screen section. The busyloop will be replaced by a poll() system call.
|
|
|
|
|
|
|
#3 |
|
Registered User
Join Date: Sep 2003
Posts: 57
|
|
|
|
|
|
|
#4 | |
|
Registered User
Join Date: Nov 2007
Posts: 18
|
You know, I spoke too fast, I just enabled that option myself and ran your test to find the same behavior. I must admit my naïvete, however; I added a call to glXWaitVideoSyncSGI(1, 0, .. ) between glXSwapBuffers and glWaitGL() and glbusy no longer consumed 100% CPU. Placing glXWaitVideoSyncSGI() before the glXSwapBuffers() or after the glWaitGL() glbusy only consumed 50% CPU. To be perfectly honest, I don't know where the glXWaitVideoSyncSGI() call belongs.
Also, I'm too inexperienced to divine if this information is actually helpful to you or not. I apologise. |
|
|
|
|
|
|
#5 |
|
Registered User
Join Date: Nov 2007
Posts: 18
|
I should add, the first case I described with the glXWaitVideoSyncSGI between the glXSwapBuffers and the glXWaitGL() calls consumed so little cpu time that it failed to register on the output of top.
|
|
|
|
|
|
#6 | |
|
Registered User
Join Date: Sep 2003
Posts: 57
|
Quote:
|
|
|
|
|
|
|
#7 |
|
Registered User
Join Date: Sep 2003
Posts: 57
|
I still see this in drivers as recent as the 190.xx set. I've since noticed this problem can be lessened by using __GL_YIELD="USLEEP", with which it uses about 3% of the CPU instead of 99%.
|
|
|
|
|
|
#8 |
|
NVIDIA Corporation
Join Date: Mar 2005
Posts: 2,487
|
I should point out that this is not a bug: the spec does not require a particular maximum CPU usage when these functions are called. However, conserving a CPU would be a useful feature request, so I'll see if I can reproduce the issue and will file a feature request.
|
|
|
|
|
|
#9 | |
|
Registered User
Join Date: Nov 2009
Posts: 1
|
Quote:
The same issue is present today. I have written a simple openGL texturing benchmark application that can be copiled easily on Linux: http://pastebin.com/f5f9c076f Running with: $ ./glfwTexture top says the process consumes a CPU core to about 100% Running with: $ __GL_YIELD="USLEEP" ./a.out top says the process consumes a CPU core to about 5% Both cases make about 30 FPS. The only difference is CPU usage. I believe it is a bug. Is there a standard way to configure openGL to wait GPU idling the CPU so that other threads may use it? I am using NVIDIA driver version 190.42 on "Linux xxx 2.6.31-15-generic #50-Ubuntu SMP Tue Nov 10 14:53:52 UTC 2009 x86_64 GNU/Linux". My GPU hardware is: GeForce 9400 GT |
|
|
|
|
|
|
#10 |
|
Registered User
Join Date: Apr 2011
Posts: 1
|
FYI, if anyone is in a position to fix this, an easy way to sleep precisely and fairly reliably without burning 100% cpu is to nanosleep() or similar for perhaps 100 micro seconds less than the actual sleep time required, then to busy wait until the exact time. Not sure if this is applicable in waiting for vsync, depends whether the time of next vsync can be predicted with any accuracy. It should be possible.
|
|
|
|
![]() |
| Thread Tools | |
|
|