Relation between task priority and the scheduling interval

eswdev14 wrote on Wednesday, January 11, 2017:

Hi all,

I’am relatively a beginner with using FreeRTOS.
I have a general, but important question about FreeRTOS and its scheduling interval.
In what way is there a relation between the assigned task priority and its corresponding task schedule interval
used by the FreeRTOS scheduler? Is there something to say about for example taskX has a priority of 4 and the corresponding scheduling task interval is say 3ms?
Any help in guiding me I will appreciate!

Thanks,
Max

hs2sf wrote on Wednesday, January 11, 2017:

prio and time slice / quantum are different things. There is no direct relationship in the sense you describe. Which higher level problem do you want to solve ?
For example a periodic task can be setup by using a timer or just a timeout and choosing a prio matching your runtime system requirements.

richard_damon wrote on Thursday, January 12, 2017:

FreeRTOS has a fixed ftask scheduling interval of 1 Tick, i.e. every tick the current running task is put at the end of the ready queue for its execution priority and the next task with the same priority (which might be the task just running) is then run. Since the class of machine that FreeRTOS runs on do not normally use virtual memory, there is little need to have lower priority tasks have a larger execution quantum.

eswdev14 wrote on Thursday, January 12, 2017:

Thanks for the answer! But if I understand it correctly, can I use several hardware timers of the ARM microcontroller to have periodic tasks with FreeRTOS? If no, how can I configure/tailor FreeRTOS to have several periodic tasks which would be scheduled in say 2, 3 and 5ms in my microcontroller application? And how about configuring the SysTick timer used by the FreeRTOS scheduler? An example would be very helpful!

rtel wrote on Thursday, January 12, 2017:

Hi Max - have a look here:
http://www.freertos.org/Documentation/RTOS_book.html

hs2sf wrote on Thursday, January 12, 2017:

Well, the most simple (hence often the best) approach could be to configure the SysTick period less or equal to your minimum period because Systick is the minimum resolution of timers resp. timeouts and use a dedicated task per rate.
The periodic tasks are merely simple loops waiting for it’s timeout to expire, doing housekeeping and wait again… The tasks can be prioritized accordingly and you’re fine :wink:
Sure - there a number of alternative approaches, but probably with the price of increasing complexity e.g using hardware timers with ISRs usually signalling events to task context, etc. On the other hand using dedicated peridiodic tasks costs a bit more RAM needed for the task stacks…

simonjwright wrote on Thursday, January 12, 2017:

You only get round-robin scheduling if configUSE_TIME_SLICING is 1.

rtel wrote on Thursday, January 12, 2017:

Depends how you defined round robin scheduling. configUSE_TIME_SLCICING
prevents a context switch between tasks of equal priority just because
of a tick interrupt - but tasks of equal priority will still take turns
to execute.