2

Is any high resolution timer available on a Raspberry Pi that can be used by an application (for micro-benchmarking, etc.) without having to write a kernel driver?

The resolution I'm looking for is sub-millisecond or microseconds, but microseconds or nanoseconds are preferred. For timing compiled C vs. ARM assembly language code. Added jitter to ameliorate Spectre is OK.

  • depends on the OS – jsotola Feb 25 '18 at 18:38
  • 1
    current default install of Raspbian Stretch or Stretch-lite from raspberrypi.org – hotpaw2 Feb 25 '18 at 19:35
  • 1
    This is a bit vague. What do you call high resolution? What do you plan to time and how? – joan Feb 25 '18 at 20:01
  • 1
    Sub-millisecond or microseconds. But microseconds or nanoseconds preferred. For timing compiled C vs. ARM assembly language code. Added jitter to ameliorate Spectre is OK. – hotpaw2 Feb 25 '18 at 22:07
  • @hotpaw2 You should add clarifications to your question rather than in comments. – joan Feb 25 '18 at 23:09
1

You should be able to check for high-resolution timer support by installing the rt-tests package and running cyclictest with the period that you're interested in. For example

cyclictest -n -p 80 -i 500 -l 5000

This does a test of clock_nanosleep(), with priority 80, at 500 microsecond intervals, running the 5000 iterations of the test.

According to a brief search, nanosleep() is supported in Raspbian.

Another source of useful information about available timers is /proc/timer_list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.