RTOS System Chapter - Statistical Task CPU Usage

RTOS System Chapter - Statistical Task CPU Usage

overview

In RTOS, some functions can be used to count the CPU time used by each task, and the proportion of the used time to the total time. For example: within a period of 100s, task A uses the CPU to run for 10s, task B uses the CPU to run for 20s, and the remaining 70s is run by idle tasks, then the total CPU utilization during this period is 30%. Among them, task A takes up 10%, and task B takes up 20%. Of course, the CPU occupation time has a lot to do with the CPU running speed. The execution time of the same program on different CPUs is different, so the CPU occupation time is also different.

When debugging code, you can analyze which task has a high CPU usage based on this time ratio, and then allocate or optimize tasks reasonably. It can also be used to evaluate the performance of different CPUs after running a program.

Common requirements for counting CPU usage

There are two main needs:

1) Count how much CPU time a task has occupied since starting the RTOS to the current time.

2) Count the CPU usage time of a task from time T1 to time T2.

The difference between them can be shown in the figure below:

insert image description here

The basic principle of statistical tasks or a piece of code occupying CPU time

1) Count how much CPU time a task has occupied since starting the RTOS to the current time.

This requirement can be fulfilled using the following function:

おすすめ

転載: blog.csdn.net/wangyx1234/article/details/129056533
おすすめ