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




Loading

Diagnostics_TASK_SWITCHED_IN and _OUT

Posted by Eduardo Goncalves on March 24, 2009
Hi :)

I've created a diagnostics module that pretends to measure the amount of time that each task runs per second.

Therefore I'm using the macros:
Diagnostics_TASK_SWITCHED_IN
Diagnostics_TASK_SWITCHED_OUT

This is the code of the ..._IN macro (the ..._OUT is very similar):

void Diagnostics_TASK_SWITCHED_IN ( pdTASK_HOOK_CODE pxTaskTag )
{
uint16 TickCount;

TickCount = xTaskGetTickCount();

...

when I use the code like this the system ends up in the __prefetch_handler, with very starnge values in the LR register.

If a comment the call to xTaskGetTickCount then all goes fine.

I've examined the function xTaskGetTickCount and it seems quite harmless.
I've tried to step into xTaskGetTickCount but it does not crash on the first 10 calls or so, it takes longer.

would there be any reason for this?

thanks

RE: Diagnostics_TASK_SWITCHED_IN and _OUT

Posted by Samuel Tardieu on March 24, 2009
Eduardo,

I'm not answering your question but just raising a warning about your methodology: do not forget that xTaskGetTickCount() will only return a number of ticks, with the granularity of the system ticks. If you run at 1000Hz (which is I believe the case for most if not all demos, see configTICK_RATE_HZ), then your precision is only that.

If a task records 1 tick with your counting method, it may well have executed only for a few nanoseconds and crossed a system tick increment. Similarily, a task may have executed for 999 microseconds and record 0 tick because it was all contained between two system ticks.

If these situations do repeat during the lifecycle of your application, you may end up with Task1 having apparently consumed all the time and Task2 having consumed none while in fact Task2 used 99% of CPU time and Task1 0,001%.

Because of that, I would suggest to use a system timer which will record the amount of time spent in each task much more accurately, especially if you intend to use rate-monotonic-scheduling to determine a set of static priorities for your task.

RE: Diagnostics_TASK_SWITCHED_IN and _OUT

Posted by Dave on March 24, 2009
I presume this is being called form the tick in which case you cannot use xTaskGetTickCount() because is uses a critical section. Create a version without a critical section or just read the tick count variable directly.

RE: Diagnostics_TASK_SWITCHED_IN and _OUT

Posted by Eduardo Goncalves on March 24, 2009
Two very good points :)

I'll try to use a timer!

thanks


[ 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