This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM263P4-Q1: CPU load

Part Number: AM263P4-Q1


Tool/software:

Hi Team,

One of my customer is trying to estimate CPU load with TaskP_loadGetTotalCpuLoad().

Exapmles is;

 - An Interrupot Service Routine with 20us execution time runs per 50us interrupt with single core.

 - TaskP_loadGetTotalCpuLoad() returned 33% CPU load.

Is this correct behavior of TaskP_loadGetTotalCpuLoad()?

Best Regards 

  • One of my customer is trying to estimate CPU load with TaskP_loadGetTotalCpuLoad().

    The CPU load is calculated as follows:

    1. The function suspends the scheduler with vTaskSuspendAll()
    2. It updates the idle task statistics with TaskP_updateIdleTaskLoad()
    3. It updates the total runtime with TaskP_updateTotalRunTime()
    4. It calculates CPU load as TaskP_LOAD_CPU_LOAD_SCALE - idle_percentage
    5. It resumes the scheduler with xTaskResumeAll()

    The critical insight: CPU load = 100% - idle_percentage

    Is this correct behavior of TaskP_loadGetTotalCpuLoad()?

    Yes, this is expected behavior for the following reasons:

    1. ISR Accounting: The FreeRTOS/SafeRTOS kernel doesn't separately account for ISR time in its CPU load calculations. ISRs "steal" time from tasks, and this theft isn't perfectly reflected in the idle task measurements. The API will calculate the time for the running task as well as ISRs in the background

    2. Measurement Method: The API measures CPU load by tracking idle task time, not by directly measuring all CPU activity

    In FreeRTOS, the time spent in ISRs is not attributed to the idle task even if the ISR interrupts the idle task. The run time counter continues incrementing during ISRs, but this time is not added to any specific task's runtime.

    Therefore, when calculating CPU load as "100% - idle_percentage", the ISR time appears as "non-idle" time, which is correctly reported as CPU load.

    If the CPU load of 33% consistently reported in every test or you see a variation? Also ensure that you call the "TaskP_loadResetAll()" before calling the CPU load API to get steady results.

    Regards,
    Shaunak