calculating CPU time with the idle task

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

calculating CPU time with the idle task

Jump to solution
8,278 Views
francois_boucha
Contributor III

Hello,

 

My question concerns the way to calculate the CPU time a program takes.  The idle task counter is here for that matter, but what is the frequency of the counter?  And what is a convenient way to calculate/output the CPU %

 

thx

0 Kudos
1 Solution
3,200 Views
JuroV
NXP Employee
NXP Employee

To get CPU usage, today there is no tool to get percentage. The only way is to use idle task counter.

 

The counter is there only to get information, if in 60 minutes it is at zero or at millions. It even is not implemented as thread-safe, so it can happen that the value is not correct (counter incrementing is not done in atomic instruction). But in more than 99.999% cases, you get the right value from the counter.

 

If you rely on the counter value and you want to get time or percentage information, there is not any easy workaround to get it. That's because counter is running without any synchronization. The speed of the counter is determined only by dissassembling _mqx_idle_task code and to find out how many instruction does it take to increment by one. Note that number of instructions depends on your compiler settings. Then, you can compute how much time does it take to execute these instructions.

Message Edited by JuroV on 2009-03-06 09:50 AM
Message Edited by JuroV on 2009-03-06 09:58 AM

View solution in original post

0 Kudos
7 Replies
3,200 Views
CarlFST60L
Senior Contributor II

The Task Aware Debugger seems to have tools that will do this an much more.. Have not personally used it, but I have read up on it at www.freescale.com/mqx

As a concept, you can access the KERNAL_DATA_STRUCT->IDLE_LOOPX (there are 3 uint_32's with different resolutions you can use depending on the accuracy you want).

To work out the speed it ticks at, I would simply run a time slice thread that runs every X seconds and save the start ticks and end ticks (not processor ticks, the IDLE_LOOPX ticks). With that, you can calibrate a value for no load and work from there.

It should be very easy to work out the resolution of each timer. If you do it, will you share the results? Or maybe the MQX guys will tell us the resolution of the IDLE_LOOP counters for the dev boards...

Dam, I could have just worked it out in the time this post this response...

0 Kudos
3,200 Views
francois_boucha
Contributor III

CarlFST60L wrote:

To work out the speed it ticks at, I would simply run a time slice thread that runs every X seconds and save the start ticks and end ticks (not processor ticks, the IDLE_LOOPX ticks). With that, you can calibrate a value for no load and work from there.


Yeah, I think it's a good way to procede.

 

I'll let you know if I got something.

 

 

0 Kudos
3,200 Views
JuroV
NXP Employee
NXP Employee
Just note that for specific targets (Ext. MRAM or Int. FLASH) you get different results- significantly different.
0 Kudos
3,200 Views
macl
Senior Contributor I

Yes, this is because the MRAM is connected through the external bus and it has slower access times so it requires a wait state cycle to be inserted in the bus transfer.  It's a performance tradeoff that is made in order to get a lot of extra non-volitile byte-writeable memory. 

 

The internal Flash however is on the internal bus and its interleaved so it's very efficient. It can read a longword in 1 or 2 cycles. 

0 Kudos
3,200 Views
CarlFST60L
Senior Contributor II

Did anyone ever write a module to calculte CPU load?

 

0 Kudos
3,201 Views
JuroV
NXP Employee
NXP Employee

To get CPU usage, today there is no tool to get percentage. The only way is to use idle task counter.

 

The counter is there only to get information, if in 60 minutes it is at zero or at millions. It even is not implemented as thread-safe, so it can happen that the value is not correct (counter incrementing is not done in atomic instruction). But in more than 99.999% cases, you get the right value from the counter.

 

If you rely on the counter value and you want to get time or percentage information, there is not any easy workaround to get it. That's because counter is running without any synchronization. The speed of the counter is determined only by dissassembling _mqx_idle_task code and to find out how many instruction does it take to increment by one. Note that number of instructions depends on your compiler settings. Then, you can compute how much time does it take to execute these instructions.

Message Edited by JuroV on 2009-03-06 09:50 AM
Message Edited by JuroV on 2009-03-06 09:58 AM
0 Kudos
3,200 Views
francois_boucha
Contributor III

If we don't know the frequency, is there a counter at same frequency that never stops?  This way we could have 2 values to calculate the CPU time %.

 

Anyway, i'll share any results if I get some.

 

   

0 Kudos