Quality RTOS & Embedded Software

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




Loading

Setting deadline for tasks

Posted by https://www.google.com/accounts on September 11, 2013
Hi, this is my first post and if I miss to include any essential information, please inform me.

I have a project that we are using FreeRTOS in. I want to have a number of tasks periodically and for that I use vTaskDelayUntil. So far everything is quite nice and easy.

What I'm looking for is to stop a task (not end it, not preemptive it, so it starts all over next period) if it goes on too long. For example a extreme value that's not thought of, creating a inf-loop.

This is because we're working with sensors and controllers and the timing need to be rather good and consistent.

For example, Task1 in a period goes over its deadline. Task2 have lower priority and gets delayed, from then on Task2 will be delayed since vTaskDelayUntil reads the tick-count when entering a task.

Example 2, Task1 in a period goes over its deadline, not finishing putting sensor values in a message queue, Task2 have higher priority and preemptives it. Task2, Task3... TaskN finishes and Task1 continues, going over into the new period.

I know this is a bit academic due to the fact that the processor won't be used 100% but since the system in this project is going to be on a truck we want it to be robust for future task-scheduling, saftey etc.

Best regards

FYI, this is a student project, so if I said something stupid, I blame it on that.
For the curoius people, we're using a TI devel-board, RM48HDK, and will implement inverse kinematic, automatic control and more.

RE: Setting deadline for tasks

Posted by Richard on September 11, 2013
“For example, Task1 in a period goes over its deadline. Task2 have lower priority and gets delayed, from then on Task2 will be delayed since vTaskDelayUntil reads the tick-count when entering a task.”


I'm not sure I understand your point exactly, but if Task1 is using vTaskDelay() then the start of the next cycle will not be effected by the time the last cycle ended. There is no slippage of time. For example, if Task1 wants to execute every 100 ticks then, and (for simplicity) assume the start time is 0.

- The first execution will be at time 100. Lets assume it ends at time 150.

- The next execution will be at time 200. Lets assume it ends at time 290.

- The next execution will be at time 300. Lets assume it ends (for whatever reason) at time 410.

- The next execution will happen immediately as it should have started at time 400, but the time is already 410. Lets assume it ends at time 490.

- The next execution will be at time 500 - still on time, even though one of the cycles overran by 10.



“Example 2, Task1 in a period goes over its deadline, not finishing putting sensor values in a message queue, Task2 have higher priority and preemptives it. Task2, Task3... TaskN finishes and Task1 continues, going over into the new period.”


Ultimately, you only have a fixed amount of CPU power. A good event driven (not polling) design using an RTOS will allow you to extract more useful work from that fixed amount of power (because code only executes when there is actually something to do). Therefore, if it is not possible to meet your deadlines with an RTOS then you will not be able to without one (assuming the design makes good use of the RTOS, that is).

If the amount of CPU power is not the issue then you will have to employ some defensive programming. Set up another task that monitors the timing of other application tasks, or do this from the tick hook function. You can see crude examples of this with the 'check' tasks in the FreeRTOS demo applications. You can then catch a task breaking its deadlines, as well as tasks that are stuck somewhere. Tasks can also monitor their own timing, but that only allows them to detect broken deadlines, obviously if they are stuck somewhere then their own self checking will not work (because they are stuck).

The question then is, what do you do if you find a task has missed its deadline? Redesign your system? If you just restart the task then chances are it will just miss a deadline again in the future, so you have not really solved anything, just masked unwanted behaviour.

Regards.

RE: Setting deadline for tasks

Posted by Figge on September 11, 2013
Thank you for a great reply.

In the first part of your answer you write vTaskDelay, do you mean vTaskDelayUntil? If that's the case, you can disregard below.
Because using vTaskDelay will phaseshift the period if a task takes longer time due to the fact that it counts from when it was called, were vTaskDelayUntil counts from when entered the task? (if I understood it right)


I will look into how to catch a task (with tick hook and more) that is breaking its deadline, but how do I handle that task? To clearify, all that I've read only seems to point that tasks gets preemptive.

RE: Setting deadline for tasks

Posted by Richard on September 11, 2013
“In the first part of your answer you write vTaskDelay, do you mean vTaskDelayUntil?”


Oops, yes, I definitely meant vTaskDelayUntil()!

Regards.

RE: Setting deadline for tasks

Posted by Figge on September 11, 2013
Thank you for your help.

After talking with my group I think I had a too academic view.

Implementing RunTimeStats and evaluating CPU-usage might be a smarter way to go for an example, making sure the cpu is not overused.

Again, thanks for your replies
Best regards

Setting deadline for tasks

Posted by sivlniko on December 10, 2013

The question then is, what do you do if you find a task has missed its deadline? Redesign your system? If you just restart the task then chances are it will just miss a deadline again in the future, so you have not really solved anything, just masked unwanted behaviour.

Hello Richard, just read your post here, while I was asking myself the same question as Figgae before. There are several options what a system could do in order to recover from timing faults (missed deadlines). This question is typical for any soft-realtime scenario, and depends on the desired system behaviour. After missing its deadline, the current job could be simply stopped, skipped, a task could even perform some kind of graceful degradation, reduce its complexity and so on. The actual question for me is, is there any notion of a "deadline" in FreeRTOS and if not is it possible to implement it? From a tasks point of view there should be a kind of callback or an event propagated to the task when the system reaches the deadline point and the task has not yet completed its current job. This leads to another question: is there any opportunity for a task to voluntarily give up control until the beginning of next period? Consider for example RTSJ, periodic threads have periods, deadlines, costs and a special waitForNextPeriod() method which blocks the thread until the beginning of next period indicating to the system a successful job completion. When a deadline point in time is reached and the appropriate task has still not blocked in waitForNextPeriod() a deadline miss is indicated to the task by a special event. It would be very helpful if FreeRTOS would provide such mechanisms too. The question is, is there any chance to implement it?


Setting deadline for tasks

Posted by drausio on February 21, 2014

Hi, I´m also having the some similar questions on the topic. As told above:

"You can see crude examples of this with the 'check' tasks in the FreeRTOS demo applications. You can then catch a task breaking its deadlines, as well as tasks that are stuck somewhere. Tasks can also monitor their own timing, but that only allows them to detect broken deadlines, obviously if they are stuck somewhere then their own self checking will not work (because they are stuck)."

Can someone give me some demo applications examples were I can find this implementation? Is there any documentation about the inner work of the timers from FreeRTOS?

Thanks in advance Best 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