How to calculate RTOS task time

I wrote code in c for Arm7 using RTOS. There are several tasks whose priority is set at the same level. Thus, tasks are performed based on round-robin.

There is an exception that one task (by default) has a lower priority than another task in rtos. Thus, if no task is performed, the task starts by default or below priority.

Now I want to calculate the exact total time (time duration) for this task by default.

Can anyone give an idea of ​​what to do ... and how to do it in code.

Relationship Dani

+4
source share
3 answers

A very easy way to see when a task is running by default or in standby mode is to make this task switch the unused (but available) GPIO output or LED indicator if your equipment has such a thing. Then, if you connect the oscilloscope to the input / output line, you can see how long the processor remains in the idle task by the length of the oscillation period observed in the region. The line will remain steady whenever other tasks are performed.

An alternative method, if you can get the OS code, is to make the line high when the default task is selected and low for any other task.

+5
source

It would be helpful if you would give us more information about your platform (CPU, RTOS), but the general idea is this:

Most RTOS have a kind of “shutdown” of the task or hook. Most embedded platforms have easily accessible timer peripheral devices (hardware timers).

So: every time you switch and perform a low priority task, take a timer snapshot and calculate the time interval.

All kinds of warnings apply, such as taking a rollover over a timer (including multiple rollovers if the timer period is very short), low power / sleep modes (if you use them), time spent in ISR, etc.

+3
source

I agree with Dan's answer - here are some additions / improvements:

(1) Window based calculations. , since there is apparently no periodicity by default, you will need to calculate its execution time in terms of the percentage spent on this task on a certain window (say, 1000 ms), you will need to determine the static variable used to accumulate clicks a timer. Once your window has expired (that is: 1000 ms has passed), you can calculate the time spent on default compared to 1000 ms, which will be the percentage spent on default. Since I am reading your description, it seems that the default state is basically a state of inactivity - this means that this percentage is approximately your available micro-consumption.

(2) one survey per hour. . If you can use a 32-bit counter, and you capture usec timestamps, you can do this 1 hour before the rollover occurs. If you use this for a home project, you have the option to ignore rollovers. This will contribute to a single distorted window of 1000 ms, and that’s it. If, on the other hand, you will monitor the maximum use and install an error or diagnosis because of this ... then you want to consider it.

(3) ISR skew. Determining whether to handle the time spent on the ISR other than the time spent on another task depends on how your RTOS handles the context switch. As Dan points out, most RTOS have a kind of callback or hook that fires when a task is switched. Some RTOS have a separate hook for ISR only. I’m not quite sure that the motivation for this is different from the general theory that users are less likely to care about the time spent (apparently) on short ISRs than about the user's tasks themselves. In any case, check how your RTOS handles this switch from there.

If you do not handle this correctly, the time spent on the ISR will be assigned to any task that was performed at the time the ISR was launched. If you find yourself in the "Default" section, then your default task has "consumed" the ISR time. If you do not have many ISRs running, I will completely ignore this.

Good luck I did this with the PowerPC 551X family, and it was for the production of automotive software, so it had to be perfect! It should be much easier for you :)

+1
source

Source: https://habr.com/ru/post/1311732/


All Articles