Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Measuring CPU usage?

Posted by keith soldavin on December 6, 2011
I have an application I am currently developing that requires me to report the CPU usage of the system periodically. I have my code compiled (FreeRTOS 7.0.1, ARM7, IAR 6.2) with the configGENERATE_RUN_TIME_STATS flag set and I can display the stats off all tasks on my debug screen. What I am looking for is not the stats of each individual task but of the overall system. My thought was that if I can get the stats for the Idle task I can subtract the number from 100 and get the total CPU usage. My problem is that I do not know how, or if it is even possible, to get the usage stats of an individual task. One option would be to get the stats for all the tasks and parse out the idle task information but that would be a waste of resources which I don't have.

The one thing I tried, that didn't seem to work well, is to set up idle and tick hook functions that incremented a uint32 variable every time they are entered. I used these values to try to calculate the percentage of time in idle. Unfortunately the values I calculated did not correspond to the RTOS task stats.

Does anyone have any suggestions?

RE: Measuring CPU usage?

Posted by Dave on December 6, 2011
You can use the traceTASK_SWICHED_IN macro.

In the macro, if pxCurrentTCB equals the handle of the idle task, then you know the idle task has just been switched in and you can start a high frequency timer (or note the time of a free running high frequency timer). If the idle task was running, and pxCurrentTCB is no longer the idle task, you know the idle task has just been switched out and you can stop the high frequency timer and note the elapsed time (or again note the time of a free running high frequency timer).

If you use FreeRTOS 7.0.2 and define INCLUDE_xTaskGetIdleTaskHandle to 1 in FreeRTOSConfig.h, then you can use xTaskGetIdleTaskHandle() after the scheduler is started to get the idle task handle.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists