cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Processor Load

Rogers.Gary
Senior II
Posted on September 19, 2014 at 04:43

Hi,

Is there a way to measure CPU load on the device? Using IAR EWARM 7.2 if that makes any difference.

I did a search but could find anything. The usual cryptic Google returns to adwords. 8--)

#freertos #profiling #runtime
9 REPLIES 9
Posted on September 19, 2014 at 09:11

What do you mean by ''CPU load''?

JW
chen
Associate II
Posted on September 19, 2014 at 10:58

Hi

''Is there a way to measure CPU load on the device? Using IAR EWARM 7.2''

As Jan said - what do you mean by ''CPU load''

First - understand that the CPU runs code at what ever speed it is configured to run.

So - technically speaking, the CPU load is 100%

It is not running 'useful' code all the time.....so how do you measure when it is and is not running 'useful code'

Have the processor run an 'idle loop' - then you can measure how often the processor is in the 'idle loop'

At this point you should start to realise this is sounding like tasking - yes, that is exactly what you want - Tasks.

''Is there a way to measure CPU load''

What you really mean : Is there a way of splitting my application into tasks and measuring when the idle task is running?

What is the proportion of the time the CPU is in the idle task?

Chris1
Senior III
Posted on September 19, 2014 at 18:34

ARM Cortex-M cores have the ability to transmit real-time trace information using a single wire when utilizing tool chain components such as the IAR Embedded Workbench for ARM [EWARM] and Segger J-Link emulator probe.  The Serial Wire Output [SWO, also referred to as TRACESWO] (which may be multiplexed with the JTDO function) must be connected to your emulator probe.

The IAR C-SPY Debugger component of the Embedded Workbench IDE can be configured to interact with the SWO communication channel.  One of several SWO capabilities is function profiling based on sampling the microcontroller’s program counter (PC Sampling-based profiling).  Using SWO trace, the program counter can be sampled periodically with execution address locations transmitted to the emulator.  The percentage of time that the CPU spends in each function can be observed this way.

Rogers.Gary
Senior II
Posted on September 25, 2014 at 03:38

Yes, I did mean how much time it spends in useful code vs idle time. For example...A timer task interrupt collects data, message queues another task that processing can begin.

Could use application idle hook task in FreeRTOS...will give it a go.

Thanks for replies.

Chris1
Senior III
Posted on September 25, 2014 at 16:12

Reviewing how I last did this, it appears that it may have actually been a J-Link feature; when Debugging with J-Link, Function Profiler can be selected from the J-Link menu and that can tell you directly what percentage of the time the CPU spends in your Idle Hook and Idle task functions. 

Alternatively, you could continuously toggle an I/O pin in your Idle Hook function and use an oscilloscope to get an approximate measure of time spent there. 

chen
Associate II
Posted on September 25, 2014 at 16:51

You did not mention you were using FreeRTOS.

I have never done it but I believe FreeRTOS has task profiling capabilities.

You have to turn then on (Compliers switch) and then enable something,

run your code and then dump the data.

They provide some way of converting the dump data into something useful?!?

I have never done it but I have read the sparse documentation about it on the web site.

let us know how it goes please

stm322399
Senior
Posted on September 25, 2014 at 17:17

FreeRTOS has a nice feature to ''count'' cycles spent in every thread, including idle thread. It must be activated, you must provide support to count cycle et voilà:

do { // This loop protects against thread creation/destruction
uxArraySize = uxTaskGetNumberOfTasks();
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( xTaskStatusType ) );
uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );
} while (uxArraySize==0);
// Do whatever you want with pxTaskStatusArray[i]
// Fields are: xTaskNumber, pcTaskName, eCurrentState, uxCurrentPriority, usStackHighWaterMark, ulRunTimeCounter
// ulRunTimeCounter is the field of interest for this topic
// Do not forget to release the array !
vPortFree(pxTaskStatusArray);

you need to define configGENERATE_RUN_TIME_STATS in FreeRTOSConfig.h and provide portCONFIGURE_TIMER_FOR_RUN_TIME_STATS and portGET_RUN_TIME_COUNTER_VALUE macros.
firatparlak
Associate II
Posted on April 21, 2015 at 10:50

Hi Gonzales,

First of all, thank you for the useful information about FreeRTOS run-time stats. In which function did you write this code? When I wrote this code in the SysTick_Handler() , I saw the pxTaskStatusArray[i] but they were changing by the time and there wasn't any useful info about ulRunTimeCounter.

Sometimes idle_task is in the pxTaskStatusArray[0], sometimes A_task is in the pxTaskStatusArray[0], and ulRunTimeCounter always changes.

Can you help me about this issue?

stm322399
Senior
Posted on April 22, 2015 at 11:22

The best place to run that code is the place where you need the data !!

What is your goal ?

In my project that codeis running ni the CGI handler of a web server, so that I can get Thread infos using a web browser.

The order of task may vary because FreeRTOS simply walk through various list of tasks (ready, delayed, overflowdelayed, terminating, suspended) without sorting.

ulRunTimeCounter always change on purpose !!! It tries to cumulate the cycles allocated to every task.