Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Cpu-usage in blocking gl-calls.  (Read 921 times)
0 Members and 1 Guest are viewing this topic.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Posted 2005-06-28 21:09:41 »

Imagine this piece of code:

1  
2  
3  
4  
5  
6  
7  
// Render Thread

while(true)
{
    glCallList(x);
    Display.update();
}


Because the display-list is huge, the framerate is rather low (10fps). Both the glCallList() and update() are blocking big-time, which is to be expected.




For me this results in CPU-usage of 100% while the CPU should be doing basicly nothing. I would be able to understand it, if OpenGL-drivers or LWJGL were yield()ing while waiting for the GPU to finish the operation, so I made a testcase to check if this was the case: I launch a thread which is burning all available cpu-cycles:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
// Math Thread

while(true)
{
                  long t0 = System.nanoTime();

                  final int count = 32 * 1024 * 1024;
                  double value = 0.0;

                  for (int i = 0; i < count; i++)
                  {
                     value = Math.sqrt(value) + i;
                  }

                  long t1 = System.nanoTime();
                  System.out.println("took: " + ((t1 - t0)/1000000) + "ms (value=" + value + ")");
}





Result:
Below follows a table with performance data for both threads. If there is a "-" that means that thread is not started.

1  
2  
3  
4  
5  
                    Render Thread              Math Thread

Case A:          10FPS thus 100% cpu      -      thus   0% cpu
Case B:          -     thus   0% cpu      1200ms thus 100% cpu
Case C:          10FPS thus  50% cpu      2400ms thus  50% cpu*





Conclusion
In "Case C" both threads are running. Because the Math Thread takes twice as long in "Case C" as in "Case B" I conclude it gets half of the cpu-cycles, explaining the percentages in "Case C".

Hm...

So this all boils down to: why are 50% of the cpu-cyles consumed (not idle, not yielding) while blocking on the 2 methods in the Render Thread?


~~
On a side-note. From the table you can also conclude that if the Render Thread is the only running thread, it's yielding 50% it' time, and actually doing *something* 50% of its time - as it can giveup only 50% of it's time to the Math Thread while maintaining it's framerate.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (28 views)
2014-09-21 02:42:18

BurntPizza (18 views)
2014-09-21 01:30:30

moogie (19 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (45 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (100 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56

mitcheeb (71 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!