Horde3D

Next-Generation Graphics Engine
It is currently 27.04.2024, 10:46

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: 13.10.2009, 16:20 
Offline

Joined: 15.08.2009, 11:34
Posts: 10
i tried to compile horde3d via cmake with gcc on windows, but the getTime() function of the Timer class

Code:
   #ifdef PLATFORM_WIN
      // Make sure that time is read from the same CPU
      DWORD_PTR threadAffMask = SetThreadAffinityMask( GetCurrentThread(), _affMask );

      // Avoid the reordering of instructions by emitting a serialization instruction
      #ifdef _MSC_VER
         _asm { CPUID };
      #else
         asm volatile("cpuid"); // <------ THIS LINE!
      #endif
      
      // Read high performance counter
      LARGE_INTEGER curTick;
      QueryPerformanceCounter( &curTick );

      // Restore affinity mask
      SetThreadAffinityMask( GetCurrentThread(), threadAffMask );

      return (double)curTick.QuadPart / (double)_timerFreq.QuadPart * 1000.0;


causes a crash in every application (for example the demos)

I have no idea what that assembler thing is doing, by commenting it out it works, but thats a dirty "solution" for that problem...

thanks, hs0


Top
 Profile  
Reply with quote  
PostPosted: 17.10.2009, 10:54 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
That asm instruction is used as a "serialization instruction". It guarantees that all instructions before which are still queued are finished before CPUID is executed. This should make sure that the timer query is at the right position in the program instruction stream and not somehow reordered. However, I am not sure if this serialization is really required.


Top
 Profile  
Reply with quote  
PostPosted: 18.10.2009, 05:18 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
On Windows/MSVC I would suggest using the intrinsic function _ReadWriteBarrier instead of an asm hack :wink:

These kinds of reordering instructions are generally only required for multi-core stuff. Seing Horde is a single-threaded library (at the moment?) we shouldn't need it (or the ThreadAffinity stuff either?)


Top
 Profile  
Reply with quote  
PostPosted: 18.10.2009, 15:21 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
***ignore me - I was thinking about another issue***

_________________
Tristam MacDonald - [swiftcoding]


Last edited by swiftcoder on 18.10.2009, 18:22, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: 18.10.2009, 16:47 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
The thread affinity is not directly related to threading in horde. Unfortunately, the whole windows performance timer is a bit messy. According to Microsoft (and many forum/blog posts), there was (is?) a bug in some systems where QueryPerformanceCounter returns different results when the application runs on different cores.

That serialization instruction was required for RDTSC to avoid out-of-order execution. Probably it is not required for QueryPerformanceCounter but some people still suggest using it. The reported crash could be related to some registers not being restored properly.

Honestly, I would like to get rid of these hacks. We could just try to do that and see on how many systems we get problems.


Top
 Profile  
Reply with quote  
PostPosted: 19.10.2009, 11:48 
Offline

Joined: 15.08.2009, 11:34
Posts: 10
okay, since neither the bullet (physics library) timing code nor the glfw timer on windows include the affinity/cpuid stuff, i think it's relativly safe to drop it

kind regards,
hs0


Top
 Profile  
Reply with quote  
PostPosted: 20.10.2009, 10:40 
Offline

Joined: 15.08.2009, 11:34
Posts: 10
nice, the problem is completly gone with gcc 4.4.1!
(I previously used gcc 3.4.5)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group