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

how to calculate total execution time of a function

I am writing a simple RTOS
i have some tasks the works with different frequencies and priorities
each task is represented by a function void f1(void),..etc.
f1 is higher priority than f2 and it interrupt its execution and when finished f2 continues.
the question is how to calculate the actual execution of f1 and f2 without pauses?
second question?
is their anyway to calculate the worst case execution time of a functions?

Parents
  • There are no general way to compute the worst-case execution time, since a low-priority task can be starved forever.

    To measure execution time you can have your task switching code keep track of timers/counters.

    Or you may have your different threads own one LED each.

    Have the threads turn on the LED when active and turn it off when calling a sleep function.

    The blinking of the LED for the high-prio thread will directly represent each iteration of the loop it is running.

    The blinking of the LED for the second most high-prio thread will also blink corresponding to the iteration of the inner loop. But you need to subtract the time when the high-prio LED is lit since then the high-prio thread have stepped in and is stealing time.

    Same for lower-prio threads - more and more other threads that can step in and steal time. If any LED of higher prio is on, then you need to subtract that time from the pulse-length you measured for your low-prio LED.

Reply
  • There are no general way to compute the worst-case execution time, since a low-priority task can be starved forever.

    To measure execution time you can have your task switching code keep track of timers/counters.

    Or you may have your different threads own one LED each.

    Have the threads turn on the LED when active and turn it off when calling a sleep function.

    The blinking of the LED for the high-prio thread will directly represent each iteration of the loop it is running.

    The blinking of the LED for the second most high-prio thread will also blink corresponding to the iteration of the inner loop. But you need to subtract the time when the high-prio LED is lit since then the high-prio thread have stepped in and is stealing time.

    Same for lower-prio threads - more and more other threads that can step in and steal time. If any LED of higher prio is on, then you need to subtract that time from the pulse-length you measured for your low-prio LED.

Children