Horde3D http://www.horde3d.org/forums/ |
|
Compiling with minGW / getTime() function of Timer http://www.horde3d.org/forums/viewtopic.php?f=3&t=979 |
Page 1 of 1 |
Author: | hs0 [ 13.10.2009, 16:20 ] |
Post subject: | Compiling with minGW / getTime() function of Timer |
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 |
Author: | marciano [ 17.10.2009, 10:54 ] |
Post subject: | Re: Compiling with minGW / getTime() function of Timer |
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. |
Author: | DarkAngel [ 18.10.2009, 05:18 ] |
Post subject: | Re: Compiling with minGW / getTime() function of Timer |
On Windows/MSVC I would suggest using the intrinsic function _ReadWriteBarrier instead of an asm hack ![]() 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?) |
Author: | swiftcoder [ 18.10.2009, 15:21 ] |
Post subject: | Re: Compiling with minGW / getTime() function of Timer |
***ignore me - I was thinking about another issue*** |
Author: | marciano [ 18.10.2009, 16:47 ] |
Post subject: | Re: Compiling with minGW / getTime() function of Timer |
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. |
Author: | hs0 [ 19.10.2009, 11:48 ] |
Post subject: | Re: Compiling with minGW / getTime() function of Timer |
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 |
Author: | hs0 [ 20.10.2009, 10:40 ] |
Post subject: | Re: Compiling with minGW / getTime() function of Timer |
nice, the problem is completly gone with gcc 4.4.1! (I previously used gcc 3.4.5) |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |