Quality RTOS & Embedded Software

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




Loading

measure execution by vApplicationTickHook, change priority?

Posted by electronicdev on May 23, 2017

Hi I have questions about the vApplicationTickHook(). How could this be used to measure the execution time of e.g. taska and taskb? Also how could I change the priority of e.g. taskb after having meausured the execution time?

The vApplicationTickHook is always run but how to measure the execution time for e.g taska and taskb so I can have the specific execution time for each of them? Also how to use e.g. vTaskPrioritySet(handle, 2) to change the priority of a task?

Grateful for examples


measure execution by vApplicationTickHook, change priority?

Posted by heinbali01 on May 23, 2017

Hi, I would introduce a third lightweight task to do that job. Let it sleep (block) for 5 seconds, check the system load, and sleep again.

vApplicationTickHook() is being called from an ISR and that gives many limitations. You can not do much from within an ISR. vApplicationTickHook() is handy if you want to have a blinking LED or so.

There are several ways to get an estimate of CPU-time per task, for instance configGENERATERUNTIME_STATS

I never had the need to do what you want to do, and I wonder if you can take a different approach? Have a look at the following :

~~~ #define configUSEPREEMPTION 1 #define configUSETIME_SLICING 1 ~~~

It is commented in this post

With these settings, the OS makes sure that runnable tasks of equal priority will get an equal amount of CPU-time! It will not depend on the task's willingness to yield. I would consider using that option and not play with the tasks' priorities.


measure execution by vApplicationTickHook, change priority?

Posted by richard_damon on May 23, 2017

As Hein says, seems wrong to need to change priorities based on CPU usage. Priorities should reflect the needs of the system, and generally don't change. The one exception that I can think of is if something changes 'mode' and some operation changes significantly in need (something changes so what used to be not important exactly when it occured, to being very important).


measure execution by vApplicationTickHook, change priority?

Posted by electronicdev on May 24, 2017

Is it possible by vApplicationTickHook to check which task that is running and then increment a counter as long as that task is executed? What function could I call inside vApplicationTickHook to check if e.g. taskb is executing and then increase my counter for every tick my taskb is executing, if not executed no count is performed. How to do this and what arguments are returned etc if checking taskb is executed?

Thank you


measure execution by vApplicationTickHook, change priority?

Posted by heinbali01 on May 24, 2017

You could ask for the current task handle ( xTaskGetCurrentTaskHandle() ), and use that pointer to increment some counter belonging to a task. The API xTaskGetCurrentTaskHandle() does not have a critical section, so it should be safe to call it from vApplicationTickHook().

I still think it would be much cleaner and more exact to use configGENERATE_RUN_TIME_STATS. You can use a spare TC timer to get an exact time in uS, and provide this function in your FreeRTOSConfig.h:

~~~ extern uint32t ulGetRunTimeCounterValue(void); #define portGETRUNTIMECOUNTER_VALUE() ulGetRunTimeCounterValue() ~~~

What it misses is the possibility to clear the ulRunTimeCounter. Here is a description of how you can add that.


measure execution by vApplicationTickHook, change priority?

Posted by rtel on May 24, 2017

You could use the task tag, or thread local storage, but it's not clear why you would do this in the tick hook rather than use the task stats or trace macros.


measure execution by vApplicationTickHook, change priority?

Posted by electronicdev on May 25, 2017

I tried vApplicationTickHook with xTaskGetCurrentTaskHandle as shown below to measure task a execution time. Only 3 task are present. I check if task_a is running by vapplicationtickhook and increment counter and print result otherwise clear the counter if another task is running. However, the icount display an increasing value at each print no clear and start from 1 except the very first which is wrong behavior. What is wrong? I’m new to rtos and still learning. Thank you all

void vApplicationTickHook(void) { static int iCount = 0;

	if (taska_handle = xTaskGetCurrentTaskHandle())
{
	iCount++;
	printf("exeqution_time_taska %d\r\n", iCount);
}

	if (taska_handle != xTaskGetCurrentTaskHandle())
{
	iCount = 0;
}

}


measure execution by vApplicationTickHook, change priority?

Posted by heinbali01 on May 25, 2017

Oops Your implementation of printf() is probably not fit to be called from within an ISR. Many standard implementations of printf() use the heap.

Beside that, you're making a C-style error :

~~~ if (taska_handle = xTaskGetCurrentTaskHandle()) { } ~~~

I suppose you mean to write a comparison ( == ) and not an assignment ( = ) :

So simply write:

~~~ if (taskahandle == xTaskGetCurrentTaskHandle()) { iCount++; printf("exequtiontime_taska %drn", iCount); } else { iCount = 0; } } ~~~

Regards.


[ 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