[SDL] Question about SDL_GetTicks()

dvereb dvereb at gmail.com
Sat Mar 1 09:54:14 PST 2014


LordHavoc wrote:
> While I can't address the core of this matter I will note that the QueryPerformanceCounter and timeGetTime can differ quite wildly on certain motherboards, mostly from the Windows XP era.
> 
> In general you can't trust QueryPerformanceCounter because it is the cpu clock and can vary on some cpus from that era as well (due to power profiles, as well as multicore CPUs that contain
> independent clocks and thread allocation to CPU cores can fluctuate wildly), constant monitoring of QueryPerformanceFrequency only partly addresses the issues with this method.
> 
> However SDL_GetTicks() uses timeGetTime() which can deviate substantially from wall time on the aforementioned motherboards.
> 
> A more reliable clock source for these offending motherboards would be greatly appreciated in my game engine as well (as I have both SDL and native implementations of the time functions, primarily for
> profiling reasons where QueryPerformanceCounter is the superior choice, but is not the default for timekeeping reasons).
> 
> I've never dug deeply into this issue, I have only made the observation that timeGetTime is not trustworthy on certain motherboards.


I initially didn't think much of this.  When googling I read that SDL_GetTicks was using gettimeofday, but isn't that linux only?  So I downloaded the full source code of SDL and had a look myself (I guess I'm an idiot for not doing this :D).  Turns out it'll use the QueryPerformanceCounter&Frequency if available - I didn't realize that.  This leads me to believe that the XP machine I'm using has an outdated BIOS based on this article:
http://support.microsoft.com/kb/895980

I'll see what I can do for updating the BIOS on the XP machine and get back to you guys, but that's not until Monday.  If that IS in fact the issue, I really don't want to tell someone "hey thanks for trying my game but please update your BIOS to play it." ...not that I'll have many (any?) XP players.  It's just a scenario I need to be aware of, I guess ... again, assuming this is the issue.

This was also interesting to read, but seems limited to Intel-based CPUs:
http://software.intel.com/en-us/articles/best-timing-function-for-measuring-ipp-api-timing

As usual, thanks everyone for helping me work through this - sorry for the delay until Monday.  If the BIOS update doesn't solve it, then I'll get back to posting code.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20140301/81e2b711/attachment-0008.htm>


More information about the SDL mailing list