MQX - CPU Utilization Performance Test

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX - CPU Utilization Performance Test

2,678 Views
mlamp
Contributor II

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 !defined(MQX_ENABLE_IDLE_LOOP) || MQX_ENABLE_IDLE_LOOP

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

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

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

++kernel_data->IDLE_LOOP.IDLE_LOOP4;

} /* Endif */

} /* 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.

4 Replies

1,066 Views
netstv73
Contributor III

I know it's been a few years since you've posted this and who knows if you even have the same email address... I just want to let you know this is AWESOME!  It's sooooo simple it's stupid... :smileyhappy: 

0 Kudos

1,066 Views
keno
Contributor II

mlamp,

I found your post as I'm interested in evaluating CPU load in our system.  I'm trying to adapt what you did for our situation.  I've gone through the math several times but I can't seem to come up with 3 minutes as the time between counter roll overs.

For a 120 MHz clock one clock cycle is 8.33 us.  5 clock cycles are required to increment the counter which equates to 41.66 us.

Multiplying 41.66 us by 2^32 (4,294,967,296) I get 178,569 seconds for the counter to roll over.  That comes out to a much larger time than 3 minutes.

I've stared at it for some time trying to figure out where I went wrong with the calculation.  What am I missing?

-Ken

0 Kudos

1,066 Views
mlamp
Contributor II

Hi Ken,

120Mhz is 8.33nS.  The counter takes 178 seconds to roll over.

Best regards.

0 Kudos

1,066 Views
keno
Contributor II

Mike,

Thanks for the quick reply and pointing out my rather dumb mistake.

I entered 120,000 over and over again never recognizing the error.

Thanks again!

-Ken