3

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.

Aurora0001
  • 6,357
  • 3
  • 25
  • 39
hotpaw2
  • 270
  • 2
  • 10

1 Answers1

2

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.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147