Michael Lamp

MQX - CPU Utilization Performance Test

Discussion created by Michael Lamp on Sep 18, 2014
Latest reply on Aug 3, 2017 by Steve Iribarne

I am providing this cpu utilization technique to the community courtesy of a brilliant and kind engineer in Texas, Jimmie Curry.  Thanks Jimmie!


In the MQX idle task (idletask.c) we find:

The idle task is of the lowest priority and is preempted by any active task and ISRs.


    while (1) {


        if (++kernel_data->IDLE_LOOP.IDLE_LOOP1 == 0) {

if (++kernel_data->IDLE_LOOP.IDLE_LOOP2 == 0) {

if (++kernel_data->IDLE_LOOP.IDLE_LOOP3 == 0) {


} /* Endif */

} /* Endif */

        } /* Endif */



The highlighted code consist of 5 assembly language instructions, each of which requires one core clock cycle. (ARM Cortex M4)


Each IDLE_LOOP counter is a 32 bits, which together becomes a 128 bit counter.


In my case, the core clock is 120 MHz


Count_Time = 1/120e6 * 5 (the time to complete one count)


Count_Time * 2^32 is required to roll over, in my case approximately 3 minutes.


Thus if I set a break point on the second if statement and only the idle task were running, three minutes would elapse between breaks.


That means that if we measure 6 minutes of operation between breaks, we have 50% CPU utilization by the OS/Application code.


10 minutes between breaks, indicates 70% OS/Application utilization.