Trying to use CLOCK_MONOTONIC and failing


(Ray Bahr) #1

Hi All,

I am trying to pull together a posix compliant benchmark and use CLOCK_MONOTONIC but can’t build it. A requirement seems to be __rtems but I don’t see it enabled anywhere.

Thoughts?

Thanks

Ray


(Jim Wilson) #2

RTEMS is a real time OS. __rtems is only defined when you use a gcc configured to emit code to run on RTEMS. If you are trying to compile code for RTEMS, then you should be using a cross compiler to riscv*-rtems instead of an elf or linux compiler.


(Ray Bahr) #3

I am trying to use clock_gettime( CLOCK_MONOTONIC,…) which is part of the Posix standard. The compile / link is failing because CLOCK_MONOTONIC is undefined. Looking at the include files, it seems like the only way of turning on the necessary #defines to instantiate this is with RTEMS.

What am I doing wrong?

Thanks

Ray


(Jim Wilson) #4

You need to provide a much better bug report. What toolchain are you using? What C library are you using? What is the target? Just because something is in the Posix standard does not mean that all targets support it. Embedded targets usually only support a small subset of what is in the Posix standard. In particular, embedded targets don’t have time of day clocks. They have timers and cycle counters and stuff like that. If you want a clock that knows about the time of day, then you need an OS that can manage a clock for you. RTEMS is one such example of an OS that can manage a clock. There are others.

We have a BSP that supports time(). It just reads and returns the cycle counter register.

If your target hardware has a real-time clock, then you might be able to do better. But that depends on the target.