RTC module used in FW12?

I am writing some C code that runs in less than a microsecond and want to time it to more than 1 sigfig. But I need to know if it’s even possible: what are the exact specs of the RTC used on the FW12’s motherboard?

No, it’s not possible because the RTC has nothing to do with the CPU. All it does is keep track of the calendar date and time when the system is powered off. The RTC is the wrong place to look for code benchmarks. For that you have to ask the operating system.

On POSIX (including Linux), you may use clock_gettime(). On Windows, this Microsoft page called “Acquiring high-resolution time stamps” may help.

2 Likes

Indeed I am using clock_gettime() right now to get time statistics on my MSYS2-based gcc compiler on Win11. It has a resolution of 100ns, but I don’t know the accuracy. What I was trying to ask is how accurate the readings from that will be.

You’ll want to consult the provider of your runtime for that information. I don’t think anybody on this forum can tell you–but what we can tell you is that it is not hardware-dependent.

1 Like

You’re going to have to verify all of this yourself, but a quick search suggests that MSYS2 is using mingw-w64’s Winpthreads library to provide clock_gettime(). The source file containing the function is here:

It basically just calls a Windows API function depending on the value of the clockid argument.

  • CLOCK_REALTIME: GetSystemTimePreciseAsFileTime()
  • CLOCK_REALTIME_COARSE: GetSystemTimeAsFileTime()
  • CLOCK_MONOTONIC: QueryPerformanceCounter()
  • CLOCK_PROCESS_CPUTIME_ID: GetProcessTimes()
  • CLOCK_THREAD_CPUTIME_ID: GetThreadTimes()

It’s obviously not going to be as good as a NIST-F2 atomic clock, but for short benchmarks it should be more than good enough. You probably want to use CLOCK_MONOTONIC since it uses QueryPerformanceCounter() under the hood. I don’t develop on Windows, so take this with a grain of salt.

You might also want to run your sub-microsecond code in a loop a few million times, measure the whole loop, then divide the elapsed time by the iteration count. But be wary of compiler/processor optimizations that can affect the result.

3 Likes

This is extremely helpful. Thanks for giving links to everything. Thank you!