This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Relative timing of os_time_get() and os_itv_wait()

In a very simple task containing an infinite loop and running on os_itv_wait() I would like to measure how long the code takes to run using os_time_get(). For example if os_itv_wait() lets my code run every 5 ticks and the difference between os_time_get() called at the top and bottom of my code is 2 ticks I know that I have time to spare. If the code takes 8 ticks I have a problem.

In my case I am running my code every 1 tick and can accept that occasionally the code runs in over 1 tick but I don't want it to take 2 ticks. Ideally therefore I'd like a sub-tick resolution timer but I haven't got that (without running a hardware timer which is a future possibility).

So for this test I'm looking to see if a whole tick has expired by the time I reach the end of the code - but this relies on the os_itv_wait() being synchronous and changing at the same time as the os_time_get() result and I don't know if they are.

For example, if os_itv_wait() allows my code to run but os_time_get() value changes 100us later I am likely to see a change between the top and bottom of my code times on every run.

I suspect that it is all driven from the same counter. A change in that counter value is synchronous with os_itv_wait() allowing my code to run and os_time_get() returning the new value.

Parents
  • Note that the start time of your thread after each wait depends on what other threads you have, and what priorities they have. The tick only means the thread is "runnable" - not that it is the most prioritized runnable thread, i.e. the one who will get the CPU.

    Next thing - changes in interrupt load will change how much wall clock time your thread takes from being woken up until it's ready to sleep again.

    The advantage with using a hw timer is that you can both measure the used wall time, and you can measure jitter in activation and jitter in run time. And you can decide yourself what resolution to use for the measurements, by having the hw timer tick significantly faster than the OS tick frequency.

Reply
  • Note that the start time of your thread after each wait depends on what other threads you have, and what priorities they have. The tick only means the thread is "runnable" - not that it is the most prioritized runnable thread, i.e. the one who will get the CPU.

    Next thing - changes in interrupt load will change how much wall clock time your thread takes from being woken up until it's ready to sleep again.

    The advantage with using a hw timer is that you can both measure the used wall time, and you can measure jitter in activation and jitter in run time. And you can decide yourself what resolution to use for the measurements, by having the hw timer tick significantly faster than the OS tick frequency.

Children