Quality RTOS & Embedded Software

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




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) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS