The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Android timer precision increase 1000x
Michael Labbe
Guest

I have attached a one line patch against 2.0.4rc1 that enables HAVE_CLOCK_GETTIME on Android.  I have been running this for about a month on various devices without issue.

On Thu, May 14, 2015 at 12:22 AM, Sam Lantinga wrote:
Quote:
Go ahead and submit a patch and we'll look at it for 2.0.4.

Thanks!


On Wed, May 13, 2015 at 3:05 PM, Michael Labbe wrote:


Quote:
SDL_GetPerformanceCounter() on Android is implemented in timer/unix/SDL_systimer.c, and uses the gettimeofday() implementation.

If HAVE_CLOCK_GETTIME is defined in the Android.mk's CCFLAGS, it successfully uses clock_gettime() instead.  This is a 1000x increase of precision (nanosecond resolution instead of microsecond).


Two time related concerns:


1. Is there a reason why HAVE_CLOCK_GETTIME is not enabled on Android?


2. SDL_GetPerformanceFrequency() returns a hardcoded value instead of calling clock_getres(). Is this a potential bug?  From the clock_getres() manpage: "The resolution of clocks depends on the implementation"


Code excerpt from Mercurial:


 #if HAVE_CLOCK_GETTIME
        return 1000000000;
#elif ... 


Asking around, experienced Android NDK game developers have told me that they have successfully shipped games using nanosecond precision on various Android hardware.  Should SDL2 enable this by default?


Michael Labbe




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Android timer precision increase 1000x
Ryan C. Gordon
Guest

Just to be clear: is there some old Android version we still support that doesn't have clock_gettime()?


--ryan.



On Jun 17, 2015, at 4:45 PM, Michael Labbe wrote:


Quote:
I have attached a one line patch against 2.0.4rc1 that enables HAVE_CLOCK_GETTIME on Android. I have been running this for about a month on various devices without issue.

On Thu, May 14, 2015 at 12:22 AM, Sam Lantinga wrote:
Quote:
Go ahead and submit a patch and we'll look at it for 2.0.4.

Thanks!


On Wed, May 13, 2015 at 3:05 PM, Michael Labbe wrote:


Quote:
SDL_GetPerformanceCounter() on Android is implemented in timer/unix/SDL_systimer.c, and uses the gettimeofday() implementation.

If HAVE_CLOCK_GETTIME is defined in the Android.mk's CCFLAGS, it successfully uses clock_gettime() instead. This is a 1000x increase of precision (nanosecond resolution instead of microsecond).


Two time related concerns:


1. Is there a reason why HAVE_CLOCK_GETTIME is not enabled on Android?


2. SDL_GetPerformanceFrequency() returns a hardcoded value instead of calling clock_getres(). Is this a potential bug? From the clock_getres() manpage: "The resolution of clocks depends on the implementation"


Code excerpt from Mercurial:


#if HAVE_CLOCK_GETTIME
return 1000000000;
#elif ...


Asking around, experienced Android NDK game developers have told me that they have successfully shipped games using nanosecond precision on various Android hardware. Should SDL2 enable this by default?


Michael Labbe




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





<Android.mk.patch>
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Android timer precision increase 1000x
Eric Wing
Guest

On 6/18/15, Ryan C. Gordon wrote:
Quote:

Just to be clear: is there some old Android version we still support that
doesn't have clock_gettime()?

--ryan.

I *think* I used clock_gettime() in ALmixer on Android on 2.2 and
maybe even 2.0. Lots of users and devices with no problems. I'm pretty
certain I used it in 2.3 without problems.

-Eric
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Android timer precision increase 1000x
SiPlus


Joined: 06 Feb 2015
Posts: 13
I doubt that, CLOCK_MONOTONIC is used by android.os.SystemClock.uptimeMillis(), which has been available since API 1.

On 19-Jun-15 4:14, Ryan C. Gordon wrote:

Quote:


Just to be clear: is there some old Android version we still support that doesn't have clock_gettime()?


--ryan.



On Jun 17, 2015, at 4:45 PM, Michael Labbe wrote:


Quote:
I have attached a one line patch against 2.0.4rc1 that enables HAVE_CLOCK_GETTIME on Android.  I have been running this for about a month on various devices without issue.

On Thu, May 14, 2015 at 12:22 AM, Sam Lantinga wrote:
Quote:
Go ahead and submit a patch and we'll look at it for 2.0.4.

Thanks!


On Wed, May 13, 2015 at 3:05 PM, Michael Labbe wrote:


Quote:
SDL_GetPerformanceCounter() on Android is implemented in timer/unix/SDL_systimer.c, and uses the gettimeofday() implementation.

If HAVE_CLOCK_GETTIME is defined in the Android.mk's CCFLAGS, it successfully uses clock_gettime() instead.  This is a 1000x increase of precision (nanosecond resolution instead of microsecond).


Two time related concerns:


1. Is there a reason why HAVE_CLOCK_GETTIME is not enabled on Android?


2. SDL_GetPerformanceFrequency() returns a hardcoded value instead of calling clock_getres(). Is this a potential bug?  From the clock_getres() manpage: "The resolution of clocks depends on the implementation"


Code excerpt from Mercurial:


 #if HAVE_CLOCK_GETTIME
        return 1000000000;
#elif ... 


Asking around, experienced Android NDK game developers have told me that they have successfully shipped games using nanosecond precision on various Android hardware.  Should SDL2 enable this by default?


Michael Labbe




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





<Android.mk.patch>
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Android timer precision increase 1000x
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
This change is in for 2.0.4, thanks!
https://hg.libsdl.org/SDL/rev/7cfd071cd9a2


On Wed, Jun 17, 2015 at 1:45 PM, Michael Labbe wrote:
Quote:
I have attached a one line patch against 2.0.4rc1 that enables HAVE_CLOCK_GETTIME on Android.  I have been running this for about a month on various devices without issue.

On Thu, May 14, 2015 at 12:22 AM, Sam Lantinga wrote:
Quote:
Go ahead and submit a patch and we'll look at it for 2.0.4.

Thanks!


On Wed, May 13, 2015 at 3:05 PM, Michael Labbe wrote:


Quote:
SDL_GetPerformanceCounter() on Android is implemented in timer/unix/SDL_systimer.c, and uses the gettimeofday() implementation.

If HAVE_CLOCK_GETTIME is defined in the Android.mk's CCFLAGS, it successfully uses clock_gettime() instead.  This is a 1000x increase of precision (nanosecond resolution instead of microsecond).


Two time related concerns:


1. Is there a reason why HAVE_CLOCK_GETTIME is not enabled on Android?


2. SDL_GetPerformanceFrequency() returns a hardcoded value instead of calling clock_getres(). Is this a potential bug?  From the clock_getres() manpage: "The resolution of clocks depends on the implementation"


Code excerpt from Mercurial:


 #if HAVE_CLOCK_GETTIME
        return 1000000000;
#elif ... 


Asking around, experienced Android NDK game developers have told me that they have successfully shipped games using nanosecond precision on various Android hardware.  Should SDL2 enable this by default?


Michael Labbe




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org







_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org