Forums

How to measure/determine processor with RTOS's

Started by Toby Harris February 3, 2009
Ok, just as an idle thought what sort of mechanisms do people use when
trying to determine how much of the processing usage is actually being
used?

This stems from doing some experiments with an FreeRTOS based device . I
tried counting tick events in an idle handler and then deriving load
from that but I don't think this takes into account the fact that tasks
may be suspended partway through a tick...

Are there any hooks provided by the RTOS kernel ?

Any thoughts ?


An Engineer's Guide to the LPC2100 Series

Toby Harris wrote:
>
> Ok, just as an idle thought what sort of mechanisms do people use when
> trying to determine how much of the processing usage is actually being
> used?
>
> This stems from doing some experiments with an FreeRTOS based device . I
> tried counting tick events in an idle handler and then deriving load
> from that but I don't think this takes into account the fact that tasks
> may be suspended partway through a tick...
>
> Are there any hooks provided by the RTOS kernel ?

Depends on what you want to do. If you want to estimate idle time, and
from that infer the CPU load (not idle) then you can set up your idle
task to simply increment a counter.

Run just the idle task (or just that loop counter) code with
interrupts disabled for a certain time (say 10 minutes) and note
the counter value. This gives a reasonable indication of counts
per second or per minute.

Now run your application normally, and stop it after a certain time.
Determine the count in the idle task, and work backwards to see how many
seconds it has been running for.

Divide the estimated idle time by the actual run time and you get
an estimate of idle CPU time as a percent.

If you want to get fancy, you can instrument your kernel and ISR
entry/exit and read a microsecond counter, and log the differences
to an array with task numbers and ISR numbers.

This will give you an estimate of the % of time that each task
or ISR is taking.

It's hard to do, but if you've done it once, you end up with
a really useful tool in your bag that you can use over and over again.

Ralph
Toby,

> Ok, just as an idle thought what sort of mechanisms do people use when
> trying to determine how much of the processing usage is actually being
> used?
>
> This stems from doing some experiments with an FreeRTOS based device . I
> tried counting tick events in an idle handler and then deriving load
> from that but I don't think this takes into account the fact that tasks
> may be suspended partway through a tick...
>
> Are there any hooks provided by the RTOS kernel ?
>
> Any thoughts ?

Yeah, what are you still doing at Robinsons? Has Brian been put out to
pasture yet? ;-)

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors

Hi Paul

Its business as usual... keeping grinding away at the keyboard and
trying to keep up to date with new technologies (Silverlight seems to be
in vogue at the moment). I'm playing around with an LPC2138 to drive a
dashboard in the race car - having tried to use a PIC 18 but always
runnning short on resources from the basic device (ROM, RAM, I/O).

Hence the question about knowing what sort of processor usage I'm using.
Using an RTOS gives makes the internal architecture a pretty flexible as
I develop new features / modules into the device.

________________________________

From: l... [mailto:l...] On Behalf
Of Paul Curtis
Sent: 03 February 2009 14:27
To: l...
Subject: RE: [lpc2000] How to measure/determine processor with RTOS's

Toby,

> Ok, just as an idle thought what sort of mechanisms do people use when
> trying to determine how much of the processing usage is actually being
> used?
>
> This stems from doing some experiments with an FreeRTOS based device .
I
> tried counting tick events in an idle handler and then deriving load
> from that but I don't think this takes into account the fact that
tasks
> may be suspended partway through a tick...
>
> Are there any hooks provided by the RTOS kernel ?
>
> Any thoughts ?

Yeah, what are you still doing at Robinsons? Has Brian been put out to
pasture yet? ;-)

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk

CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors




>
> Are there any hooks provided by the RTOS kernel ?
Yep - lots. Nearly all events can be traced using the hook macros. See:
http://www.freertos.org/rtos-trace-macros.html

I often use this mechanism to hook up a logic analyser and see the entire
execution pattern for all tasks.
If you want to look at just the idle task then do something along these
lines:

1) Set configUSE_IDLE_HOOK to 1 in FreeRTOSConfig.h.
2) Define an idle hook function. This is just done to get the handle of the
idle task - you could alternatively hack the code to save the handle of the
idle task as it is created:

xTaskHandle xIdleHandle = NULL;
void vApplicationIdleHook( void )
{
____if( xIdleHandle == NULL )
____{
________/* Store the handle to the idle task. */
________xIdleHandle = xTaskGetCurrentTaskHandle();
____}
}

3) Define a 'task switched in macro', this can be placed in FreeRTOSConfig.h
to have the desired effect.

/* Perform action when idle task start to run. */
#define traceTASK_SWITCHED_IN() if( xCurrentTCB == xIdleHandle )
StartIdleMonitor()
4) Define a 'task switched out macro'.

/* Perform action when the idle task stops running. */
#define traceTASK_SWITCHED_OUT() if( xCurrentTCB == xIdleHandle )
EndIdleMonitor()

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers. More than 7000 downloads per month.

+ http://www.FreeRTOS.org/Documentation
New FreeRTOS eBook - learn how to use an RTOS.

Toby Harris Wrote
>Ok, just as an idle thought what sort of mechanisms do people use when
>trying to determine how much of the processing usage is actually being
>used?

Spare pin and a 'scope That gives you idle time, length of idle period,
distribution of CPU usage all at a glance. With appropriate pin usage you
can get latency etc...

Less intrusive than a timer but you can measure fewer things at once.

Robert

--------------------------------
mail2web.com Enhanced email for the mobile individual based on Microsoft
Exchange - http://link.mail2web.com/Personal/EnhancedEmail